import org.collectionspace.services.blob.BlobsCommon;
import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
import org.collectionspace.services.client.BlobClient;
-import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.config.service.ObjectPartType;
-import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.jaxb.BlobJAXBSchema;
import org.collectionspace.services.nuxeo.client.java.CommonList;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
-import org.nuxeo.ecm.core.schema.types.Schema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
}
private void extractMetadata(String nuxeoImageID, String metadataLabel) {
- PayloadOutputPart result = null;
Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
ObjectPartType partMeta = partsMetaMap.get(metadataLabel);
@Override
public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
throws Exception {
- ServiceContext ctx = this.getServiceContext();
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
BlobInput blobInput = BlobUtil.getBlobInput(ctx);
RepositoryInstance repoSession = this.getRepositorySession();
DocumentModel docModel = wrapDoc.getWrappedObject();
@Override
public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
- ServiceContext ctx = this.getServiceContext();
- BlobInput blobInput = BlobUtil.getBlobInput(ctx);
- if (blobInput.getBlobFile() != null) {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
+ BlobInput blobInput = BlobUtil.getBlobInput(ctx); // The blobInput should have been put into the context by the Blob or Media resource
+ if (blobInput != null && blobInput.getBlobFile() != null) {
//
// If blobInput has a file then we just received a multipart/form-data file post or a URI query parameter
//
DocumentModel documentModel = wrapDoc.getWrappedObject();
RepositoryInstance repoSession = this.getRepositorySession();
- BlobsCommon blobsCommon = NuxeoImageUtils.createPicture(ctx, repoSession, blobInput);
- PoxPayloadIn input = (PoxPayloadIn)ctx.getInput();
+ BlobsCommon blobsCommon = NuxeoImageUtils.createBlobInRepository(ctx, repoSession, blobInput);
+ blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID
+
+ PoxPayloadIn input = ctx.getInput();
//
// If the input payload is null, then we're creating a new blob from a post or a uri. This means there
// is no "input" payload for our framework to process. Therefore we need to synthesize a payload from
output.addPart(commonPart);
input = new PoxPayloadIn(output.toXML());
ctx.setInput(input);
- }
-// this.setCommonPartProperties(documentModel, blobsCommon);
- blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID
+ } else {
+ // At this point, we've created a blob document in the Nuxeo repository. Usually, we use the blob to create and instance of BlobsCommon and use
+ // that to populate the resource record. However, since the "input" var is not null the requester provided their own resource record data
+ // so we'll use it rather than deriving one from the blob.
+ logger.warn("A resource record payload was provided along with the actually blob binary file. This payload is usually derived from the blob binary. Since a payload was provided, we're creating the resource record from the payload and not from the corresponding blob binary." +
+ " The data in blob resource record fields may not correspond completely with the persisted blob binary file.");
+ }
}
super.fillAllParts(wrapDoc, action);
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.api.DocumentRef;\r
\r
+import org.nuxeo.ecm.core.schema.DocumentType;\r
import org.nuxeo.ecm.core.schema.SchemaManager;\r
import org.nuxeo.ecm.core.schema.types.Schema;\r
\r
// empty constructor\r
}\r
\r
+ /*\r
+ * Use this for debugging Nuxeo's PictureView class\r
+ */\r
private static String toStringPictureView(PictureView pictureView) {\r
StringBuffer strBuffer = new StringBuffer();\r
strBuffer.append("Description: " + pictureView.getDescription() + '\n');\r
DocumentModel documentModel, Blob blob) {\r
DefaultBinaryManager binaryManager = null;\r
RepositoryDescriptor descriptor = null;\r
+ File file = null;\r
\r
try {\r
RepositoryService repositoryService1 = (RepositoryService) Framework\r
.getRepositoryManager();\r
descriptor = repositoryManager.getDescriptor(repositoryName);\r
\r
+// Keep this code around for future work/enhancements \r
// binaryManager = new DefaultBinaryManager();\r
//\r
// File storageDir = binaryManager.getStorageDir();\r
e.printStackTrace();\r
}\r
\r
- try {\r
- binaryManager.initialize(SQLRepository.getDescriptor(descriptor));\r
- } catch (IOException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (Exception e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
-\r
- File storageDir = binaryManager.getStorageDir();\r
- // SQLBlob blob = (SQLBlob)\r
- // documentModel.getPropertyValue("schema:blobField");\r
- File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
+// Keep this code around for future work/enhancements\r
+// try {\r
+// binaryManager.initialize(SQLRepository.getDescriptor(descriptor));\r
+// } catch (IOException e) {\r
+// // TODO Auto-generated catch block\r
+// e.printStackTrace();\r
+// } catch (Exception e) {\r
+// // TODO Auto-generated catch block\r
+// e.printStackTrace();\r
+// }\r
+\r
+// Keep this code around for future work/enhancements\r
+// File storageDir = binaryManager.getStorageDir();\r
+// SQLBlob blob = (SQLBlob)\r
+// documentModel.getPropertyValue("schema:blobField");\r
+// File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
\r
return file;\r
}\r
\r
/**\r
- * Returns a schema, given the name of a schema.\r
+ * Returns a schema, given the name of a schema. Possibly usefule in the future\r
* \r
* @param schemaName\r
* a schema name.\r
}\r
\r
/**\r
- * Gets the blob.\r
+ * Gets the blob. Not in use now, but might be useful in the future.\r
* \r
* @param nuxeoSession\r
* the nuxeo session\r
}\r
\r
/**\r
- * Gets the type service.\r
+ * Gets the type service. Not in use, but please keep for future reference\r
* \r
* @return the type service\r
* @throws ClientException\r
}\r
\r
/**\r
- * Creates the serializable blob.\r
+ * Creates the serializable blob. We may need this code, do not remove.\r
* \r
* @param fileInputStream\r
* the file input stream\r
return blob;\r
}\r
\r
- private static Blob createFileBlob(File file) {\r
+ private static Blob createNuxeoFileBasedBlob(File file) {\r
Blob result = null;\r
\r
result = new FileBlob(file);\r
* @param filePath\r
* the file path\r
* @return the string\r
+ * @throws Exception \r
*/\r
- public static BlobsCommon createPicture(ServiceContext ctx,\r
- RepositoryInstance repoSession, BlobInput blobInput) {\r
+ public static BlobsCommon createBlobInRepository(ServiceContext ctx,\r
+ RepositoryInstance repoSession, BlobInput blobInput) throws Exception {\r
BlobsCommon result = null;\r
\r
try {\r
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();\r
DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);\r
DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);\r
-\r
- // FileInputStream inputStream = new FileInputStream(blobFile);\r
- // //FIXME: REM - With an embedded Nuxeo server, we may no longer\r
- // need to pass in a stream but instead just pass them the File\r
- // instance\r
- // if (inputStream != null) {\r
- result = createImage(repoSession, wspaceDoc,\r
- /* inputStream, */blobFile, null);\r
- // }\r
+ \r
+ if (logger.isDebugEnabled()) {\r
+ for (String facet : wspaceDoc.getFacets()) {\r
+ logger.debug("Facet: " + facet);\r
+ }\r
+ for (String docType : wspaceDoc.getDocumentType().getChildrenTypes()) {\r
+ logger.debug("Child type: " + docType);\r
+ }\r
+ } \r
+\r
+ result = createBlobInRepository(repoSession, wspaceDoc, blobFile, null /*mime type*/);\r
} catch (Exception e) {\r
- logger.error("Could not create image blob", e); //FIXME: REM - We should probably be re-throwing the exception?\r
+ logger.error("Could not create image blob", e);\r
+ throw e;\r
}\r
\r
return result;\r
* the mime type\r
* @return the string\r
*/\r
- static public BlobsCommon createImage(RepositoryInstance nuxeoSession,\r
+ static public BlobsCommon createBlobInRepository(RepositoryInstance nuxeoSession,\r
DocumentModel blobLocation,\r
// InputStream file,\r
File file, String mimeType) {\r
try {\r
// Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(),\r
// mimeType);\r
- Blob fileBlob = createFileBlob(file);\r
+ Blob fileBlob = createNuxeoFileBasedBlob(file);\r
String digestAlgorithm = getFileManagerService()\r
- .getDigestAlgorithm(); // Need some way on initializing the\r
- // FileManager with a call.\r
+ .getDigestAlgorithm(); // Only call this because we seem to need some way of initializing Nuxeo's FileManager with a call.\r
\r
- logger.debug("Start --> Calling Nuxeo to create an image blob."); // See Nuxeo's DefaultPictureAdapter class for details\r
+ logger.debug("Start --> Starting call to Nuxeo to create the blob document."); // For example, see Nuxeo's DefaultPictureAdapter class for details\r
DocumentModel documentModel = getFileManagerService()\r
.createDocumentFromBlob(nuxeoSession, fileBlob,\r
blobLocation.getPathAsString(), true,\r
file.getName());\r
- logger.debug("Stop --> Calling Nuxeo to create an image blob.");\r
+ logger.debug("Stop --> Finished calling Nuxeo to create the blob document.");\r
\r
- result = createBlobsCommon(documentModel, fileBlob);\r
+ result = createBlobsCommon(documentModel, fileBlob); // Now create our metadata resource document\r
} catch (Exception e) {\r
result = null;\r
- logger.error("Could not create new image blob", e); //FIXME: REM - This should probably be re-throwing the exception?\r
+ logger.error("Could not create new Nuxeo blob document.", e); //FIXME: REM - This should probably be re-throwing the exception?\r
}\r
\r
return result;\r
* @return the image\r
*/\r
static public BlobOutput getBlobOutput(ServiceContext ctx,\r
- RepositoryInstance repoSession, String repositoryId,\r
- String derivativeTerm, Boolean getContentFlag) {\r
+ RepositoryInstance repoSession,\r
+ String repositoryId,\r
+ String derivativeTerm,\r
+ Boolean getContentFlag) {\r
BlobOutput result = new BlobOutput();\r
\r
if (repositoryId != null && repositoryId.isEmpty() == false)\r
try {\r
IdRef documentRef = new IdRef(repositoryId);\r
- DocumentModel documentModel = repoSession\r
- .getDocument(documentRef);\r
+ DocumentModel documentModel = repoSession.getDocument(documentRef);\r
\r
Blob docBlob = null;\r
DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel\r
.getAdapter(BlobHolder.class);\r
- if (docBlobHolder instanceof PictureBlobHolder) { // if it is a\r
- // PictureDocument\r
- // then it\r
- // has these\r
- // Nuxeo\r
- // schemas:\r
- // [dublincore,\r
- // uid,\r
- // picture,\r
- // iptc,\r
- // common,\r
- // image_metadata]\r
+ if (docBlobHolder instanceof PictureBlobHolder) {\r
+ // if it is a PictureDocument then it has these\r
+ // Nuxeo schemas: [dublincore, uid, picture, iptc, common, image_metadata]\r
//\r
// Need to add the "MultiviewPictureAdapter" support here to\r
// get the view data, see above.\r
}\r
\r
//\r
- // Create the result instance that will contain the blob\r
- // metadata\r
+ // Create the result instance that will contain the blob metadata\r
// and an InputStream with the bits if the 'getContentFlag' is\r
- // set\r
+ // set.\r
//\r
- BlobsCommon blobsCommon = createBlobsCommon(documentModel,\r
- docBlob);\r
+ BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
result.setBlobsCommon(blobsCommon);\r
if (getContentFlag == true) {\r
InputStream remoteStream = docBlob.getStream();\r
BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
- remoteStream); // FIXME: REM - To improve\r
- // performance, try\r
- // BufferedInputStream(InputStream\r
- // in, int size)\r
- result.setBlobInputStream(bufferedInputStream); // the input\r
- // stream of\r
- // blob bits\r
+ remoteStream); // FIXME: REM - To improve performance, try\r
+ // BufferedInputStream(InputStream in, int size)\r
+ result.setBlobInputStream(bufferedInputStream);\r
}\r
\r
} catch (Exception e) {\r