Merge branch 'feature/FileAndDeclareApi'

Conflicts:
	rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/nodes/RecordsEntityResource.java
This commit is contained in:
Tuna Aksoy
2016-12-20 20:51:33 +00:00
16 changed files with 578 additions and 50 deletions

View File

@@ -45,18 +45,23 @@
</property> </property>
</bean> </bean>
<bean class="org.alfresco.rm.rest.api.nodes.FileplanComponentsEntityResource"> <bean class="org.alfresco.rm.rest.api.fileplancomponents.FileplanComponentsEntityResource">
<property name="nodes" ref="rm.Nodes" /> <property name="nodes" ref="rm.Nodes" />
</bean> </bean>
<bean class="org.alfresco.rm.rest.api.nodes.RecordsEntityResource"> <bean class="org.alfresco.rm.rest.api.fileplancomponents.FileplanComponentChildrenRelation">
<property name="nodes" ref="rm.Nodes" /> <property name="nodes" ref="rm.Nodes" />
</bean> </bean>
<bean class="org.alfresco.rm.rest.api.nodes.FileplanComponentChildrenRelation"> <bean class="org.alfresco.rm.rest.api.records.RecordsEntityResource">
<property name="nodes" ref="rm.Nodes" /> <property name="nodes" ref="rm.Nodes" />
<property name="records" ref="Records" />
</bean> </bean>
<bean class="org.alfresco.rm.rest.api.files.FilesEntityResource">
<property name="records" ref="Records" />
</bean>
<!-- extended sites bean definition --> <!-- extended sites bean definition -->
<bean id="rm.sites" class="org.alfresco.rm.rest.api.impl.RMSitesImpl" parent="sites"> <bean id="rm.sites" class="org.alfresco.rm.rest.api.impl.RMSitesImpl" parent="sites">
<property name="siteSurfConfig" ref="rm.siteSurfConfig" /> <property name="siteSurfConfig" ref="rm.siteSurfConfig" />
@@ -84,6 +89,30 @@
<property name="sites" ref="rm.Sites" /> <property name="sites" ref="rm.Sites" />
</bean> </bean>
<bean id="records" class="org.alfresco.rm.rest.api.impl.RecordsImpl">
<property name="recordService" ref="RecordService"/>
<property name="filePlanService" ref="FilePlanService"/>
<property name="nodes" ref="rm.nodes"/>
<property name="nodeService" ref="NodeService"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="dictionaryService" ref="DictionaryService"/>
</bean>
<bean id="Records" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.rm.rest.api.Records</value>
</property>
<property name="target">
<ref bean="records" />
</property>
<property name="interceptorNames">
<list>
<idref bean="legacyExceptionInterceptor" />
</list>
</property>
</bean>
<!-- Map RM exceptions to HTML status codes --> <!-- Map RM exceptions to HTML status codes -->
<bean id="rm.simpleMappingExceptionResolver" abstract="true" parent="simpleMappingExceptionResolver"> <bean id="rm.simpleMappingExceptionResolver" abstract="true" parent="simpleMappingExceptionResolver">
<property name="exceptionMappings"> <property name="exceptionMappings">

View File

@@ -28,6 +28,8 @@
package org.alfresco.rm.rest.api; package org.alfresco.rm.rest.api;
import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.Nodes;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/** /**
* RM Nodes API * RM Nodes API
@@ -45,4 +47,15 @@ public interface RMNodes extends Nodes
public static String PARAM_INCLUDE_HAS_RETENTION_SCHEDULE = "hasRetentionSchedule"; public static String PARAM_INCLUDE_HAS_RETENTION_SCHEDULE = "hasRetentionSchedule";
public static String PARAM_INCLUDE_IS_CLOSED = "isClosed"; public static String PARAM_INCLUDE_IS_CLOSED = "isClosed";
public static String PARAM_INCLUDE_IS_COMPLETED = "isCompleted"; public static String PARAM_INCLUDE_IS_COMPLETED = "isCompleted";
/**
* Gets or creates the relative path starting from the provided parent folder.
* The method decides the type of the created elements considering the
* parent container's type and the type of the node to be created.
* @param parentFolderNodeId the parent folder to start from
* @param relativePath the relative path
* @param nodeTypeQName the type of the node to be created
* @return reference to the last element of the created path
*/
public NodeRef getOrCreatePath(String parentFolderNodeId, String relativePath, QName nodeTypeQName);
} }

