From: Aron Roberts Date: Tue, 15 Nov 2011 23:52:26 +0000 (+0000) Subject: CSPACE-4460: Authority services now no longer accept client-supplied refNames; all... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e45bb81f37a775da776d013b211b53208bd30025;p=tmp%2Fjakarta-migration.git CSPACE-4460: Authority services now no longer accept client-supplied refNames; all refNames are generated by the services. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 9235008b3..84cb9cfa1 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -80,6 +80,10 @@ public abstract class AuthorityDocumentModelHandler updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178 } + /** + * If no short identifier was provided in the input payload, + * generate a short identifier from the display name. + */ private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception { String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER); String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME); @@ -89,24 +93,29 @@ public abstract class AuthorityDocumentModelHandler docModel.setProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier); } } - + + /** + * Generate a refName for the authority from the short identifier + * and display name. + * + * All refNames for authorities are generated. If a client supplies + * a refName, it will be overwritten during create (per this method) + * or discarded during update (per filterReadOnlyPropertiesForPart). + * + * @see #filterReadOnlyPropertiesForPart(Map, org.collectionspace.services.common.service.ObjectPartType) + * + */ protected void updateRefnameForAuthority(DocumentWrapper wrapDoc, String schemaName) throws Exception { DocumentModel docModel = wrapDoc.getWrappedObject(); - String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME); - // CSPACE-3178: - // Temporarily accept client-supplied refName values, rather than always generating such values, - // Remove the surrounding 'if' statement when clients should no longer supply refName values. - if (suppliedRefName == null || suppliedRefName.isEmpty()) { - 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); - } + 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 wrapDoc, String schemaName) { @@ -134,9 +143,7 @@ public abstract class AuthorityDocumentModelHandler if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) { objectProps.remove(AuthorityJAXBSchema.CSID); objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER); - // Enable when clients should no longer supply refName values - // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178 - + objectProps.remove(AuthorityJAXBSchema.REF_NAME); } } } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 8a74fcf9a..a41a6451b 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -233,12 +233,11 @@ public abstract class AuthorityItemDocumentModelHandler * Assumes refName is already correct. Just ensures it is right. * * @param docModel the doc model + * @param newDisplayName the new display name * @throws Exception the exception */ protected String handleItemRefNameUpdateForDisplayName(DocumentModel docModel, String newDisplayName) throws Exception { - //String suppliedRefName = (String) docModel.getProperty(authorityItemCommonSchemaName, - // AuthorityItemJAXBSchema.REF_NAME); RefName.AuthorityItem authItem = RefName.AuthorityItem.parse(oldRefNameOnUpdate); if (authItem == null) { String err = "Authority Item has illegal refName: " + oldRefNameOnUpdate; @@ -266,7 +265,7 @@ public abstract class AuthorityItemDocumentModelHandler } ServiceContext ctx = getServiceContext(); RepositoryClient repoClient = getRepositoryClient(ctx); - // HACK - this should be defined for each handler, as with + // FIXME HACK - this should be defined for each handler, as with // AuthorityResource.getRefPropName() String refNameProp = ServiceBindingUtils.AUTH_REF_PROP; @@ -278,6 +277,10 @@ public abstract class AuthorityItemDocumentModelHandler } } + /** + * If no short identifier was provided in the input payload, + * generate a short identifier from the display name. + */ 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); @@ -288,38 +291,35 @@ public abstract class AuthorityItemDocumentModelHandler // Do nothing on exception. Some vocabulary schemas may not include a short display name. } if (Tools.isEmpty(shortIdentifier)) { - String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName); + String generatedShortIdentifier = + AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName); docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier); } } + /** + * Generate a refName for the authority item from the short identifier + * and display name. + * + * All refNames for authority items are generated. If a client supplies + * a refName, it will be overwritten during create (per this method) + * or discarded during update (per filterReadOnlyPropertiesForPart). + * + * @see #filterReadOnlyPropertiesForPart(Map, org.collectionspace.services.common.service.ObjectPartType) + * + */ protected void updateRefnameForAuthorityItem(DocumentWrapper wrapDoc, String schemaName, String authorityRefBaseName) throws Exception { DocumentModel docModel = wrapDoc.getWrappedObject(); - String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME); - // CSPACE-3178: - // Temporarily accept client-supplied refName values, rather than always generating such values. - // Remove first block and the surrounding 'if' statement when clients should no longer supply refName values. - if (!Tools.isEmpty(suppliedRefName)) { - // Supplied refName must at least be legal - RefName.AuthorityItem item = RefName.AuthorityItem.parse(suppliedRefName); - if (item == null) { - logger.error("Passed refName for authority item not legal: " + suppliedRefName); - suppliedRefName = null; // Clear this and compute a new one below. - } - } - // Recheck, in case we cleared it for being illegal - if (Tools.isEmpty(suppliedRefName)) { - 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("Could not create the refName for this authority term, because the refName for its authority parent was empty."); - } - RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName); - String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString(); - docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName); + 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("Could not create the refName for this authority term, because the refName for its authority parent was empty."); } + RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName); + String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString(); + docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName); } /** @@ -371,9 +371,7 @@ public abstract class AuthorityItemDocumentModelHandler objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY); objectProps.remove(AuthorityItemJAXBSchema.CSID); objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER); - // Enable when clients should no longer supply refName values - // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178 - + objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); } }