Skip to content

Commit a48953d

Browse files
authored
1 parent 09de618 commit a48953d

File tree

21 files changed

+574
-95
lines changed

21 files changed

+574
-95
lines changed

commons/api/src/bundle/commons.properties

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ link_button_tooltip = Insert a link
5050
image_button_tooltip = Insert an image
5151
choose_image_file = Choose an image file. It must be a png, gif, or a jpeg, no bigger than {max}MB.
5252

53+
search_title_post=Commons Post
54+
search_title_comment=Commons Comment
55+
5356
# this defines the entity description for the commons provider
5457
commons = <br />Provides a set of RESTful endpoints for retrieving COMMONS posts. <br /><br />
5558

commons/api/src/java/org/sakaiproject/commons/api/CommonsConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
public interface CommonsConstants {
1919

20+
public enum PostType { POST, COMMENT };
21+
2022
public static final String ASSIGNMENT = "ASSIGNMENT";
23+
public static final String SEARCH = "SEARCH";
2124
public static final String SITE = "SITE";
2225
public static final String SOCIAL = "SOCIAL";
2326
}

commons/api/src/java/org/sakaiproject/commons/api/CommonsManager.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package org.sakaiproject.commons.api;
1717

18-
import java.util.*;
18+
import java.util.List;
19+
import java.util.Optional;
1920

