Also extended Location and Media tests to exercise some other features.
import org.collectionspace.services.common.relation.IRelationsManager;
import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
+import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler;
import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;
import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.common.context.JaxRsContext;
import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.relation.RelationResource;
import org.collectionspace.services.relation.RelationsCommon;
import org.collectionspace.services.relation.RelationsCommonList;
final static int URN_NAME_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_NAME.length();
final static String URN_PREFIX_ID = "id(";
final static int URN_ID_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_ID.length();
+ final static String FETCH_SHORT_ID = "_fetch_";
final Logger logger = LoggerFactory.getLogger(AuthorityResource.class);
*
* @throws Exception the exception
*/
- public DocumentHandler createItemDocumentHandler(
+ protected DocumentHandler createItemDocumentHandler(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
- String inAuthority)
+ String inAuthority, String parentShortIdentifier)
throws Exception {
- AuthItemHandler docHandler;
+ String authorityRefNameBase;
+ AuthorityItemDocumentModelHandler<?,?> docHandler;
+
+ if(parentShortIdentifier==null) {
+ authorityRefNameBase = null;
+ } else {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx =
+ createServiceContext(getServiceName());
+ if(parentShortIdentifier.equals(FETCH_SHORT_ID)) {
+ // Get from parent document
+ parentShortIdentifier = getAuthShortIdentifier(parentCtx, inAuthority);
+ }
+ authorityRefNameBase = buildAuthorityRefNameBase(parentCtx, parentShortIdentifier);
+ }
- docHandler = (AuthItemHandler)createDocumentHandler(ctx,
+ docHandler = (AuthorityItemDocumentModelHandler<?,?>)createDocumentHandler(ctx,
ctx.getCommonPartLabel(getItemServiceName()),
authCommonClass);
- ((AuthorityItemDocumentModelHandler<?,?>)docHandler).setInAuthority(inAuthority);
+ docHandler.setInAuthority(inAuthority);
+ docHandler.setAuthorityRefNameBase(authorityRefNameBase);
return (DocumentHandler)docHandler;
}
+
+ public String getAuthShortIdentifier(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String authCSID)
+ throws DocumentNotFoundException, DocumentException {
+ String shortIdentifier = null;
+ try {
+ DocumentWrapper<DocumentModel> wrapDoc = getRepositoryClient(ctx).getDocFromCsid(ctx, authCSID);
+ AuthorityDocumentModelHandler<?,?> handler =
+ (AuthorityDocumentModelHandler<?,?>)createDocumentHandler(ctx);
+ shortIdentifier = handler.getShortIdentifier(wrapDoc, authorityCommonSchemaName);
+ } catch (DocumentNotFoundException dnfe) {
+ throw dnfe;
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ }
+ return shortIdentifier;
+ }
+
+
+ protected String buildAuthorityRefNameBase(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String shortIdentifier) {
+ RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
+ ctx.getServiceName(), shortIdentifier, null);
+ return authority.toString();
+ }
+
+
/**
* Creates the authority.
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM");
String parentcsid;
+ String parentShortIdentifier;
if(spec.form==SpecifierForm.CSID) {
parentcsid = spec.value;
+ // Uncomment when app layer is ready to integrate
+ // parentShortIdentifier = FETCH_SHORT_ID;
+ parentShortIdentifier = null;
} else {
+ parentShortIdentifier = spec.value;
String whereClause = buildWhereForAuthByName(spec.value);
ctx = createServiceContext(getServiceName());
parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
}
ctx = createServiceContext(getItemServiceName(), input);
ctx.setUriInfo(ui); //Laramie
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ // Note: must have the parentShortId, to do the create.
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, parentShortIdentifier);
String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(resourceClass);
path.path(parentcsid + "/items/" + itemcsid);
throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
}
}
-
+
@GET
@Path("{csid}/items/{itemcsid}" + WorkflowClient.SERVICE_PATH)
public byte[] getItemWorkflow(
ctx = (RemoteServiceContext)createServiceContext(getItemServiceName(), queryParams);
ctx.setJaxRsContext(jaxRsContext);
+ ctx.setUriInfo(ui); //ARG! must pass this or subsequent calls will not have a ui.
-
- // NEW laramie
- ctx.setUriInfo(ui); //ARG! must pass this or subsequent calls will not have a ui.
- // NEW
-
-
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ // We omit the parentShortId, only needed when doing a create...
+ DocumentHandler handler = createItemDocumentHandler(ctx,
+ parentcsid, null);
if(itemSpec.form==SpecifierForm.CSID) {
getRepositoryClient(ctx).get(ctx, itemSpec.value, handler);
} else {
parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
}
ctx = createServiceContext(getItemServiceName(), queryParams);
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ // We omit the parentShortId, only needed when doing a create...
+ DocumentHandler handler = createItemDocumentHandler(ctx,
+ parentcsid, null);
DocumentFilter myFilter = handler.getDocumentFilter();
myFilter.appendWhereClause(authorityItemCommonSchemaName + ":" +
AuthorityItemJAXBSchema.IN_AUTHORITY + "=" +
itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); //FIXME: REM - Should we be looking for the 'wf_deleted' query param and filtering on it?
}
// Note that we have to create the service context for the Items, not the main service
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ // We omit the parentShortId, only needed when doing a create...
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
RepositoryClient repoClient = getRepositoryClient(ctx);
DocumentFilter myFilter = handler.getDocumentFilter();
String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
}
ctx = createServiceContext(getItemServiceName(), queryParams);
+ // We omit the parentShortId, only needed when doing a create...
RemoteDocumentModelHandlerImpl handler =
- (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid);
+ (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx,
+ parentcsid, null);
String itemcsid;
if(itemSpec.form==SpecifierForm.CSID) {
itemcsid = itemSpec.value;
itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause);
}
// Note that we have to create the service context for the Items, not the main service
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ // We omit the parentShortId, only needed when doing a create...
+ DocumentHandler handler = createItemDocumentHandler(ctx,
+ parentcsid, null);
ctx.setUriInfo(ui);
getRepositoryClient(ctx).update(ctx, itemcsid, handler);
result = ctx.getOutput();
import java.util.Map;
+import javax.management.RuntimeErrorException;
+
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentException;
+import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.service.ObjectPartType;
+import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
/**
return unQObjectProperties;
}
+ @Override
+ public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ super.handleCreate(wrapDoc);
+ // Uncomment once debugged and App layer is read to integrate
+ //updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
+ }
+
+ protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
+ DocumentModel docModel = wrapDoc.getWrappedObject();
+ String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+ String displayName = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
+ MultipartServiceContext ctx = (MultipartServiceContext)getServiceContext();
+ RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
+ ctx.getServiceName(),
+ shortIdentifier,
+ displayName);
+ String refName = authority.toString();
+ docModel.setProperty(schemaName , AuthorityJAXBSchema.REF_NAME, refName);
+ }
+
+
+ public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
+ DocumentModel docModel = wrapDoc.getWrappedObject();
+ String shortIdentifier = null;
+ try {
+ shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+ } catch (ClientException ce) {
+ throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
+ }
+ return shortIdentifier;
+ }
+
}
import org.collectionspace.services.client.RelationClient;
//import org.collectionspace.services.common.authority.AuthorityItemRelations;
import org.collectionspace.services.common.api.CommonAPI;
+import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
* inVocabulary is the parent Authority for this context
*/
protected String inAuthority;
+ protected String authorityRefNameBase;
public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
}
+ public String getAuthorityRefNameBase(){
+ return this.authorityRefNameBase;
+ }
+
+ public void setAuthorityRefNameBase(String value){
+ this.authorityRefNameBase = value;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
*/
// first fill all the parts of the document
super.handleCreate(wrapDoc);
handleInAuthority(wrapDoc.getWrappedObject());
+ // Uncomment once debugged and App layer is read to integrate
+ //handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
+ //updateRefnameForAuthorityItem(wrapDoc, authorityItemCommonSchemaName, getAuthorityRefNameBase()); //CSPACE-3178
}
+ private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
+ String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+ String displayName = (String)docModel.getProperty(schemaName, AuthorityItemJAXBSchema.DISPLAY_NAME);
+ if (Tools.isEmpty(shortIdentifier) && Tools.notEmpty(displayName)){
+ String cookedShortIdentifier = Tools.squeeze(displayName)+'-'+Tools.now().toString();
+ docModel.setProperty(schemaName , AuthorityItemJAXBSchema.SHORT_IDENTIFIER, cookedShortIdentifier);
+ }
+ }
+
+ protected void updateRefnameForAuthorityItem(DocumentWrapper<DocumentModel> wrapDoc,
+ String schemaName,
+ String authorityRefBaseName) throws Exception {
+ DocumentModel docModel = wrapDoc.getWrappedObject();
+ String shortIdentifier = (String)docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+ String displayName = (String)docModel.getProperty(schemaName, AuthorityItemJAXBSchema.DISPLAY_NAME);
+ if (Tools.isEmpty(authorityRefBaseName)){
+ throw new Exception("updateRefnameForAuthorityItem requires an authorityRefBaseName, but none was supplied.");
+ }
+ RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName);
+ String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString();
+ docModel.setProperty(schemaName , AuthorityItemJAXBSchema.REF_NAME, refName);
+ }
+
/**
* Check the logic around the parent pointer. Note that we only need do this on
* create, since we have logic to make this read-only on update.
public String name;\r
public String displayName;\r
\r
- public AuthorityInfo(String refNameTokens[]) throws Exception {\r
+ public AuthorityInfo(String refNameTokens[]) throws IllegalArgumentException {\r
try {\r
if(refNameTokens.length < MIN_TOKENS) {\r
throw new IllegalArgumentException("Malformed refName for Authority (too few tokens)");\r
this.displayName = \r
((idTokens.length<INSTANCE_TOKENS_MAX)||(idTokens[INSTANCE_DISPLAYNAME_TOKEN].length()<3))? null:\r
idTokens[INSTANCE_DISPLAYNAME_TOKEN].substring(1, idTokens[INSTANCE_DISPLAYNAME_TOKEN].length()-1);\r
- } catch (Exception e) {\r
+ } catch (IllegalArgumentException e) {\r
if (logger.isDebugEnabled()) {\r
logger.debug("Problem Building AuthorityInfo from tokens: " \r
+ RefNameUtils.implodeStringArray(refNameTokens, ", "));\r
public String name;\r
public String displayName;\r
\r
- public AuthorityTermInfo(String refNameTokens[]) throws Exception {\r
+ public AuthorityTermInfo(String refNameTokens[]) throws IllegalArgumentException {\r
try {\r
if(refNameTokens.length < MIN_TOKENS) {\r
throw new IllegalArgumentException("Malformed refName for AuthorityTerm (too few tokens)");\r
this.displayName = \r
((idTokens.length<INSTANCE_TOKENS_MAX)||(idTokens[INSTANCE_DISPLAYNAME_TOKEN].length()<3))? null:\r
idTokens[INSTANCE_DISPLAYNAME_TOKEN].substring(1, idTokens[INSTANCE_DISPLAYNAME_TOKEN].length()-1);\r
- } catch (Exception e) {\r
+ } catch (IllegalArgumentException e) {\r
if (logger.isDebugEnabled()) {\r
logger.debug("Problem Building AuthorityTermInfo from tokens: " \r
+ RefNameUtils.implodeStringArray(refNameTokens, ", "));\r
};\r
\r
public static AuthorityInfo parseAuthorityInfo(String refName)\r
- throws Exception {\r
+ throws IllegalArgumentException {\r
if(refName==null || !refName.startsWith(URN_PREFIX))\r
- throw new RuntimeException( "Null or invalid refName syntax");\r
+ throw new IllegalArgumentException( "Null or invalid refName syntax");\r
return new AuthorityInfo(refName.substring(URN_PREFIX_LEN).split(SEPARATOR));\r
}\r
\r
public static AuthorityTermInfo parseAuthorityTermInfo(String refName)\r
- throws Exception {\r
+ throws IllegalArgumentException {\r
if(refName==null || !refName.startsWith(URN_PREFIX))\r
- throw new RuntimeException( "Null or invalid refName syntax");\r
+ throw new IllegalArgumentException( "Null or invalid refName syntax");\r
return new AuthorityTermInfo(refName.substring(URN_PREFIX_LEN).split(SEPARATOR));\r
}\r
\r
public AbstractCommonList extractCommonPartListPATRICK(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {\r
//String label = getServiceContext().getCommonPartLabel();\r
\r
- /*\r
- AbstractCommonList commonList = createAbstractCommonListImpl();\r
- extractPagingInfo(((TL)commonList), wrapDoc);\r
- commonList.setFieldsReturned(getSummaryFields(commonList));\r
- List list = createItemsList(commonList);\r
- Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
- while(iter.hasNext()){\r
- DocumentModel docModel = iter.next();\r
- String id = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
- Object item = createItemForCommonList(docModel, label, id);\r
- list.add(item);\r
- }\r
- */\r
- /* Rewrite\r
- * Create the CommonList\r
- * List<ListResultField> resultsFields = getListItemsArray();\r
- * Construct array of strings of resultsFields\r
- * add csid and uri\r
- * Set the fieldNames for CommonList\r
- * For each doc in list:\r
- * Create HashMap of values\r
- * get csid, set csid hashmap value\r
- * get uri, set uri hashmap value\r
- * for (ListResultField field : resultsFields ){\r
- * get String value from Xpath\r
- * set hashMap value\r
- * AddItem to CommonList\r
- * \r
- */\r
String commonSchema = getServiceContext().getCommonPartLabel();\r
CommonList commonList = new CommonList();\r
extractPagingInfo(commonList, wrapDoc);\r
}\r
\r
//================== UTILITY METHODS ================================================\r
-\r
public static ReflectionMapper.STATUS callPropertySetterWithXPathValue(DocumentModel docModel,\r
Object listItem,\r
String setterName,\r
(LocationauthoritiesCommon) extractPart(input,
client.getCommonPartName(), LocationauthoritiesCommon.class);
Assert.assertNotNull(locationAuthority);
+ Assert.assertNotNull(locationAuthority.getDisplayName());
+ Assert.assertNotNull(locationAuthority.getShortIdentifier());
+ Assert.assertNotNull(locationAuthority.getRefName());
} catch (Exception e) {
throw new RuntimeException(e);
}
import java.io.File;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.media.LanguageList;
import org.collectionspace.services.media.MediaCommon;
+import org.collectionspace.services.media.SubjectList;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
String identifier = "media.title-" + title;
MediaCommon media = new MediaCommon();
media.setTitle(identifier);
+ media.setContributor("Joe-bob briggs");
+ media.setCoverage("Lots of stuff");
+ media.setPublisher("Ludicrum Enterprises");
+ SubjectList subjects = new SubjectList();
+ List<String> subjList = subjects.getSubject();
+ subjList.add("Pints of blood");
+ subjList.add("Much skin");
+ media.setSubjectList(subjects);
+ LanguageList languages = new LanguageList();
+ List<String> langList = languages.getLanguage();
+ langList.add("English");
+ langList.add("German");
+ media.setLanguageList(languages);
PoxPayloadOut multipart = new PoxPayloadOut(MediaClient.SERVICE_PAYLOAD_NAME);
PayloadOutputPart commonPart = multipart.addPart(media, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(new MediaClient().getCommonPartName());