From: Patrick Schmitz Date: Mon, 9 May 2011 20:10:54 +0000 (+0000) Subject: NOJIRA - Partial port of Laramie's 3178 branch. Still has some bugs, and key enabling... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=77bc8a0ef5f0dbc2d0200f5268810d1886f2460b;p=tmp%2Fjakarta-migration.git NOJIRA - Partial port of Laramie's 3178 branch. Still has some bugs, and key enabling statements are commented out, as they cause app tests to fail. Work done (mistakenly) to address 3930, which was really about something else. Slightly refactored from the branch, bust utility code just ported over. RefName construction utils seem not be working correctly yet (strings are not proper syntax). Also extended Location and Media tests to exercise some other features. --- diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index c389af556..e97d2a646 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -57,12 +57,14 @@ import org.collectionspace.services.common.document.JaxbUtils; 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; @@ -72,6 +74,7 @@ import org.collectionspace.services.common.context.RemoteServiceContext; 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; @@ -80,6 +83,7 @@ import org.collectionspace.services.common.repository.RepositoryClient; 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; @@ -110,6 +114,7 @@ public abstract class AuthorityResource ctx, - String inAuthority) + String inAuthority, String parentShortIdentifier) throws Exception { - AuthItemHandler docHandler; + String authorityRefNameBase; + AuthorityItemDocumentModelHandler docHandler; + + if(parentShortIdentifier==null) { + authorityRefNameBase = null; + } else { + ServiceContext 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 ctx, String authCSID) + throws DocumentNotFoundException, DocumentException { + String shortIdentifier = null; + try { + DocumentWrapper 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 ctx, String shortIdentifier) { + RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(), + ctx.getServiceName(), shortIdentifier, null); + return authority.toString(); + } + + /** * Creates the authority. @@ -435,16 +488,22 @@ public abstract class AuthorityResource 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); @@ -458,7 +517,7 @@ public abstract class AuthorityResource * inVocabulary is the parent Authority for this context */ protected String inAuthority; + protected String authorityRefNameBase; public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) { this.authorityItemCommonSchemaName = authorityItemCommonSchemaName; @@ -108,6 +110,14 @@ public abstract class AuthorityItemDocumentModelHandler } + 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) */ @@ -116,8 +126,34 @@ public abstract class AuthorityItemDocumentModelHandler // 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 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. diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java index 209ed79d6..ae255a054 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java @@ -70,7 +70,7 @@ public class RefNameUtils { public String name; public String displayName; - public AuthorityInfo(String refNameTokens[]) throws Exception { + public AuthorityInfo(String refNameTokens[]) throws IllegalArgumentException { try { if(refNameTokens.length < MIN_TOKENS) { throw new IllegalArgumentException("Malformed refName for Authority (too few tokens)"); @@ -94,7 +94,7 @@ public class RefNameUtils { this.displayName = ((idTokens.length extends RemoteDocumentModelHandlerImpl wrapDoc) throws Exception { //String label = getServiceContext().getCommonPartLabel(); - /* - AbstractCommonList commonList = createAbstractCommonListImpl(); - extractPagingInfo(((TL)commonList), wrapDoc); - commonList.setFieldsReturned(getSummaryFields(commonList)); - List list = createItemsList(commonList); - Iterator iter = wrapDoc.getWrappedObject().iterator(); - while(iter.hasNext()){ - DocumentModel docModel = iter.next(); - String id = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); - Object item = createItemForCommonList(docModel, label, id); - list.add(item); - } - */ - /* Rewrite - * Create the CommonList - * List resultsFields = getListItemsArray(); - * Construct array of strings of resultsFields - * add csid and uri - * Set the fieldNames for CommonList - * For each doc in list: - * Create HashMap of values - * get csid, set csid hashmap value - * get uri, set uri hashmap value - * for (ListResultField field : resultsFields ){ - * get String value from Xpath - * set hashMap value - * AddItem to CommonList - * - */ String commonSchema = getServiceContext().getCommonPartLabel(); CommonList commonList = new CommonList(); extractPagingInfo(commonList, wrapDoc); @@ -273,7 +244,6 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl subjList = subjects.getSubject(); + subjList.add("Pints of blood"); + subjList.add("Much skin"); + media.setSubjectList(subjects); + LanguageList languages = new LanguageList(); + List 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());