Merge 'master' into feature/RM-5012_recordIdentifier

This commit is contained in:
Ana Bozianu
2017-05-18 11:36:43 +03:00
35 changed files with 475 additions and 98 deletions

View File

@@ -39,22 +39,23 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.node.getchildren.FilterProp;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.impl.Util;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.rm.rest.api.impl.ApiNodesModelFactory;
import org.alfresco.rm.rest.api.impl.FilePlanComponentsApiUtils;
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
import org.alfresco.rm.rest.api.model.FilePlan;
import org.alfresco.rm.rest.api.model.Record;
import org.alfresco.rm.rest.api.model.RecordCategory;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
@@ -63,6 +64,7 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ParameterCheck;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.extensions.webscripts.servlet.FormData;
/**
* File plan children relation
@@ -72,7 +74,9 @@ import org.springframework.beans.factory.InitializingBean;
*/
@RelationshipResource(name="categories", entityResource = FilePlanEntityResource.class, title = "Category children of file plan")
public class FilePlanChildrenRelation implements RelationshipResourceAction.Read<RecordCategory>,
RelationshipResourceAction.Create<RecordCategory>, InitializingBean
RelationshipResourceAction.Create<RecordCategory>,
MultiPartRelationshipResourceAction.Create<RecordCategory>,
InitializingBean
{
/** Record category type */
public static final String RECORD_CATEGORY_TYPE = "rma:recordCategory";
@@ -198,8 +202,8 @@ public class FilePlanChildrenRelation implements RelationshipResourceAction.Read
for (RecordCategory nodeInfo : nodeInfos)
{
// Create the node
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo.getName(), RECORD_CATEGORY_TYPE,
nodeInfo.getProperties(), nodeInfo.getAspectNames());
nodeInfo.setNodeType(RECORD_CATEGORY_TYPE);
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
createdNodes.add(newNodeRef);
}
return createdNodes;
@@ -218,4 +222,13 @@ public class FilePlanChildrenRelation implements RelationshipResourceAction.Read
return result;
}
/**
* @see org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction.Create#create(java.lang.String, org.springframework.extensions.webscripts.servlet.FormData, org.alfresco.rest.framework.resource.parameters.Parameters, org.alfresco.rest.framework.webscripts.WithResponse)
*/
@Override
public RecordCategory create(String entityResourceId, FormData formData, Parameters parameters, WithResponse withResponse)
{
throw new IntegrityException("Uploading records into file plan root is not allowed.", null);
}
}

View File

@@ -55,8 +55,9 @@ import org.springframework.beans.factory.InitializingBean;
* @since 2.6
*/
@EntityResource(name = "file-plans", title = "File plans")
public class FilePlanEntityResource
implements EntityResourceAction.ReadById<FilePlan>, EntityResourceAction.Update<FilePlan>, InitializingBean
public class FilePlanEntityResource implements EntityResourceAction.ReadById<FilePlan>,
EntityResourceAction.Update<FilePlan>,
InitializingBean
{
private FilePlanComponentsApiUtils apiUtils;

View File

@@ -136,6 +136,12 @@ public class FilePlanComponentsApiUtils
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER,
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 */
private Nodes nodes;
private FileFolderService fileFolderService;
@@ -600,27 +606,43 @@ public class FilePlanComponentsApiUtils
* Create an RM node
*
* @param parentNodeRef the parent of the node
* @param name the name of the new node
* @param type the type of the node
* @param properties properties to set on the new node
* @param aspects aspects to set on the new node
* @param nodeInfo the node infos to create
* @param parameters the object to get the parameters passed into the request
* @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);
checkNotBlank(RMNode.PARAM_NAME, name);
checkNotBlank(RMNode.PARAM_NODE_TYPE, type);
mandatory("nodeInfo", nodeInfo);
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
NodeRef newNodeRef = null;
boolean autoRename = Boolean.valueOf(parameters.getParameter(RMNode.PARAM_AUTO_RENAME));
try
{
QName typeQName = nodes.createQName(type);
newNodeRef = fileFolderService.create(parentNodeRef, name, typeQName).getNodeRef();
QName typeQName = nodes.createQName(nodeType);
// Existing file/folder name handling
if (TYPES_CAN_USE_AUTORENAME.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
Map<QName, Serializable> qnameProperties = mapToNodeProperties(properties);
Map<QName, Serializable> qnameProperties = mapToNodeProperties(nodeInfo.getProperties());
if (qnameProperties != null)
{
nodeService.addProperties(newNodeRef, qnameProperties);
@@ -630,18 +652,19 @@ public class FilePlanComponentsApiUtils
if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)
&& 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
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)
{
throw new InvalidArgumentException("The given type:'" + type + "' is invalid '");
throw new InvalidArgumentException("The given type:'" + nodeType + "' is invalid '");
}
catch(DuplicateAttributeException ex)
{
@@ -962,7 +985,45 @@ public class FilePlanComponentsApiUtils
activityPoster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(), activityInfo.getSiteId(),
activityInfo.getParentNodeRef(), activityInfo.getNodeRef(), activityInfo.getFileName(), Activities.APP_TOOL,
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;
}
}

View File

