From: Richard Millet Date: Tue, 12 Feb 2019 00:40:49 +0000 (-0800) Subject: DRYD-573: Changed code to store uploaded Nuxeo Blob/File record into a /Blobs workspa... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=1439dbfef5f7b0b45e838961dfe898fd17a22dcb;p=tmp%2Fjakarta-migration.git DRYD-573: Changed code to store uploaded Nuxeo Blob/File record into a /Blobs workspace subfolder. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java index 8b2bd79e1..34c3af857 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java @@ -40,6 +40,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import org.nuxeo.runtime.api.Framework; import org.nuxeo.ecm.platform.picture.api.ImageInfo; @@ -766,7 +767,6 @@ public class NuxeoBlobUtils { // We'll store the blob inside the workspace directory of the calling service String nuxeoWspaceId = ctx.getRepositoryWorkspaceId(); DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId); - DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace); // // If the original file's name contains "illegal" characters, then we create a copy of the file to give Nuxeo. // @@ -779,9 +779,12 @@ public class NuxeoBlobUtils { } } + DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace); + DocumentModel newBlobFolder = NuxeoUtils.createFolder(wspaceDoc, UUID.randomUUID().toString()); + result = createBlobInRepository(ctx, repoSession, - wspaceDoc, + newBlobFolder, purgeOriginal, targetFile, blobInput.isTemporaryFile(), diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 66c53b116..377cfee38 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -50,6 +50,7 @@ import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm; +import org.collectionspace.services.config.tenant.RepositoryDomainType; import org.collectionspace.services.lifecycle.Lifecycle; import org.collectionspace.services.lifecycle.State; import org.collectionspace.services.lifecycle.StateList; @@ -58,6 +59,7 @@ import org.collectionspace.services.lifecycle.TransitionDefList; import org.collectionspace.services.lifecycle.TransitionList; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; +import org.collectionspace.services.nuxeo.client.java.CoreSessionWrapper; import org.dom4j.Document; import org.dom4j.io.SAXReader; import org.nuxeo.ecm.core.NXCore; @@ -94,7 +96,7 @@ public class NuxeoUtils { // Base document type in Nuxeo is "Document" // public static final String BASE_DOCUMENT_TYPE = "Document"; - public static final String WORKSPACE_DOCUMENT_TYPE = "Workspace"; + public static final String WORKSPACE_DOCUMENT_TYPE = "Workspace"; // public static final String WORKSPACE_FOLDER_TYPE = "Folder"; public static final String Workspaces = "Workspaces"; public static final String workspaces = "workspaces"; // to make it easier to migrate older versions of the CollectionSpace services -i.e., pre v2.0. @@ -163,6 +165,33 @@ public class NuxeoUtils { return result; } + /** + * Create a Nuxeo 'Folder' inside the passed in 'parentDoc'. + * + * @param parentDoc + * @param folderName + * @return + * @throws Exception + */ + static public DocumentModel createFolder(DocumentModel parentDoc, String folderName) throws Exception { + CoreSessionInterface repoSession = new CoreSessionWrapper(parentDoc.getCoreSession()); + + DocumentModel folder = repoSession.createDocumentModel(parentDoc.getPathAsString(), + folderName, NuxeoUtils.WORKSPACE_DOCUMENT_TYPE); + folder.setPropertyValue("dc:title", folderName); + folder.setPropertyValue("dc:description", "A CollectionSpace folder of " + + parentDoc.getName()); + folder = repoSession.createDocument(folder); + + repoSession.save(); + + if (logger.isDebugEnabled()) { + logger.debug("Created folder name=" + folderName + + " Nuxeo ID=" + folder.getId()); + } + + return folder; + } /* * Map Nuxeo's life cycle object to our JAX-B based life cycle object @@ -873,6 +902,7 @@ public class NuxeoUtils { } */ + /** * createPathRef creates a PathRef for given service context using given id * @param ctx