Search in sources :

Example 1 with RestoreNodeReport

use of org.alfresco.repo.node.archive.RestoreNodeReport in project acs-community-packaging by Alfresco.

the class TrashcanDialog method saveReportDetail.

/**
 * Save the detail of the items that were successfully or unsuccessfully restored
 *
 * @param reports     The List of RestoreNodeReport objects to walk for results
 */
protected void saveReportDetail(List<RestoreNodeReport> reports) {
    // store the results ready for the next dialog page
    int failureItemsCount = 0;
    property.setSuccessItems(new ArrayList<Node>(reports.size()));
    property.setFailureItems(new ArrayList<Node>(reports.size()));
    for (RestoreNodeReport report : reports) {
        if (RestoreStatus.SUCCESS == report.getStatus()) {
            Node node = new Node(report.getRestoredNodeRef());
            node.getProperties().put(PROP_RECOVERSTATUS, report.getStatus());
            property.getSuccessItems().add(node);
        } else {
            if (failureItemsCount < MAX_FAILURE_REPORTS) {
                Node node = new Node(report.getArchivedNodeRef());
                node.getProperties().put(PROP_RECOVERSTATUS, report.getStatus());
                node.getProperties().put(PROP_RECOVERERRORMESSAGE, report.getCause().getMessage());
                property.getFailureItems().add(node);
                failureItemsCount++;
            }
        }
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode)

Example 2 with RestoreNodeReport

use of org.alfresco.repo.node.archive.RestoreNodeReport in project acs-community-packaging by Alfresco.

the class TrashcanRecoverItemDialog method recoverItem.

private String recoverItem(FacesContext context, String outcome) {
    Node item = property.getItem();
    if (item != null) {
        FacesContext fc = context;
        try {
            String msg;
            FacesMessage errorfacesMsg = null;
            // restore the node - the user may have requested a restore to a
            // different parent
            RestoreNodeReport report;
            if (property.getDestination() == null) {
                report = property.getNodeArchiveService().restoreArchivedNode(item.getNodeRef());
            } else {
                report = property.getNodeArchiveService().restoreArchivedNode(item.getNodeRef(), property.getDestination(), null, null);
            }
            switch(report.getStatus()) {
                case SUCCESS:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_SUCCESS), item.getName());
                    FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
                    fc.addMessage(RICHLIST_MSG_ID, facesMsg);
                    break;
                case FAILURE_INVALID_PARENT:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_PARENT), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_PERMISSION:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_PERMISSION), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_INTEGRITY:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_INTEGRITY), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                case FAILURE_DUPLICATE_CHILD_NODE_NAME:
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_DUPLICATE), item.getName());
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
                default:
                    String reason = report.getCause().getMessage();
                    msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_FAILURE), item.getName(), reason);
                    errorfacesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
                    break;
            }
            // screen
            if (errorfacesMsg != null) {
                fc.addMessage(null, errorfacesMsg);
            }
        } catch (Throwable err) {
            // most exceptions will be caught and returned as
            // RestoreNodeReport objects by the service
            String reason = err.getMessage();
            String msg = MessageFormat.format(Application.getMessage(fc, MSG_RECOVERED_ITEM_FAILURE), item.getName(), reason);
            FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
            fc.addMessage(null, facesMsg);
            ReportedException.throwIfNecessary(err);
        }
    }
    return outcome;
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node) FacesMessage(javax.faces.application.FacesMessage)

Example 3 with RestoreNodeReport

use of org.alfresco.repo.node.archive.RestoreNodeReport in project acs-community-packaging by Alfresco.

the class TrashcanRecoverListedItemsDialog method recoverListedItems.

private String recoverListedItems(FacesContext context, String outcome) {
    if (property.isInProgress())
        return null;
    property.setInProgress(true);
    try {
        // restore the nodes - the user may have requested a restore to a
        // different parent
        List<NodeRef> nodeRefs = new ArrayList<NodeRef>(property.getListedItems().size());
        for (Node node : property.getListedItems()) {
            nodeRefs.add(node.getNodeRef());
        }
        List<RestoreNodeReport> reports;
        if (property.getDestination() == null) {
            reports = property.getNodeArchiveService().restoreArchivedNodes(nodeRefs);
        } else {
            reports = property.getNodeArchiveService().restoreArchivedNodes(nodeRefs, property.getDestination(), null, null);
        }
        saveReportDetail(reports);
    } finally {
        property.setInProgress(false);
    }
    return OUTCOME_RECOVERY_REPORT;
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList)

Example 4 with RestoreNodeReport

use of org.alfresco.repo.node.archive.RestoreNodeReport in project alfresco-remote-api by Alfresco.

the class DeletedNodesImpl method restoreArchivedNode.

@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
    // First check the node is valid and has been archived.
    NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    RestoreNodeReport restored = null;
    if (nodeTargetAssoc != null) {
        NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
        QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
    } else {
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
    }
    switch(restored.getStatus()) {
        case SUCCESS:
            return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
        case FAILURE_PERMISSION:
            throw new PermissionDeniedException();
        case FAILURE_INTEGRITY:
            throw new IntegrityException("Restore failed due to an integrity error", null);
        case FAILURE_DUPLICATE_CHILD_NODE_NAME:
            throw new ConstraintViolatedException("Name already exists in target");
        case FAILURE_INVALID_ARCHIVE_NODE:
            throw new EntityNotFoundException(archivedId);
        case FAILURE_INVALID_PARENT:
            throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
        default:
            throw new ApiException("Unable to restore node " + archivedId);
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 5 with RestoreNodeReport

use of org.alfresco.repo.node.archive.RestoreNodeReport in project alfresco-remote-api by Alfresco.

the class ArchivedNodePut method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // Current user
    String userID = AuthenticationUtil.getFullyAuthenticatedUser();
    if (userID == null) {
        throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script [" + req.getServiceMatch().getWebScript().getDescription() + "] requires user authentication.");
    }
    NodeRef nodeRefToBeRestored = parseRequestForNodeRef(req);
    if (nodeRefToBeRestored == null) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "nodeRef not recognised. Could not restore.");
    }
    // check if the current user has the permission to restore the node
    validatePermission(nodeRefToBeRestored, userID);
    RestoreNodeReport report = nodeArchiveService.restoreArchivedNode(nodeRefToBeRestored);
    // Handling of some error scenarios
    if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_ARCHIVE_NODE)) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find archive node: " + nodeRefToBeRestored);
    } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_PERMISSION)) {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Unable to restore archive node: " + nodeRefToBeRestored);
    } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_DUPLICATE_CHILD_NODE_NAME)) {
        throw new WebScriptException(HttpServletResponse.SC_CONFLICT, "Unable to restore archive node: " + nodeRefToBeRestored + ". Duplicate child node name");
    } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_PARENT) || report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INTEGRITY) || report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_OTHER)) {
        throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to restore archive node: " + nodeRefToBeRestored);
    }
    model.put("restoreNodeReport", report);
    return model;
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap)

Aggregations

RestoreNodeReport (org.alfresco.repo.node.archive.RestoreNodeReport)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Node (org.alfresco.web.bean.repository.Node)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FacesMessage (javax.faces.application.FacesMessage)1 FacesContext (javax.faces.context.FacesContext)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 QName (org.alfresco.service.namespace.QName)1 MapNode (org.alfresco.web.bean.repository.MapNode)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1