diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
index 139752b62c..b3526fb18b 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
@@ -1523,4 +1523,59 @@
+
+
+
+
+
+
+
+
+
+
+
+ org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${server.transaction.mode.default}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
index 7d0452627e..c3512e1aab 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
@@ -64,14 +64,13 @@
-
+
-
@@ -88,8 +87,7 @@
-
-
+
@@ -97,7 +95,7 @@
-
+
@@ -105,7 +103,7 @@
-
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/Relationship.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/Relationship.java
new file mode 100644
index 0000000000..7265491122
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/Relationship.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * Interface representing the relationship
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public interface Relationship
+{
+ /**
+ * Gets the unique name of the relationship
+ *
+ * @return The unique name of the relationship
+ */
+ String getUniqueName();
+
+ /**
+ * Gets the source of the relationship
+ *
+ * @return The source of the relationship
+ */
+ NodeRef getSource();
+
+ /**
+ * Gets the target of the relationship
+ *
+ * @return The target of the relationship
+ */
+ NodeRef getTarget();
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinition.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinition.java
new file mode 100644
index 0000000000..0a2ad1e943
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinition.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+/**
+ * Interface representing the relationship definition
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public interface RelationshipDefinition
+{
+ /**
+ * Gets the unique name of the relationship definition
+ *
+ * @return The unique name of the relationship definition
+ */
+ String getUniqueName();
+
+ /**
+ * Gets the type of the relationship definition
+ *
+ * @return The type of the relationship definition
+ */
+ RelationshipType getType();
+
+ /**
+ * Gets the display name of the relationship definition
+ *
+ * @return The display name of the relationship definition
+ */
+ RelationshipDisplayName getDisplayName();
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinitionImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinitionImpl.java
new file mode 100644
index 0000000000..3b90dec107
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinitionImpl.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+import static org.alfresco.util.ParameterCheck.mandatoryString;
+
+/**
+ * Relationship definition implementation
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public class RelationshipDefinitionImpl implements RelationshipDefinition
+{
+ /** The unique name of the relationship definition */
+ private String uniqueName;
+
+ /** The type of the relationship definition */
+ private RelationshipType type;
+
+ /** The display name of the relationship definition */
+ private RelationshipDisplayName displayName;
+
+ /**
+ * Constructor for creating a relationship definition
+ *
+ * @param uniqueName The unique name of the relationship definition
+ * @param type The type of the relationship definition
+ * @param displayName The display name of the relationship definition
+ */
+ public RelationshipDefinitionImpl(String uniqueName, RelationshipType type, RelationshipDisplayName displayName)
+ {
+ mandatoryString("uniqueName", uniqueName);
+ mandatory("type", type);
+ mandatory("displayName", displayName);
+
+ setUniqueName(uniqueName);
+ setType(type);
+ setDisplayName(displayName);
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition#getUniqueName()
+ */
+ @Override
+ public String getUniqueName()
+ {
+ return this.uniqueName;
+ }
+
+ /**
+ * Sets the name of the relationship definition
+ *
+ * @param uniqueName The name of the relationship definition
+ */
+ private void setUniqueName(String uniqueName)
+ {
+ this.uniqueName = uniqueName;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition#getType()
+ */
+ @Override
+ public RelationshipType getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * Sets the type of the relationship definition
+ *
+ * @param type The type of the relationship definition
+ */
+ private void setType(RelationshipType type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition#getDisplayName()
+ */
+ @Override
+ public RelationshipDisplayName getDisplayName()
+ {
+ return this.displayName;
+ }
+
+ /**
+ * Sets the display name of the relationship definition
+ *
+ * @param displayName The display name of the relationship definition
+ */
+ private void setDisplayName(RelationshipDisplayName displayName)
+ {
+ this.displayName = displayName;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDisplayName.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDisplayName.java
new file mode 100644
index 0000000000..8d090469c0
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDisplayName.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+/**
+ * POJO representing the relationship display name
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public class RelationshipDisplayName
+{
+ /** The label text for {@link RelationshipType#BIDIRECTIONAL} */
+ private String labelText;
+
+ /** The source text for {@link RelationshipType#PARENTCHILD} */
+ private String sourceText;
+
+ /** The target text for {@link RelationshipType#PARENTCHILD} */
+ private String targetText;
+
+ /**
+ * Constructor for creating the relationship display name
+ *
+ * @param sourceText The source text of the relationship definition
+ * @param targetText The target text of the relationship definition
+ * @param labelText The label text of the relationship definition
+ */
+ public RelationshipDisplayName(String sourceText, String targetText, String labelText)
+ {
+ // Parameters might be blank. No check required.
+
+ setSourceText(sourceText);
+ setTargetText(targetText);
+ setLabelText(labelText);
+ }
+
+ /**
+ * Gets the label text of {@link RelationshipType#BIDIRECTIONAL}
+ *
+ * @return The label text of {@link RelationshipType#BIDIRECTIONAL}
+ */
+ public String getLabelText()
+ {
+ return this.labelText;
+ }
+
+ /**
+ * Sets the label text of {@link RelationshipType#BIDIRECTIONAL}
+ *
+ * @param labelText The label text of {@link RelationshipType#BIDIRECTIONAL}
+ */
+ private void setLabelText(String labelText)
+ {
+ this.labelText = labelText;
+ }
+
+ /**
+ * Gets the source text of {@link RelationshipType#PARENTCHILD}
+ *
+ * @return The source text of {@link RelationshipType#PARENTCHILD}
+ */
+ public String getSourceText()
+ {
+ return this.sourceText;
+ }
+
+ /**
+ * Sets the source text of {@link RelationshipType#PARENTCHILD}
+ *
+ * @param sourceText The source text of {@link RelationshipType#PARENTCHILD}
+ */
+ private void setSourceText(String sourceText)
+ {
+ this.sourceText = sourceText;
+ }
+
+ /**
+ * Gets the target text of {@link RelationshipType#PARENTCHILD}
+ *
+ * @return The target text of {@link RelationshipType#PARENTCHILD}
+ */
+ public String getTargetText()
+ {
+ return this.targetText;
+ }
+
+ /**
+ * Sets the target text of {@link RelationshipType#PARENTCHILD}
+ *
+ * @param targetText The target text of {@link RelationshipType#PARENTCHILD}
+ */
+ private void setTargetText(String targetText)
+ {
+ this.targetText = targetText;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipImpl.java
new file mode 100644
index 0000000000..118f83a197
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipImpl.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+import static org.alfresco.util.ParameterCheck.mandatoryString;
+
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * Relationship implementation
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public class RelationshipImpl implements Relationship
+{
+ /** The unique name of the relationship */
+ private String uniqueName;
+
+ /** The source of the relationship */
+ private NodeRef source;
+
+ /** The target of the relationship */
+ private NodeRef target;
+
+ /**
+ * Constructor for creating a relationship
+ *
+ * @param uniqueName The unique name of the relationship
+ * @param source The source of the relationship
+ * @param target The target of the relationship
+ */
+ public RelationshipImpl(String uniqueName, NodeRef source, NodeRef target)
+ {
+ mandatoryString("uniqueName", uniqueName);
+ mandatory("source", source);
+ mandatory("target", target);
+
+ setUniqueName(uniqueName);
+ setSource(source);
+ setTarget(target);
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.Relationship#getUniqueName()
+ */
+ @Override
+ public String getUniqueName()
+ {
+ return uniqueName;
+ }
+
+ /**
+ * Sets the unique name of the relationship
+ *
+ * @param uniqueName The unique name of the relationship
+ */
+ private void setUniqueName(String uniqueName)
+ {
+ this.uniqueName = uniqueName;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.Relationship#getSource()
+ */
+ @Override
+ public NodeRef getSource()
+ {
+ return source;
+ }
+
+ /**
+ * Sets the source of the relationship
+ *
+ * @param source The source of the relationship
+ */
+ private void setSource(NodeRef source)
+ {
+ this.source = source;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.Relationship#getTarget()
+ */
+ @Override
+ public NodeRef getTarget()
+ {
+ return target;
+ }
+
+ /**
+ * Sets the target of the relationship
+ *
+ * @param target The target of the relationship
+ */
+ private void setTarget(NodeRef target)
+ {
+ this.target = target;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipService.java
new file mode 100644
index 0000000000..ecf674156f
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipService.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+import java.util.Set;
+
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * The relationship service interface
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public interface RelationshipService
+{
+ /**
+ * Gets all the existing relationship definitions
+ *
+ * @return All existing relationship definitions
+ */
+ Set getRelationshipDefinitions();
+
+ /**
+ * Gets the relationship definition for the given unique name
+ *
+ * @param uniqueName The unique name of the relationship definition
+ * @return The relationship definition for the given unique name if it exist, null
otherwise
+ */
+ RelationshipDefinition getRelationshipDefinition(String uniqueName);
+
+ /**
+ * Creates a relationship definition using the display name
+ *
+ * @param displayName The display name of the relationship definition
+ * @return The new relationship definition
+ */
+ RelationshipDefinition createRelationshipDefinition(RelationshipDisplayName displayName);
+
+ /**
+ * Updates an existing relationship definition
+ *
+ * @param uniqueName The unique name of the relationship definition
+ * @param displayName The display name of the relationship definition
+ * @return The updated relationship definition
+ */
+ RelationshipDefinition updateReleationshipDefinition(String uniqueName, RelationshipDisplayName displayName);
+
+ /**
+ * Removes a relationship definition
+ *
+ * @param uniqueName The unique name of the relationship definition
+ * @return true
if the relationship definition was removed successfully, false
otherwise
+ */
+ boolean removeRelationshipDefinition(String uniqueName);
+
+ /**
+ * Checks if a relationship exists or not
+ *
+ * @param uniqueName The unique name of the relationship definition
+ * @return true
if the relationship definition exists, false
otherwise
+ */
+ boolean existsRelationshipDefinition(String uniqueName);
+
+ /**
+ * Gets all the relationships that come out from the given node reference
+ *
+ * @param nodeRef The node reference
+ * @return All relationships that come out from the given node reference
+ */
+ Set getRelationshipsFrom(NodeRef nodeRef);
+
+ /**
+ * Gets all the relationships that go in to the given node reference
+ *
+ * @param nodeRef The node reference
+ * @return All relationships that go in to the given node reference
+ */
+ Set getRelationshipsTo(NodeRef nodeRef);
+
+ /**
+ * Adds a relationship from the given node source
+ * to the give node target
with the given unique name
+ *
+ * @param uniqueName The unique name of the relationship
+ * @param source The node reference which the relationship come from
+ * @param target The node reference which the relationship go to
+ */
+ void addRelationship(String uniqueName, NodeRef source, NodeRef target);
+
+ /**
+ * Removes the relationship from the given node source
+ * to the given node target
with the given unique name
+ *
+ * @param uniqueName The unique name of the relationship
+ * @param source The node reference which the relationship come from
+ * @param target The node reference which the relationship go to
+ */
+ void removeRelationship(String uniqueName, NodeRef source, NodeRef target);
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java
new file mode 100644
index 0000000000..fbdb0dc2e2
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java
@@ -0,0 +1,551 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+import static org.alfresco.util.ParameterCheck.mandatoryString;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.alfresco.error.AlfrescoRuntimeException;
+import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
+import org.alfresco.service.cmr.dictionary.AssociationDefinition;
+import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
+import org.alfresco.service.cmr.dictionary.DictionaryService;
+import org.alfresco.service.cmr.repository.AssociationRef;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.namespace.NamespacePrefixResolver;
+import org.alfresco.service.namespace.QName;
+
+/**
+ * The relationship service implementation
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public class RelationshipServiceImpl implements RelationshipService
+{
+ /** Records management admin service */
+ private RecordsManagementAdminService recordsManagementAdminService;
+
+ /** Dictionary service */
+ private DictionaryService dictionaryService;
+
+ /** Namespace prefix resolver */
+ private NamespacePrefixResolver namespacePrefixResolver;
+
+ /**
+ * Gets the records management admin service instance
+ *
+ * @return The records management admin service instance
+ */
+ protected RecordsManagementAdminService getRecordsManagementAdminService()
+ {
+ return this.recordsManagementAdminService;
+ }
+
+ /**
+ * Sets the records management admin service instance
+ *
+ * @param recordsManagementAdminService The records management admin service instance
+ */
+ public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
+ {
+ this.recordsManagementAdminService = recordsManagementAdminService;
+ }
+
+ /**
+ * Gets the dictionary service instance
+ *
+ * @return The dictionary service instance
+ */
+ protected DictionaryService getDictionaryService()
+ {
+ return this.dictionaryService;
+ }
+
+ /**
+ * Sets the dictionary service instance
+ *
+ * @param dictionaryService The dictionary service instance
+ */
+ public void setDictionaryService(DictionaryService dictionaryService)
+ {
+ this.dictionaryService = dictionaryService;
+ }
+
+ /**
+ * Gets the namespace prefix resolver instance
+ *
+ * @return The namespace prefix resolver instance
+ */
+ protected NamespacePrefixResolver getNamespacePrefixResolver()
+ {
+ return this.namespacePrefixResolver;
+ }
+
+ /**
+ * Sets the namespace prefix resolver instance
+ *
+ * @param namespacePrefixResolver The namespace prefix resolver instance
+ */
+ public void setNamespacePrefixResolver(NamespacePrefixResolver namespacePrefixResolver)
+ {
+ this.namespacePrefixResolver = namespacePrefixResolver;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipDefinitions()
+ */
+ @Override
+ public Set getRelationshipDefinitions()
+ {
+ Set relationshipDefinitions = new HashSet();
+
+ Map customReferenceDefinitions = getRecordsManagementAdminService().getCustomReferenceDefinitions();
+ for (Map.Entry customReferenceDefinitionEntry : customReferenceDefinitions.entrySet())
+ {
+ AssociationDefinition associationDefinition = customReferenceDefinitionEntry.getValue();
+ RelationshipDefinition relationshipDefinition = createRelationshipDefinition(associationDefinition);
+ if (relationshipDefinition != null)
+ {
+ relationshipDefinitions.add(relationshipDefinition);
+ }
+ }
+
+ return relationshipDefinitions;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipDefinition(java.lang.String)
+ */
+ @Override
+ public RelationshipDefinition getRelationshipDefinition(String uniqueName)
+ {
+ mandatoryString("uniqueName", uniqueName);
+
+ RelationshipDefinition relationshipDefinition = null;
+
+ QName associationDefinitionQName = getRecordsManagementAdminService().getQNameForClientId(uniqueName);
+ if (associationDefinitionQName != null)
+ {
+ AssociationDefinition associationDefinition = getRecordsManagementAdminService().getCustomReferenceDefinitions().get(associationDefinitionQName);
+ relationshipDefinition = createRelationshipDefinition(associationDefinition);
+ }
+
+ return relationshipDefinition;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#createRelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName)
+ */
+ @Override
+ public RelationshipDefinition createRelationshipDefinition(RelationshipDisplayName displayName)
+ {
+ mandatory("displayName", displayName);
+
+ RelationshipType type = determineRelationshipTypeFromDisplayName(displayName);
+
+ QName relationshipDefinitionQName;
+
+ switch (type)
+ {
+ case BIDIRECTIONAL:
+
+ String labelText = displayName.getLabelText();
+ relationshipDefinitionQName = getRecordsManagementAdminService().addCustomAssocDefinition(labelText);
+ break;
+
+ case PARENTCHILD:
+
+ String sourceText = displayName.getSourceText();
+ String targetText = displayName.getTargetText();
+ relationshipDefinitionQName = getRecordsManagementAdminService().addCustomChildAssocDefinition(sourceText, targetText);
+ break;
+
+ default:
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("Unsupported relationship type: '")
+ .append(type.toString())
+ .append("'.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ String uniqueName = relationshipDefinitionQName.getLocalName();
+
+ return new RelationshipDefinitionImpl(uniqueName, type, displayName);
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#updateReleationshipDefinition(java.lang.String)
+ */
+ @Override
+ public RelationshipDefinition updateReleationshipDefinition(String uniqueName, RelationshipDisplayName displayName)
+ {
+ mandatoryString("uniqueName", uniqueName);
+
+ QName associationDefinitionQName = getRecordsManagementAdminService().getQNameForClientId(uniqueName);
+ if (associationDefinitionQName == null)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("The qualified name for '")
+ .append(uniqueName)
+ .append("' was not found.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ Map customReferenceDefinitions = getRecordsManagementAdminService().getCustomReferenceDefinitions();
+ AssociationDefinition associationDefinition = customReferenceDefinitions.get(associationDefinitionQName);
+ RelationshipType type = getRelationshipType(associationDefinition);
+ QName updatedAssociationDefinitionQName;
+
+ switch (type)
+ {
+ case BIDIRECTIONAL:
+
+ String labelText = displayName.getLabelText();
+
+ if (isBlank(labelText))
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Label text '")
+ .append(labelText)
+ .append(" cannot be blank.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ updatedAssociationDefinitionQName = getRecordsManagementAdminService().updateCustomAssocDefinition(associationDefinitionQName, labelText);
+ break;
+
+ case PARENTCHILD:
+
+ String sourceText = displayName.getSourceText();
+ String targetText = displayName.getTargetText();
+
+ if (isBlank(sourceText) || isBlank(targetText))
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Neither source text '")
+ .append(sourceText)
+ .append("' nor target text '")
+ .append(targetText)
+ .append(" can be blank.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ updatedAssociationDefinitionQName = getRecordsManagementAdminService().updateCustomChildAssocDefinition(associationDefinitionQName, sourceText, targetText);
+ break;
+
+ default:
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("Unsupported relationship type: '")
+ .append(type.toString())
+ .append("'.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ customReferenceDefinitions = getRecordsManagementAdminService().getCustomReferenceDefinitions();
+ AssociationDefinition updatedAssociationDefinition = customReferenceDefinitions.get(updatedAssociationDefinitionQName);
+ RelationshipDefinition updatedRelationshipDefinition = createRelationshipDefinition(updatedAssociationDefinition);
+ if (updatedRelationshipDefinition == null)
+ {
+ throw new AlfrescoRuntimeException("The relationship definition was not updated successfully.");
+ }
+
+ return updatedRelationshipDefinition;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#removeRelationshipDefinition(java.lang.String)
+ */
+ @Override
+ public boolean removeRelationshipDefinition(String uniqueName)
+ {
+ mandatoryString("uniqueName", uniqueName);
+
+ // FIXME!!! There is no method on the backend for this. Must be implemented.
+ throw new UnsupportedOperationException("Not implemented yet.");
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#existsRelationshipDefinition(java.lang.String)
+ */
+ @Override
+ public boolean existsRelationshipDefinition(String uniqueName)
+ {
+ mandatoryString("uniqueName", uniqueName);
+
+ boolean exists = false;
+
+ QName associationDefinitionQName = getRecordsManagementAdminService().getQNameForClientId(uniqueName);
+ if (associationDefinitionQName != null)
+ {
+ Map customReferenceDefinitions = getRecordsManagementAdminService().getCustomReferenceDefinitions();
+ exists = customReferenceDefinitions.containsKey(associationDefinitionQName);
+ }
+
+ return exists;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipsFrom(org.alfresco.service.cmr.repository.NodeRef)
+ */
+ @Override
+ public Set getRelationshipsFrom(NodeRef nodeRef)
+ {
+ mandatory("nodeRef", nodeRef);
+
+ Set relationships = new HashSet();
+
+ List customReferencesFrom = getRecordsManagementAdminService().getCustomReferencesFrom(nodeRef);
+ relationships.addAll(generateRelationshipFromAssociationRef(customReferencesFrom));
+
+ List customChildReferences = getRecordsManagementAdminService().getCustomChildReferences(nodeRef);
+ relationships.addAll(generateRelationshipFromParentChildAssociationRef(customChildReferences));
+
+ return relationships;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipsTo(org.alfresco.service.cmr.repository.NodeRef)
+ */
+ @Override
+ public Set getRelationshipsTo(NodeRef nodeRef)
+ {
+ mandatory("nodeRef", nodeRef);
+
+ Set relationships = new HashSet();
+
+ List customReferencesTo = getRecordsManagementAdminService().getCustomReferencesTo(nodeRef);
+ relationships.addAll(generateRelationshipFromAssociationRef(customReferencesTo));
+
+ List customParentReferences = getRecordsManagementAdminService().getCustomParentReferences(nodeRef);
+ relationships.addAll(generateRelationshipFromParentChildAssociationRef(customParentReferences));
+
+ return relationships;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#addRelationship(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
+ */
+ @Override
+ public void addRelationship(String uniqueName, NodeRef source, NodeRef target)
+ {
+ mandatoryString("uniqueName", uniqueName);
+ mandatory("source", source);
+ mandatory("target", target);
+
+ QName associationDefinitionQName = getRecordsManagementAdminService().getQNameForClientId(uniqueName);
+ getRecordsManagementAdminService().addCustomReference(source, target, associationDefinitionQName);
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#removeRelationship(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
+ */
+ @Override
+ public void removeRelationship(String uniqueName, NodeRef source, NodeRef target)
+ {
+ mandatoryString("uniqueName", uniqueName);
+ mandatory("source", source);
+ mandatory("target", target);
+
+ QName associationDefinitionQName = getRecordsManagementAdminService().getQNameForClientId(uniqueName);
+ getRecordsManagementAdminService().removeCustomReference(source, target, associationDefinitionQName);
+ }
+
+ /**
+ * Creates the relationship definition from the association definition
+ *
+ * @param associationDefinition The association definition
+ * @return The relationship definition if associationDefinition
exists, null
otherwise
+ */
+ private RelationshipDefinition createRelationshipDefinition(AssociationDefinition associationDefinition)
+ {
+ RelationshipDefinition relationshipDefinition = null;
+
+ if (associationDefinition != null)
+ {
+ String uniqueName = associationDefinition.getName().getLocalName();
+
+ RelationshipType type = getRelationshipType(associationDefinition);
+
+ String title = associationDefinition.getTitle(getDictionaryService());
+ RelationshipDisplayName displayName = getRelationshipDisplayName(type, title);
+
+ relationshipDefinition = new RelationshipDefinitionImpl(uniqueName, type, displayName);
+ }
+
+ return relationshipDefinition;
+ }
+
+ /**
+ * Gets the relationship type from the association definition
+ *
+ * @param associationDefinition The association definition
+ * @return The type of the relationship definition
+ */
+ private RelationshipType getRelationshipType(AssociationDefinition associationDefinition)
+ {
+ RelationshipType type;
+
+ if (associationDefinition instanceof ChildAssociationDefinition)
+ {
+ type = RelationshipType.PARENTCHILD;
+ }
+ else if (associationDefinition instanceof AssociationDefinition)
+ {
+ type = RelationshipType.BIDIRECTIONAL;
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Unsupported association definition: '")
+ .append(associationDefinition.getName().getLocalName())
+ .append("'.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ return type;
+ }
+
+ /**
+ * Gets the relationship display name of the relationship definition
+ *
+ * @param type The type of the relationship definition
+ * @param title The title of the association definition
+ * @return The relationship display name of the relationship definition
+ */
+ private RelationshipDisplayName getRelationshipDisplayName(RelationshipType type, String title)
+ {
+ String sourceText = null;
+ String targetText = null;
+ String labelText = null;
+
+ switch (type)
+ {
+ case BIDIRECTIONAL:
+
+ labelText = title;
+ break;
+
+ case PARENTCHILD:
+
+ String[] sourceAndTarget = getRecordsManagementAdminService().splitSourceTargetId(title);
+ sourceText = sourceAndTarget[0];
+ targetText = sourceAndTarget[1];
+ break;
+
+ default:
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("Unsupported relationship type: '")
+ .append(type.toString())
+ .append("'.");
+ throw new AlfrescoRuntimeException(sb.toString());
+ }
+
+ return new RelationshipDisplayName(sourceText, targetText, labelText);
+ }
+
+ /**
+ * Generates relationships from the given association references
+ *
+ * @param associationRefs Association references
+ * @return Relationships generated from the given association references
+ */
+ private Set generateRelationshipFromAssociationRef(List associationRefs)
+ {
+ Set relationships = new HashSet();
+
+ for (AssociationRef associationRef : associationRefs)
+ {
+ String uniqueName = associationRef.getTypeQName().getLocalName();
+ NodeRef from = associationRef.getSourceRef();
+ NodeRef to = associationRef.getTargetRef();
+ relationships.add(new RelationshipImpl(uniqueName, from, to));
+ }
+
+ return relationships;
+ }
+
+ /**
+ * Generates relationships from the given child association references
+ *
+ * @param childAssociationRefs Child association references
+ * @return Relationships generated from the given child association references
+ */
+ private Set generateRelationshipFromParentChildAssociationRef(List childAssociationRefs)
+ {
+ Set relationships = new HashSet();
+
+ for (ChildAssociationRef childAssociationRef : childAssociationRefs)
+ {
+ String uniqueName = childAssociationRef.getQName().getLocalName();
+ NodeRef from = childAssociationRef.getParentRef();
+ NodeRef to = childAssociationRef.getChildRef();
+ relationships.add(new RelationshipImpl(uniqueName, from, to));
+ }
+
+ return relationships;
+ }
+
+ /**
+ * Determines the relationship type from the display name
+ *
+ * @param displayName The display name of the relationship
+ * @return The relationship type from the display name
+ */
+ private RelationshipType determineRelationshipTypeFromDisplayName(RelationshipDisplayName displayName)
+ {
+ RelationshipType relationshipType;
+
+ String labelText = displayName.getLabelText();
+ String sourceText = displayName.getSourceText();
+ String targetText = displayName.getTargetText();
+
+ String errorMsg = "Relationship type could not be determined from the display name. It is neither biderectional nor parent/child relationship";
+
+ if (isBlank(labelText))
+ {
+ if (isBlank(sourceText) || isBlank(targetText))
+ {
+ throw new AlfrescoRuntimeException(errorMsg);
+ }
+ relationshipType = RelationshipType.PARENTCHILD;
+ }
+ else
+ {
+ if (isNotBlank(sourceText) || isNotBlank(targetText))
+ {
+ throw new AlfrescoRuntimeException(errorMsg);
+ }
+ relationshipType = RelationshipType.BIDIRECTIONAL;
+ }
+
+ return relationshipType;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipType.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipType.java
new file mode 100644
index 0000000000..acc78cc977
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipType.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2005-2014 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 .
+ */
+package org.alfresco.module.org_alfresco_module_rm.relationship;
+
+/**
+ * Enum representing the relationship types
+ *
+ * @author Tuna Aksoy
+ * @since 2.3
+ */
+public enum RelationshipType
+{
+ BIDIRECTIONAL,
+ PARENTCHILD;
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/AbstractRmWebScript.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/AbstractRmWebScript.java
index dc484da543..a6c0ff4c79 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/AbstractRmWebScript.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/AbstractRmWebScript.java
@@ -34,7 +34,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Abstract base class for all RM webscript classes.
- * Includes util methods for processing the webscript request.
+ * Includes utility methods for processing the webscript request.
*
* @author Neil McErlean
* @author Tuna Aksoy
@@ -43,21 +43,34 @@ public abstract class AbstractRmWebScript extends DeclarativeWebScript
{
/** Constants */
protected static final String PATH_SEPARATOR = "/";
+ protected static final String STORE_TYPE = "store_type";
+ protected static final String STORE_ID = "store_id";
+ protected static final String ID = "id";
protected static final String SUCCESS = "success";
/** Disposition service */
- protected DispositionService dispositionService;
+ private DispositionService dispositionService;
/** Namespace service */
- protected NamespaceService namespaceService;
+ private NamespaceService namespaceService;
/** Node service */
- protected NodeService nodeService;
+ private NodeService nodeService;
/**
- * Sets the disposition service
+ * Gets the disposition service instance
*
- * @param dispositionService The disposition serviceS
+ * @return The disposition service instance
+ */
+ protected DispositionService getDispositionService()
+ {
+ return this.dispositionService;
+ }
+
+ /**
+ * Sets the disposition service instance
+ *
+ * @param dispositionService The disposition service instance
*/
public void setDispositionService(DispositionService dispositionService)
{
@@ -65,9 +78,19 @@ public abstract class AbstractRmWebScript extends DeclarativeWebScript
}
/**
- * Sets the namespace service
+ * Gets the namespace service instance
*
- * @param namespaceService The namespace service
+ * @return The namespace service instance
+ */
+ protected NamespaceService getNamespaceService()
+ {
+ return this.namespaceService;
+ }
+
+ /**
+ * Sets the namespace service instance
+ *
+ * @param namespaceService The namespace service instance
*/
public void setNamespaceService(NamespaceService namespaceService)
{
@@ -75,9 +98,19 @@ public abstract class AbstractRmWebScript extends DeclarativeWebScript
}
/**
- * Sets the node service
+ * Gets the node service instance
*
- * @param nodeService The node service
+ * @return The node service instance
+ */
+ protected NodeService getNodeService()
+ {
+ return this.nodeService;
+ }
+
+ /**
+ * Sets the node service instance
+ *
+ * @param nodeService The node service instance
*/
public void setNodeService(NodeService nodeService)
{
@@ -97,14 +130,14 @@ public abstract class AbstractRmWebScript extends DeclarativeWebScript
// get the parameters that represent the NodeRef, we know they are present
// otherwise this webscript would not have matched
Map templateVars = getTemplateVars(req);
- String storeType = templateVars.get("store_type");
- String storeId = templateVars.get("store_id");
- String nodeId = templateVars.get("id");
+ String storeType = templateVars.get(STORE_TYPE);
+ String storeId = templateVars.get(STORE_ID);
+ String nodeId = templateVars.get(ID);
// create the NodeRef and ensure it is valid
NodeRef nodeRef = new NodeRef(storeType, storeId, nodeId);
- if (!nodeService.exists(nodeRef))
+ if (!getNodeService().exists(nodeRef))
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: '" +
nodeRef.toString() + "'.");
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BaseCustomPropertyWebScript.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BaseCustomPropertyWebScript.java
index cd501c6083..0463060cb8 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BaseCustomPropertyWebScript.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/BaseCustomPropertyWebScript.java
@@ -58,7 +58,7 @@ public class BaseCustomPropertyWebScript extends AbstractRmWebScript
else
{
// Try and convert the string to a qname
- return QName.createQName(elementName, namespaceService);
+ return QName.createQName(elementName, getNamespaceService());
}
}
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionDelete.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionDelete.java
index 2dacf7910c..df9754b380 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionDelete.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionDelete.java
@@ -106,7 +106,7 @@ public class CustomPropertyDefinitionDelete extends AbstractRmWebScript
rmAdminService.removeCustomPropertyDefinition(propQName);
- result.put("propertyqname", propQName.toPrefixString(namespaceService));
+ result.put("propertyqname", propQName.toPrefixString(getNamespaceService()));
return result;
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java
index 1d9d10b735..97ef604047 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPost.java
@@ -41,7 +41,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to add RM custom property definitions
* to the custom model.
- *
+ *
* @author Neil McErlean
*/
public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
@@ -101,22 +101,22 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
/**
* Applies custom properties.
- * @throws CustomMetadataException
+ * @throws CustomMetadataException
*/
protected Map createPropertyDefinition(WebScriptRequest req, JSONObject json)
throws JSONException, CustomMetadataException
{
Map result = new HashMap();
Map params = getParamsFromUrlAndJson(req, json);
-
+
QName propertyQName = createNewPropertyDefinition(params);
String localName = propertyQName.getLocalName();
-
+
result.put(PROP_ID, localName);
-
+
String urlResult = req.getServicePath() + "/" + propertyQName.getLocalName();
result.put(URL, urlResult);
-
+
return result;
}
@@ -127,33 +127,33 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
Map params;
params = new HashMap();
params.put(PARAM_ELEMENT, req.getParameter(PARAM_ELEMENT));
-
+
for (Iterator iter = json.keys(); iter.hasNext(); )
{
String nextKeyString = (String)iter.next();
String nextValueString = json.getString(nextKeyString);
-
+
params.put(nextKeyString, nextValueString);
}
-
+
return params;
}
/**
* Create a property definition based on the parameter values provided
- *
+ *
* @param params parameter values
* @return {@link QName} qname of the newly created custom property
- * @throws CustomMetadataException
+ * @throws CustomMetadataException
*/
protected QName createNewPropertyDefinition(Map params) throws CustomMetadataException
{
- // Get the customisable type name
+ // Get the customisable type name
String customisableElement = (String)params.get(PARAM_ELEMENT);
QName customisableType = mapToTypeQName(customisableElement);
-
+
String label = URLDecoder.decode((String)params.get(PARAM_LABEL));
-
+
//According to the wireframes, type here can only be date|text|number
Serializable serializableParam = params.get(PARAM_DATATYPE);
QName type = null;
@@ -161,7 +161,7 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
{
if (serializableParam instanceof String)
{
- type = QName.createQName((String)serializableParam, namespaceService);
+ type = QName.createQName((String)serializableParam, getNamespaceService());
}
else if (serializableParam instanceof QName)
{
@@ -172,41 +172,41 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
throw new AlfrescoRuntimeException("Unexpected type of dataType param: "+serializableParam+" (expected String or QName)");
}
}
-
+
// The title is actually generated, so this parameter will be ignored
// by the RMAdminService
String title = (String)params.get(PARAM_TITLE);
String description = (String)params.get(PARAM_DESCRIPTION);
String defaultValue = (String)params.get(PARAM_DEFAULT_VALUE);
-
+
boolean mandatory = false;
serializableParam = params.get(PARAM_MANDATORY);
if (serializableParam != null)
{
mandatory = Boolean.valueOf(serializableParam.toString());
}
-
+
boolean isProtected = false;
serializableParam = params.get(PARAM_PROTECTED);
if (serializableParam != null)
{
isProtected = Boolean.valueOf(serializableParam.toString());
}
-
+
boolean multiValued = false;
serializableParam = params.get(PARAM_MULTI_VALUED);
if (serializableParam != null)
{
multiValued = Boolean.valueOf(serializableParam.toString());
}
-
+
serializableParam = params.get(PARAM_CONSTRAINT_REF);
QName constraintRef = null;
if (serializableParam != null)
{
if (serializableParam instanceof String)
{
- constraintRef = QName.createQName((String)serializableParam, namespaceService);
+ constraintRef = QName.createQName((String)serializableParam, getNamespaceService());
}
else if (serializableParam instanceof QName)
{
@@ -217,29 +217,29 @@ public class CustomPropertyDefinitionPost extends BaseCustomPropertyWebScript
throw new AlfrescoRuntimeException("Unexpected type of constraintRef param: "+serializableParam+" (expected String or QName)");
}
}
-
+
// if propId is specified, use it.
QName proposedQName = null;
String propId = (String)params.get(PROP_ID);
if (propId != null)
{
- proposedQName = QName.createQName(RecordsManagementCustomModel.RM_CUSTOM_PREFIX, propId, namespaceService);
+ proposedQName = QName.createQName(RecordsManagementCustomModel.RM_CUSTOM_PREFIX, propId, getNamespaceService());
}
-
+
return rmAdminService.addCustomPropertyDefinition(
- proposedQName,
- customisableType,
- label,
+ proposedQName,
+ customisableType,
+ label,
type,
- title,
- description,
- defaultValue,
- multiValued,
- mandatory,
- isProtected,
+ title,
+ description,
+ defaultValue,
+ multiValued,
+ mandatory,
+ isProtected,
constraintRef);
}
-
-
-
+
+
+
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java
index 5e38684cd4..c48fd97aa1 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomPropertyDefinitionPut.java
@@ -163,7 +163,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
}
if (!exists)
{
- QName constraintRefQName = QName.createQName(constraintRef, namespaceService);
+ QName constraintRefQName = QName.createQName(constraintRef, getNamespaceService());
result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName);
updated = true;
}
@@ -181,7 +181,7 @@ public class CustomPropertyDefinitionPut extends BaseCustomPropertyWebScript
{
if (!updated)
{
- String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(namespaceService);
+ String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(getNamespaceService());
throw new PropertyAlreadyExistsMetadataException(propIdAsString);
}
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefDelete.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefDelete.java
index a49ab808f0..f4fc9d8a69 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefDelete.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefDelete.java
@@ -23,18 +23,17 @@ import static org.alfresco.util.WebScriptUtils.getRequestParameterValue;
import java.util.HashMap;
import java.util.Map;
-import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
-import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
- * Implementation for Java backed webscript to remove RM custom reference instances from a node.
+ * Implementation for Java backed webscript to remove RM custom relationship from a node.
*
* @author Neil McErlean
* @author Tuna Aksoy
@@ -45,28 +44,47 @@ public class CustomRefDelete extends AbstractRmWebScript
private static final String REF_ID = "refId";
private static final String ST = "st";
private static final String SI = "si";
- private static final String ID = "id";
- /** RM admin service */
- private RecordsManagementAdminService rmAdminService;
+ /** Relationship service */
+ private RelationshipService relationshipService;
/** Rule service */
private RuleService ruleService;
/**
- * Sets the RM admin service
+ * Gets the relationship service instance
*
- * @param rmAdminService RM admin service
+ * @return The relationship service instance
*/
- public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService)
+ protected RelationshipService getRelationshipService()
{
- this.rmAdminService = rmAdminService;
+ return this.relationshipService;
}
/**
- * Sets the rule service
+ * Sets the relationship service instance
*
- * @param ruleService Rule service
+ * @param relationshipService The relationship service instance
+ */
+ public void setRelationshipService(RelationshipService relationshipService)
+ {
+ this.relationshipService = relationshipService;
+ }
+
+ /**
+ * Returns the rule service instance
+ *
+ * @return The rule service instance
+ */
+ protected RuleService getRuleService()
+ {
+ return this.ruleService;
+ }
+
+ /**
+ * Sets the rule service instance
+ *
+ * @param ruleService The rule service instance
*/
public void setRuleService(RuleService ruleService)
{
@@ -74,83 +92,61 @@ public class CustomRefDelete extends AbstractRmWebScript
}
/**
- * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
+ * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
+ * org.springframework.extensions.webscripts.Status,
+ * org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map model = new HashMap(1);
-
try
{
- ruleService.disableRuleType(RuleType.OUTBOUND);
- removeCustomReferenceInstance(req);
+ getRuleService().disableRuleType(RuleType.OUTBOUND);
+ removeCustomRelationship(req);
model.put(SUCCESS, true);
}
finally
{
- ruleService.enableRuleType(RuleType.OUTBOUND);
+ getRuleService().enableRuleType(RuleType.OUTBOUND);
}
-
return model;
}
/**
- * Removes custom reference instance
+ * Removes a custom relationship
*
* @param req The webscript request
*/
- private void removeCustomReferenceInstance(WebScriptRequest req)
+ private void removeCustomRelationship(WebScriptRequest req)
{
- NodeRef fromNode = parseRequestForNodeRef(req);
- NodeRef toNodeRef = getToNode(req);
- QName associationQName = getAssociationQName(req);
+ String uniqueName = getRequestParameterValue(req, REF_ID);
+ NodeRef source = parseRequestForNodeRef(req);
+ NodeRef target = getTargetNode(req);
- rmAdminService.removeCustomReference(fromNode, toNodeRef, associationQName);
- rmAdminService.removeCustomReference(toNodeRef, fromNode, associationQName);
+ getRelationshipService().removeRelationship(uniqueName, source, target);
+ getRelationshipService().removeRelationship(uniqueName, target, source);
}
/**
- * Gets the node from which the reference will be removed
+ * Gets the target node
*
* @param req The webscript request
- * @return The node from which the reference will be removed
+ * @return The target node
*/
- private NodeRef getToNode(WebScriptRequest req)
+ private NodeRef getTargetNode(WebScriptRequest req)
{
- // Get the toNode from the URL query string.
String storeType = req.getParameter(ST);
String storeId = req.getParameter(SI);
String nodeId = req.getParameter(ID);
- // Create the NodeRef and ensure it is valid
- NodeRef toNode = new NodeRef(storeType, storeId, nodeId);
- if (!nodeService.exists(toNode))
+ NodeRef targetNode = new NodeRef(storeType, storeId, nodeId);
+ if (!getNodeService().exists(targetNode))
{
- throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unable to find toNode: '" +
- toNode.toString() + "'.");
+ throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unable to find the target node: '" +
+ targetNode.toString() + "'.");
}
- return toNode;
- }
-
- /**
- * Gets the QName of the association
- *
- * @param req The webscript request
- * @return QName of the association
- */
- private QName getAssociationQName(WebScriptRequest req)
- {
- String clientsRefId = getRequestParameterValue(req, REF_ID);
- QName qName = rmAdminService.getQNameForClientId(clientsRefId);
-
- if (qName == null)
- {
- throw new WebScriptException(Status.STATUS_NOT_FOUND,
- "Unable to find reference type: '" + clientsRefId + "'.");
- }
-
- return qName;
+ return targetNode;
}
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefPost.java
index 633c850402..b65fac1c01 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefPost.java
@@ -24,11 +24,10 @@ import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
import java.util.HashMap;
import java.util.Map;
-import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
-import org.alfresco.service.namespace.QName;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
@@ -36,7 +35,7 @@ import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
- * Implementation for Java backed webscript to add RM custom reference instances to a node.
+ * Implementation for Java backed webscript to add RM custom relationship to a node.
*
* @author Neil McErlean
* @author Tuna Aksoy
@@ -47,26 +46,46 @@ public class CustomRefPost extends AbstractRmWebScript
private static final String TO_NODE = "toNode";
private static final String REF_ID = "refId";
- /** RM admin service */
- private RecordsManagementAdminService rmAdminService;
+ /** Relationship service */
+ private RelationshipService relationshipService;
/** Rule service */
private RuleService ruleService;
/**
- * Sets the RM admin service
+ * Gets the relationship service instance
*
- * @param rmAdminService RM admin service
+ * @return The relationship service instance
*/
- public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService)
+ protected RelationshipService getRelationshipService()
{
- this.rmAdminService = rmAdminService;
+ return this.relationshipService;
}
/**
- * Sets the rule service
+ * Sets the relationship service instance
*
- * @param ruleService Rule service
+ * @param relationshipService The relationship service instance
+ */
+ public void setRelationshipService(RelationshipService relationshipService)
+ {
+ this.relationshipService = relationshipService;
+ }
+
+ /**
+ * Gets the rule service instance
+ *
+ * @return The rule service instance
+ */
+ protected RuleService getRuleService()
+ {
+ return this.ruleService;
+ }
+
+ /**
+ * Sets the rule service instance
+ *
+ * @param ruleService The rule service instance
*/
public void setRuleService(RuleService ruleService)
{
@@ -74,79 +93,59 @@ public class CustomRefPost extends AbstractRmWebScript
}
/**
- * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
+ * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
+ * org.springframework.extensions.webscripts.Status,
+ * org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map model = new HashMap(1);
-
try
{
- ruleService.disableRuleType(RuleType.INBOUND);
- addCustomReferenceInstance(req);
+ getRuleService().disableRuleType(RuleType.INBOUND);
+ addCustomRelationship(req);
model.put(SUCCESS, true);
}
finally
{
- ruleService.enableRuleType(RuleType.INBOUND);
+ getRuleService().enableRuleType(RuleType.INBOUND);
}
-
return model;
}
/**
- * Adds a custom reference instance
+ * Adds a custom relationship
*
* @param req The webscript request
*/
- protected void addCustomReferenceInstance(WebScriptRequest req)
+ protected void addCustomRelationship(WebScriptRequest req)
{
- NodeRef fromNode = parseRequestForNodeRef(req);
JSONObject json = getRequestContentAsJsonObject(req);
- NodeRef toNode = getToNode(json);
- QName associationQName = getAssociationQName(json);
+ String uniqueName = getStringValueFromJSONObject(json, REF_ID);
+ NodeRef target = getTargetNode(json);
+ NodeRef source = parseRequestForNodeRef(req);
- rmAdminService.addCustomReference(fromNode, toNode, associationQName);
+ getRelationshipService().addRelationship(uniqueName, source, target);
}
/**
- * Gets the node to which the reference will be added
+ * Gets the target node
*
* @param json Request content as json object
- * @return The node to which the reference will be added
+ * @return The target node
*/
- private NodeRef getToNode(JSONObject json)
+ private NodeRef getTargetNode(JSONObject json)
{
- String toNodeString = getStringValueFromJSONObject(json, TO_NODE);
- NodeRef toNode = new NodeRef(toNodeString);
+ String targetNodeString = getStringValueFromJSONObject(json, TO_NODE);
+ NodeRef targetNode = new NodeRef(targetNodeString);
- if (!nodeService.exists(toNode))
+ if (!getNodeService().exists(targetNode))
{
- throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unable to find toNode: '" +
- toNode.toString() + "'.");
+ throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unable to find the target node: '" +
+ targetNode.toString() + "'.");
}
- return toNode;
- }
-
- /**
- * Gets the QName of the association
- *
- * @param json Request content as json object
- * @return QName of the association
- */
- private QName getAssociationQName(JSONObject json)
- {
- String clientsRefId = getStringValueFromJSONObject(json, REF_ID);
- QName qName = rmAdminService.getQNameForClientId(clientsRefId);
-
- if (qName == null)
- {
- throw new WebScriptException(Status.STATUS_NOT_FOUND,
- "Unable to find reference type: '" + clientsRefId + "'.");
- }
-
- return qName;
+ return targetNode;
}
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
index a3eef06e9c..5db73136ee 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
@@ -20,11 +20,9 @@ package org.alfresco.module.org_alfresco_module_rm.script;
import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
-import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
-import org.alfresco.service.namespace.QName;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService;
import org.json.JSONObject;
-import org.springframework.extensions.webscripts.Status;
-import org.springframework.extensions.webscripts.WebScriptException;
/**
* Base class for custom reference definition classes
@@ -42,62 +40,41 @@ public class CustomReferenceDefinitionBase extends AbstractRmWebScript
protected static final String TARGET = "target";
protected static final String CUSTOM_REFS = "customRefs";
protected static final String URL = "url";
- protected static final String SUCCESS = "success";
- /** Records Management Admin Service */
- private RecordsManagementAdminService rmAdminService;
+ /** Relationship service */
+ private RelationshipService relationshipService;
/**
- * Sets the records management admin service
+ * Gets the relationship service instance
*
- * @param rmAdminService The records management admin service
+ * @return The relationship service instance
*/
- public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService)
+ protected RelationshipService getRelationshipService()
{
- this.rmAdminService = rmAdminService;
+ return this.relationshipService;
}
/**
- * Gets the records management admin service instance
+ * Sets the relationship service instance
*
- * @return The records management admin service instance
+ * @param relationshipService The relationship service instance
*/
- protected RecordsManagementAdminService getRmAdminService()
+ public void setRelationshipService(RelationshipService relationshipService)
{
- return this.rmAdminService;
+ this.relationshipService = relationshipService;
}
/**
- * Gets the QName for the given custom reference id
- *
- * @param referenceId The reference id
- * @return The QName for the given custom reference id
- */
- protected QName getCustomReferenceQName(String referenceId)
- {
- QName customReferenceQName = getRmAdminService().getQNameForClientId(referenceId);
- if (customReferenceQName == null)
- {
- StringBuilder msg = new StringBuilder();
- msg.append("Unable to find QName for the reference: '");
- msg.append(referenceId);
- msg.append("'.");
- String errorMsg = msg.toString();
-
- throw new WebScriptException(Status.STATUS_NOT_FOUND, errorMsg);
- }
- return customReferenceQName;
- }
-
- /**
- * Gets the custom reference type from the json object
+ * Creates the relationship display name from request content
*
* @param requestContent The request content as json object
- * @return Returns the custom reference type which is either parent/child or bidirectional
+ * @return The relationship display name
*/
- protected CustomReferenceType getCustomReferenceType(JSONObject requestContent)
+ protected RelationshipDisplayName createDisplayName(JSONObject requestContent)
{
- String referenceType = getStringValueFromJSONObject(requestContent, REFERENCE_TYPE);
- return CustomReferenceType.getEnumFromString(referenceType);
+ String sourceText = getStringValueFromJSONObject(requestContent, SOURCE, false, false);
+ String targetText = getStringValueFromJSONObject(requestContent, TARGET, false, false);
+ String labelText = getStringValueFromJSONObject(requestContent, LABEL, false, false);
+ return new RelationshipDisplayName(sourceText, targetText, labelText);
}
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
index f2f65f9a6e..0d86218f48 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
@@ -19,16 +19,15 @@
package org.alfresco.module.org_alfresco_module_rm.script;
import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject;
-import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
import java.util.HashMap;
import java.util.Map;
-import org.alfresco.service.namespace.QName;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
-import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
@@ -41,69 +40,40 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class CustomReferenceDefinitionPost extends CustomReferenceDefinitionBase
{
/**
- * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
+ * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
+ * org.springframework.extensions.webscripts.Status,
+ * org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
JSONObject requestContent = getRequestContentAsJsonObject(req);
- CustomReferenceType customReferenceType = getCustomReferenceType(requestContent);
- QName customReference = addCustomReference(requestContent, customReferenceType);
+ RelationshipDisplayName displayName = createDisplayName(requestContent);
+ RelationshipDefinition relationshipDefinition = getRelationshipService().createRelationshipDefinition(displayName);
Map model = new HashMap();
String servicePath = req.getServicePath();
- Map customReferenceData = getCustomReferenceData(customReferenceType, customReference, servicePath);
- model.putAll(customReferenceData);
+ Map customRelationshipData = createRelationshipDefinitionData(relationshipDefinition, servicePath);
+ model.putAll(customRelationshipData);
return model;
}
/**
- * Adds custom reference to the model
+ * Creates relationship definition data for the ftl template
*
- * @param requestContent The request content as json object
- * @param customReferenceType The custom reference type
- * @return Returns the {@link QName} of the new custom reference
- */
- private QName addCustomReference(JSONObject requestContent, CustomReferenceType customReferenceType)
- {
- QName referenceQName;
-
- if (CustomReferenceType.PARENT_CHILD.equals(customReferenceType))
- {
- String source = getStringValueFromJSONObject(requestContent, SOURCE);
- String target = getStringValueFromJSONObject(requestContent, TARGET);
- referenceQName = getRmAdminService().addCustomChildAssocDefinition(source, target);
- }
- else if (CustomReferenceType.BIDIRECTIONAL.equals(customReferenceType))
- {
- String label = getStringValueFromJSONObject(requestContent, LABEL);
- referenceQName = getRmAdminService().addCustomAssocDefinition(label);
- }
- else
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unsupported custom reference type.");
- }
-
- return referenceQName;
- }
-
- /**
- * Gets the custom reference data
- *
- * @param customReferenceType The custom reference type
- * @param customReference The qualified name of the custom reference
+ * @param relationshipDefinition The relationship definition
* @param servicePath The service path
- * @return The custom reference data
+ * @return The relationship definition data
*/
- private Map getCustomReferenceData(CustomReferenceType customReferenceType, QName customReference, String servicePath)
+ private Map createRelationshipDefinitionData(RelationshipDefinition relationshipDefinition, String servicePath)
{
- Map result = new HashMap();
- String qnameLocalName = customReference.getLocalName();
- result.put(REFERENCE_TYPE, customReferenceType.toString());
- result.put(REF_ID, qnameLocalName);
- result.put(URL, servicePath + PATH_SEPARATOR + qnameLocalName);
- result.put(SUCCESS, Boolean.TRUE);
- return result;
+ Map relationshipDefinitionData = new HashMap(4);
+ String uniqueName = relationshipDefinition.getUniqueName();
+ relationshipDefinitionData.put(REFERENCE_TYPE, relationshipDefinition.getType().toString());
+ relationshipDefinitionData.put(REF_ID, uniqueName);
+ relationshipDefinitionData.put(URL, servicePath + PATH_SEPARATOR + uniqueName);
+ relationshipDefinitionData.put(SUCCESS, Boolean.TRUE);
+ return relationshipDefinitionData;
}
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
index 323d5e3ebc..9c0f49b974 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
@@ -20,16 +20,14 @@ package org.alfresco.module.org_alfresco_module_rm.script;
import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject;
import static org.alfresco.util.WebScriptUtils.getRequestParameterValue;
-import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
import java.util.HashMap;
import java.util.Map;
-import org.alfresco.service.namespace.QName;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
-import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
@@ -42,65 +40,40 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/
public class CustomReferenceDefinitionPut extends CustomReferenceDefinitionBase
{
- /**
- * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
+ /**
+ * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
+ * org.springframework.extensions.webscripts.Status,
+ * org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
+ String uniqueName = getRequestParameterValue(req, REF_ID);
JSONObject requestContent = getRequestContentAsJsonObject(req);
- String referenceId = getRequestParameterValue(req, REF_ID);
- updateCustomReference(requestContent, referenceId);
+ RelationshipDisplayName displayName = createDisplayName(requestContent);
+ getRelationshipService().updateReleationshipDefinition(uniqueName, displayName);
Map model = new HashMap();
String servicePath = req.getServicePath();
- Map customReferenceData = getCustomReferenceData(servicePath, referenceId);
+ Map customReferenceData = createRelationshipDefinitionData(servicePath, uniqueName);
model.putAll(customReferenceData);
return model;
}
/**
- * Updates the custom reference
- *
- * @param requestContent The request content as json object
- * @param referenceId The reference id
- */
- private void updateCustomReference(JSONObject requestContent, String referenceId)
- {
- QName referenceQName = getCustomReferenceQName(referenceId);
- CustomReferenceType customReferenceType = getCustomReferenceType(requestContent);
-
- if (CustomReferenceType.PARENT_CHILD.equals(customReferenceType))
- {
- String source = getStringValueFromJSONObject(requestContent, SOURCE);
- String target = getStringValueFromJSONObject(requestContent, TARGET);
- getRmAdminService().updateCustomChildAssocDefinition(referenceQName, source, target);
- }
- else if (CustomReferenceType.BIDIRECTIONAL.equals(customReferenceType))
- {
- String label = getStringValueFromJSONObject(requestContent, LABEL);
- getRmAdminService().updateCustomAssocDefinition(referenceQName, label);
- }
- else
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unsupported custom reference type.");
- }
- }
-
- /**
- * Gets the custom reference data
+ * Creates relationship definition data for the ftl template
*
* @param servicePath The service path
- * @param String The reference id
- * @return The custom reference data
+ * @param String The relationship unique name
+ * @return The relationship definition data
*/
- private Map getCustomReferenceData(String servicePath, String referenceId)
+ private Map createRelationshipDefinitionData(String servicePath, String uniqueName)
{
- Map result = new HashMap();
- result.put(URL, servicePath);
- result.put(REF_ID, referenceId);
- result.put(SUCCESS, Boolean.TRUE);
- return result;
+ Map relationshipDefinitionData = new HashMap(3);
+ relationshipDefinitionData.put(URL, servicePath);
+ relationshipDefinitionData.put(REF_ID, uniqueName);
+ relationshipDefinitionData.put(SUCCESS, Boolean.TRUE);
+ return relationshipDefinitionData;
}
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
index e33520547a..3c922c7532 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
@@ -19,18 +19,18 @@
package org.alfresco.module.org_alfresco_module_rm.script;
import static org.alfresco.util.WebScriptUtils.getRequestParameterValue;
+import static org.apache.commons.lang3.StringUtils.isBlank;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Set;
-import org.alfresco.service.cmr.dictionary.AssociationDefinition;
-import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
-import org.alfresco.service.cmr.dictionary.DictionaryService;
-import org.alfresco.service.namespace.QName;
-import org.apache.commons.lang.StringUtils;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName;
+import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
@@ -44,175 +44,93 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/
public class CustomReferenceDefinitionsGet extends CustomReferenceDefinitionBase
{
- /** Dictionary Service */
- private DictionaryService dictionaryService;
-
/**
- * Sets the dictionary service
- *
- * @param dictionaryService The dictionary service
- */
- public void setDictionaryService(DictionaryService dictionaryService)
- {
- this.dictionaryService = dictionaryService;
- }
-
- /**
- * Gets the dictionary service instance
- *
- * @return The dictionary service instance
- */
- protected DictionaryService getDictionaryService()
- {
- return this.dictionaryService;
- }
-
- /**
- * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
+ * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
+ * org.springframework.extensions.webscripts.Status,
+ * org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
- String referenceId = getRequestParameterValue(req, REF_ID, false);
- Map customReferenceDefinitions = getCustomReferenceDefinitions(referenceId);
- List