001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/shared/mgt/impl/FileArtifactFinder.java $
003: * $Id: FileArtifactFinder.java 19408 2006-12-11 23:52:11Z john.ellis@rsmart.com $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.mgt.impl;
021:
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import org.sakaiproject.content.api.ContentHostingService;
028: import org.sakaiproject.content.api.ContentResource;
029: import org.sakaiproject.entity.api.ResourceProperties;
030: import org.sakaiproject.exception.IdUnusedException;
031: import org.sakaiproject.exception.PermissionException;
032: import org.sakaiproject.exception.TypeException;
033: import org.sakaiproject.metaobj.shared.ArtifactFinder;
034: import org.sakaiproject.metaobj.shared.mgt.AgentManager;
035: import org.sakaiproject.metaobj.shared.mgt.IdManager;
036: import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
037: import org.sakaiproject.metaobj.shared.model.Agent;
038: import org.sakaiproject.metaobj.shared.model.Artifact;
039: import org.sakaiproject.metaobj.shared.model.ContentResourceArtifact;
040: import org.sakaiproject.metaobj.shared.model.Id;
041: import org.sakaiproject.metaobj.shared.model.MimeType;
042:
043: /**
044: * Created by IntelliJ IDEA.
045: * User: John Ellis
046: * Date: Aug 17, 2005
047: * Time: 2:08:27 PM
048: * To change this template use File | Settings | File Templates.
049: */
050: public class FileArtifactFinder implements ArtifactFinder {
051:
052: private ContentHostingService contentHostingService;
053: private AgentManager agentManager;
054: private IdManager idManager;
055: private ReadableObjectHome contentResourceHome = null;
056:
057: public Collection findByOwnerAndType(Id owner, String type) {
058: return findByOwnerAndType(owner, type, null);
059: }
060:
061: public Collection findByOwnerAndType(Id owner, String type,
062: MimeType mimeType) {
063: String primaryMimeType = null;
064: String subMimeType = null;
065:
066: if (mimeType != null) {
067: primaryMimeType = mimeType.getPrimaryType();
068: subMimeType = mimeType.getSubType();
069: }
070:
071: List artifacts = getContentHostingService().findResources(
072: ResourceProperties.FILE_TYPE, primaryMimeType,
073: subMimeType);
074:
075: Collection returned = new ArrayList();
076:
077: for (Iterator i = artifacts.iterator(); i.hasNext();) {
078: ContentResource resource = (ContentResource) i.next();
079: Artifact resourceArtifact = createArtifact(resource);
080: returned.add(resourceArtifact);
081: }
082:
083: return returned;
084: }
085:
086: protected Artifact createArtifact(ContentResource resource) {
087: Agent resourceOwner = getAgentManager().getAgent(
088: resource.getProperties().getProperty(
089: ResourceProperties.PROP_CREATOR));
090: Id resourceId = getIdManager().getId(
091: getContentHostingService().getUuid(resource.getId()));
092: ContentResourceArtifact resourceArtifact = new ContentResourceArtifact(
093: resource, resourceId, resourceOwner);
094: resourceArtifact.setHome(getContentResourceHome());
095: return resourceArtifact;
096: }
097:
098: public Collection findByOwner(Id owner) {
099: return null;
100: }
101:
102: public Collection findByWorksiteAndType(Id worksiteId, String type) {
103: return null;
104: }
105:
106: public Collection findByWorksite(Id worksiteId) {
107: return null;
108: }
109:
110: public Artifact load(Id artifactId) {
111: String resourceId = getContentHostingService().resolveUuid(
112: artifactId.getValue());
113:
114: if (resourceId == null) {
115: return null;
116: }
117:
118: try {
119: ContentResource resource = getContentHostingService()
120: .getResource(resourceId);
121: Artifact returned = createArtifact(resource);
122: return returned;
123: } catch (PermissionException e) {
124: throw new RuntimeException(e);
125: } catch (IdUnusedException e) {
126: throw new RuntimeException(e);
127: } catch (TypeException e) {
128: throw new RuntimeException(e);
129: }
130: }
131:
132: public Collection findByType(String type) {
133: return null;
134: }
135:
136: public boolean getLoadArtifacts() {
137: return false;
138: }
139:
140: public void setLoadArtifacts(boolean loadArtifacts) {
141: }
142:
143: public ContentHostingService getContentHostingService() {
144: return contentHostingService;
145: }
146:
147: public void setContentHostingService(
148: ContentHostingService contentHostingService) {
149: this .contentHostingService = contentHostingService;
150: }
151:
152: public AgentManager getAgentManager() {
153: return agentManager;
154: }
155:
156: public void setAgentManager(AgentManager agentManager) {
157: this .agentManager = agentManager;
158: }
159:
160: public IdManager getIdManager() {
161: return idManager;
162: }
163:
164: public void setIdManager(IdManager idManager) {
165: this .idManager = idManager;
166: }
167:
168: public ReadableObjectHome getContentResourceHome() {
169: return contentResourceHome;
170: }
171:
172: public void setContentResourceHome(
173: ReadableObjectHome contentResourceHome) {
174: this.contentResourceHome = contentResourceHome;
175: }
176:
177: }
|