From 4bd8e7f978475a0e7a8a76d1ec1e488896d209de Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Fri, 26 Sep 2014 12:56:55 +0000 Subject: [PATCH] RM-1641 (Create Relationship Service) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@85790 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-service-context.xml | 55 ++ .../rm-webscript-context.xml | 10 +- .../relationship/Relationship.java | 51 ++ .../relationship/RelationshipDefinition.java | 49 ++ .../RelationshipDefinitionImpl.java | 115 ++++ .../relationship/RelationshipDisplayName.java | 113 ++++ .../relationship/RelationshipImpl.java | 117 ++++ .../relationship/RelationshipService.java | 116 ++++ .../relationship/RelationshipServiceImpl.java | 551 ++++++++++++++++++ .../relationship/RelationshipType.java | 31 + .../script/AbstractRmWebScript.java | 61 +- .../script/BaseCustomPropertyWebScript.java | 2 +- .../CustomPropertyDefinitionDelete.java | 2 +- .../script/CustomPropertyDefinitionPost.java | 72 +-- .../script/CustomPropertyDefinitionPut.java | 4 +- .../script/CustomRefDelete.java | 106 ++-- .../script/CustomRefPost.java | 103 ++-- .../script/CustomReferenceDefinitionBase.java | 61 +- .../script/CustomReferenceDefinitionPost.java | 70 +-- .../script/CustomReferenceDefinitionPut.java | 63 +- .../script/CustomReferenceDefinitionsGet.java | 216 +++---- .../script/CustomRefsGet.java | 181 +++--- .../script/DispositionAbstractBase.java | 12 +- .../DispositionActionDefinitionDelete.java | 2 +- .../DispositionActionDefinitionPost.java | 4 +- .../DispositionActionDefinitionPut.java | 8 +- .../script/DispositionLifecycleGet.java | 50 +- .../slingshot/RecordedVersionConfigGet.java | 2 +- .../slingshot/RecordedVersionConfigPost.java | 2 +- .../org/alfresco/util/WebScriptUtils.java | 7 +- 30 files changed, 1642 insertions(+), 594 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/Relationship.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinition.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDefinitionImpl.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipDisplayName.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipImpl.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipService.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipType.java 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> customReferenceData = getCustomReferenceData(customReferenceDefinitions); + String uniqueName = getRequestParameterValue(req, REF_ID, false); + Set relationshipDefinitions = getRelationshipDefinitons(uniqueName); + List> relationshipDefinitionData = createRelationshipDefinitionData(relationshipDefinitions); Map model = new HashMap(); - model.put(CUSTOM_REFS, customReferenceData); - + model.put(CUSTOM_REFS, relationshipDefinitionData); return model; } /** - * Gets the custom reference definition(s) for the given reference id + * Gets the relationship definition for the unique name. If the unique + * name is blank all relationship definitions will be retrieved * - * @param referenceId The reference id - * @return If the reference id is not blank the custom definition for the given reference id will be returned, - * otherwise all custom definitions will be returned. + * @param uniqueName The unique name of the relationship definition + * @return Relationship definition for the given unique name or all + * relationship definitions if unique name is blank */ - private Map getCustomReferenceDefinitions(String referenceId) + private Set getRelationshipDefinitons(String uniqueName) { - Map customReferenceDefinitions = new HashMap(); + Set relationshipDefinitions = new HashSet(); - if (StringUtils.isNotBlank(referenceId)) + if (isBlank(uniqueName)) { - QName referenceQName = getCustomReferenceQName(referenceId); - AssociationDefinition associationDefinition = getAssosiationDefinitionForCustomReference(referenceQName); - customReferenceDefinitions.put(referenceQName, associationDefinition); + relationshipDefinitions.addAll(getRelationshipService().getRelationshipDefinitions()); } else { - customReferenceDefinitions.putAll(getRmAdminService().getCustomReferenceDefinitions()); - } - - return customReferenceDefinitions; - } - - /** - * Gets the association definition for the given reference QName - * - * @param referenceQName The reference QName - * @return The association definition for the given reference QName - */ - private AssociationDefinition getAssosiationDefinitionForCustomReference(QName referenceQName) - { - AssociationDefinition associationDefinition = getRmAdminService().getCustomReferenceDefinitions().get(referenceQName); - if (associationDefinition == null) - { - StringBuilder msg = new StringBuilder(); - msg.append("Unable to find association definition for the reference: '"); - msg.append(referenceQName.getLocalName()); - msg.append("'."); - String errorMsg = msg.toString(); - - throw new WebScriptException(Status.STATUS_NOT_FOUND, errorMsg); - } - return associationDefinition; - } - - /** - * Gets the custom reference type from the association definition - * - * @param associationDefinition The association definition - * @return Returns the custom reference type which is either parent/child or bidirectional - */ - private CustomReferenceType getCustomReferenceType(AssociationDefinition associationDefinition) - { - CustomReferenceType referenceType; - - if (associationDefinition instanceof ChildAssociationDefinition) - { - referenceType = CustomReferenceType.PARENT_CHILD; - } - else if (associationDefinition instanceof AssociationDefinition) - { - referenceType = CustomReferenceType.BIDIRECTIONAL; - } - else - { - StringBuilder msg = new StringBuilder(); - msg.append("Unsupported association definition: '"); - msg.append(associationDefinition.getName().getLocalName()); - msg.append("'."); - String errorMsg = msg.toString(); - - throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, errorMsg); - } - - return referenceType; - } - - /** - * Gets the custom reference data - * - * @param customReferenceDefinitions The custom reference definitions - * @return Custom reference data - */ - private List> getCustomReferenceData(Map customReferenceDefinitions) - { - List> customReferences = new ArrayList>(); - - for (Entry entry : customReferenceDefinitions.entrySet()) - { - Map customReference = new HashMap(); - AssociationDefinition associationDefinition = entry.getValue(); - CustomReferenceType referenceType = getCustomReferenceType(associationDefinition); - String title = getAssociationDefinitionTitle(associationDefinition); - - if (CustomReferenceType.PARENT_CHILD.equals(referenceType)) + RelationshipDefinition relationshipDefinition = getRelationshipService().getRelationshipDefinition(uniqueName); + if (relationshipDefinition != null) { - String[] sourceAndTarget = getRmAdminService().splitSourceTargetId(title); - customReference.put(SOURCE, sourceAndTarget[0]); - customReference.put(TARGET, sourceAndTarget[1]); + relationshipDefinitions.add(relationshipDefinition); } - else if (CustomReferenceType.BIDIRECTIONAL.equals(referenceType)) + } + + return relationshipDefinitions; + } + + /** + * Creates relationship definition data for the ftl template + * + * @param relationshipDefinitions The relationship definitions + * @return The relationship definition data + */ + private List> createRelationshipDefinitionData(Set relationshipDefinitions) + { + List> relationshipDefinitionData = new ArrayList>(); + + for (RelationshipDefinition relationshipDefinition : relationshipDefinitions) + { + Map data = new HashMap(); + + RelationshipType type = relationshipDefinition.getType(); + RelationshipDisplayName displayName = relationshipDefinition.getDisplayName(); + + if (RelationshipType.BIDIRECTIONAL.equals(type)) { - customReference.put(LABEL, title); + data.put(LABEL, displayName.getLabelText()); + } + else if (RelationshipType.PARENTCHILD.equals(type)) + { + data.put(SOURCE, displayName.getSourceText()); + data.put(TARGET, displayName.getTargetText()); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.append("Unsupported relationship type '") + .append(type) + .append("'."); + + throw new WebScriptException(Status.STATUS_BAD_REQUEST, sb.toString()); } - String referenceId = entry.getKey().getLocalName(); - customReference.put(REF_ID, referenceId); - customReference.put(REFERENCE_TYPE, referenceType.toString()); + data.put(REF_ID, relationshipDefinition.getUniqueName()); + data.put(REFERENCE_TYPE, type.toString().toLowerCase()); - customReferences.add(customReference); + relationshipDefinitionData.add(data); } - return customReferences; - } - - /** - * Gets the association definition title - * - * @param associationDefinition The association definition - * @return The title of the association definition - */ - private String getAssociationDefinitionTitle(AssociationDefinition associationDefinition) - { - String title = associationDefinition.getTitle(getDictionaryService()); - if (StringUtils.isBlank(title)) - { - throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Association definition title is blank."); - } - return title; + return relationshipDefinitionData; } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefsGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefsGet.java index f7f626465e..8edeb9bac3 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefsGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomRefsGet.java @@ -22,21 +22,22 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService; import org.alfresco.module.org_alfresco_module_rm.capability.Capability; import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; -import org.alfresco.service.cmr.dictionary.AssociationDefinition; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.AssociationRef; -import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; +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.RelationshipService; +import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AccessStatus; -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; /** @@ -62,38 +63,46 @@ public class CustomRefsGet extends AbstractRmWebScript private static final String NODE_NAME = "nodeName"; private static final String NODE_TITLE = "nodeTitle"; - /** RM admin service */ - private RecordsManagementAdminService rmAdminService; - - /** Dictionary service */ - private DictionaryService dictionaryService; + /** Relationship service */ + private RelationshipService relationshipService; /** Capability service */ private CapabilityService capabilityService; /** - * Sets the RM admin service - * @param rmAdminService RM admin service + * Gets the relationship service instance + * + * @return The relationship service instance */ - public void setRecordsManagementAdminService(RecordsManagementAdminService rmAdminService) + protected RelationshipService getRelationshipService() { - this.rmAdminService = rmAdminService; + return this.relationshipService; } /** - * Sets the dictionary service + * Sets the relationship service instance * - * @param dictionaryService Dictionary service + * @param relationshipService The relationship service instance */ - public void setDictionaryService(DictionaryService dictionaryService) + public void setRelationshipService(RelationshipService relationshipService) { - this.dictionaryService = dictionaryService; + this.relationshipService = relationshipService; } /** - * Sets the capability service + * Gets the capability service instance * - * @param capabilityService Capability service + * @return The capability service instance + */ + protected CapabilityService getCapabilityService() + { + return this.capabilityService; + } + + /** + * Sets the capability service instance + * + * @param capabilityService Capability service instance */ public void setCapabilityService(CapabilityService capabilityService) { @@ -101,15 +110,17 @@ public class CustomRefsGet extends AbstractRmWebScript } /** - * @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) { Map model = new HashMap(4); NodeRef nodeRef = parseRequestForNodeRef(req); - model.put(NODE_NAME, nodeService.getProperty(nodeRef, ContentModel.PROP_NAME)); - model.put(NODE_TITLE, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE)); + model.put(NODE_NAME, getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME)); + model.put(NODE_TITLE, getNodeService().getProperty(nodeRef, ContentModel.PROP_TITLE)); model.put(CUSTOM_REFS_FROM, getOutwardReferences(nodeRef)); model.put(CUSTOM_REFS_TO, getInwardReferenceData(nodeRef)); return model; @@ -124,13 +135,8 @@ public class CustomRefsGet extends AbstractRmWebScript private List> getOutwardReferences(NodeRef nodeRef) { List> outwardReferenceData = new ArrayList>(); - - List assocsFromThisNode = rmAdminService.getCustomReferencesFrom(nodeRef); - outwardReferenceData.addAll(getBidirectionalReferenceData(assocsFromThisNode)); - - List childAssocs = rmAdminService.getCustomChildReferences(nodeRef); - outwardReferenceData.addAll(getParentChildReferenceData(childAssocs)); - + Set relationships = getRelationshipService().getRelationshipsFrom(nodeRef); + outwardReferenceData.addAll(getRelationshipData(relationships)); return outwardReferenceData; } @@ -143,91 +149,68 @@ public class CustomRefsGet extends AbstractRmWebScript private List> getInwardReferenceData(NodeRef nodeRef) { List> inwardReferenceData = new ArrayList>(); - - List assocsToThisNode = rmAdminService.getCustomReferencesTo(nodeRef); - inwardReferenceData.addAll(getBidirectionalReferenceData(assocsToThisNode)); - - List parentAssocs = rmAdminService.getCustomParentReferences(nodeRef); - inwardReferenceData.addAll(getParentChildReferenceData(parentAssocs)); - + Set relationships = getRelationshipService().getRelationshipsTo(nodeRef); + inwardReferenceData.addAll(getRelationshipData(relationships)); return inwardReferenceData; } /** - * This method goes through the associationRefs specified and constructs a Map - * for each assRef. FTL-relevant data are added to that map. The associationRefs must all be - * parent/child references. + * Creates relationship data for the ftl template * - * @param childAssocs Association references - * @return The reference data + * @param relationships The relationships + * @return The relationship data */ - private List> getParentChildReferenceData(List childAssocs) + private List> getRelationshipData(Set relationships) { - List> referenceData = new ArrayList>(); + List> relationshipData = new ArrayList>(); - for (ChildAssociationRef childAssRef : childAssocs) + for (Relationship relationship : relationships) { - Map data = new HashMap(); + String uniqueName = relationship.getUniqueName(); + RelationshipDefinition relationshipDefinition = getRelationshipService().getRelationshipDefinition(uniqueName); - data.put(CHILD_REF, childAssRef.getChildRef().toString()); - data.put(PARENT_REF, childAssRef.getParentRef().toString()); + NodeRef source = relationship.getSource(); + NodeRef target = relationship.getTarget(); - QName typeQName = childAssRef.getTypeQName(); - AssociationDefinition assDef = rmAdminService.getCustomReferenceDefinitions().get(typeQName); - - if (assDef != null && - hasView(childAssRef.getParentRef()) && - hasView(childAssRef.getChildRef())) + if (relationshipDefinition != null && hasView(source) && hasView(target)) { - String compoundTitle = assDef.getTitle(dictionaryService); + Map data = new HashMap(); - String[] sourceAndTarget = rmAdminService.splitSourceTargetId(compoundTitle); - data.put(SOURCE, sourceAndTarget[0]); - data.put(TARGET, sourceAndTarget[1]); - data.put(REFERENCE_TYPE, CustomReferenceType.PARENT_CHILD.toString()); - data.put(REF_ID, typeQName.getLocalName()); + RelationshipType type = relationshipDefinition.getType(); + RelationshipDisplayName displayName = relationshipDefinition.getDisplayName(); - referenceData.add(data); + if (RelationshipType.BIDIRECTIONAL.equals(type)) + { + data.put(LABEL, displayName.getLabelText()); + data.put(SOURCE_REF, source.toString()); + data.put(TARGET_REF, target.toString()); + } + else if (RelationshipType.PARENTCHILD.equals(type)) + { + data.put(SOURCE, displayName.getSourceText()); + data.put(TARGET, displayName.getTargetText()); + data.put(PARENT_REF, source.toString()); + data.put(CHILD_REF, target.toString()); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.append("Unsupported relationship type '") + .append(type) + .append("'."); + + throw new WebScriptException(Status.STATUS_BAD_REQUEST, sb.toString()); + } + + data.put(REFERENCE_TYPE, type.toString().toLowerCase()); + data.put(REF_ID, uniqueName); + + relationshipData.add(data); } - } - return referenceData; - } - - /** - * This method goes through the associationRefs specified and constructs a Map - * for each assRef. FTL-relevant data are added to that map. The associationRefs must all be - * bidirectional references. - * - * @param assocs Association references - * @return The reference data - */ - private List> getBidirectionalReferenceData(List assocs) - { - List> referenceData = new ArrayList>(); - - for (AssociationRef assRef : assocs) - { - Map data = new HashMap(); - - QName typeQName = assRef.getTypeQName(); - AssociationDefinition assDef = rmAdminService.getCustomReferenceDefinitions().get(typeQName); - - if (assDef != null && - hasView(assRef.getTargetRef()) && - hasView(assRef.getSourceRef())) - { - data.put(LABEL, assDef.getTitle(dictionaryService)); - data.put(REF_ID, typeQName.getLocalName()); - data.put(REFERENCE_TYPE, CustomReferenceType.BIDIRECTIONAL.toString()); - data.put(SOURCE_REF, assRef.getSourceRef().toString()); - data.put(TARGET_REF, assRef.getTargetRef().toString()); - - referenceData.add(data); - } } - return referenceData; + return relationshipData; } /** @@ -240,7 +223,7 @@ public class CustomRefsGet extends AbstractRmWebScript { boolean result = false; - Capability viewRecordCapability = capabilityService.getCapability(ViewRecordsCapability.NAME); + Capability viewRecordCapability = getCapabilityService().getCapability(ViewRecordsCapability.NAME); if (AccessStatus.ALLOWED.equals(viewRecordCapability.hasPermission(nodeRef))) { result = true; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionAbstractBase.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionAbstractBase.java index a73e2a0c67..f3e2e8f771 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionAbstractBase.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionAbstractBase.java @@ -63,11 +63,11 @@ public class DispositionAbstractBase extends AbstractRmWebScript DispositionSchedule schedule = null; if (inherited) { - schedule = this.dispositionService.getDispositionSchedule(nodeRef); + schedule = getDispositionService().getDispositionSchedule(nodeRef); } else { - schedule = dispositionService.getAssociatedDispositionSchedule(nodeRef); + schedule = getDispositionService().getAssociatedDispositionSchedule(nodeRef); } if (schedule == null) { @@ -132,7 +132,7 @@ public class DispositionAbstractBase extends AbstractRmWebScript if (actionDef.getPeriodProperty() != null) { - model.put("periodProperty", actionDef.getPeriodProperty().toPrefixString(this.namespaceService)); + model.put("periodProperty", actionDef.getPeriodProperty().toPrefixString(getNamespaceService())); } if (actionDef.getLocation() != null) @@ -181,7 +181,7 @@ public class DispositionAbstractBase extends AbstractRmWebScript scheduleModel.put("nodeRef", schedule.getNodeRef().toString()); scheduleModel.put("recordLevelDisposition", schedule.isRecordLevelDisposition()); scheduleModel.put("canStepsBeRemoved", - !this.dispositionService.hasDisposableItems(schedule)); + !getDispositionService().hasDisposableItems(schedule)); if (schedule.getDispositionAuthority() != null) { @@ -200,10 +200,10 @@ public class DispositionAbstractBase extends AbstractRmWebScript for (DispositionActionDefinition actionDef : schedule.getDispositionActionDefinitions()) { NodeRef actionDefNodeRef = actionDef.getNodeRef(); - if (nodeService.hasAspect(actionDefNodeRef, RecordsManagementModel.ASPECT_UNPUBLISHED_UPDATE)) + if (getNodeService().hasAspect(actionDefNodeRef, RecordsManagementModel.ASPECT_UNPUBLISHED_UPDATE)) { unpublishedUpdates = true; - publishInProgress = ((Boolean)nodeService.getProperty(actionDefNodeRef, RecordsManagementModel.PROP_PUBLISH_IN_PROGRESS)).booleanValue(); + publishInProgress = ((Boolean) getNodeService().getProperty(actionDefNodeRef, RecordsManagementModel.PROP_PUBLISH_IN_PROGRESS)).booleanValue(); } actions.add(createActionDefModel(actionDef, actionsUrl + "/" + actionDef.getId())); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionDelete.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionDelete.java index e224812af9..3fc0dbb8a6 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionDelete.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionDelete.java @@ -67,7 +67,7 @@ public class DispositionActionDefinitionDelete extends DispositionAbstractBase { if (dispositionActionDefinition.getIndex() >= index) { - dispositionService.removeDispositionActionDefinition(schedule, dispositionActionDefinition); + getDispositionService().removeDispositionActionDefinition(schedule, dispositionActionDefinition); } } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPost.java index fe9a6384b1..dbcaf2569c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPost.java @@ -114,7 +114,7 @@ public class DispositionActionDefinitionPost extends DispositionAbstractBase if (json.has("periodProperty")) { - QName periodProperty = QName.createQName(json.getString("periodProperty"), this.namespaceService); + QName periodProperty = QName.createQName(json.getString("periodProperty"), getNamespaceService()); props.put(RecordsManagementModel.PROP_DISPOSITION_PERIOD_PROPERTY, periodProperty); } @@ -154,6 +154,6 @@ public class DispositionActionDefinitionPost extends DispositionAbstractBase } // add the action definition to the schedule - return this.dispositionService.addDispositionActionDefinition(schedule, props); + return getDispositionService().addDispositionActionDefinition(schedule, props); } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPut.java index 9f2d8ad025..68ba13854b 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPut.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionActionDefinitionPut.java @@ -41,7 +41,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * Implementation for Java backed webscript to update an existing dispositon * action definition. - * + * * @author Gavin Cornwell */ public class DispositionActionDefinitionPut extends DispositionAbstractBase @@ -84,7 +84,7 @@ public class DispositionActionDefinitionPut extends DispositionAbstractBase /** * Updates a dispositionActionDefinition node in the repo. - * + * * @param actionDef The action definition to update * @param json The JSON to use to create the action definition * @param schedule The DispositionSchedule the action definition belongs to @@ -113,7 +113,7 @@ public class DispositionActionDefinitionPut extends DispositionAbstractBase if (json.has("periodProperty")) { - QName periodProperty = QName.createQName(json.getString("periodProperty"), this.namespaceService); + QName periodProperty = QName.createQName(json.getString("periodProperty"), getNamespaceService()); props.put(RecordsManagementModel.PROP_DISPOSITION_PERIOD_PROPERTY, periodProperty); } @@ -153,6 +153,6 @@ public class DispositionActionDefinitionPut extends DispositionAbstractBase } // update the action definition - return this.dispositionService.updateDispositionActionDefinition(actionDef, props); + return getDispositionService().updateDispositionActionDefinition(actionDef, props); } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionLifecycleGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionLifecycleGet.java index 83c5dc4132..70dbb265d5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionLifecycleGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/DispositionLifecycleGet.java @@ -36,23 +36,23 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * Implementation for Java backed webscript to return full details * about a disposition lifecycle (next disposition action). - * + * * @author Gavin Cornwell */ public class DispositionLifecycleGet extends DispositionAbstractBase { PersonService personService; - + /** * Sets the PersonService instance - * + * * @param personService The PersonService instance */ public void setPersonService(PersonService personService) { this.personService = personService; } - + /* * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache) */ @@ -61,9 +61,9 @@ public class DispositionLifecycleGet extends DispositionAbstractBase { // parse the request to retrieve the next action NodeRef nodeRef = parseRequestForNodeRef(req); - + // make sure the node passed in has a next action attached - DispositionAction nextAction = this.dispositionService.getNextDispositionAction(nodeRef); + DispositionAction nextAction = getDispositionService().getNextDispositionAction(nodeRef); if (nextAction == null) { Map nextActionModel = new HashMap(2); @@ -81,84 +81,84 @@ public class DispositionLifecycleGet extends DispositionAbstractBase nextActionModel.put("url", serviceUrl); nextActionModel.put("name", nextAction.getName()); nextActionModel.put("label", nextAction.getLabel()); - nextActionModel.put("eventsEligible", this.dispositionService.isNextDispositionActionEligible(nodeRef)); - + nextActionModel.put("eventsEligible", getDispositionService().isNextDispositionActionEligible(nodeRef)); + if (nextAction.getAsOfDate() != null) { nextActionModel.put("asOf", ISO8601DateFormat.format(nextAction.getAsOfDate())); } - + if (nextAction.getStartedAt() != null) { nextActionModel.put("startedAt", ISO8601DateFormat.format(nextAction.getStartedAt())); } - + String startedBy = nextAction.getStartedBy(); if (startedBy != null) { nextActionModel.put("startedBy", startedBy); addUsersRealName(nextActionModel, startedBy, "startedBy"); } - + if (nextAction.getCompletedAt() != null) { nextActionModel.put("completedAt", ISO8601DateFormat.format(nextAction.getCompletedAt())); } - + String completedBy = nextAction.getCompletedBy(); if (completedBy != null) { nextActionModel.put("completedBy", completedBy); addUsersRealName(nextActionModel, completedBy, "completedBy"); } - + List> events = new ArrayList>(); for (EventCompletionDetails event : nextAction.getEventCompletionDetails()) { events.add(createEventModel(event)); } nextActionModel.put("events", events); - + // create model object with just the schedule data Map model = new HashMap(1); model.put("nextaction", nextActionModel); return model; } } - + /** * Helper to create a model to represent the given event execution. - * + * * @param event The event to create a model for * @return Map representing the model */ protected Map createEventModel(EventCompletionDetails event) { Map model = new HashMap(8); - + model.put("name", event.getEventName()); model.put("label", event.getEventLabel()); model.put("automatic", event.isEventExecutionAutomatic()); model.put("complete", event.isEventComplete()); - + String completedBy = event.getEventCompletedBy(); if (completedBy != null) { model.put("completedBy", completedBy); addUsersRealName(model, completedBy, "completedBy"); } - + if (event.getEventCompletedAt() != null) { model.put("completedAt", ISO8601DateFormat.format(event.getEventCompletedAt())); } - + return model; } - + /** * Adds the given username's first and last name to the given model. - * + * * @param model The model to add the first and last name to * @param userName The username of the user to lookup * @param propertyPrefix The prefix of the property name to use when adding to the model @@ -168,13 +168,13 @@ public class DispositionLifecycleGet extends DispositionAbstractBase NodeRef user = this.personService.getPerson(userName); if (user != null) { - String firstName = (String)this.nodeService.getProperty(user, ContentModel.PROP_FIRSTNAME); + String firstName = (String) getNodeService().getProperty(user, ContentModel.PROP_FIRSTNAME); if (firstName != null) { model.put(propertyPrefix + "FirstName", firstName); } - - String lastName = (String)this.nodeService.getProperty(user, ContentModel.PROP_LASTNAME); + + String lastName = (String) getNodeService().getProperty(user, ContentModel.PROP_LASTNAME); if (lastName != null) { model.put(propertyPrefix + "LastName", lastName); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigGet.java index d84b7f02de..fbb37d6f46 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigGet.java @@ -85,7 +85,7 @@ public class RecordedVersionConfigGet extends AbstractRmWebScript implements Rec private boolean isVersionPolicySelected(RecordableVersionPolicy recordableVersionPolicy, NodeRef nodeRef) { boolean isVersionPolicySelected = false; - String policy = (String) nodeService.getProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY); + String policy = (String) getNodeService().getProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY); if (StringUtils.isNotBlank(policy)) { if (RecordableVersionPolicy.valueOf(policy).equals(recordableVersionPolicy)) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigPost.java index a13cd8cf0b..2cec963e2f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/slingshot/RecordedVersionConfigPost.java @@ -52,7 +52,7 @@ public class RecordedVersionConfigPost extends AbstractRmWebScript implements Re { NodeRef nodeRef = parseRequestForNodeRef(req); RecordableVersionPolicy recordableVersionPolicy = getRecordableVersionPolicy(req); - nodeService.setProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY, recordableVersionPolicy); + getNodeService().setProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY, recordableVersionPolicy); return new HashMap(1); } diff --git a/rm-server/source/java/org/alfresco/util/WebScriptUtils.java b/rm-server/source/java/org/alfresco/util/WebScriptUtils.java index 75271017b0..79806c52ea 100644 --- a/rm-server/source/java/org/alfresco/util/WebScriptUtils.java +++ b/rm-server/source/java/org/alfresco/util/WebScriptUtils.java @@ -227,7 +227,7 @@ public final class WebScriptUtils checkMandatoryJsonParam(jsonObject, key); } - String value; + String value = null; try { @@ -239,7 +239,10 @@ public final class WebScriptUtils } catch (JSONException error) { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get value for the key '" + key + "'.", error); + if (checkValue) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get value for the key '" + key + "'.", error); + } } return value;