From 5c491c20f8201b1a90335899aa0f2eb72ed0daff Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 4 Sep 2018 12:25:14 +0300 Subject: ActivityStreams initial support --- .../java/com/juick/server/api/activity/Info.java | 44 ++++++++++++++++++++ .../server/api/activity/model/ActivityObject.java | 18 +++++++++ .../juick/server/api/activity/model/Person.java | 47 ++++++++++++++++++++++ .../com/juick/server/api/webfinger/Resource.java | 1 - 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 juick-server/src/main/java/com/juick/server/api/activity/Info.java create mode 100644 juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java create mode 100644 juick-server/src/main/java/com/juick/server/api/activity/model/Person.java (limited to 'juick-server/src/main') diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Info.java b/juick-server/src/main/java/com/juick/server/api/activity/Info.java new file mode 100644 index 00000000..4cff15c1 --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/api/activity/Info.java @@ -0,0 +1,44 @@ +package com.juick.server.api.activity; + +import com.juick.User; +import com.juick.server.api.activity.model.ActivityObject; +import com.juick.server.api.activity.model.Person; +import com.juick.server.util.HttpNotFoundException; +import com.juick.service.UserService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.inject.Inject; + +@RestController +public class Info { + @Inject + private UserService userService; + @Value("${web_domain:localhost}") + private String domain; + @Value("${ap_base_uri:http://localhost:8080/}") + private String baseUri; + @Value("${img_url:http://localhost:8080/i/}") + private String baseImagesUri; + + @GetMapping(value = "/u/{userName}", produces = ActivityObject.CONTENT_TYPE) + public Person getUser(@PathVariable String userName) { + User user = userService.getUserByName(userName); + if (!user.isAnonymous()) { + Person person = new Person(); + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUri); + builder.path(String.format("/u/%s", userName)); + person.setId(builder.toUriString()); + person.setName(userName); + person.setOutbox(builder.path(String.format("/u/%s/blog", userName)).toUriString()); + UriComponentsBuilder imgBuilder = UriComponentsBuilder.fromUriString(baseImagesUri); + imgBuilder.path(String.format("/a/%d.png", user.getUid())); + person.setIcon(imgBuilder.toUriString()); + return person; + } + throw new HttpNotFoundException(); + } +} diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java new file mode 100644 index 00000000..bc682d2b --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java @@ -0,0 +1,18 @@ +package com.juick.server.api.activity.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public abstract class ActivityObject { + + public abstract String getId(); + + public abstract String getType(); + + @JsonProperty("@context") + public String getContext() { + return CONTEXT_URI; + } + + public final static String CONTEXT_URI = "https://www.w3.org/ns/activitystreams"; + public final static String CONTENT_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""; +} diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java new file mode 100644 index 00000000..031cd73b --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java @@ -0,0 +1,47 @@ +package com.juick.server.api.activity.model; + +public class Person extends ActivityObject { + + private String id; + private String name; + private String icon; + private String outbox; + + @Override + public String getId() { + return id; + } + + @Override + public String getType() { + return "Person"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getOutbox() { + return outbox; + } + + public void setOutbox(String outbox) { + this.outbox = outbox; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java b/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java index e43e02d1..d3829de4 100644 --- a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java +++ b/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java @@ -14,7 +14,6 @@ import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.util.Arrays; -import java.util.Collections; @RestController public class Resource { -- cgit v1.2.3