import org.collectionspace.services.common.ServiceMessages;
import org.collectionspace.services.common.blob.BlobInput;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.blob.BlobsCommon;
import org.collectionspace.services.blob.BlobsCommonList;
//FIXME: REM - We should not have Nuxeo dependencies in our resource classes.
import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
+import org.collectionspace.services.jaxb.AbstractCommonList;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
import javax.servlet.http.HttpServletRequest;
return BlobsCommon.class;
}
- public BlobsCommonList getBlobList(MultivaluedMap<String, String> queryParams) {
+ //FIXME: Is this method used/needed?
+ @Deprecated
+ private BlobsCommonList getBlobList(MultivaluedMap<String, String> queryParams) {
return (BlobsCommonList)getList(queryParams);
}
return (BlobsCommonList) getList(csidList);
}
+ @Deprecated
protected BlobsCommonList search(MultivaluedMap<String,String> queryParams,String keywords) {
return (BlobsCommonList) super.search(queryParams, keywords);
}
+ private BlobsCommonList getDerivativeList(String csid) throws Exception {
+ BlobsCommonList result = null;
+
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+ ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, Boolean.TRUE);
+ MultipartOutput response = this.get(csid, ctx);
+ if (logger.isDebugEnabled() == true) {
+ logger.debug(response.toString());
+ }
+ result = (BlobsCommonList)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY);
+
+ return result;
+ }
+
private InputStream getBlobContent(String csid, String derivativeTerm) throws WebApplicationException {
InputStream result = null;
try {
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
- ctx.setProperty(BlobInput.DERIVATIVE_TERM_KEY, derivativeTerm);
+ ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivativeTerm);
+ ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, Boolean.TRUE);
MultipartOutput response = this.get(csid, ctx);
if (logger.isDebugEnabled() == true) {
logger.debug(response.toString());
}
- result = (InputStream)ctx.getProperty(BlobInput.DERIVATIVE_CONTENT_KEY);
+ result = (InputStream)ctx.getProperty(BlobInput.BLOB_CONTENT_KEY);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
}
@GET
@Path("{csid}/content")
@Produces({"image/jpeg", "image/png", "image/tiff"})
- public InputStream getPicture(
+ public InputStream getBlobContent(
@PathParam("csid") String csid) {
InputStream result = null;
- result = getBlobContent(csid, BlobInput.DERIVATIVE_ORIGINAL_VALUE);
+ result = getBlobContent(csid, null /*derivative term*/);
return result;
}
@PathParam("csid") String csid,
@PathParam("derivative_term") String derivative_term) {
InputStream result = null;
- result = getBlobContent(csid, derivative_term);
+ result = getBlobContent(csid, derivative_term);
+
+ return result;
+ }
+
+ @GET
+ @Path("{csid}/derivatives/{derivative_term}")
+ public MultipartOutput getDerivative(@PathParam("csid") String csid,
+ @PathParam("derivative_term") String derivative_term) {
+ MultipartOutput result = null;
+
+ ensureCSID(csid, READ);
+ try {
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+ ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivative_term);
+ result = get(csid, ctx);
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+ }
+
+ return result;
+ }
+
+ @GET
+ @Path("{csid}/derivatives")
+ @Produces("application/xml")
+ public BlobsCommonList getDerivatives(
+ @PathParam("csid") String csid) {
+ BlobsCommonList result = null;
+
+ ensureCSID(csid, READ);
+ try {
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+ ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, true);
+ result = this.getDerivativeList(csid);
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+ }
+
return result;
}
import org.collectionspace.services.jaxb.BlobJAXBSchema;
import org.collectionspace.services.common.blob.BlobInput;
+import org.collectionspace.services.common.blob.BlobOutput;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.document.DocumentHandler.Action;
List list = ((BlobsCommonList)commonList).getBlobListItem();
return list;
}
+
+ private String getDerivativePathBase(DocumentModel docModel) {
+ return getServiceContextPath() + docModel.getName() + "/" +
+ BlobInput.URI_DERIVATIVES_PATH + "/";
+ }
public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
BlobListItem item = new BlobListItem();
docModel.getProperty(label, BlobJAXBSchema.name));
result.setRepositoryId((String)
docModel.getProperty(label, BlobJAXBSchema.repositoryId));
- result.setUri(getServiceContextPath() + docModel.getName() + "/content");
+ result.setUri(getServiceContextPath() + docModel.getName() + "/" +
+ BlobInput.URI_CONTENT_PATH);
return result;
}
public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
throws Exception {
ServiceContext ctx = this.getServiceContext();
+ RepositoryInstance repoSession = this.getRepositorySession();
DocumentModel docModel = wrapDoc.getWrappedObject();
- //
- // Setup of the content URL's
- //
- BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);
- String derivativeTerm = (String)ctx.getProperty(BlobInput.DERIVATIVE_TERM_KEY);
- if (derivativeTerm != null && !derivativeTerm.equalsIgnoreCase(BlobInput.DERIVATIVE_ORIGINAL_VALUE)) {
- blobsCommon.setUri(getServiceContextPath() + docModel.getName() + "/derivatives/" +
- derivativeTerm + "/content");
- }
- blobsCommon.setRepositoryId(null); //hide the repository id from the GET results since it is private
- this.setCommonPartProperties(docModel, blobsCommon);
+ BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);
+ String blobRepositoryId = blobsCommon.getRepositoryId(); //cache the value to pass to the blob retriever
- super.extractAllParts(wrapDoc);
- //
- // If the derivativeTerm is set then we need to get the blob stream
- //
+ if (ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY) != null) {
+ BlobsCommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives(
+ repoSession, blobRepositoryId, getDerivativePathBase(docModel));
+ ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList);
+ return; //FIXME: Don't like this exit point. Perhaps derivatives should be a sub-resource?
+ }
+
+ String derivativeTerm = (String)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY);
+ Boolean getContentFlag = ctx.getProperty(BlobInput.BLOB_CONTENT_KEY) != null ? true : false;
+ BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession,
+ blobRepositoryId, derivativeTerm, getContentFlag);
+ if (getContentFlag == true) {
+ ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, blobOutput.getBlobInputStream());
+ }
+
if (derivativeTerm != null) {
- RepositoryInstance repoSession = this.getRepositorySession();
- InputStream blobStream = NuxeoImageUtils.getPicture(ctx, repoSession, blobsCommon.getRepositoryId(), derivativeTerm);
- ctx.setProperty(BlobInput.DERIVATIVE_CONTENT_KEY, blobStream);
+ // reset 'blobsCommon' if we have a derivative request
+ blobsCommon = blobOutput.getBlobsCommon();
+ blobsCommon.setUri(getDerivativePathBase(docModel) +
+ derivativeTerm + "/" + BlobInput.URI_CONTENT_PATH);
}
+
+ blobsCommon.setRepositoryId(null); //hide the repository id from the GET results payload since it is private
+ this.setCommonPartProperties(docModel, blobsCommon);
+ // finish extracting the other parts by calling the parent
+ super.extractAllParts(wrapDoc);
}
@Override
return result;
}
-
- @GET
- @Path("{csid}/getpicture/{blobId}")
- @Produces({"image/jpeg", "image/png", "image/tiff"})
- public InputStream getPicture(
- @PathParam("csid") String csid,
- @PathParam("blobId") String blobId) {
- InputStream result = null;
- RepositoryInstance repoSession = null;
- try {
- repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
- result = NuxeoImageUtils.getPicture(ctx, repoSession, blobId, null);
- } catch (Exception e) {
- logger.error("Could not get image blob: " + blobId, e);
- } finally {
- try {
- ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
- } catch (Exception e) {
- logger.error("Could not release Nuxeo repository session", e);
- }
- }
-
- if (result == null) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
- throw new WebApplicationException(response);
- }
-
- return result;
- }
-
- @GET
- @Path("{csid}/getpicture/{blobId}/{derivativeTerm}")
- @Produces({"image/jpeg", "image/png", "image/tiff"})
- public InputStream getPicture(
- @PathParam("csid") String csid,
- @PathParam("blobId") String blobId,
- @PathParam("derivativeTerm") String derivativeTerm) {
- InputStream result = null;
- RepositoryInstance repoSession = null;
- try {
- repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
- result = NuxeoImageUtils.getPicture(ctx, repoSession, blobId, derivativeTerm);
- } catch (Exception e) {
- logger.error("Could not get image blob: " + blobId, e);
- } finally {
- try {
- ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
- } catch (Exception e) {
- logger.error("Could not release Nuxeo repository session", e);
- }
- }
-
- if (result == null) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
- throw new WebApplicationException(response);
- }
-
- return result;
- }
-
- @POST
- @Path("{csid}/postpicture")
- @Consumes("multipart/form-data")
- @Produces("application/xml")
- public String createPictureDocument(@Context HttpServletRequest req,
- @PathParam("csid") String csid,
- @QueryParam("blobUri") String blobUri) {
- String result = null;
-
- RepositoryInstance repoSession = null;
- try {
- repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
- File tmpFile = FileUtils.createTmpFile(req);
- BlobInput blobInput = new BlobInput(tmpFile, blobUri);
- BlobsCommon blobCommon = NuxeoImageUtils.createPicture(ctx, repoSession, blobInput);
- if (blobCommon != null) {
- result = blobCommon.getRepositoryId();
- }
- } catch (Exception e) {
- logger.error("Could not create the new image file", e);
- } finally {
- try {
- ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
- } catch (Exception e) {
- logger.error("Could not release Nuxeo repository session", e);
- }
- }
-
- if (result == null) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
- throw new WebApplicationException(response);
- }
-
- return result;
- }
/**
* This method is deprecated. Use kwSearchCollectionObjects() method instead.
\r
//======================= GET without csid. List, search, etc. =====================================\r
\r
- @GET\r
- @Produces("application/xml")\r
- public AbstractCommonList getList (@Context UriInfo ui,\r
- @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {\r
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();\r
- if (keywords != null) {\r
- return search(queryParams, keywords);\r
- } else {\r
- return getList(queryParams);\r
- }\r
- }\r
+ @GET\r
+ @Produces("application/xml")\r
+ public AbstractCommonList getList(@Context UriInfo ui,\r
+ @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {\r
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();\r
+ if (keywords != null) {\r
+ return search(queryParams, keywords);\r
+ } else {\r
+ return getList(queryParams);\r
+ }\r
+ }\r
\r
protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {\r
try {\r
}\r
}\r
\r
-\r
protected AbstractCommonList search(MultivaluedMap<String, String> queryParams, String keywords) {\r
try {\r
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);\r
}\r
}\r
\r
+ //FIXME: REM - This should not be @Deprecated since we may want to implement this -it has been on the wish list.\r
@Deprecated\r
public AbstractCommonList getList(List<String> csidList) {\r
try {\r
private File blobFile;\r
private String blobUri;\r
\r
- public static final String DERIVATIVE_TERM_KEY = "Derivative";\r
- public static final String DERIVATIVE_ORIGINAL_VALUE = "Original";\r
- public static final String DERIVATIVE_CONTENT_KEY = "Derivative_Content_Stream";\r
+ public static final String URI_CONTENT_PATH = "content";\r
+ public static final String URI_DERIVATIVES_PATH = "derivatives";\r
+ \r
+ public static final String BLOB_DERIVATIVE_TERM_KEY = "derivative";\r
+ public static final String BLOB_DERIVATIVE_LIST_KEY = "derivative.list";\r
+ public static final String BLOB_CONTENT_KEY = "derivative.content.stream";\r
\r
public BlobInput(File blobFile, String blobUri) {\r
this.blobFile = blobFile;\r
import org.collectionspace.services.common.document.DocumentUtils;\r
import org.collectionspace.services.common.FileUtils;\r
import org.collectionspace.services.blob.BlobsCommon;\r
+import org.collectionspace.services.blob.BlobsCommonList;\r
+import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;\r
+import org.collectionspace.services.common.blob.BlobOutput;\r
\r
// TODO: Auto-generated Javadoc\r
/**\r
public class NuxeoImageUtils {\r
/** The Constant logger. */\r
private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class);\r
+ \r
+ /*\r
+ * FIXME: REM - These constants should be coming from configuration and NOT hard coded.\r
+ */\r
+ public static final String DERIVATIVE_ORIGINAL = "Original";\r
+ public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + "_";\r
+ \r
+ public static final String DERIVATIVE_ORIGINAL_JPEG = "OriginalJpeg";\r
+ public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + "_";\r
+ \r
+ public static final String DERIVATIVE_MEDIUM = "Medium";\r
+ public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_";\r
+ \r
+ public static final String DERIVATIVE_THUMBNAIL = "Thumbnail";\r
+ public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + "_";\r
+ \r
+ public static final String DERIVATIVE_UNKNOWN = "_UNKNOWN_DERIVATIVE_NAME_";\r
\r
// static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class)\r
\r
//empty method\r
} \r
\r
- static private BlobsCommon createBlobCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
+ //FIXME: This needs to be configuration-bases and NOT hard coded!\r
+ static private String getDerivativeUri(String uri, String derivativeName) {\r
+ String result = DERIVATIVE_UNKNOWN;\r
+ \r
+ if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_TAG) == true) {\r
+ result = DERIVATIVE_ORIGINAL;\r
+ } else if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_JPEG_TAG) == true) {\r
+ result = DERIVATIVE_ORIGINAL_JPEG;\r
+ } else if (derivativeName.startsWith(DERIVATIVE_MEDIUM_TAG) == true) {\r
+ result = DERIVATIVE_MEDIUM;\r
+ } else if (derivativeName.startsWith(DERIVATIVE_THUMBNAIL_TAG) == true) {\r
+ result = DERIVATIVE_THUMBNAIL;\r
+ }\r
+ \r
+ return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
+ }\r
+ \r
+ static private BlobListItem createBlobListItem(Blob blob, String uri) {\r
+ BlobListItem result = new BlobListItem();\r
+\r
+ result.setEncoding(blob.getEncoding());\r
+ result.setLength(Long.toString(blob.getLength()));\r
+ result.setMimeType(blob.getMimeType());\r
+ result.setName(blob.getFilename());\r
+ result.setUri(getDerivativeUri(uri, blob.getFilename()));\r
+ \r
+ return result;\r
+ }\r
+ \r
+ static public BlobsCommonList getBlobDerivatives(RepositoryInstance repoSession,\r
+ String repositoryId,\r
+ String uri) throws Exception {\r
+ BlobsCommonList result = new BlobsCommonList();\r
+ \r
+ IdRef documentRef = new IdRef(repositoryId);\r
+ DocumentModel documentModel = repoSession.getDocument(documentRef); \r
+ DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
+ List<Blob> docBlobs = docBlobHolder.getBlobs(); \r
+ List<BlobListItem> blobListItems = result.getBlobListItem();\r
+ BlobListItem blobListItem = null;\r
+ for (Blob blob : docBlobs) {\r
+ blobListItem = createBlobListItem(blob, uri);\r
+ blobListItems.add(blobListItem);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
BlobsCommon result = new BlobsCommon();\r
if (documentModel != null) {\r
result.setMimeType(nuxeoBlob.getMimeType());\r
static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) {\r
DefaultBinaryManager binaryManager = null;\r
RepositoryDescriptor descriptor = null;\r
- \r
- \r
+ \r
try {\r
ServiceManager sm = (ServiceManager) Framework.getService(ServiceManager.class);\r
ServiceDescriptor[] sd = sm.getServiceDescriptors();\r
String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call.\r
DocumentModel documentModel = getFileManagerService().createDocumentFromBlob(nuxeoSession,\r
fileBlob, blobLocation.getPathAsString(), true, fileName);\r
- result = createBlobCommon(documentModel, fileBlob);\r
+ result = createBlobsCommon(documentModel, fileBlob);\r
} catch (Exception e) {\r
result = null;\r
logger.error("Could not create new image blob", e);\r
\r
return result;\r
}\r
- \r
- \r
- /**\r
- * Gets the picture.\r
- *\r
- * @param ctx the ctx\r
- * @param repoSession the repo session\r
- * @param blobId the blob id\r
- * @param derivativeTerm the derivative term\r
- * @return the picture\r
- */\r
- public static InputStream getPicture(ServiceContext ctx, RepositoryInstance repoSession,\r
- String blobId, String derivativeTerm) {\r
- return getImage(repoSession, blobId, derivativeTerm);\r
- }\r
- \r
+ \r
/**\r
* Gets the image.\r
*\r
* @param derivativeTerm the derivative term\r
* @return the image\r
*/\r
- static public InputStream getImage(RepositoryInstance repoSession,\r
- String repositoryId, String derivativeTerm) {\r
- InputStream result = null;\r
+ static public BlobOutput getBlobOutput(ServiceContext ctx,\r
+ RepositoryInstance repoSession,\r
+ String repositoryId, \r
+ String derivativeTerm,\r
+ Boolean getContentFlag) {\r
+ BlobOutput result = new BlobOutput();\r
\r
try {\r
IdRef documentRef = new IdRef(repositoryId);\r
} else {\r
pictureBlob = pictureBlobHolder.getBlob();\r
}\r
+ //\r
+ // Create the result instance\r
+ //\r
+ BlobsCommon blobsCommon = createBlobsCommon(documentModel, pictureBlob);\r
+ result.setBlobsCommon(blobsCommon); // the blob metadata\r
+ if (getContentFlag == true) {\r
+ InputStream remoteStream = pictureBlob.getStream();\r
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream);\r
+ result.setBlobInputStream(bufferedInputStream); // the blob stream\r
+ }\r
\r
- InputStream remoteStream = pictureBlob.getStream();\r
- BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream);\r
- result = bufferedInputStream;\r
-// File tmpFile = FileUtils.createTmpFile(remoteStream);\r
-// result = new FileInputStream(tmpFile);\r
} catch (Exception e) {\r
logger.error(e.getMessage(), e);\r
}\r