RM-4012 - moved the rest api to org.alfresco.rest.api package and extended nodes service

This commit is contained in:
Ana Bozianu
2016-10-06 16:34:01 +03:00
parent feb9bc09c7
commit 19e02d402c
10 changed files with 370 additions and 241 deletions

View File

@@ -0,0 +1,73 @@
/*
* #%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.rest.api;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.resource.RelationshipResource;
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;
/**
* An implementation of an Entity Resource for a fileplan component
*
* @author Ana Bozianu
* @since 2.6
*/
@RelationshipResource(name="children", entityResource = FileplanComponentsEntityResource.class, title = "Children of fileplan component")
public class FileplanComponentChildrenRelation implements RelationshipResourceAction.Read<Node>,
RelationshipResourceAction.Create<Node>
{
private Nodes nodes;
public void setNodes(Nodes nodes)
{
this.nodes = nodes;
}
@Override
public CollectionWithPagingInfo<Node> readAll(String parentFolderNodeId, Parameters parameters)
{
return nodes.listChildren(parentFolderNodeId, parameters);
}
@Override
public List<Node> create(String parentFolderNodeId, List<Node> nodeInfos, Parameters parameters)
{
List<Node> result = new ArrayList<>(nodeInfos.size());
for (Node nodeInfo : nodeInfos)
{
result.add(nodes.createNode(parentFolderNodeId, nodeInfo, parameters));
}
return result;
}
}

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.rest.api;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.WebApiParam;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.parameters.Parameters;
/**
* Fileplan component children
*
* @author Ana Bozianu
* @since 2.6
*/
@EntityResource(name="fileplan-components", title = "Fileplan Components")
public class FileplanComponentsEntityResource implements
EntityResourceAction.ReadById<Node>
{
private Nodes nodes;
public void setNodes(Nodes nodes)
{
this.nodes = nodes;
}
@WebApiDescription(title = "Get Node Information", description = "Get information for the fileplan component with id 'nodeId'")
@WebApiParam(name = "nodeId", title = "The node id")
public Node readById(String nodeId, Parameters parameters)
{
return nodes.getFolderOrDocument(nodeId, parameters);
}
}

View File

