RM-735 (DOD Recert: Bugs on the "Edit Custom Metadata" page)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/DODRECERT@50970 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-06-12 16:42:47 +00:00
parent 63b90e1558
commit 3882980ca5
2 changed files with 101 additions and 71 deletions

View File

@@ -1,43 +1,43 @@
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"data": "data":
{ {
"customProperties": "customProperties":
{ {
<#list customProps as prop> <#list customProps as prop>
"${prop.name.toPrefixString()}": "${prop.name.toPrefixString()}":
{ {
"dataType": "<#if prop.dataType??>${prop.dataType.name.toPrefixString()}</#if>", "dataType": "<#if prop.dataType??>${prop.dataType.name.toPrefixString()}</#if>",
"label": "${prop.title!""}", "label": "${prop.title!""}",
"description": "${prop.description!""}", "description": "${prop.description!""}",
"mandatory": ${prop.mandatory?string}, "mandatory": ${prop.mandatory?string},
"multiValued": ${prop.multiValued?string}, "multiValued": ${prop.multiValued?string},
"defaultValue": "${prop.defaultValue!""}", "defaultValue": "${prop.defaultValue!""}",
"protected": ${prop.protected?string}, "protected": ${prop.protected?string},
"propId": "${prop.name.localName}", "propId": "${prop.name.localName}",
"constraintRefs": "constraintRefs":
[ [
<#list prop.constraints as con> <#list prop.constraints as con>
{ {
"name": "${con.constraint.shortName!""}", "name": "${con.constraint.shortName!""}",
"title": "${con.title!""}", "title": "${con.constraint.title!""}",
"type": "${con.constraint.type!""}", "type": "${con.constraint.type!""}",
"parameters": "parameters":
{ {
<#-- Basic implementation. Only providing 2 hardcoded parameters. --> <#-- Basic implementation. Only providing 2 hardcoded parameters. -->
<#assign lov = con.constraint.parameters["allowedValues"]> <#assign lov = con.constraint.parameters["allowedValues"]>
"caseSensitive": ${con.constraint.parameters["caseSensitive"]?string}, "caseSensitive": ${con.constraint.parameters["caseSensitive"]?string},
"listOfValues" : "listOfValues" :
[ [
<#list lov as val>"${val}"<#if val_has_next>,</#if></#list> <#list lov as val>"${val}"<#if val_has_next>,</#if></#list>
] ]
} }
}<#if con_has_next>,</#if> }<#if con_has_next>,</#if>
</#list> </#list>
] ]
}<#if prop_has_next>,</#if> }<#if prop_has_next>,</#if>
</#list> </#list>
} }
} }
} }
</#escape> </#escape>

View File

@@ -22,19 +22,22 @@ import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
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.CustomMetadataException;
import org.alfresco.module.org_alfresco_module_rm.PropertyAlreadyExistsMetadataException;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.extensions.surf.util.ParameterCheck; import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
/** /**
* Implementation for Java backed webscript to update RM custom property definitions * Implementation for Java backed webscript to update RM custom property definitions
@@ -125,6 +128,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException
{ {
QName result = null; QName result = null;
boolean updated = false;
String propId = (String)params.get(PROP_ID); String propId = (String)params.get(PROP_ID);
ParameterCheck.mandatoryString("propId", propId); ParameterCheck.mandatoryString("propId", propId);
@@ -138,29 +142,55 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
if (params.containsKey(PARAM_CONSTRAINT_REF)) if (params.containsKey(PARAM_CONSTRAINT_REF))
{ {
String constraintRef = (String)params.get(PARAM_CONSTRAINT_REF); String constraintRef = (String)params.get(PARAM_CONSTRAINT_REF);
List<ConstraintDefinition> constraints = rmAdminService.getCustomPropertyDefinitions().get(propQName).getConstraints();
if (constraintRef == null) if (constraintRef == null)
{ {
result = rmAdminService.removeCustomPropertyDefinitionConstraints(propQName); result = rmAdminService.removeCustomPropertyDefinitionConstraints(propQName);
} updated = constraints.isEmpty() ? false : true;
else }
{ else
QName constraintRefQName = QName.createQName(constraintRef, namespaceService); {
result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName); boolean exists = false;
} for (ConstraintDefinition constraintDefinition : constraints)
{
if (constraintDefinition.getConstraint().getShortName().equalsIgnoreCase(constraintRef))
{
exists = true;
break;
}
}
if (exists == false)
{
QName constraintRefQName = QName.createQName(constraintRef, namespaceService);
result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName);
updated = true;
}
}
} }
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.updateCustomPropertyDefinitionName(propQName, label); try
{
result = rmAdminService.updateCustomPropertyDefinitionName(propQName, label);
}
catch (PropertyAlreadyExistsMetadataException ex)
{
if (updated == false)
{
String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(namespaceService);
throw new PropertyAlreadyExistsMetadataException(propIdAsString);
}
}
} }
return result; return result;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
protected Map<String, Serializable> getParamsFromUrlAndJson(WebScriptRequest req, JSONObject json) protected Map<String, Serializable> getParamsFromUrlAndJson(WebScriptRequest req, JSONObject json)
throws JSONException throws JSONException
{ {