View File

@@ -0,0 +1,63 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rm.rest.api.model.TargetContainer;
/**
* Records API
*
* @author Ana Bozianu
* @since 2.6
*/
public interface Records
{
public static final String PARAM_HIDE_RECORD = "hideRecord";
/**
* Creates a record from a file
*
* @param fileId the id of a non record file
* @param parameters the {@link Parameters} object to get the parameters passed into the request
* @return information about the created record
*/
public Node declareFileAsRecord(String fileId, Parameters parameters);
/**
* Files a record into th fileplan.
* If the record is already filed it links the record to the target folder
*
* @param recordId the id of the record do file/link
* @param target the target parent folder
* @param parameters the {@link Parameters} object to get the parameters passed into the request
* @return information about the new state of the record
*/
public Node fileOrLinkRecord(String recordId, TargetContainer target, Parameters parameters);
}

View File

@@ -25,7 +25,7 @@
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.fileplancomponents;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -25,7 +25,7 @@
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.fileplancomponents;
import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiDescription;

View File

@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
/**
* Package info that defines the Information Governance Fileplan Components REST API
*
* @author Ana Bozianu
* @since 2.6
*/
@WebApi(name="ig", scope=Api.SCOPE.PUBLIC, version=1)
package org.alfresco.rm.rest.api.fileplancomponents;
import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.WebApi;

View File

@@ -0,0 +1,69 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.files;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.Operation;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.rm.rest.api.Records;
import org.alfresco.rm.rest.api.model.TargetContainer;
import org.alfresco.util.ParameterCheck;
import org.springframework.beans.factory.InitializingBean;
/**
* An implementation of an Entity Resource for a file
*
* @author Ana Bozianu
* @since 2.6
*/
@EntityResource(name="files", title = "Files")
public class FilesEntityResource implements InitializingBean
{
private Records records;
public void setRecords(Records records)
{
this.records = records;
}
@Operation("declare")
@WebApiDescription(title = "Declare as record", description="Declare a file as record.")
public Node declareAsRecord(String fileId, Void body, Parameters parameters, WithResponse withResponse)
{
return records.declareFileAsRecord(fileId, parameters);
}
@Override
public void afterPropertiesSet() throws Exception
{
ParameterCheck.mandatory("records", this.records);
}
}

View File

@@ -26,12 +26,12 @@
*/ */
/** /**
* Package info that defines the Information Governance Nodes REST API * Package info that defines the Information Governance Files REST API
* *
* @author Ana Bozianu * @author Ana Bozianu
* @since 2.6 * @since 2.6
*/ */
@WebApi(name="ig", scope=Api.SCOPE.PUBLIC, version=1) @WebApi(name="ig", scope=Api.SCOPE.PUBLIC, version=1)
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.files;
import org.alfresco.rest.framework.Api; import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.WebApi; import org.alfresco.rest.framework.WebApi;

View File

