mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-486 (RM Data Set Service)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@41313 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.dataset;
|
||||
|
||||
public interface DataSet
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the label of the data set
|
||||
*
|
||||
* @return String the label of the data set
|
||||
*/
|
||||
String getLabel();
|
||||
|
||||
/**
|
||||
* Gets the id of the data set
|
||||
*
|
||||
* @return String the id of the data set
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Gets the path of the data set
|
||||
*
|
||||
* @return String the path of the data set
|
||||
*/
|
||||
String getPath();
|
||||
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.dataset;
|
||||
|
||||
public class DataSetBase implements DataSet
|
||||
{
|
||||
|
||||
/** Data set service */
|
||||
private DataSetService dataSetService;
|
||||
|
||||
/** Data set label */
|
||||
private String label;
|
||||
|
||||
/** Data set id */
|
||||
private String id;
|
||||
|
||||
/** Data set path */
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* Sets the data set service
|
||||
*
|
||||
* @param dataSetService the data set service
|
||||
*/
|
||||
public void setDataSetService(DataSetService dataSetService)
|
||||
{
|
||||
this.dataSetService = dataSetService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSet#getLabel()
|
||||
*/
|
||||
public String getLabel()
|
||||
{
|
||||
return this.label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label of the data set service
|
||||
*
|
||||
* @param label the label
|
||||
*/
|
||||
public void setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSet#getId()
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id of the data set service
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSet#getPath()
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path of the data set service
|
||||
*
|
||||
* @param path the path
|
||||
*/
|
||||
public void setPath(String path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the data set implementation with the data set service.
|
||||
*/
|
||||
public void register()
|
||||
{
|
||||
this.dataSetService.register(this);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.dataset;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
public interface DataSetService
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a data set implementation with the service
|
||||
*
|
||||
* @param dataSet the data set
|
||||
*/
|
||||
void register(DataSet dataSet);
|
||||
|
||||
/**
|
||||
* Gets the details of all available data sets.
|
||||
*
|
||||
* @return Map<String, DataSet> details of all available data sets
|
||||
*/
|
||||
Map<String, DataSet> getDataSets();
|
||||
|
||||
/**
|
||||
* Loads the data set with the specified id into the specified file plan
|
||||
*
|
||||
* @param dataSetId the id of the data set which will be imported
|
||||
* @param filePlan the file plan which the data set will load into
|
||||
*/
|
||||
void loadDataSet(String dataSetId, NodeRef filePlan);
|
||||
|
||||
}
|
@@ -0,0 +1,368 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.dataset;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementSearchBehaviour;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.Role;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.view.ImporterService;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class DataSetServiceImpl implements DataSetService, RecordsManagementModel
|
||||
{
|
||||
|
||||
/** Logger */
|
||||
private static Log logger = LogFactory.getLog(DataSetServiceImpl.class);
|
||||
|
||||
/** Registered data set implementations */
|
||||
private Map<String, DataSet> dataSets = new HashMap<String, DataSet>();
|
||||
|
||||
/** Spaces store */
|
||||
private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
|
||||
"SpacesStore");
|
||||
|
||||
/** Importer service */
|
||||
private ImporterService importerService;
|
||||
|
||||
/** Search service */
|
||||
private SearchService searchService;
|
||||
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Records management service */
|
||||
private RecordsManagementService recordsManagementService;
|
||||
|
||||
/** Records management action service */
|
||||
private RecordsManagementActionService recordsManagementActionService;
|
||||
|
||||
/** Permission service */
|
||||
private PermissionService permissionService;
|
||||
|
||||
/** Authority service */
|
||||
private AuthorityService authorityService;
|
||||
|
||||
/** Records management security service */
|
||||
private RecordsManagementSecurityService recordsManagementSecurityService;
|
||||
|
||||
/** Records management search behaviour */
|
||||
private RecordsManagementSearchBehaviour recordsManagementSearchBehaviour;
|
||||
|
||||
/** Disposition service */
|
||||
private DispositionService dispositionService;
|
||||
|
||||
/**
|
||||
* Set importer service
|
||||
*
|
||||
* @param importerService the importer service
|
||||
*/
|
||||
public void setImporterService(ImporterService importerService)
|
||||
{
|
||||
this.importerService = importerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set search service
|
||||
*
|
||||
* @param searchService the search service
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set node service
|
||||
*
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set records management service
|
||||
*
|
||||
* @param recordsManagementService the records management service
|
||||
*/
|
||||
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
|
||||
{
|
||||
this.recordsManagementService = recordsManagementService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set records management action service
|
||||
*
|
||||
* @param recordsManagementActionService the records management action
|
||||
* service
|
||||
*/
|
||||
public void setRecordsManagementActionService(
|
||||
RecordsManagementActionService recordsManagementActionService)
|
||||
{
|
||||
this.recordsManagementActionService = recordsManagementActionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set permission service
|
||||
*
|
||||
* @param permissionService the permission service
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set authority service
|
||||
*
|
||||
* @param authorityService the authority service
|
||||
*/
|
||||
public void setAuthorityService(AuthorityService authorityService)
|
||||
{
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set records management security service
|
||||
*
|
||||
* @param recordsManagementSecurityService the records management security
|
||||
* service
|
||||
*/
|
||||
public void setRecordsManagementSecurityService(
|
||||
RecordsManagementSecurityService recordsManagementSecurityService)
|
||||
{
|
||||
this.recordsManagementSecurityService = recordsManagementSecurityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set records management search behaviour
|
||||
*
|
||||
* @param recordsManagementSearchBehaviour the records management search
|
||||
* behaviour
|
||||
*/
|
||||
public void setRecordsManagementSearchBehaviour(
|
||||
RecordsManagementSearchBehaviour recordsManagementSearchBehaviour)
|
||||
{
|
||||
this.recordsManagementSearchBehaviour = recordsManagementSearchBehaviour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set disposition service
|
||||
*
|
||||
* @param dispositionService the disposition service
|
||||
*/
|
||||
public void setDispositionService(DispositionService dispositionService)
|
||||
{
|
||||
this.dispositionService = dispositionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#register(org.alfresco.module.org_alfresco_module_rm.dataset.DataSet)
|
||||
*/
|
||||
@Override
|
||||
public void register(DataSet dataSet)
|
||||
{
|
||||
this.dataSets.put(dataSet.getId(), dataSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#getDataSets()
|
||||
*/
|
||||
@Override
|
||||
public Map<String, DataSet> getDataSets()
|
||||
{
|
||||
return this.dataSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService#loadDataSet(java.lang.String,
|
||||
* org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void loadDataSet(String dataSetId, NodeRef filePlan)
|
||||
{
|
||||
// Get the data set
|
||||
DataSet dataSet = getDataSets().get(dataSetId);
|
||||
|
||||
// Import the RM test data ACP into the the provided file plan node reference
|
||||
InputStream is = DataSetServiceImpl.class.getClassLoader().getResourceAsStream(
|
||||
dataSet.getPath());
|
||||
if (is == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The '" + dataSet.getLabel()
|
||||
+ "' import file could not be found!");
|
||||
}
|
||||
|
||||
// Import view
|
||||
Reader viewReader = new InputStreamReader(is);
|
||||
Location location = new Location(filePlan);
|
||||
importerService.importView(viewReader, location, null, null);
|
||||
|
||||
// Patch data
|
||||
DataSetServiceImpl.patchLoadedData(searchService, nodeService, recordsManagementService,
|
||||
recordsManagementActionService, permissionService, authorityService,
|
||||
recordsManagementSecurityService, recordsManagementSearchBehaviour,
|
||||
dispositionService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Temp method to patch AMP'ed data
|
||||
*
|
||||
* @param searchService
|
||||
* @param nodeService
|
||||
* @param recordsManagementService
|
||||
* @param recordsManagementActionService
|
||||
*/
|
||||
private static void patchLoadedData(final SearchService searchService,
|
||||
final NodeService nodeService, final RecordsManagementService recordsManagementService,
|
||||
final RecordsManagementActionService recordsManagementActionService,
|
||||
final PermissionService permissionService, final AuthorityService authorityService,
|
||||
final RecordsManagementSecurityService recordsManagementSecurityService,
|
||||
final RecordsManagementSearchBehaviour recordManagementSearchBehaviour,
|
||||
final DispositionService dispositionService)
|
||||
{
|
||||
AuthenticationUtil.RunAsWork<Object> runAsWork = new AuthenticationUtil.RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
java.util.List<NodeRef> rmRoots = recordsManagementService.getFilePlans();
|
||||
logger.info("Bootstraping " + rmRoots.size() + " rm roots ...");
|
||||
for (NodeRef rmRoot : rmRoots)
|
||||
{
|
||||
if (permissionService.getInheritParentPermissions(rmRoot) == true)
|
||||
{
|
||||
logger.info("Updating permissions for rm root: " + rmRoot);
|
||||
permissionService.setInheritParentPermissions(rmRoot, false);
|
||||
}
|
||||
|
||||
String allRoleShortName = "AllRoles" + rmRoot.getId();
|
||||
String allRoleGroupName = authorityService.getName(AuthorityType.GROUP,
|
||||
allRoleShortName);
|
||||
|
||||
if (authorityService.authorityExists(allRoleGroupName) == false)
|
||||
{
|
||||
logger.info("Creating all roles group for root node: " + rmRoot.toString());
|
||||
|
||||
// Create "all" role group for root node
|
||||
String allRoles = authorityService.createAuthority(AuthorityType.GROUP,
|
||||
allRoleShortName, "All Roles", null);
|
||||
|
||||
// Put all the role groups in it
|
||||
Set<Role> roles = recordsManagementSecurityService.getRoles(rmRoot);
|
||||
for (Role role : roles)
|
||||
{
|
||||
logger.info(" - adding role group " + role.getRoleGroupName()
|
||||
+ " to all roles group");
|
||||
authorityService.addAuthority(allRoles, role.getRoleGroupName());
|
||||
}
|
||||
|
||||
// Set the permissions
|
||||
permissionService.setPermission(rmRoot, allRoles, RMPermissionModel.READ_RECORDS,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure all the containers do not inherit permissions
|
||||
ResultSet rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE,
|
||||
"TYPE:\"rma:recordsManagementContainer\"");
|
||||
try
|
||||
{
|
||||
logger.info("Bootstraping " + rs.length() + " record containers ...");
|
||||
|
||||
for (NodeRef container : rs.getNodeRefs())
|
||||
{
|
||||
String containerName = (String) nodeService.getProperty(container,
|
||||
ContentModel.PROP_NAME);
|
||||
|
||||
// Set permissions
|
||||
if (permissionService.getInheritParentPermissions(container) == true)
|
||||
{
|
||||
logger.info("Updating permissions for record container: " + containerName);
|
||||
permissionService.setInheritParentPermissions(container, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
|
||||
// fix up the test dataset to fire initial events for disposition
|
||||
// schedules
|
||||
rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE,
|
||||
"TYPE:\"rma:recordFolder\"");
|
||||
try
|
||||
{
|
||||
logger.info("Bootstraping " + rs.length() + " record folders ...");
|
||||
|
||||
for (NodeRef recordFolder : rs.getNodeRefs())
|
||||
{
|
||||
String folderName = (String) nodeService.getProperty(recordFolder,
|
||||
ContentModel.PROP_NAME);
|
||||
|
||||
// Set permissions
|
||||
if (permissionService.getInheritParentPermissions(recordFolder) == true)
|
||||
{
|
||||
logger.info("Updating permissions for record folder: " + folderName);
|
||||
permissionService.setInheritParentPermissions(recordFolder, false);
|
||||
}
|
||||
|
||||
if (nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE) == false)
|
||||
{
|
||||
// See if the folder has a disposition schedule that needs
|
||||
// to be applied
|
||||
DispositionSchedule ds = dispositionService
|
||||
.getDispositionSchedule(recordFolder);
|
||||
if (ds != null)
|
||||
{
|
||||
// Fire action to "set-up" the folder correctly
|
||||
logger.info("Setting up bootstraped record folder: " + folderName);
|
||||
recordsManagementActionService.executeRecordsManagementAction(recordFolder,
|
||||
"setupRecordFolder");
|
||||
}
|
||||
}
|
||||
|
||||
// fixup the search behaviour aspect for the record folder
|
||||
logger.info("Setting up search aspect for record folder: " + folderName);
|
||||
recordManagementSearchBehaviour.fixupSearchAspect(recordFolder);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user