mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-5116 - added support for autoRename parameter
This commit is contained in:
@@ -184,7 +184,8 @@ public class FilePlanChildrenRelation implements RelationshipResourceAction.Read
|
|||||||
for (RecordCategory nodeInfo : nodeInfos)
|
for (RecordCategory nodeInfo : nodeInfos)
|
||||||
{
|
{
|
||||||
// Create the node
|
// Create the node
|
||||||
NodeRef newNode = apiUtils.createRMNode(parentNodeRef, nodeInfo.getName(), RECORD_CATEGORY_TYPE, nodeInfo.getProperties(), nodeInfo.getAspectNames());
|
nodeInfo.setNodeType(RECORD_CATEGORY_TYPE);
|
||||||
|
NodeRef newNode = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
|
||||||
FileInfo info = fileFolderService.getFileInfo(newNode);
|
FileInfo info = fileFolderService.getFileInfo(newNode);
|
||||||
result.add(nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, false));
|
result.add(nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, false));
|
||||||
}
|
}
|
||||||
|
@@ -134,6 +134,12 @@ public class FilePlanComponentsApiUtils
|
|||||||
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER,
|
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER,
|
||||||
RecordsManagementModel.TYPE_HOLD_CONTAINER);
|
RecordsManagementModel.TYPE_HOLD_CONTAINER);
|
||||||
|
|
||||||
|
public static final List<QName> TYPES_CAN_USE_AUTORENAME = Arrays.asList(
|
||||||
|
RecordsManagementModel.TYPE_RECORD_CATEGORY,
|
||||||
|
RecordsManagementModel.TYPE_RECORD_FOLDER,
|
||||||
|
RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER,
|
||||||
|
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
|
||||||
|
|
||||||
/** RM Nodes API */
|
/** RM Nodes API */
|
||||||
private Nodes nodes;
|
private Nodes nodes;
|
||||||
private FileFolderService fileFolderService;
|
private FileFolderService fileFolderService;
|
||||||
@@ -598,27 +604,43 @@ public class FilePlanComponentsApiUtils
|
|||||||
* Create an RM node
|
* Create an RM node
|
||||||
*
|
*
|
||||||
* @param parentNodeRef the parent of the node
|
* @param parentNodeRef the parent of the node
|
||||||
* @param name the name of the new node
|
* @param nodeInfo the node infos to create
|
||||||
* @param type the type of the node
|
* @param parameters the object to get the parameters passed into the request
|
||||||
* @param properties properties to set on the new node
|
|
||||||
* @param aspects aspects to set on the new node
|
|
||||||
* @return the new node
|
* @return the new node
|
||||||
*/
|
*/
|
||||||
public NodeRef createRMNode(NodeRef parentNodeRef, String name, String type, Map<String, Object> properties, List<String> aspects)
|
public NodeRef createRMNode(NodeRef parentNodeRef, RMNode nodeInfo, Parameters parameters)
|
||||||
{
|
{
|
||||||
mandatory("parentNodeRef", parentNodeRef);
|
mandatory("parentNodeRef", parentNodeRef);
|
||||||
checkNotBlank(RMNode.PARAM_NAME, name);
|
mandatory("nodeInfo", nodeInfo);
|
||||||
checkNotBlank(RMNode.PARAM_NODE_TYPE, type);
|
mandatory("parameters", parameters);
|
||||||
|
|
||||||
|
String nodeName = nodeInfo.getName();
|
||||||
|
String nodeType = nodeInfo.getNodeType();
|
||||||
|
checkNotBlank(RMNode.PARAM_NAME, nodeName);
|
||||||
|
checkNotBlank(RMNode.PARAM_NODE_TYPE, nodeType);
|
||||||
|
|
||||||
// Create the node
|
// Create the node
|
||||||
NodeRef newNodeRef = null;
|
NodeRef newNodeRef = null;
|
||||||
|
boolean autoRename = Boolean.valueOf(parameters.getParameter(RMNode.PARAM_AUTO_RENAME));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QName typeQName = nodes.createQName(type);
|
QName typeQName = nodes.createQName(nodeType);
|
||||||
newNodeRef = fileFolderService.create(parentNodeRef, name, typeQName).getNodeRef();
|
|
||||||
|
// Existing file/folder name handling
|
||||||
|
if (TYPES_CAN_CREATE.contains(typeQName) && autoRename)
|
||||||
|
{
|
||||||
|
NodeRef existingNode = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
|
||||||
|
if (existingNode != null)
|
||||||
|
{
|
||||||
|
// File already exists, find a unique name
|
||||||
|
nodeName = findUniqueName(parentNodeRef, nodeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newNodeRef = fileFolderService.create(parentNodeRef, nodeName, typeQName).getNodeRef();
|
||||||
|
|
||||||
// Set the provided properties if any
|
// Set the provided properties if any
|
||||||
Map<QName, Serializable> qnameProperties = mapToNodeProperties(properties);
|
Map<QName, Serializable> qnameProperties = mapToNodeProperties(nodeInfo.getProperties());
|
||||||
if (qnameProperties != null)
|
if (qnameProperties != null)
|
||||||
{
|
{
|
||||||
nodeService.addProperties(newNodeRef, qnameProperties);
|
nodeService.addProperties(newNodeRef, qnameProperties);
|
||||||
@@ -628,18 +650,19 @@ public class FilePlanComponentsApiUtils
|
|||||||
if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)
|
if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)
|
||||||
&& dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT))
|
&& dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT))
|
||||||
{
|
{
|
||||||
writeContent(newNodeRef, name, new ByteArrayInputStream("".getBytes()), false);
|
writeContent(newNodeRef, nodeName, new ByteArrayInputStream("".getBytes()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the provided aspects if any
|
// Add the provided aspects if any
|
||||||
if (aspects != null)
|
List<String> aspectNames = nodeInfo.getAspectNames();
|
||||||
|
if (aspectNames != null)
|
||||||
{
|
{
|
||||||
nodes.addCustomAspects(newNodeRef, aspects, ApiNodesModelFactory.EXCLUDED_ASPECTS);
|
nodes.addCustomAspects(newNodeRef, aspectNames, ApiNodesModelFactory.EXCLUDED_ASPECTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidTypeException ex)
|
catch (InvalidTypeException ex)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("The given type:'" + type + "' is invalid '");
|
throw new InvalidArgumentException("The given type:'" + nodeType + "' is invalid '");
|
||||||
}
|
}
|
||||||
|
|
||||||
return newNodeRef;
|
return newNodeRef;
|
||||||
@@ -955,7 +978,45 @@ public class FilePlanComponentsApiUtils
|
|||||||
activityPoster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(), activityInfo.getSiteId(),
|
activityPoster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(), activityInfo.getSiteId(),
|
||||||
activityInfo.getParentNodeRef(), activityInfo.getNodeRef(), activityInfo.getFileName(), Activities.APP_TOOL,
|
activityInfo.getParentNodeRef(), activityInfo.getNodeRef(), activityInfo.getFileName(), Activities.APP_TOOL,
|
||||||
Activities.RESTAPI_CLIENT, activityInfo.getFileInfo());
|
Activities.RESTAPI_CLIENT, activityInfo.getFileInfo());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Creates a unique file name, if the upload component was configured to
|
||||||
|
* find a new unique name for clashing filenames.
|
||||||
|
*
|
||||||
|
* @param parentNodeRef the parent node
|
||||||
|
* @param fileName the original fileName
|
||||||
|
* @return a new file name
|
||||||
|
*/
|
||||||
|
private String findUniqueName(NodeRef parentNodeRef, String fileName)
|
||||||
|
{
|
||||||
|
int counter = 1;
|
||||||
|
String tmpFilename;
|
||||||
|
NodeRef existingFile;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int dotIndex = fileName.lastIndexOf('.');
|
||||||
|
if (dotIndex == 0)
|
||||||
|
{
|
||||||
|
// File didn't have a proper 'name' instead it
|
||||||
|
// had just a suffix and started with a ".", create "1.txt"
|
||||||
|
tmpFilename = counter + fileName;
|
||||||
|
}
|
||||||
|
else if (dotIndex > 0)
|
||||||
|
{
|
||||||
|
// Filename contained ".", create "fileName-1.txt"
|
||||||
|
tmpFilename = fileName.substring(0, dotIndex) + "-" + counter + fileName.substring(dotIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Filename didn't contain a dot at all, create "fileName-1"
|
||||||
|
tmpFilename = fileName + "-" + counter;
|
||||||
|
}
|
||||||
|
existingFile = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, tmpFilename);
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
} while (existingFile != null);
|
||||||
|
|
||||||
|
return tmpFilename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,7 @@ public abstract class RMNode
|
|||||||
public static final String PARAM_PROPERTIES = "properties";
|
public static final String PARAM_PROPERTIES = "properties";
|
||||||
public static final String PARAM_PATH = "path";
|
public static final String PARAM_PATH = "path";
|
||||||
public static final String PARAM_ALLOWABLE_OPERATIONS = "allowableOperations";
|
public static final String PARAM_ALLOWABLE_OPERATIONS = "allowableOperations";
|
||||||
|
public static final String PARAM_AUTO_RENAME = "autoRename";
|
||||||
|
|
||||||
public static final String PARAM_ISPRIMARY = "isPrimary";
|
public static final String PARAM_ISPRIMARY = "isPrimary";
|
||||||
|
|
||||||
|
@@ -174,7 +174,7 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the node
|
// Create the node
|
||||||
NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames());
|
NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
|
||||||
FileInfo info = fileFolderService.getFileInfo(newNode);
|
FileInfo info = fileFolderService.getFileInfo(newNode);
|
||||||
result.add(nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, false));
|
result.add(nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, false));
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
|
|||||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -57,7 +56,6 @@ import org.alfresco.rm.rest.api.impl.FilePlanComponentsApiUtils;
|
|||||||
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
|
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
|
||||||
import org.alfresco.rm.rest.api.model.Record;
|
import org.alfresco.rm.rest.api.model.Record;
|
||||||
import org.alfresco.rm.rest.api.model.RecordFolder;
|
import org.alfresco.rm.rest.api.model.RecordFolder;
|
||||||
import org.alfresco.rm.rest.api.model.UnfiledContainerChild;
|
|
||||||
import org.alfresco.rm.rest.api.model.UploadInfo;
|
import org.alfresco.rm.rest.api.model.UploadInfo;
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
@@ -169,7 +167,7 @@ public class RecordFolderChildrenRelation implements RelationshipResourceAction.
|
|||||||
List<NodeRef> createdNodes = new LinkedList<>();
|
List<NodeRef> createdNodes = new LinkedList<>();
|
||||||
for (Record nodeInfo : nodeInfos)
|
for (Record nodeInfo : nodeInfos)
|
||||||
{
|
{
|
||||||
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames());
|
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
|
||||||
createdNodes.add(newNodeRef);
|
createdNodes.add(newNodeRef);
|
||||||
}
|
}
|
||||||
return createdNodes;
|
return createdNodes;
|
||||||
|
@@ -31,7 +31,6 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
|
|||||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -187,7 +186,7 @@ public class UnfiledContainerChildrenRelation implements RelationshipResourceAct
|
|||||||
List<NodeRef> createdNodes = new LinkedList<>();
|
List<NodeRef> createdNodes = new LinkedList<>();
|
||||||
for (UnfiledContainerChild nodeInfo : nodeInfos)
|
for (UnfiledContainerChild nodeInfo : nodeInfos)
|
||||||
{
|
{
|
||||||
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames());
|
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
|
||||||
createdNodes.add(newNodeRef);
|
createdNodes.add(newNodeRef);
|
||||||
}
|
}
|
||||||
return createdNodes;
|
return createdNodes;
|
||||||
|
@@ -31,7 +31,6 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
|
|||||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -60,7 +59,6 @@ import org.alfresco.rm.rest.api.impl.FilePlanComponentsApiUtils;
|
|||||||
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
|
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
|
||||||
import org.alfresco.rm.rest.api.model.RMNode;
|
import org.alfresco.rm.rest.api.model.RMNode;
|
||||||
import org.alfresco.rm.rest.api.model.UnfiledChild;
|
import org.alfresco.rm.rest.api.model.UnfiledChild;
|
||||||
import org.alfresco.rm.rest.api.model.UnfiledContainerChild;
|
|
||||||
import org.alfresco.rm.rest.api.model.UnfiledRecordFolder;
|
import org.alfresco.rm.rest.api.model.UnfiledRecordFolder;
|
||||||
import org.alfresco.rm.rest.api.model.UnfiledRecordFolderChild;
|
import org.alfresco.rm.rest.api.model.UnfiledRecordFolderChild;
|
||||||
import org.alfresco.rm.rest.api.model.UploadInfo;
|
import org.alfresco.rm.rest.api.model.UploadInfo;
|
||||||
@@ -194,7 +192,7 @@ public class UnfiledRecordFolderChildrenRelation implements RelationshipResource
|
|||||||
nodeParent = parentNodeRef;
|
nodeParent = parentNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeRef newNodeRef = apiUtils.createRMNode(nodeParent, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames());
|
NodeRef newNodeRef = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
|
||||||
createdNodes.add(newNodeRef);
|
createdNodes.add(newNodeRef);
|
||||||
}
|
}
|
||||||
return createdNodes;
|
return createdNodes;
|
||||||
|
Reference in New Issue
Block a user