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

@@ -1127,6 +1127,12 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
public QName addCustomAssocDefinition(String label) public QName addCustomAssocDefinition(String label)
{ {
ParameterCheck.mandatoryString("label", label); 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 NodeRef modelRef = getCustomModelRef(""); // defaults to RM_CUSTOM_URI
M2Model deserializedModel = readCustomContentModel(modelRef); M2Model deserializedModel = readCustomContentModel(modelRef);
@@ -1140,12 +1146,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName)); 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); QName generatedQName = this.generateQNameFor(label);
String generatedShortQName = generatedQName.toPrefixString(namespaceService); String generatedShortQName = generatedQName.toPrefixString(namespaceService);
@@ -1178,6 +1178,18 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
return generatedQName; 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 // note: currently RMC custom assocs only
public QName addCustomChildAssocDefinition(String source, String target) public QName addCustomChildAssocDefinition(String source, String target)
@@ -1185,6 +1197,12 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
ParameterCheck.mandatoryString("source", source); ParameterCheck.mandatoryString("source", source);
ParameterCheck.mandatoryString("target", target); 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 NodeRef modelRef = getCustomModelRef(""); // defaults to RM_CUSTOM_URI
M2Model deserializedModel = readCustomContentModel(modelRef); M2Model deserializedModel = readCustomContentModel(modelRef);
@@ -1197,12 +1215,6 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName)); 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); M2ClassAssociation customAssoc = customAssocsAspect.getAssociation(compoundID);
if (customAssoc != null) if (customAssoc != null)
{ {
@@ -1238,13 +1250,23 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
public QName updateCustomChildAssocDefinition(QName refQName, String newSource, String newTarget) public QName updateCustomChildAssocDefinition(QName refQName, String newSource, String newTarget)
{ {
String compoundId = getCompoundIdFor(newSource, 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); return persistUpdatedAssocTitle(refQName, compoundId);
} }
// note: currently RMC custom assocs only // note: currently RMC custom assocs only
public QName updateCustomAssocDefinition(QName refQName, String newLabel) public QName updateCustomAssocDefinition(QName refQName, String newLabel)
{ {
return persistUpdatedAssocTitle(refQName, 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, throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not parse JSON from req.", je); "Could not parse JSON from req.", je);
} }
catch (IllegalArgumentException iae)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
iae.getMessage(), iae);
}
return ftlModel; return ftlModel;
} }

View File

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