mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-312: Updated services to return JSON content on errors creating custom metadata
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@38224 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"propId": "${propId}",
|
||||
"url": "${url}"
|
||||
"propId": "${propId!""}",
|
||||
"url": "${url!""}",
|
||||
"message": "${errorMessage!""}"
|
||||
}
|
||||
</#escape>
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
@@ -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).
|
||||
|
@@ -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,11 +663,21 @@ 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)));
|
||||
throw new NotCustomisableMetadataException(aspectName.toPrefixString(namespaceService));
|
||||
}
|
||||
|
||||
// title parameter is currently ignored. Intentionally.
|
||||
@@ -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);
|
||||
|
||||
|
@@ -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,9 +75,17 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
|
||||
try
|
||||
{
|
||||
ftlModel = createPropertyDefinition(req, json);
|
||||
}
|
||||
catch (CustomMetadataException e)
|
||||
{
|
||||
status.setCode(Status.STATUS_BAD_REQUEST);
|
||||
ftlModel = new HashMap<String, Object>();
|
||||
ftlModel.put(MESSAGE, e.getMessage());
|
||||
}
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||
@@ -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<String, Object> createPropertyDefinition(WebScriptRequest req, JSONObject json)
|
||||
throws JSONException
|
||||
throws JSONException, CustomMetadataException
|
||||
{
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
Map<String, Serializable> params = getParamsFromUrlAndJson(req, json);
|
||||
@@ -135,8 +144,9 @@ 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<String, Serializable> params)
|
||||
protected QName createNewPropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException
|
||||
{
|
||||
// Get the customisable type name
|
||||
String customisableElement = (String)params.get(PARAM_ELEMENT);
|
||||
|
Reference in New Issue
Block a user