Skip to content

Commit f3cefec

Browse files
authored
Revert "LSNBLDR-542: New Lessons component: Add Resources Folder (sakaiproject#3622)" (sakaiproject#4084)
This reverts commit 4c8573c.
1 parent 4c8573c commit f3cefec

File tree

25 files changed

+13
-1489
lines changed

25 files changed

+13
-1489
lines changed

content/content-tool/tool/src/java/org/sakaiproject/content/entityproviders/ContentEntityProvider.java

+3-194
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.sakaiproject.content.entityproviders;
22

3-
import java.text.DateFormat;
4-
import java.text.ParseException;
5-
import java.text.SimpleDateFormat;
6-
import java.util.*;
73
import java.net.URI;
84
import java.util.ArrayList;
95
import java.util.Comparator;
@@ -17,8 +13,6 @@
1713
import lombok.Setter;
1814
import lombok.extern.slf4j.Slf4j;
1915
import org.apache.commons.lang.StringUtils;
20-
import org.apache.commons.logging.Log;
21-
import org.apache.commons.logging.LogFactory;
2216
import org.sakaiproject.authz.api.SecurityService;
2317
import org.sakaiproject.component.cover.ComponentManager;
2418
import org.sakaiproject.content.api.ContentCollection;
@@ -27,31 +21,27 @@
2721
import org.sakaiproject.content.api.ContentResource;
2822
import org.sakaiproject.content.api.ResourceTypeRegistry;
2923
import org.sakaiproject.content.tool.ListItem;
30-
import org.sakaiproject.entity.api.EntityManager;
31-
import org.sakaiproject.entity.api.EntityPermissionException;
32-
import org.sakaiproject.entity.api.Reference;
3324
import org.sakaiproject.entity.api.ResourceProperties;
3425
import org.sakaiproject.entitybroker.EntityView;
3526
import org.sakaiproject.entitybroker.entityprovider.EntityProvider;
3627
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityCustomAction;
28+
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityId;
29+
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityOwner;
30+
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityTitle;
3731
import org.sakaiproject.entitybroker.entityprovider.capabilities.ActionsExecutable;
3832
import org.sakaiproject.entitybroker.entityprovider.capabilities.AutoRegisterEntityProvider;
3933
import org.sakaiproject.entitybroker.entityprovider.capabilities.Describeable;
4034
import org.sakaiproject.entitybroker.entityprovider.capabilities.Outputable;
4135
import org.sakaiproject.entitybroker.entityprovider.extension.Formats;
4236
import org.sakaiproject.entitybroker.exception.EntityNotFoundException;
4337
import org.sakaiproject.entitybroker.util.AbstractEntityProvider;
44-
import org.sakaiproject.entitybroker.util.EntityDataUtils;
45-
import org.sakaiproject.entitybroker.util.model.EntityContent;
4638
import org.sakaiproject.exception.IdUnusedException;
4739
import org.sakaiproject.exception.PermissionException;
4840
import org.sakaiproject.exception.ServerOverloadException;
4941
import org.sakaiproject.exception.TypeException;
5042
import org.sakaiproject.site.api.Site;
5143
import org.sakaiproject.site.api.SiteService;
5244
import org.sakaiproject.site.api.ToolConfiguration;
53-
import org.sakaiproject.time.api.Time;
54-
import org.sakaiproject.time.cover.TimeService;
5545
import org.sakaiproject.tool.api.ToolManager;
5646
import org.sakaiproject.tool.api.Session;
5747
import org.sakaiproject.tool.cover.SessionManager;
@@ -69,9 +59,6 @@ public class ContentEntityProvider extends AbstractEntityProvider implements Ent
6959
public static final String PREFIX = "resources.";
7060
public static final String SYS = "sys.";
7161
private static final String STATE_RESOURCES_TYPE_REGISTRY = PREFIX + SYS + "type_registry";
72-
private static Log log = LogFactory.getLog(ContentEntityProvider.class);
73-
private static final String PARAMETER_DEPTH = "depth";
74-
private static final String PARAMETER_TIMESTAMP = "timestamp";
7562

7663
@Override
7764
public String getEntityPrefix() {
@@ -165,183 +152,7 @@ public List<ContentItem> getContentCollectionForSite(EntityView view) {
165152
return getSiteListItems(siteId);
166153

167154
}
168-
@EntityCustomAction(action="resources", viewKey=EntityView.VIEW_LIST)
169-
public List<EntityContent> getResources(EntityView view, Map<String, Object> params)
170-
throws EntityPermissionException {
171-
String userId = developerHelperService.getCurrentUserId();
172-
if (userId == null) {
173-
throw new SecurityException(
174-
"This action is not accessible to anon and there is no current user.");
175-
}
176-
177-
Map<String, Object> parameters = getQueryMap((String)params.get("queryString"));
178-
Time timeStamp = getTime((String)parameters.get(PARAMETER_TIMESTAMP));
179-
180-
int requestedDepth = 1;
181-
int currentDepth = 0;
182-
if (parameters.containsKey(PARAMETER_DEPTH)) {
183-
if ("all".equals((String)parameters.get(PARAMETER_DEPTH))) {
184-
requestedDepth = Integer.MAX_VALUE;
185-
} else {
186-
requestedDepth = Integer.parseInt((String)parameters.get(PARAMETER_DEPTH));
187-
}
188-
}
189-
190-
String[] segments = view.getPathSegments();
191-
192-
StringBuffer resourceId = new StringBuffer();
193-
for (int i=2; i<segments.length; i++) {
194-
resourceId.append("/"+segments[i]);
195-
}
196-
resourceId.append("/");
197-
198-
Reference reference = entityManager.newReference(
199-
ContentHostingService.REFERENCE_ROOT+resourceId.toString());
200-
201-
// We could have used contentHostingService.getAllEntities(id) bit it doesn't do
202-
// permission checks on any contained resources (documentation wrong).
203-
// contentHostingService.getAllResources(String id) does do permission checks
204-
// but it doesn't include collections in it's returned list.
205-
// Also doing the recursion ourselves means that we don't loads lots of entities
206-
// when the depth of recursion is low.
207-
ContentCollection collection= null;
208-
try {
209-
collection = contentHostingService.getCollection(reference.getId());
210-
211-
} catch (IdUnusedException e) {
212-
throw new IllegalArgumentException("IdUnusedException in Resource Entity Provider");
213-
214-
} catch (TypeException e) {
215-
throw new IllegalArgumentException("TypeException in Resource Entity Provider");
216-
217-
} catch (PermissionException e) {
218-
throw new SecurityException("PermissionException in Resource Entity Provider");
219-
}
220-
221-
List<EntityContent> resourceDetails = new ArrayList<EntityContent>();
222-
if (collection!=null) {
223-
EntityContent resourceDetail = getResourceDetails(collection, currentDepth, requestedDepth, timeStamp);
224-
if (resourceDetail != null) {
225-
resourceDetails.add(resourceDetail);
226-
} else {
227-
log.error("Initial permission check passed but subsequent permission check failed on "+ reference.getId());
228-
}
229-
}
230-
return resourceDetails;
231-
}
232-
233-
/**
234-
*
235-
* @param entity The entity to load details of.
236-
* @param currentDepth How many collections we have already processed
237-
* @param requestedDepth The maximum number depth of the tree to scan.
238-
* @param timeStamp All returned details must be newer than this timestamp.
239-
* @return EntityContent containing details of all resources the user can access.
240-
* <code>null</code> is returned if the current user isn't allowed to access the resource.
241-
*/
242-
private EntityContent getResourceDetails(
243-
ContentEntity entity, int currentDepth, int requestedDepth, Time timeStamp) {
244-
boolean allowed = (entity.isCollection()) ?
245-
contentHostingService.allowGetCollection(entity.getId()) :
246-
contentHostingService.allowGetResource(entity.getId());
247-
if (!allowed) {
248-
// If the user isn't allowed to see this we return null.
249-
return null;
250-
}
251-
EntityContent tempRd = EntityDataUtils.getResourceDetails(entity);
252-
253-
// If it's a collection recurse down into it.
254-
if ((requestedDepth > currentDepth) && entity.isCollection()) {
255-
256-
ContentCollection collection = (ContentCollection)entity;
257-
// This is all members, no permission check has been done yet.
258-
List<ContentEntity> contents = collection.getMemberResources();
259-
260-
Comparator comparator = getComparator(entity);
261-
if (null != comparator) {
262-
Collections.sort(contents, comparator);
263-
}
264-
265-
for (Iterator<ContentEntity> i = contents.iterator(); i.hasNext();) {
266-
ContentEntity content = i.next();
267-
EntityContent resource = getResourceDetails(content, currentDepth+1, requestedDepth, timeStamp);
268-
269-
if (resource != null && resource.after(timeStamp)) {
270-
tempRd.addResourceChild(resource);
271-
}
272-
}
273-
}
274-
275-
return tempRd;
276-
}
277-
278-
/**
279-
*
280-
* @param entity
281-
* @return
282-
*/
283-
private Comparator getComparator(ContentEntity entity) {
284-
285-
boolean hasCustomSort = false;
286-
try {
287-
hasCustomSort = entity.getProperties().getBooleanProperty(
288-
ResourceProperties.PROP_HAS_CUSTOM_SORT);
289-
290-
} catch(Exception e) {
291-
// ignore -- let value of hasCustomSort stay false
292-
}
293-
294-
if(hasCustomSort) {
295-
return contentHostingService.newContentHostingComparator(
296-
ResourceProperties.PROP_CONTENT_PRIORITY, true);
297-
} else {
298-
return contentHostingService.newContentHostingComparator(
299-
ResourceProperties.PROP_DISPLAY_NAME, true);
300-
}
301-
}
302-
303-
/**
304-
*
305-
* @param queryString
306-
* @return
307-
*/
308-
private Map<String, Object> getQueryMap(String queryString) {
309-
310-
Map<String, Object> params = new HashMap<String, Object>();
311-
if (null != queryString && !queryString.isEmpty()) {
312-
String[] strings = queryString.split("&");
313-
for (int i=0; i<strings.length; i++) {
314-
String parameter = strings[i];
315-
int j = parameter.indexOf("=");
316-
params.put(parameter.substring(0, j), parameter.substring(j+1));
317-
}
318-
}
319-
return params;
320-
}
321-
322-
/**
323-
*
324-
* @param timestamp use formatter A: yyyyMMddHHmmssSSS
325-
* @return
326-
*/
327-
private Time getTime(String timestamp) {
328155

329-
try {
330-
331-
if (null != timestamp) {
332-
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
333-
Date date = format.parse(timestamp);
334-
Calendar c = Calendar.getInstance();
335-
c.setTime(date);
336-
337-
return TimeService.newTimeGmt(format.format(date));
338-
}
339-
340-
} catch (ParseException e) {
341-
return TimeService.newTimeGmt("20201231235959999");
342-
}
343-
return null;
344-
}
345156
private List<ContentItem> getSiteListItems(String siteId) {
346157
List<ContentItem> rv = new ArrayList<ContentItem>();
347158
String wsCollectionId = contentHostingService.getSiteCollection(siteId);
@@ -714,8 +525,6 @@ public String[] getHandledOutputFormats() {
714525
@Setter
715526
private UserDirectoryService userDirectoryService;
716527

717-
@Setter
718-
private EntityManager entityManager;
719528

720529

721530

content/content-tool/tool/src/webapp/WEB-INF/applicationContext.xml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager"/>
2323
<property name="securityService" ref="org.sakaiproject.authz.api.SecurityService"/>
2424
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService"/>
25-
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
2625
</bean>
2726

2827
</beans>

entitybroker/rest/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
<groupId>org.sakaiproject.entitybroker</groupId>
2727
<artifactId>entitybroker-utils</artifactId>
2828
</dependency>
29-
<dependency>
30-
<groupId>org.sakaiproject.kernel</groupId>
31-
<artifactId>sakai-kernel-api</artifactId>
32-
</dependency>
3329
<!-- internal testing -->
3430
<dependency>
3531
<groupId>org.sakaiproject.entitybroker</groupId>

entitybroker/utils/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
<groupId>org.sakaiproject.kernel</groupId>
4747
<artifactId>sakai-component-manager</artifactId>
4848
</dependency>
49-
<dependency>
50-
<groupId>org.sakaiproject.kernel</groupId>
51-
<artifactId>sakai-kernel-api</artifactId>
52-
</dependency>
5349
<!-- required for bean cloning and reflection -->
5450
<dependency>
5551
<groupId>org.azeckoski</groupId>

0 commit comments

Comments
 (0)