RM-6137 Add record category identifier to search changes added

This commit is contained in:
Ross Gale
2018-04-10 17:11:26 +01:00
parent e690c80906
commit 44bed4a796
4 changed files with 249 additions and 0 deletions

View File

@@ -100,6 +100,9 @@ public class RMSearchGet extends DeclarativeWebScript
/** Person data cache */
private Map<String, String> personDataCache = null;
/** Utility class for record categories */
private RecordCategoryUtil recordCategoryUtil;
/**
* @param recordsManagementSearchService records management search service
*/
@@ -148,6 +151,14 @@ public class RMSearchGet extends DeclarativeWebScript
this.permissionService = permissionService;
}
/**
* @param recordCategoryUtil utility class for record categories
*/
public void setRecordCategoryUtil(RecordCategoryUtil recordCategoryUtil)
{
this.recordCategoryUtil = recordCategoryUtil;
}
/**
* @param personService person service
*/
@@ -247,6 +258,7 @@ public class RMSearchGet extends DeclarativeWebScript
private String createdBy;
private Map<QName, Serializable> nodeProperties;
private Map<String, Serializable> properties;
private String recordCategoryId;
public Item(NodeRef parent, NodeRef nodeRef)
{
@@ -340,6 +352,7 @@ public class RMSearchGet extends DeclarativeWebScript
properties.put(prefixName, entry.getValue());
}
}
properties.put("rma_recordCategoryIdentifier", recordCategoryUtil.getCategoryIdFromNodeId(nodeRef, false));
}
private String getDisplayName(String userName)
@@ -445,5 +458,15 @@ public class RMSearchGet extends DeclarativeWebScript
{
return properties;
}
public String getRecordCategoryId()
{
return recordCategoryId;
}
public void setRecordCategoryId(String recordCategoryId)
{
this.recordCategoryId = recordCategoryId;
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2018 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.module.org_alfresco_module_rm.script.slingshot;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_IDENTIFIER;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.TYPE_RECORD_CATEGORY;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.TYPE_RECORD_FOLDER;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
/**
* Utility class for record categories
* @author Ross Gale
* @since 2.7
*/
public class RecordCategoryUtil
{
/**
* Node service
*/
private NodeService nodeService;
/**
* Setter for the node service
* @param nodeService Node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Return the record category id for a file plan element
* @param nodeRef the node reference of the file plan element
* @param includeFolders return an id for records, folders and categories
* @return Record category identifier
*/
public String getCategoryIdFromNodeId(NodeRef nodeRef, boolean includeFolders)
{
if(!includeFolders)
{
if (nodeService.getType(nodeRef).equals(TYPE_RECORD_FOLDER) || nodeService.getType(nodeRef).equals(TYPE_RECORD_CATEGORY))
{
return null;
}
}
//Search for the first category from the end of the path to save time
Path path = nodeService.getPath(nodeRef);
for(int x = path.size()-1; x >= 0; x--)
{
NodeRef ref = ((ChildAssocElement) path.get(x)).getRef().getChildRef();
if (nodeService.getType(ref).equals(TYPE_RECORD_CATEGORY))
{
return nodeService.getProperty(ref, PROP_IDENTIFIER).toString();
}
}
return null;
}
}