Search in sources :

Example 1 with DispositionSchedule

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOutputStream(java.io.FileOutputStream) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) Date(java.util.Date)

Example 2 with DispositionSchedule

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());
}
Also used : DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) Role(org.alfresco.module.org_alfresco_module_rm.security.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 3 with DispositionSchedule

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) ArrayList(java.util.ArrayList) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with DispositionSchedule

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)

Example 5 with DispositionSchedule

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;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) JSONException(org.json.JSONException) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Aggregations

DispositionSchedule (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)34 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 DispositionActionDefinition (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition)10 QName (org.alfresco.service.namespace.QName)9 HashMap (java.util.HashMap)8 Serializable (java.io.Serializable)7 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Test (org.junit.Test)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 List (java.util.List)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 DispositionAction (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)2 DispositionScheduleImpl (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionScheduleImpl)2