mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-192: Prevent users from editing custom metadata to use an name already in use
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@38268 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -679,6 +679,7 @@
|
|||||||
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.existsCustomProperty=RM_ALLOW
|
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.getCustomPropertyDefinitions=RM_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.addCustomPropertyDefinition=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.setCustomPropertyDefinitionLabel=RM_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.setCustomPropertyDefinitionConstraint=RM_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.setCustomPropertyDefinitionConstraint=RM_ALLOW
|
||||||
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.removeCustomPropertyDefinitionConstraints=RM_ALLOW
|
org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService.removeCustomPropertyDefinitionConstraints=RM_ALLOW
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
{
|
{
|
||||||
"propId": "${propId}",
|
"propId": "${propId!""}",
|
||||||
"url": "${url}"
|
"url": "${url!""}",
|
||||||
|
"message": "${errorMessage!""}"
|
||||||
}
|
}
|
||||||
</#escape>
|
</#escape>
|
||||||
|
@@ -185,8 +185,17 @@ public interface RecordsManagementAdminService
|
|||||||
* @param newLabel the new value for the label.
|
* @param newLabel the new value for the label.
|
||||||
* @return the propId.
|
* @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.
|
* Sets a new list of values constraint on the custom property definition.
|
||||||
*
|
*
|
||||||
|
@@ -749,6 +749,47 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
|
|||||||
return propId;
|
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)
|
* @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;
|
if (newLabel == null) return propQName;
|
||||||
|
|
||||||
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
|
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
|
||||||
M2Model deserializedModel = readCustomContentModel(modelRef);
|
M2Model deserializedModel = readCustomContentModel(modelRef);
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
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.module.org_alfresco_module_rm.RecordsManagementAdminService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
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 PARAM_CONSTRAINT_REF = "constraintRef";
|
||||||
private static final String PROP_ID = "propId";
|
private static final String PROP_ID = "propId";
|
||||||
private static final String URL = "url";
|
private static final String URL = "url";
|
||||||
|
private static final String MESSAGE = "errorMessage";
|
||||||
|
|
||||||
public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService)
|
public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService)
|
||||||
{
|
{
|
||||||
@@ -63,8 +65,16 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||||
|
try
|
||||||
ftlModel = handlePropertyDefinitionUpdate(req, json);
|
{
|
||||||
|
ftlModel = handlePropertyDefinitionUpdate(req, json);
|
||||||
|
}
|
||||||
|
catch (CustomMetadataException e)
|
||||||
|
{
|
||||||
|
status.setCode(Status.STATUS_BAD_REQUEST);
|
||||||
|
ftlModel = new HashMap<String, Object>();
|
||||||
|
ftlModel.put(MESSAGE, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException iox)
|
catch (IOException iox)
|
||||||
{
|
{
|
||||||
@@ -82,9 +92,10 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies custom properties.
|
* Applies custom properties.
|
||||||
|
* @throws CustomMetadataException
|
||||||
*/
|
*/
|
||||||
protected Map<String, Object> handlePropertyDefinitionUpdate(WebScriptRequest req, JSONObject json)
|
protected Map<String, Object> handlePropertyDefinitionUpdate(WebScriptRequest req, JSONObject json)
|
||||||
throws JSONException
|
throws JSONException, CustomMetadataException
|
||||||
{
|
{
|
||||||
Map<String, Object> result = new HashMap<String, Object>();
|
Map<String, Object> result = new HashMap<String, Object>();
|
||||||
|
|
||||||
@@ -109,8 +120,9 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
|
|||||||
*
|
*
|
||||||
* @param params
|
* @param params
|
||||||
* @return
|
* @return
|
||||||
|
* @throws CustomMetadataException
|
||||||
*/
|
*/
|
||||||
protected QName updatePropertyDefinition(Map<String, Serializable> params)
|
protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException
|
||||||
{
|
{
|
||||||
QName result = null;
|
QName result = null;
|
||||||
|
|
||||||
@@ -127,7 +139,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
|
|||||||
if (params.containsKey(PARAM_LABEL))
|
if (params.containsKey(PARAM_LABEL))
|
||||||
{
|
{
|
||||||
String label = (String)params.get(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))
|
if (params.containsKey(PARAM_CONSTRAINT_REF))
|
||||||
|
Reference in New Issue
Block a user