RM-528 (It's possible to create relationship with the same name as already exists)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@42983 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2012-10-23 11:33:18 +00:00
parent 8772fd4b2d
commit 8b4990c758
3 changed files with 45 additions and 13 deletions

View File

@@ -1128,6 +1128,12 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
{
ParameterCheck.mandatoryString("label", label);
// If this label is already taken...
if (existsLabel(label))
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, label));
}
NodeRef modelRef = getCustomModelRef(""); // defaults to RM_CUSTOM_URI
M2Model deserializedModel = readCustomContentModel(modelRef);
@@ -1140,12 +1146,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
}
// If this label is already taken...
if (getQNameForClientId(label) != null)
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, label));
}
QName generatedQName = this.generateQNameFor(label);
String generatedShortQName = generatedQName.toPrefixString(namespaceService);
@@ -1179,12 +1179,30 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
return generatedQName;
}
private boolean existsLabel(String label)
{
for (AssociationDefinition associationDefinition : getCustomReferenceDefinitions().values())
{
if (associationDefinition.getTitle().equalsIgnoreCase(label))
{
return true;
}
}
return false;
}
// note: currently RMC custom assocs only
public QName addCustomChildAssocDefinition(String source, String target)
{
ParameterCheck.mandatoryString("source", source);
ParameterCheck.mandatoryString("target", target);
String compoundID = this.getCompoundIdFor(source, target);
if (existsLabel(compoundID))
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, compoundID));
}
NodeRef modelRef = getCustomModelRef(""); // defaults to RM_CUSTOM_URI
M2Model deserializedModel = readCustomContentModel(modelRef);
@@ -1197,12 +1215,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
}
String compoundID = this.getCompoundIdFor(source, target);
if (getQNameForClientId(compoundID) != null)
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, compoundID));
}
M2ClassAssociation customAssoc = customAssocsAspect.getAssociation(compoundID);
if (customAssoc != null)
{
@@ -1238,12 +1250,22 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
public QName updateCustomChildAssocDefinition(QName refQName, String newSource, String newTarget)
{
String compoundId = getCompoundIdFor(newSource, newTarget);
// If this compoundId is already taken...
if (existsLabel(compoundId))
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, compoundId));
}
return persistUpdatedAssocTitle(refQName, compoundId);
}
// note: currently RMC custom assocs only
public QName updateCustomAssocDefinition(QName refQName, String newLabel)
{
// If this label is already taken...
if (existsLabel(newLabel))
{
throw new IllegalArgumentException(I18NUtil.getMessage(MSG_REF_LABEL_IN_USE, newLabel));
}
return persistUpdatedAssocTitle(refQName, newLabel);
}

View File

@@ -85,6 +85,11 @@ public class CustomReferenceDefinitionPost extends AbstractRmWebScript
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not parse JSON from req.", je);
}
catch (IllegalArgumentException iae)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
iae.getMessage(), iae);
}
return ftlModel;
}

View File

@@ -86,6 +86,11 @@ public class CustomReferenceDefinitionPut extends AbstractRmWebScript
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not parse JSON from req.", je);
}
catch (IllegalArgumentException iae)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
iae.getMessage(), iae);
}
return ftlModel;
}