diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.post.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.post.json.ftl index ef996b6013..abc5de2085 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.post.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/custompropdefinition.post.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/CannotApplyConstraintMetadataException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/CannotApplyConstraintMetadataException.java new file mode 100644 index 0000000000..184e04e4d0 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/CannotApplyConstraintMetadataException.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm; + +import org.alfresco.service.namespace.QName; +import org.springframework.extensions.surf.util.I18NUtil; + +public class CannotApplyConstraintMetadataException extends CustomMetadataException +{ + private static final long serialVersionUID = -6194867814140009959L; + public static final String MSG_CANNOT_APPLY_CONSTRAINT = "rm.admin.cannot-apply-constraint"; + + public CannotApplyConstraintMetadataException(QName lovConstraint, String propIdAsString, QName dataType) + { + super(I18NUtil.getMessage(CannotApplyConstraintMetadataException.MSG_CANNOT_APPLY_CONSTRAINT, lovConstraint, propIdAsString, dataType)); + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/CustomMetadataException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/CustomMetadataException.java new file mode 100644 index 0000000000..d44cb74734 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/CustomMetadataException.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm; + +public abstract class CustomMetadataException extends Exception +{ + private static final long serialVersionUID = -6676112294794381360L; + + public CustomMetadataException(String msg) + { + super(msg); + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/InvalidCustomAspectMetadataException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/InvalidCustomAspectMetadataException.java new file mode 100644 index 0000000000..61dc95b3a2 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/InvalidCustomAspectMetadataException.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm; + +import org.alfresco.service.namespace.QName; +import org.springframework.extensions.surf.util.I18NUtil; + +public class InvalidCustomAspectMetadataException extends CustomMetadataException +{ + private static final long serialVersionUID = -6194867814140009959L; + public static final String MSG_INVALID_CUSTOM_ASPECT = "rm.admin.invalid-custom-aspect"; + + public InvalidCustomAspectMetadataException(QName customAspect, String aspectName) + { + super(I18NUtil.getMessage(MSG_INVALID_CUSTOM_ASPECT, customAspect, aspectName)); + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/NotCustomisableMetadataException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/NotCustomisableMetadataException.java new file mode 100644 index 0000000000..564507a713 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/NotCustomisableMetadataException.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm; + +import org.springframework.extensions.surf.util.I18NUtil; + +public class NotCustomisableMetadataException extends CustomMetadataException +{ + private static final long serialVersionUID = -6194867814140009959L; + public static final String MSG_NOT_CUSTOMISABLE = "rm.admin.not-customisable"; + + public NotCustomisableMetadataException(String aspectName) + { + super(I18NUtil.getMessage(MSG_NOT_CUSTOMISABLE, aspectName)); + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/PropertyAlreadyExistsMetadataException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/PropertyAlreadyExistsMetadataException.java new file mode 100644 index 0000000000..6d8b2526c9 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/PropertyAlreadyExistsMetadataException.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm; + +import org.springframework.extensions.surf.util.I18NUtil; + +public class PropertyAlreadyExistsMetadataException extends CustomMetadataException +{ + private static final long serialVersionUID = -6194867814140009959L; + + public static final String MSG_PROPERTY_ALREADY_EXISTS = "rm.admin.property-already-exists"; + + public PropertyAlreadyExistsMetadataException(String propIdAsString) + { + super(I18NUtil.getMessage(MSG_PROPERTY_ALREADY_EXISTS, propIdAsString)); + } +} 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 cc33374030..5b6110f99c 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 @@ -138,7 +138,7 @@ public interface RecordsManagementAdminService * @return the propId, whether supplied as a parameter or generated. * @see CustomisableRmElement#getCorrespondingAspect() */ - public QName addCustomPropertyDefinition(QName propId, QName typeName, String label, QName dataType, String title, String description); + public QName addCustomPropertyDefinition(QName propId, QName typeName, String label, QName dataType, String title, String description) throws CustomMetadataException; /** * Add custom property definition with one optional constraint reference @@ -166,7 +166,17 @@ public interface RecordsManagementAdminService // TODO propId string (not QName) ? // TODO remove title (since it is ignored) (or remove label to title) - public QName addCustomPropertyDefinition(QName propId, QName typeName, String label, QName dataType, String title, String description, String defaultValue, boolean multiValued, boolean mandatory, boolean isProtected, QName lovConstraintQName); + public QName addCustomPropertyDefinition(QName propId, + QName typeName, + String label, + QName dataType, + String title, + String description, + String defaultValue, + boolean multiValued, + boolean mandatory, + boolean isProtected, + QName lovConstraintQName) throws CustomMetadataException; /** * Update the custom property definition's label (title). 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 ebb89d124f..9e8368ca31 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 @@ -54,10 +54,10 @@ import org.alfresco.repo.dictionary.M2Model; import org.alfresco.repo.dictionary.M2Namespace; import org.alfresco.repo.dictionary.M2Property; import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.ClassPolicyDelegate; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; -import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.Constraint; @@ -100,10 +100,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin /** I18N messages*/ private static final String MSG_SERVICE_NOT_INIT = "rm.admin.service-not-init"; - private static final String MSG_NOT_CUSTOMISABLE = "rm.admin.not-customisable"; - private static final String MSG_INVALID_CUSTOM_ASPECT = "rm.admin.invalid-custom-aspect"; - private static final String MSG_PROPERTY_ALREADY_EXISTS = "rm.admin.property-already-exists"; - private static final String MSG_CANNOT_APPLY_CONSTRAINT = "rm.admin.cannot-apply-constraint"; private static final String MSG_PROP_EXIST = "rm.admin.prop-exist"; private static final String MSG_CUSTOM_PROP_EXIST = "rm.admin.custom-prop-exist"; private static final String MSG_UNKNOWN_ASPECT = "rm.admin.unknown-aspect"; @@ -656,9 +652,10 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin } /** + * @throws CustomMetadataException * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#addCustomPropertyDefinition(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName, java.lang.String, org.alfresco.service.namespace.QName, java.lang.String, java.lang.String) */ - public QName addCustomPropertyDefinition(QName propId, QName aspectName, String label, QName dataType, String title, String description) + public QName addCustomPropertyDefinition(QName propId, QName aspectName, String label, QName dataType, String title, String description) throws CustomMetadataException { return addCustomPropertyDefinition(propId, aspectName, label, dataType, title, description, null, false, false, false, null); } @@ -666,13 +663,23 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#addCustomPropertyDefinition(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName, java.lang.String, org.alfresco.service.namespace.QName, java.lang.String, java.lang.String, java.lang.String, boolean, boolean, boolean, org.alfresco.service.namespace.QName) */ - public QName addCustomPropertyDefinition(QName propId, QName aspectName, String label, QName dataType, String title, String description, String defaultValue, boolean multiValued, boolean mandatory, boolean isProtected, QName lovConstraint) + public QName addCustomPropertyDefinition(QName propId, + QName aspectName, + String label, + QName dataType, + String title, + String description, + String defaultValue, + boolean multiValued, + boolean mandatory, + boolean isProtected, + QName lovConstraint) throws CustomMetadataException { - if (isCustomisable(aspectName) == false) - { - throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_NOT_CUSTOMISABLE, aspectName.toPrefixString(namespaceService))); - } - + if (isCustomisable(aspectName) == false) + { + throw new NotCustomisableMetadataException(aspectName.toPrefixString(namespaceService)); + } + // title parameter is currently ignored. Intentionally. if (propId == null) { @@ -692,14 +699,14 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin if (customPropsAspect == null) { - throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_INVALID_CUSTOM_ASPECT, customAspect, aspectName.toPrefixString(namespaceService))); + throw new InvalidCustomAspectMetadataException(customAspect, aspectName.toPrefixString(namespaceService)); } String propIdAsString = propId.toPrefixString(namespaceService); M2Property customProp = customPropsAspect.getProperty(propIdAsString); if (customProp != null) { - throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROPERTY_ALREADY_EXISTS, propIdAsString)); + throw new PropertyAlreadyExistsMetadataException(propIdAsString); } M2Property newProp = customPropsAspect.createProperty(propIdAsString); @@ -724,7 +731,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin { if (! dataType.equals(DataTypeDefinition.TEXT)) { - throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_APPLY_CONSTRAINT, lovConstraint, propIdAsString, dataType)); + throw new CannotApplyConstraintMetadataException(lovConstraint, propIdAsString, dataType); } String lovConstraintQNameAsString = lovConstraint.toPrefixString(namespaceService); @@ -796,7 +803,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin if (! dataType.equals(DataTypeDefinition.TEXT.toPrefixString(namespaceService))) { - throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_APPLY_CONSTRAINT, newLovConstraint, targetProp.getName(), dataType)); + throw new AlfrescoRuntimeException(I18NUtil.getMessage(CannotApplyConstraintMetadataException.MSG_CANNOT_APPLY_CONSTRAINT, newLovConstraint, targetProp.getName(), dataType)); } String lovConstraintQNameAsString = newLovConstraint.toPrefixString(namespaceService); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java index 8682ad83b2..bf529306db 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java @@ -25,10 +25,10 @@ import java.util.Iterator; import java.util.Map; import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.module.org_alfresco_module_rm.CustomMetadataException; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService; -import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel; -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.service.cmr.dictionary.DictionaryException; import org.alfresco.service.namespace.QName; import org.json.JSONException; import org.json.JSONObject; @@ -59,6 +59,7 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript private static final String PARAM_ELEMENT = "element"; private static final String PARAM_LABEL = "label"; private static final String PROP_ID = "propId"; + private static final String MESSAGE = "errorMessage"; private static final String URL = "url"; public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService) @@ -74,8 +75,16 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript try { json = new JSONObject(new JSONTokener(req.getContent().getContent())); - - ftlModel = createPropertyDefinition(req, json); + try + { + ftlModel = createPropertyDefinition(req, json); + } + catch (CustomMetadataException e) + { + status.setCode(Status.STATUS_BAD_REQUEST); + ftlModel = new HashMap(); + ftlModel.put(MESSAGE, e.getMessage()); + } } catch (IOException iox) { @@ -87,15 +96,15 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je); } - return ftlModel; } /** * Applies custom properties. + * @throws CustomMetadataException */ protected Map createPropertyDefinition(WebScriptRequest req, JSONObject json) - throws JSONException + throws JSONException, CustomMetadataException { Map result = new HashMap(); Map params = getParamsFromUrlAndJson(req, json); @@ -135,11 +144,12 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript * * @param params parameter values * @return {@link QName} qname of the newly created custom property + * @throws CustomMetadataException */ - protected QName createNewPropertyDefinition(Map params) + protected QName createNewPropertyDefinition(Map params) throws CustomMetadataException { // Get the customisable type name - String customisableElement = (String)params.get(PARAM_ELEMENT); + String customisableElement = (String)params.get(PARAM_ELEMENT); QName customisableType = mapToTypeQName(customisableElement); String label = (String)params.get(PARAM_LABEL);