use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule in project records-management by Alfresco.
the class TransferReportGet method generateJSONTransferReport.
/**
* Generates a File containing the JSON representation of a transfer report.
*
* @param transferNode The transfer node
* @return File containing JSON representation of a transfer report
* @throws IOException
*/
File generateJSONTransferReport(NodeRef transferNode) throws IOException {
File report = TempFileProvider.createTempFile(REPORT_FILE_PREFIX, REPORT_FILE_SUFFIX);
// create the writer
try (FileOutputStream fileOutputStream = new FileOutputStream(report);
Writer writer = new OutputStreamWriter(fileOutputStream, Charset.forName("UTF-8"))) {
// get all 'transferred' nodes
NodeRef[] itemsToTransfer = getTransferNodes(transferNode);
if (logger.isDebugEnabled()) {
logger.debug("Generating JSON transfer report for " + itemsToTransfer.length + " items into file: " + report.getAbsolutePath());
}
// use RMService to get disposition authority
String dispositionAuthority = null;
if (itemsToTransfer.length > 0) {
// use the first transfer item to get to disposition schedule
DispositionSchedule ds = dispositionService.getDispositionSchedule(itemsToTransfer[0]);
if (ds != null) {
dispositionAuthority = ds.getDispositionAuthority();
}
}
// write the JSON header
writer.write("{\n\t\"data\":\n\t{");
writer.write("\n\t\t\"transferDate\": \"");
writer.write(ISO8601DateFormat.format((Date) this.nodeService.getProperty(transferNode, ContentModel.PROP_CREATED)));
writer.write("\",\n\t\t\"transferPerformedBy\": \"");
writer.write(AuthenticationUtil.getRunAsUser());
writer.write("\",\n\t\t\"dispositionAuthority\": \"");
writer.write(dispositionAuthority != null ? dispositionAuthority : "");
writer.write("\",\n\t\t\"items\":\n\t\t[");
// write out JSON representation of items to transfer
generateTransferItemsJSON(writer, itemsToTransfer);
// write the JSON footer
writer.write("\n\t\t]\n\t}\n}");
}
return report;
}
use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule in project records-management by Alfresco.
the class BootstrapTestDataGet method patchLoadedData.
/**
* Temp method to patch AMP'ed data
*
* @param searchService
* @param nodeService
* @param recordsManagementService
* @param recordsManagementActionService
*/
public 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, final RecordFolderService recordFolderService) {
AuthenticationUtil.RunAsWork<Object> runAsWork = new AuthenticationUtil.RunAsWork<Object>() {
public Object doWork() {
java.util.List<NodeRef> rmRoots = recordsManagementService.getFilePlans();
logger.info("Bootstraping " + rmRoots.size() + " rm roots ...");
for (NodeRef rmRoot : rmRoots) {
if (permissionService.getInheritParentPermissions(rmRoot)) {
logger.info("Updating permissions for rm root: " + rmRoot);
permissionService.setInheritParentPermissions(rmRoot, false);
}
String allRoleShortName = RMAuthority.ALL_ROLES_PREFIX + rmRoot.getId();
String allRoleGroupName = authorityService.getName(AuthorityType.GROUP, allRoleShortName);
if (!authorityService.authorityExists(allRoleGroupName)) {
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, RMAuthority.ALL_ROLES_DISPLAY_NAME, new HashSet<String>(Arrays.asList(RMAuthority.ZONE_APP_RM)));
// 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_FTS_ALFRESCO, "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)) {
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_FTS_ALFRESCO, "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)) {
logger.info("Updating permissions for record folder: " + folderName);
permissionService.setInheritParentPermissions(recordFolder, false);
}
if (!nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE)) {
// 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);
recordFolderService.setupRecordFolder(recordFolder);
}
}
// 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());
}
use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule in project records-management by Alfresco.
the class DispositionAbstractBase method getDispositionScheduleModel.
/**
* Helper method to parse the request and retrieve the disposition schedule model.
*
* @param req The webscript request
* @return Map representing the model
*/
protected Map<String, Object> getDispositionScheduleModel(WebScriptRequest req) {
// parse the request to retrieve the schedule object
DispositionSchedule schedule = parseRequestForSchedule(req);
// add all the schedule data to Map
Map<String, Object> scheduleModel = new HashMap<String, Object>(8);
// build url
String serviceUrl = req.getServiceContextPath() + req.getPathInfo();
scheduleModel.put("url", serviceUrl);
String actionsUrl = serviceUrl + "/dispositionactiondefinitions";
scheduleModel.put("actionsUrl", actionsUrl);
scheduleModel.put("nodeRef", schedule.getNodeRef().toString());
scheduleModel.put("recordLevelDisposition", schedule.isRecordLevelDisposition());
scheduleModel.put("canStepsBeRemoved", !getDispositionService().hasDisposableItems(schedule));
if (schedule.getDispositionAuthority() != null) {
scheduleModel.put("authority", schedule.getDispositionAuthority());
}
if (schedule.getDispositionInstructions() != null) {
scheduleModel.put("instructions", schedule.getDispositionInstructions());
}
boolean unpublishedUpdates = false;
boolean publishInProgress = false;
List<Map<String, Object>> actions = new ArrayList<Map<String, Object>>();
for (DispositionActionDefinition actionDef : schedule.getDispositionActionDefinitions()) {
NodeRef actionDefNodeRef = actionDef.getNodeRef();
if (getNodeService().hasAspect(actionDefNodeRef, RecordsManagementModel.ASPECT_UNPUBLISHED_UPDATE)) {
unpublishedUpdates = true;
publishInProgress = ((Boolean) getNodeService().getProperty(actionDefNodeRef, RecordsManagementModel.PROP_PUBLISH_IN_PROGRESS)).booleanValue();
}
actions.add(createActionDefModel(actionDef, actionsUrl + "/" + actionDef.getId()));
}
scheduleModel.put("actions", actions);
scheduleModel.put("unpublishedUpdates", unpublishedUpdates);
scheduleModel.put("publishInProgress", publishInProgress);
// create model object with just the schedule data
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("schedule", scheduleModel);
return model;
}
use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule in project records-management by Alfresco.
the class DispositionAbstractBase method parseRequestForSchedule.
/**
* Parses the request and providing it's valid returns the DispositionSchedule object.
*
* @param req The webscript request
* @return The DispositionSchedule object the request is aimed at
*/
protected DispositionSchedule parseRequestForSchedule(WebScriptRequest req) {
// get the NodeRef from the request
NodeRef nodeRef = parseRequestForNodeRef(req);
// Determine whether we are getting the inherited disposition schedule or not
boolean inherited = true;
String inheritedString = req.getParameter("inherited");
if (inheritedString != null) {
inherited = Boolean.parseBoolean(inheritedString);
}
// make sure the node passed in has a disposition schedule attached
DispositionSchedule schedule = null;
if (inherited) {
schedule = getDispositionService().getDispositionSchedule(nodeRef);
} else {
schedule = getDispositionService().getAssociatedDispositionSchedule(nodeRef);
}
if (schedule == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Node " + nodeRef.toString() + " does not have a disposition schedule");
}
return schedule;
}
use of org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule in project records-management by Alfresco.
the class DispositionActionDefinitionPost method executeImpl.
/*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
// parse the request to retrieve the schedule object
DispositionSchedule schedule = parseRequestForSchedule(req);
// retrieve the rest of the post body and create the action
// definition
JSONObject json = null;
DispositionActionDefinition actionDef = null;
try {
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
actionDef = createActionDefinition(json, schedule);
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
// create model object with just the action data
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("action", createActionDefModel(actionDef, req.getURL() + "/" + actionDef.getId()));
return model;
}
Aggregations