2021
import org.sakaiproject.commons.api.datamodel.Comment;
2122
import org.sakaiproject.commons.api.datamodel.Post;
@@ -32,14 +33,16 @@ public interface CommonsManager extends EntityProducer {
3233

3334
public static final String POST_CACHE = "org.sakaiproject.commons.sortedPostCache";
3435

35-
public Post getPost(String postId, boolean loadComments);
36+
public Optional<Post> getPost(String postId, boolean loadComments);
3637

3738
public List<Post> getPosts(QueryBean query) throws Exception;
3839

3940
public Post savePost(Post post);
4041

4142
public boolean deletePost(String postId);
4243

44+
public Optional<Comment> getComment(String commentId);
45+
4346
public Comment saveComment(String commonsId, Comment comment);
4447

4548
public boolean deleteComment(String siteId, String commonsId, String embedder, String commentId, String commentCreatorId, String postCreatorId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) 2003-2017 The Apereo Foundation
3+
*
4+
* Licensed under the Educational Community License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://opensource.org/licenses/ecl2
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.sakaiproject.commons.api;
17+
18+
import org.sakaiproject.entity.api.Entity;
19+
20+
import org.apache.commons.lang3.StringUtils;
21+
22+
import lombok.Builder;
23+
24+
@Builder
25+
public class CommonsReferenceBuilder {
26+
27+
private String siteId;
28+
private String postId;
29+
private String commentId;
30+
31+
public String getReference() {
32+
33+
if (StringUtils.isNotBlank(siteId) || StringUtils.isNotBlank(postId) || StringUtils.isNotBlank(commentId)) {
34+
if (this.postId != null) {
35+
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + this.siteId + Entity.SEPARATOR + "posts" + Entity.SEPARATOR + this.postId;
36+
} else if (this.commentId != null) {
37+
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + this.siteId + Entity.SEPARATOR + "comments" + Entity.SEPARATOR + this.commentId;
38+
} else {
39+
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + this.siteId;
40+
}
41+
} else {
42+
return CommonsManager.REFERENCE_ROOT;
43+
}
44+
}
45+
46+
public CommonsReferenceBuilder reference(String reference) {
47+
48+
String[] parts = reference.split(Entity.SEPARATOR);
49+
50+
if (parts.length > 4) {
51+
siteId = parts[2];
52+
if ("post".equals(parts[3])) {
53+
postId = parts[4];
54+
} else if ("comments".equals(parts[3])) {
55+
commentId = parts[4];
56+
}
57+
}
58+
59+
return this;
60+
}
61+
62+
public String toString() {
63+
return getReference();
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright (c) 2003-2017 The Apereo Foundation
3+
*
4+
* Licensed under the Educational Community License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://opensource.org/licenses/ecl2
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.sakaiproject.commons.api;
17+
18+
import lombok.AccessLevel;
19+
import lombok.Builder;
20+
import lombok.Getter;
21+
import lombok.Value;
22+
import lombok.extern.slf4j.Slf4j;
23+
import org.apache.commons.lang3.StringUtils;
24+
import org.sakaiproject.commons.api.datamodel.Comment;
25+
import org.sakaiproject.commons.api.datamodel.Post;
26+
import org.sakaiproject.entity.api.Entity;
27+
28+
@Slf4j
29+
public class CommonsReferenceReckoner {
30+
31+
@Value
32+
public static class CommonsReference {
33+
34+
private CommonsConstants.PostType type;
35+
private String context;
36+
private String postId;
37+
private String commentId;
38+
@Getter(AccessLevel.NONE) private String reference;
39+
40+
@Override
41+
public String toString() {
42+
43+
if (type == CommonsConstants.PostType.POST) {
44+
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + context + Entity. SEPARATOR + "posts" + Entity.SEPARATOR + postId;
45+
} else {
46+
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + context + Entity. SEPARATOR + "posts" + Entity.SEPARATOR + postId + Entity.SEPARATOR + "comments" + Entity.SEPARATOR + commentId;
47+
}
48+
}
49+
50+
public String getReference() {
51+
return toString();
52+
}
53+
}
54+
55+
/**
56+
* This is a builder for an AssignmentReference
57+
*
58+
* @param context
59+
* @param id
60+
* @param reference
61+
* @return
62+
*/
63+
@Builder(builderMethodName = "reckoner", buildMethodName = "reckon")
64+
public static CommonsReference newCommonsReferenceReckoner(Post post, Comment comment, String context, String postId, String commentId, String reference) {
65+
66+
CommonsConstants.PostType type = null;
67+
68+
if (StringUtils.startsWith(reference, CommonsManager.REFERENCE_ROOT)) {
69+
String[] parts = StringUtils.splitPreserveAllTokens(reference, Entity.SEPARATOR);
70+
if (parts.length >= 5) {
71+
if (context == null) context = parts[2];
72+
if (postId == null) postId = parts[4];
73+
if (parts.length == 5) {
74+
type = CommonsConstants.PostType.POST;
75+
} else if (parts.length == 7) {
76+
type = CommonsConstants.PostType.COMMENT;
77+
if (commentId == null) commentId = parts[6];
78+
}
79+
}
80+
} else if (post != null) {
81+
context = post.getSiteId();
82+
type = CommonsConstants.PostType.POST;
83+
postId = post.getId();
84+
} else if (comment != null) {
85+
type = CommonsConstants.PostType.COMMENT;
86+
if (context == null) context = comment.getPost().getSiteId();
87+
postId = comment.getPost().getId();
88+
commentId = comment.getId();
89+
}
90+
91+
return new CommonsReference(
92+
type,
93+
(context == null) ? "" : context,
94+
(postId == null) ? "" : postId,
95+
(commentId == null) ? "" : commentId,
96+
(reference == null) ? "" : reference);
97+
}
98+
}

commons/api/src/java/org/sakaiproject/commons/api/PersistenceManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.sakaiproject.commons.api;
1717

1818
import java.util.List;
19+
import java.util.Optional;
1920

2021
import org.sakaiproject.commons.api.datamodel.Comment;
2122
import org.sakaiproject.commons.api.datamodel.Commons;
@@ -30,7 +31,7 @@ public interface PersistenceManager {
3031
public boolean postExists(String postId);
3132
public List<Post> getAllPost(QueryBean queryBean) throws Exception;
3233
public List<Post> getAllPost(QueryBean queryBean, boolean populate) throws Exception;
33-
public Comment getComment(String commentId);
34+
public Optional<Comment> getComment(String commentId);
3435
public Comment saveComment(Comment comment);
3536
public boolean deleteComment(String commentId);
3637
public Post savePost(Post post);

commons/api/src/java/org/sakaiproject/commons/api/QueryBean.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23+
import lombok.Getter;
24+
import lombok.Builder;
25+
2326
/**
2427
* @author Adrian Fish ([email protected])
2528
*/
29+
@Getter
30+
@Builder
2631
public class QueryBean {
2732

28-
public String commonsId = "";
29-
public String siteId = "";
30-
public String embedder = "";
31-
public boolean isUserSite = false;
32-
public List<String> fromIds = new ArrayList();
33-
public String callerId = "";
33+
@Builder.Default private String commonsId = "";
34+
@Builder.Default private String siteId = "";
35+
@Builder.Default private String embedder = "";
36+
@Builder.Default private boolean userSite = false;
37+
@Builder.Default private List<String> fromIds = new ArrayList<>();
38+
@Builder.Default private String callerId = "";
3439
}

commons/api/src/java/org/sakaiproject/commons/api/datamodel/Comment.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.commons.text.StringEscapeUtils;
2929
import org.sakaiproject.commons.api.CommonsManager;
30+
import org.sakaiproject.commons.api.CommonsReferenceReckoner;
3031
import org.sakaiproject.entity.api.Entity;
3132
import org.sakaiproject.entity.api.ResourceProperties;
3233
import org.sakaiproject.util.BaseResourceProperties;
@@ -59,6 +60,9 @@ public class Comment implements Entity {
5960
@Getter @Setter
6061
private String postId;
6162

63+
@Getter @Setter
64+
private Post post;
65+
6266
@Getter @Setter
6367
private String url;
6468

@@ -120,10 +124,10 @@ public ResourceProperties getProperties() {
120124
}
121125

122126
public String getReference() {
123-
return CommonsManager.REFERENCE_ROOT + Entity.SEPARATOR + "comments" + Entity.SEPARATOR + id;
127+
return CommonsReferenceReckoner.reckoner().comment(this).reckon().getReference();
124128
}
125129

126-
public String getReference(String arg0) {
130+
public String getReference(String base) {
127131
return getReference();
128132
}
129133

@@ -132,7 +136,6 @@ public String getUrl(String arg0) {
132136
}
133137

134138
public Element toXml(Document arg0, Stack arg1) {
135-
// TODO Auto-generated method stub
136139
return null;
137140
}
138141
}

commons/impl/pom.xml

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
<groupId>org.sakaiproject.commons</groupId>
1414
<version>21-SNAPSHOT</version>
1515
</parent>
16+
1617
<properties>
1718
<deploy.target>components</deploy.target>
18-
</properties>
19+
</properties>
20+
1921
<dependencies>
2022
<dependency>
2123
<groupId>org.sakaiproject.commons</groupId>
@@ -53,6 +55,22 @@
5355
<groupId>org.sakaiproject.delegatedaccess</groupId>
5456
<artifactId>delegatedaccess-api</artifactId>
5557
</dependency>
58+
<dependency>
59+
<groupId>org.sakaiproject.search</groupId>
60+
<artifactId>search-api</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.springframework</groupId>
64+
<artifactId>spring-context</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>javax.inject</groupId>
68+
<artifactId>javax.inject</artifactId>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.springframework</groupId>
72+
<artifactId>spring-tx</artifactId>
73+
</dependency>
5674
<dependency>
5775
<groupId>org.slf4j</groupId>
5876
<artifactId>slf4j-api</artifactId>

0 commit comments

Comments
 (0)