@@ -198,6 +198,7 @@ public class SearchTypesFactory
Boolean isRecordFolder = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_FOLDER,
WhereClauseParser.EQUALS, Boolean.class);
Boolean isRecordCategory = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_CATEGORY, WhereClauseParser.EQUALS, Boolean.class);
if ((isRecordFolder != null && isRecordFolder.booleanValue()) || (isRecordCategory != null && !isRecordCategory.booleanValue()))
{
includeRecordFolders = true;
@@ -221,6 +222,7 @@ public class SearchTypesFactory
if (nodeTypeQNameStr.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
{
includeRecordFolders = true;
}
else if (filterNodeTypeQName.equals(RecordsManagementModel.TYPE_RECORD_CATEGORY))
{

View File

@@ -57,6 +57,7 @@ public abstract class RMNode
public static final String PARAM_PROPERTIES = "properties";
public static final String PARAM_PATH = "path";
public static final String PARAM_ALLOWABLE_OPERATIONS = "allowableOperations";
public static final String PARAM_AUTO_RENAME = "autoRename";
public static final String PARAM_ISPRIMARY = "isPrimary";

View File

@@ -26,6 +26,7 @@
*/
package org.alfresco.rm.rest.api.model;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
@@ -50,6 +51,8 @@ public class UploadInfo
public UploadInfo(FormData formData)
{
properties = new HashMap<>();
for (FormData.FormField field : formData.getFields())
{
switch (field.getName().toLowerCase())

View File

@@ -130,7 +130,15 @@ public class RecordCategoriesEntityResource implements
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
FileInfo info = fileFolderService.getFileInfo(nodeRef);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
return nodesModelFactory.createRecordCategory(info, parameters, null, false);
}

View File

@@ -33,6 +33,7 @@ import static org.alfresco.util.ParameterCheck.mandatory;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -40,18 +41,22 @@ 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.model.RecordsManagementModel;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.node.getchildren.FilterProp;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.impl.Util;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.rm.rest.api.impl.ApiNodesModelFactory;
import org.alfresco.rm.rest.api.impl.FilePlanComponentsApiUtils;
import org.alfresco.rm.rest.api.impl.SearchTypesFactory;
@@ -64,6 +69,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.extensions.webscripts.servlet.FormData;
/**
* Record category children relation
@@ -74,7 +80,8 @@ import org.apache.commons.lang3.StringUtils;
*/
@RelationshipResource(name="children", entityResource = RecordCategoriesEntityResource.class, title = "Children of a record category")
public class RecordCategoryChildrenRelation implements RelationshipResourceAction.Read<RecordCategoryChild>,
RelationshipResourceAction.Create<RecordCategoryChild>
RelationshipResourceAction.Create<RecordCategoryChild>,
MultiPartRelationshipResourceAction.Create<RecordCategoryChild>
{
private final static Set<String> LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES = new HashSet<>(Arrays
.asList(new String[] { RecordCategoryChild.PARAM_IS_RECORD_CATEGORY, RecordCategoryChild.PARAM_IS_RECORD_FOLDER,
@@ -123,10 +130,11 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio
// list record categories and record folders
Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesCategoriesEndpoint(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
Set<QName> assocTypeQNames = Collections.singleton(ContentModel.ASSOC_CONTAINS);
List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef,
null,
assocTypeQNames,
searchTypeQNames,
null,
apiUtils.getSortProperties(parameters),
@@ -189,8 +197,7 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio
RecordsManagementModel.TYPE_RECORD_CATEGORY);
}
// Create the node
NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo.getName(), nodeInfo.getNodeType(),
nodeInfo.getProperties(), nodeInfo.getAspectNames());
NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
createdNodes.add(newNode);
}
return createdNodes;
@@ -206,4 +213,10 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio
return result;
}
@Override
public RecordCategoryChild create(String entityResourceId, FormData formData, Parameters parameters, WithResponse withResponse)
{
throw new IntegrityException("Uploading records into record categories is not allowed.", null);
}
}

View File

@@ -167,7 +167,7 @@ public class RecordFolderChildrenRelation implements RelationshipResourceAction.
List<NodeRef> createdNodes = new LinkedList<>();
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);
}
return createdNodes;

View File

@@ -125,7 +125,15 @@ public class RecordFolderEntityResource implements EntityResourceAction.ReadById
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
FileInfo info = fileFolderService.getFileInfo(nodeRef);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
return nodesModelFactory.createRecordFolder(info, parameters, null, false);
}

View File

@@ -217,7 +217,15 @@ public class RecordsEntityResource implements BinaryResourceAction.Read,
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// return record state
FileInfo info = fileFolderService.getFileInfo(record);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(record);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
apiUtils.postActivity(info, recordInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createRecord(info, parameters, null, false);
}

View File

@@ -128,7 +128,15 @@ public class TransferContainerEntityResource implements
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
FileInfo info = fileFolderService.getFileInfo(nodeRef);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
return nodesModelFactory.createTransferContainer(info, parameters, null, false);
}
}

View File

@@ -186,7 +186,7 @@ public class UnfiledContainerChildrenRelation implements RelationshipResourceAct
List<NodeRef> createdNodes = new LinkedList<>();
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);
}
return createdNodes;

View File

@@ -126,7 +126,15 @@ public class UnfiledContainerEntityResource
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
FileInfo info = fileFolderService.getFileInfo(nodeRef);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
apiUtils.postActivity(info, unfiledContainerInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createUnfiledContainer(info, parameters, null, false);
}

View File

@@ -174,7 +174,7 @@ public class UnfiledRecordFolderChildrenRelation implements RelationshipResource
mandatory("parameters", parameters);
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
// Create the children
RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>()
{
@@ -193,7 +193,7 @@ public class UnfiledRecordFolderChildrenRelation implements RelationshipResource
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);
}
return createdNodes;

View File

@@ -130,7 +130,15 @@ public class UnfiledRecordFolderEntityResource implements EntityResourceAction.R
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
FileInfo info = fileFolderService.getFileInfo(nodeRef);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>()
{
public FileInfo execute()
{
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
apiUtils.postActivity(info, unfiledRecordFolderInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createUnfiledRecordFolder(info, parameters, null, false);
}