From: Patrick Schmitz Date: Fri, 11 Jun 2010 20:02:41 +0000 (+0000) Subject: CSPACE-1895 Work towards adding repeating sections. For now, just put in notes in... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c2c37f2fde5ce3bf5332fffa76faf7c453c4d0c2;p=tmp%2Fjakarta-migration.git CSPACE-1895 Work towards adding repeating sections. For now, just put in notes in the key places where we need to make changes to support this, as we explore alternatives. --- diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 33d7ef941..b88b4d85e 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -73,11 +73,20 @@ public abstract class DocumentModelHandler @Override public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + // TODO for sub-docs - check to see if the current service context is a multipart input, + // OR a docfragment, and call a variant to fill the DocModel. fillAllParts(wrapDoc); } + + // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments + // and create the subitems. We will create service contexts with the doc fragments + // and then call + @Override public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + // TODO for sub-docs - check to see if the current service context is a multipart input, + // OR a docfragment, and call a variant to fill the DocModel. fillAllParts(wrapDoc); } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 8d2aafc50..14bfe0cce 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -218,6 +218,9 @@ public abstract class RemoteDocumentModelHandlerImpl protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta) throws Exception { InputStream payload = part.getBody(InputStream.class, null); + +// TODO for sub-docs - after we parse the doc, we need to look for elements that are configured as +// subitem lists, for this part (schema), pull them out, and set them aside for later processing. //check if this is an xml part if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){ diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 737dec28b..e51105cdf 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -226,6 +226,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient { setCollectionSpaceCoreValues(ctx, doc, Action.CREATE); doc = repoSession.createDocument(doc); repoSession.save(); +// TODO for sub-docs need to call into the handler to let it deal with subitems. Pass in the id, +// and assume the handler has the state it needs (doc fragments). handler.complete(Action.CREATE, wrapDoc); return id; } catch (BadRequestException bre) { diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index 4919c3795..063f1ac17 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -1,5 +1,6 @@ package org.collectionspace.services.client; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -9,6 +10,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; +import org.apache.commons.io.FileUtils; import org.collectionspace.services.LocationJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.location.LocationsCommon; @@ -18,11 +20,19 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.testng.Assert; public class LocationAuthorityClientUtils { private static final Logger logger = LoggerFactory.getLogger(LocationAuthorityClientUtils.class); + /** + * Creates a new Location Authority + * @param displayName The displayName used in UI, etc. + * @param refName The proper refName for this authority + * @param headerLabel The common part label + * @return The MultipartOutput payload for the create call + */ public static MultipartOutput createLocationAuthorityInstance( String displayName, String refName, String headerLabel ) { LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon(); @@ -41,6 +51,13 @@ public class LocationAuthorityClientUtils { return multipart; } + /** + * @param inAuthority CSID of the authority to create a new location in + * @param locationRefName The proper refName for this authority + * @param locationInfo the properties for the new Location + * @param headerLabel The common part label + * @return The MultipartOutput payload for the create call + */ public static MultipartOutput createLocationInstance(String inAuthority, String locationRefName, Map locationInfo, String headerLabel){ LocationsCommon location = new LocationsCommon(); @@ -74,6 +91,13 @@ public class LocationAuthorityClientUtils { return multipart; } + /** + * @param vcsid CSID of the authority to create a new location in + * @param locationAuthorityRefName The refName for the authority + * @param locationMap the properties for the new Location + * @param client the service client + * @return the CSID of the new item + */ public static String createItemInAuthority(String vcsid, String locationAuthorityRefName, Map locationMap, LocationAuthorityClient client ) { @@ -121,6 +145,61 @@ public class LocationAuthorityClientUtils { return extractId(res); } + public static MultipartOutput createLocationInstance( + String commonPartXML, String headerLabel){ + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(commonPartXML, + MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, location common ", commonPartXML); + } + + return multipart; + } + + public static String createItemInAuthority(String vcsid, + String commonPartXML, + LocationAuthorityClient client ) { + // Expected status code: 201 Created + int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + + MultipartOutput multipart = + createLocationInstance( commonPartXML, client.getItemCommonPartName() ); + ClientResponse res = client.createItem(vcsid, multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+commonPartXML + +"\" in locationAuthority: \"" + vcsid + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML + +"\" in locationAuthority: \"" + vcsid +"\", Status:"+ statusCode); + } + + return extractId(res); + } + + /** + * Creates the from xml file. + * + * @param fileName the file name + * @return new CSID as string + * @throws Exception the exception + */ + private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName, + LocationAuthorityClient client) throws Exception { + byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName)); + String commonPartXML = new String(b); + return createItemInAuthority(vcsid, commonPartXML, client ); + } + public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name(" +locationAuthorityName+")";