@@ -0,0 +1,247 @@
/*
* #%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.rest.api.impl;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
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.repo.model.Repository;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.PathInfo;
import org.alfresco.rest.api.model.RMNode;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* Centralizes access to the repository.
*
* @author Ana Bozianu
* @since 2.6
*/
public class RMNodesImpl extends NodesImpl
{
String FILE_PLAN = "-filePlan-";
String TRANSFERS = "-transfers-";
String UNFILED = "-unfiled-";
String HOLDS = "-holds-";
private enum RMNodeType
{
// Note: ordered
CATEGORY, RECORD_FOLDER, FILE
}
private FilePlanService filePlanService;
private NodeService nodeService;
private ServiceRegistry sr;
private Repository repositoryHelper;
private DictionaryService dictionaryService;
private NamespaceService namespaceService;
public void init()
{
super.init();
this.nodeService = sr.getNodeService();
this.dictionaryService = sr.getDictionaryService();
this.namespaceService = sr.getNamespaceService();
}
public void setServiceRegistry(ServiceRegistry sr)
{
super.setServiceRegistry(sr);
this.sr = sr;
}
public void setRepositoryHelper(Repository repositoryHelper)
{
super.setRepositoryHelper(repositoryHelper);
this.repositoryHelper = repositoryHelper;
}
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
@Override
public Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo)
{
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
// Get general information
if (nodeTypeQName == null)
{
nodeTypeQName = nodeService.getType(nodeRef);
}
if (parentNodeRef == null)
{
parentNodeRef = getParentNodeRef(nodeRef);
}
RMNodeType type = getType(nodeTypeQName, nodeRef);
RMNode node;
node = new RMNode(nodeRef, parentNodeRef, properties, mapUserInfo, sr);
if (type == RMNodeType.CATEGORY)
{
node.setIsCategory(true);
}
else if (type == RMNodeType.RECORD_FOLDER)
{
node.setIsRecordFolder(true);
}
else if (type == RMNodeType.FILE)
{
node.setIsFile(true);
}
PathInfo pathInfo = null;
if (includeParam.contains(PARAM_INCLUDE_PATH))
{
ChildAssociationRef archivedParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
pathInfo = lookupPathInfo(nodeRef, archivedParentAssoc);
}
node.setPath(pathInfo);
node.setNodeType(nodeTypeQName.toPrefixString(namespaceService));
// Get optional fields
if (includeParam.size() > 0)
{
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo));
}
if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES))
{
node.setAspectNames(mapFromNodeAspects(nodeService.getAspects(nodeRef)));
}
return node;
}
@Override
public NodeRef validateOrLookupNode(String nodeId, String path)
{
if ((nodeId == null) || (nodeId.isEmpty()))
{
throw new InvalidArgumentException("Missing nodeId");
}
if (nodeId.equals(FILE_PLAN))
{
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if(filePlan != null)
{
return filePlan;
}
else
{
throw new EntityNotFoundException(nodeId);
}
}
else if (nodeId.equals(TRANSFERS))
{
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if(filePlan != null)
{
return filePlanService.getTransferContainer(filePlan);
}
else
{
throw new EntityNotFoundException(nodeId);
}
}
else if (nodeId.equals(UNFILED))
{
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if(filePlan != null)
{
return filePlanService.getUnfiledContainer(filePlan);
}
else
{
throw new EntityNotFoundException(nodeId);
}
}
else if (nodeId.equals(HOLDS))
{
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if(filePlan != null)
{
return filePlanService.getHoldContainer(filePlan);
}
else
{
throw new EntityNotFoundException(nodeId);
}
}
return super.validateOrLookupNode(nodeId, path);
}
private NodeRef getParentNodeRef(NodeRef nodeRef)
{
if (repositoryHelper.getCompanyHome().equals(nodeRef))
{
return null; // note: does not make sense to return parent above C/H
}
return nodeService.getPrimaryParent(nodeRef).getParentRef();
}
private RMNodeType getType(QName typeQName, NodeRef nodeRef)
{
// quick check for common types
if (typeQName.equals(RecordsManagementModel.TYPE_RECORD_FOLDER))
{
return RMNodeType.RECORD_FOLDER;
}
if (typeQName.equals(RecordsManagementModel.TYPE_RECORD_CATEGORY))
{
return RMNodeType.CATEGORY;
}
else if (typeQName.equals(ContentModel.TYPE_CONTENT) || dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT))
{
return RMNodeType.FILE;
}
return null; // unknown
}
}

View File

@@ -0,0 +1,87 @@
/*
* #%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.rest.api.model;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* Concrete class carrying general information for an RM node
*
* @author Ana Bozianu
* @since 2.6
*/
public class RMNode extends Node
{
protected Boolean isCategory;
protected Boolean isRecordFolder;
protected Boolean hasRetentionSchedule;
public RMNode(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
super(nodeRef, parentNodeRef, nodeProps, mapUserInfo, sr);
isCategory = false;
isRecordFolder = false;
isFile = false;
}
public Boolean getIsCategory()
{
return isCategory;
}
public Boolean getIsRecordFolder()
{
return isRecordFolder;
}
public Boolean getHasRetentionSchedule()
{
return hasRetentionSchedule;
}
public void setIsCategory(Boolean isCategory)
{
this.isCategory = isCategory;
}
public void setIsRecordFolder(Boolean isRecordFolder)
{
this.isRecordFolder = isRecordFolder;
}
public void setHasRetentionSchedule(Boolean hasRetentionSchedule)
{
this.hasRetentionSchedule = hasRetentionSchedule;
}
}

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 REST API
*
* @author Ana Bozianu
* @since 2.6
*/
@WebApi(name="ig", scope=Api.SCOPE.PUBLIC, version=1)
package org.alfresco.rest.api;
import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.WebApi;