diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 9720652190..4f1d02dde2 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -679,6 +679,7 @@ org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.existsCustomProperty=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.getCustomPropertyDefinitions=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.addCustomPropertyDefinition=RM_ALLOW + org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.updateCustomPropertyDefinitionName=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.setCustomPropertyDefinitionLabel=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.setCustomPropertyDefinitionConstraint=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.removeCustomPropertyDefinitionConstraints=RM_ALLOW diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.put.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.put.json.ftl index ef996b6013..4df42a5c6a 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.put.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.put.json.ftl @@ -1,6 +1,7 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "propId": "${propId}", - "url": "${url}" + "propId": "${propId!""}", + "url": "${url!""}", + "message": "${errorMessage!""}" } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminService.java index 5b6110f99c..1b0e22380d 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminService.java @@ -185,8 +185,17 @@ public interface RecordsManagementAdminService * @param newLabel the new value for the label. * @return the propId. */ - public QName setCustomPropertyDefinitionLabel(QName propQName, String newLabel); + public QName setCustomPropertyDefinitionLabel(QName propQName, String newLabel) throws PropertyAlreadyExistsMetadataException; + /** + * Update the name and label of the custom property definition. + * @param propQName The qname of the existing property definition + * @param newName THe new name for both the custom property and its label. + * @return + * @throws CustomMetadataException + */ + public QName updateCustomPropertyDefinitionName(QName propQName, String newName) throws CustomMetadataException; + /** * Sets a new list of values constraint on the custom property definition. * diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminServiceImpl.java index 9e8368ca31..0a876180cd 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementAdminServiceImpl.java @@ -749,6 +749,47 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin return propId; } + /** + * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#updateCustomPropertyDefinitionName(org.alfresco.service.namespace.QName, java.lang.String) + */ + public QName updateCustomPropertyDefinitionName(QName propQName, String newName) throws CustomMetadataException + { + ParameterCheck.mandatory("propQName", propQName); + + PropertyDefinition propDefn = dictionaryService.getProperty(propQName); + if (propDefn == null) + { + throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName)); + } + + if (newName == null) return propQName; + + QName newPropQName = getQNameForClientId(newName); + propDefn = dictionaryService.getProperty(newPropQName); + if (propDefn != null) + { + // The requested QName is already in use + String propIdAsString = newPropQName.toPrefixString(namespaceService); + throw new PropertyAlreadyExistsMetadataException(propIdAsString); + } + + NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI()); + M2Model deserializedModel = readCustomContentModel(modelRef); + + M2Property targetProperty = findProperty(propQName, deserializedModel); + targetProperty.setName(newName); + targetProperty.setTitle(newName); + writeCustomContentModel(modelRef, deserializedModel); + + if (logger.isInfoEnabled()) + { + logger.info("setCustomPropertyDefinitionLabel: "+propQName+ + "=" + newName); + } + + return propQName; + } + /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionLabel(org.alfresco.service.namespace.QName, java.lang.String) */ @@ -763,7 +804,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin } if (newLabel == null) return propQName; - + NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI()); M2Model deserializedModel = readCustomContentModel(modelRef); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java index fd4ec16c89..2dc8f1155a 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.alfresco.module.org_alfresco_module_rm.CustomMetadataException; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService; import org.alfresco.service.namespace.QName; import org.springframework.extensions.surf.util.ParameterCheck; @@ -49,6 +50,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript private static final String PARAM_CONSTRAINT_REF = "constraintRef"; private static final String PROP_ID = "propId"; private static final String URL = "url"; + private static final String MESSAGE = "errorMessage"; public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService) { @@ -63,8 +65,16 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript try { json = new JSONObject(new JSONTokener(req.getContent().getContent())); - - ftlModel = handlePropertyDefinitionUpdate(req, json); + try + { + ftlModel = handlePropertyDefinitionUpdate(req, json); + } + catch (CustomMetadataException e) + { + status.setCode(Status.STATUS_BAD_REQUEST); + ftlModel = new HashMap(); + ftlModel.put(MESSAGE, e.getMessage()); + } } catch (IOException iox) { @@ -82,9 +92,10 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript /** * Applies custom properties. + * @throws CustomMetadataException */ protected Map handlePropertyDefinitionUpdate(WebScriptRequest req, JSONObject json) - throws JSONException + throws JSONException, CustomMetadataException { Map result = new HashMap(); @@ -109,8 +120,9 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript * * @param params * @return + * @throws CustomMetadataException */ - protected QName updatePropertyDefinition(Map params) + protected QName updatePropertyDefinition(Map params) throws CustomMetadataException { QName result = null; @@ -127,7 +139,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript if (params.containsKey(PARAM_LABEL)) { String label = (String)params.get(PARAM_LABEL); - result = rmAdminService.setCustomPropertyDefinitionLabel(propQName, label); + result = rmAdminService.updateCustomPropertyDefinitionName(propQName, label); } if (params.containsKey(PARAM_CONSTRAINT_REF))