From 8aa3602287f7b4ebf115b82182e18f7af3a38507 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 5 Sep 2018 13:37:45 +0300 Subject: ActivityStreams: refactor UriComponentsBuilder usage --- .../com/juick/server/api/activity/Profile.java | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java index 0974444f..c3f838ee 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java @@ -37,24 +37,19 @@ public class Profile { public Person getUser(@PathVariable String userName) { User user = userService.getUserByName(userName); if (!user.isAnonymous()) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); Person person = new Person(); - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUri); - builder.path(String.format("/u/%s", userName)); - person.setId(builder.toUriString()); + uri.replacePath(String.format("/u/%s", userName)); + person.setId(uri.toUriString()); person.setName(userName); - UriComponentsBuilder inboxBuilder = UriComponentsBuilder.fromUriString(baseUri); - inboxBuilder.path("/post"); - person.setInbox(inboxBuilder.toUriString()); - UriComponentsBuilder outboxBuilder = UriComponentsBuilder.fromUriString(baseUri); - person.setOutbox(outboxBuilder.path(String.format("/u/%s/blog/toc", userName)).toUriString()); - UriComponentsBuilder followersBuilder = UriComponentsBuilder.fromUriString(baseUri); - person.setFollowers(followersBuilder.path(String.format("/u/%s/followers/toc", userName)).toUriString()); - UriComponentsBuilder followingBuilder = UriComponentsBuilder.fromUriString(baseUri); - person.setFollowing(followingBuilder.path(String.format("/u/%s/following/toc", userName)).toUriString()); - UriComponentsBuilder imgBuilder = UriComponentsBuilder.fromUriString(baseImagesUri); - imgBuilder.path(String.format("/a/%d.png", user.getUid())); + uri.replacePath("/post"); + person.setInbox(uri.toUriString()); + person.setOutbox(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString()); + person.setFollowers(uri.replacePath(String.format("/u/%s/followers/toc", userName)).toUriString()); + person.setFollowing(uri.replacePath(String.format("/u/%s/following/toc", userName)).toUriString()); + uri.replacePath(String.format("/a/%d.png", user.getUid())); Image avatar = new Image(); - avatar.setUrl(imgBuilder.toUriString()); + avatar.setUrl(uri.toUriString()); avatar.setMediaType("image/png"); person.setIcon(avatar); return person; -- cgit v1.2.3