@@ -336,25 +336,30 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
public Node createNode(String parentFolderNodeId, Node nodeInfo, Parameters parameters) public Node createNode(String parentFolderNodeId, Node nodeInfo, Parameters parameters)
{ {
// create RM path if needed and call the super method with the last element of the created path // create RM path if needed and call the super method with the last element of the created path
NodeRef parentNodeRef = getOrCreatePath(parentFolderNodeId, nodeInfo); String relativePath = nodeInfo.getRelativePath();
// Get the type of the node to be created
String nodeType = nodeInfo.getNodeType();
if ((nodeType == null) || nodeType.isEmpty())
{
throw new InvalidArgumentException("Node type is expected: "+parentFolderNodeId+","+nodeInfo.getName());
}
QName nodeTypeQName = createQName(nodeType);
// Get or create the path
NodeRef parentNodeRef = getOrCreatePath(parentFolderNodeId, relativePath, nodeTypeQName);
// Set relative path to null as we pass the last element from the path
nodeInfo.setRelativePath(null); nodeInfo.setRelativePath(null);
return super.createNode(parentNodeRef.getId(), nodeInfo, parameters); return super.createNode(parentNodeRef.getId(), nodeInfo, parameters);
} }
/** @Override
* Gets or creates the relative path specified in nodeInfo.relativePath public NodeRef getOrCreatePath(String parentFolderNodeId, String relativePath, QName nodeTypeQName)
* starting from the provided parent folder.
* The method decides the type of the created elements considering the
* parent container's type and the type of the node to be created.
* @param parentFolderNodeId the parent folder to start from
* @param nodeInfo information about the node to be created
* @return reference to the last element of the created path
*/
protected NodeRef getOrCreatePath(String parentFolderNodeId, Node nodeInfo)
{ {
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null); NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
String relativePath = nodeInfo.getRelativePath();
if (relativePath == null) if (relativePath == null)
{ {
return parentNodeRef; return parentNodeRef;
@@ -413,14 +418,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
} }
else else
{ {
// Get the type of the node to be created
String nodeType = nodeInfo.getNodeType();
if ((nodeType == null) || nodeType.isEmpty())
{
throw new InvalidArgumentException("Node type is expected: "+parentFolderNodeId+","+nodeInfo.getName());
}
QName nodeTypeQName = createQName(nodeType);
/* Outside the unfiled record container the path elements are record categories /* Outside the unfiled record container the path elements are record categories
* except the last element which is a record folder if the created node is of type content * except the last element which is a record folder if the created node is of type content
*/ */

View File

@@ -0,0 +1,198 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.impl;
import java.security.InvalidParameterException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rm.rest.api.RMNodes;
import org.alfresco.rm.rest.api.Records;
import org.alfresco.rm.rest.api.model.TargetContainer;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.extensions.surf.util.ParameterCheck;
public class RecordsImpl implements Records, InitializingBean
{
protected RecordService recordService;
protected FilePlanService filePlanService;
protected NodeService nodeService;
protected FileFolderService fileFolderService;
protected DictionaryService dictionaryService;
protected RMNodes nodes;
public void setRecordService(RecordService recordService)
{
this.recordService = recordService;
}
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
public void setNodes(RMNodes nodes)
{
this.nodes = nodes;
}
@Override
public Node declareFileAsRecord(String fileId, Parameters parameters)
{
// Parameter check
if ((fileId == null) || (fileId.isEmpty()))
{
throw new InvalidArgumentException("Missing fileId");
}
// Get file to be declared
NodeRef fileNodeRef = nodes.validateNode(fileId) ;
// Get fileplan
NodeRef filePlan = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
{
@Override
public NodeRef doWork()
{
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
});
// default false (if not provided)
boolean hideRecord = Boolean.valueOf(parameters.getParameter(PARAM_HIDE_RECORD));
// Create the record
recordService.createRecord(filePlan, fileNodeRef, !hideRecord);
// Get information about the new record
return nodes.getFolderOrDocument(fileId, parameters);
}
@Override
public Node fileOrLinkRecord(String recordId, TargetContainer target, Parameters parameters)
{
ParameterCheck.mandatoryString("recordId", recordId);
if((target.getTargetParentId() == null || target.getTargetParentId().isEmpty()) &&
(target.getRelativePath() == null || target.getRelativePath().isEmpty()))
{
throw new InvalidParameterException("No target folder information was provided");
}
// Get record
NodeRef record = nodes.validateNode(recordId);
// Get record folder to file/link the record to
String parentContainerId = target.getTargetParentId();
if(parentContainerId == null || parentContainerId.isEmpty())
{
// If target container not provided get fileplan
parentContainerId = AuthenticationUtil.runAsSystem(new RunAsWork<String>()
{
@Override
public String doWork()
{
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID).getId();
}
});
}
NodeRef parentRecordFolder = nodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT);
// Check if the target is a record folder
if(!dictionaryService.isSubClass(nodeService.getType(parentRecordFolder), RecordsManagementModel.TYPE_RECORD_FOLDER))
{
throw new InvalidArgumentException("The provided target parent is not a record folder");
}
// Get the current parent type to decide if we link or move the record
NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
if(dictionaryService.isSubClass(nodeService.getType(primaryParent), RecordsManagementModel.TYPE_RECORD_FOLDER))
{
recordService.link(record, parentRecordFolder);
}
else
{
try
{
fileFolderService.moveFrom(record, primaryParent, parentRecordFolder, null);
}
catch (FileExistsException e)
{
throw new IntegrityException(e.getMessage(), null);
}
catch (FileNotFoundException e)
{
throw new ConcurrencyFailureException("The record was deleted while filing it", e);
}
}
// Get the record info
return nodes.getFolderOrDocument(recordId, parameters);
}
@Override
public void afterPropertiesSet() throws Exception
{
ParameterCheck.mandatory("recordService", recordService);
ParameterCheck.mandatory("filePlanService", filePlanService);
ParameterCheck.mandatory("nodes", nodes);
ParameterCheck.mandatory("nodeService", nodeService);
ParameterCheck.mandatory("fileFolderService", fileFolderService);
ParameterCheck.mandatory("dictionaryService", dictionaryService);
}
}

View File

@@ -0,0 +1,74 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.model;
/**
* A target container object
*
* @author Ana Bozianu
* @since 2.6
*/
public class TargetContainer
{
String targetParentId;
String relativePath;
public TargetContainer()
{
}
public String getTargetParentId()
{
return targetParentId;
}
public void setTargetParentId(String targetParentId)
{
this.targetParentId = targetParentId;
}
public String getRelativePath()
{
return relativePath;
}
public void setRelativePath(String relativePath)
{
this.relativePath = relativePath;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder("NodeTarget{");
sb.append("targetParentId=").append(targetParentId);
sb.append(", relativePath='").append(relativePath).append('\'');
sb.append('}');
return sb.toString();
}
}

View File

@@ -25,16 +25,21 @@
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.records;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.BinaryProperties; import org.alfresco.rest.framework.BinaryProperties;
import org.alfresco.rest.framework.Operation;
import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.content.BinaryResource;
import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.rm.rest.api.RMNodes; import org.alfresco.rm.rest.api.RMNodes;
import org.alfresco.rm.rest.api.Records;
import org.alfresco.rm.rest.api.model.TargetContainer;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@@ -50,16 +55,16 @@ public class RecordsEntityResource implements BinaryResourceAction.Read,
{ {
private RMNodes nodes; private RMNodes nodes;
private Records records;
public void setNodes(RMNodes nodes) public void setNodes(RMNodes nodes)
{ {
this.nodes = nodes; this.nodes = nodes;
} }
@Override public void setRecords(Records records)
public void afterPropertiesSet() throws Exception
{ {
ParameterCheck.mandatory("nodes", this.nodes); this.records = records;
} }
/** /**
@@ -78,4 +83,22 @@ public class RecordsEntityResource implements BinaryResourceAction.Read,
return nodes.getContent(recordId, parameters, true); return nodes.getContent(recordId, parameters, true);
} }
@Operation("file")
@WebApiDescription(title = "File record", description="File a record into fileplan.")
public Node fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse)
{
try{
return records.fileOrLinkRecord(recordId, target, parameters);
}catch(Exception ex)
{
throw ex;
}
}
@Override
public void afterPropertiesSet() throws Exception
{
ParameterCheck.mandatory("nodes", this.nodes);
ParameterCheck.mandatory("records", this.records);
}
} }

View File

@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
/**
* Package info that defines the Information Governance Records REST API
*
* @author Ana Bozianu
* @since 2.6
*/
@WebApi(name="ig", scope=Api.SCOPE.PUBLIC, version=1)
package org.alfresco.rm.rest.api.records;
import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.WebApi;

View File

@@ -25,7 +25,7 @@
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.fileplancomponents;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@@ -25,7 +25,7 @@
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.fileplancomponents;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;

View File

@@ -90,8 +90,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
* When trying to create a node in the parent node with no relative path * When trying to create a node in the parent node with no relative path
*/ */
Node nodeInfo = mock(Node.class); Node nodeInfo = mock(Node.class);
when(nodeInfo.getRelativePath()).thenReturn(null); NodeRef returnedPath = rmNodesImpl.getOrCreatePath(parentNode.getId(), null, ContentModel.TYPE_CONTENT);
NodeRef returnedPath = rmNodesImpl.getOrCreatePath(parentNode.getId(), nodeInfo);
/* /*
* Then the parent node is returned and no node is created * Then the parent node is returned and no node is created
@@ -126,8 +125,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
* When trying to create a node in the parent node with the relative path c1/f1 * When trying to create a node in the parent node with the relative path c1/f1
*/ */
Node nodeInfo = mock(Node.class); Node nodeInfo = mock(Node.class);
when(nodeInfo.getRelativePath()).thenReturn(category + "/" + recordFolder); NodeRef returnedPath = rmNodesImpl.getOrCreatePath(parentNode.getId(), category + "/" + recordFolder, ContentModel.TYPE_CONTENT);
NodeRef returnedPath = rmNodesImpl.getOrCreatePath(parentNode.getId(), nodeInfo);
/* /*
* Then the node f1 is returned and no node is created * Then the node f1 is returned and no node is created
@@ -166,9 +164,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
/* /*
* When trying to create a content node in the relative path c1/c2/c3/f1 * When trying to create a content node in the relative path c1/c2/c3/f1
*/ */
Node nodeInfo = mock(Node.class);
when(nodeInfo.getNodeType()).thenReturn("cm:content");
// c3 // c3
String category3 = "c3"; String category3 = "c3";
NodeRef categoryNode3 = AlfMock.generateNodeRef(mockedNodeService); NodeRef categoryNode3 = AlfMock.generateNodeRef(mockedNodeService);
@@ -182,8 +177,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
when(mockedFileFolderService.create(categoryNode3, recordFolder, RecordsManagementModel.TYPE_RECORD_FOLDER)).thenReturn(recordFolderFileInfo); when(mockedFileFolderService.create(categoryNode3, recordFolder, RecordsManagementModel.TYPE_RECORD_FOLDER)).thenReturn(recordFolderFileInfo);
// call the class under tests // call the class under tests
when(nodeInfo.getRelativePath()).thenReturn(category1 + "/" + category2 + "/" + category3 + "/" + recordFolder); NodeRef returnedPath = rmNodesImpl.getOrCreatePath(fileplanNodeRef.getId(), category1 + "/" + category2 + "/" + category3 + "/" + recordFolder, ContentModel.TYPE_CONTENT);
NodeRef returnedPath = rmNodesImpl.getOrCreatePath(fileplanNodeRef.getId(), nodeInfo);
/* /*
* Then the category c1 and the record folder f1 should be created and f1 should be returned * Then the category c1 and the record folder f1 should be created and f1 should be returned
@@ -232,9 +226,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
when(mockedFileFolderService.create(folderNode2, folder3, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)).thenReturn(folderFileInfo3); when(mockedFileFolderService.create(folderNode2, folder3, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)).thenReturn(folderFileInfo3);
// call the class under tests // call the class under tests
Node nodeInfo = mock(Node.class); NodeRef returnedParentNode = rmNodesImpl.getOrCreatePath(unfiledRecordContainer.getId(), folder1 + "/" + folder2 + "/" + folder3, ContentModel.TYPE_CONTENT);
when(nodeInfo.getRelativePath()).thenReturn(folder1 + "/" + folder2 + "/" + folder3);
NodeRef returnedParentNode = rmNodesImpl.getOrCreatePath(unfiledRecordContainer.getId(), nodeInfo);
/* /*
* Then the category c1 and the record folder rf1 should be created * Then the category c1 and the record folder rf1 should be created
@@ -267,9 +259,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
/* /*
* When trying to create a folder node in the relative path c1/c2/c3 * When trying to create a folder node in the relative path c1/c2/c3
*/ */
Node nodeInfo = mock(Node.class);
when(nodeInfo.getNodeType()).thenReturn("rma:recordFolder");
// c1 // c1
String category1 = "c1"; String category1 = "c1";
NodeRef categoryNode1 = AlfMock.generateNodeRef(mockedNodeService); NodeRef categoryNode1 = AlfMock.generateNodeRef(mockedNodeService);
@@ -286,8 +275,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest
when(mockedFilePlanService.createRecordCategory(categoryNode2, category3)).thenReturn(categoryNode3); when(mockedFilePlanService.createRecordCategory(categoryNode2, category3)).thenReturn(categoryNode3);
// call the class under tests // call the class under tests
when(nodeInfo.getRelativePath()).thenReturn(category1 + "/" + category2 + "/" + category3); NodeRef returnedParentNode = rmNodesImpl.getOrCreatePath(fileplanNodeRef.getId(), category1 + "/" + category2 + "/" + category3, RecordsManagementModel.TYPE_RECORD_FOLDER);
NodeRef returnedParentNode = rmNodesImpl.getOrCreatePath(fileplanNodeRef.getId(), nodeInfo);
/* /*
* Then the categories c1, c2 and c3 should be created and c3 should be returned * Then the categories c1, c2 and c3 should be created and c3 should be returned