Search in sources :

Example 1 with IntegrityException

use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.

the class RecordFolderType method onCreateChildAssociationOnCommit.

/**
 * On transaction commit
 *
 * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
 */
@Behaviour(kind = BehaviourKind.ASSOCIATION, policy = "alf:onCreateChildAssociation", notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT)
public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) {
    final NodeRef child = childAssocRef.getChildRef();
    if (!nodeService.exists(child)) {
        return;
    }
    // only records can be added in a record folder or hidden folders(is the case of e-mail attachments)
    if (instanceOf(child, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) {
        throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(child)), null);
    }
    behaviourFilter.disableBehaviour();
    try {
        AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                // setup vital record definition
                vitalRecordService.setupVitalRecordDefinition(child);
                return null;
            }
        });
    } finally {
        behaviourFilter.enableBehaviour();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 2 with IntegrityException

use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.

the class RecordsEntityResource method fileRecord.

@Operation("file")
@WebApiDescription(title = "File record", description = "File a record into fileplan.")
public Record fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordId", recordId);
    mandatory("target", target);
    mandatory("targetParentId", target.getTargetParentId());
    mandatory("parameters", parameters);
    // Get record and target folder
    NodeRef record = apiUtils.validateRecord(recordId);
    NodeRef targetRecordFolder = apiUtils.lookupAndValidateNodeType(target.getTargetParentId(), RecordsManagementModel.TYPE_RECORD_FOLDER);
    // Get the current parent type to decide if we link or move the record
    NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
    if (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(primaryParent))) {
        recordService.link(record, targetRecordFolder);
    } else {
        try {
            fileFolderService.moveFrom(record, primaryParent, targetRecordFolder, null);
        } catch (FileExistsException e) {
            throw new IntegrityException(e.getMessage(), null);
        } catch (FileNotFoundException e) {
            throw new ConcurrencyFailureException("The record was deleted while filing it", e);
        }
    }
    // return record state
    FileInfo info = fileFolderService.getFileInfo(record);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 3 with IntegrityException

use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.

the class RecordsEntityResource method completeRecord.

@Operation("complete")
@WebApiDescription(title = "Complete record", description = "Complete a record.")
public Record completeRecord(String recordId, Void body, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordId", recordId);
    mandatory("parameters", parameters);
    // Get record
    NodeRef record = apiUtils.validateRecord(recordId);
    // Complete the record
    try {
        recordService.complete(record);
    } catch (RecordMissingMetadataException e) {
        throw new IntegrityException("The record has missing mandatory properties.", null);
    }
    // return record state
    FileInfo info = fileFolderService.getFileInfo(record);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) RecordMissingMetadataException(org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 4 with IntegrityException

use of org.alfresco.repo.node.integrity.IntegrityException 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 IntegrityException

use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method createRMNode.

/**
 * Create an RM node
 *
 * @param parentNodeRef  the parent of the node
 * @param nodeInfo  the node infos to create
 * @param parameters  the object to get the parameters passed into the request
 * @return the new node
 */
public NodeRef createRMNode(NodeRef parentNodeRef, RMNode nodeInfo, Parameters parameters) {
    mandatory("parentNodeRef", parentNodeRef);
    mandatory("nodeInfo", nodeInfo);
    mandatory("parameters", parameters);
    String nodeName = nodeInfo.getName();
    String nodeType = nodeInfo.getNodeType();
    checkNotBlank(RMNode.PARAM_NAME, nodeName);
    checkNotBlank(RMNode.PARAM_NODE_TYPE, nodeType);
    // Create the node
    NodeRef newNodeRef = null;
    boolean autoRename = Boolean.valueOf(parameters.getParameter(RMNode.PARAM_AUTO_RENAME));
    try {
        QName typeQName = nodes.createQName(nodeType);
        // Existing file/folder name handling
        if (autoRename) {
            NodeRef existingNode = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
            if (existingNode != null) {
                // File already exists, find a unique name
                nodeName = findUniqueName(parentNodeRef, nodeName);
            }
        }
        newNodeRef = fileFolderService.create(parentNodeRef, nodeName, typeQName).getNodeRef();
        // Set the provided properties if any
        Map<QName, Serializable> qnameProperties = mapToNodeProperties(nodeInfo.getProperties());
        if (qnameProperties != null) {
            nodeService.addProperties(newNodeRef, qnameProperties);
        }
        // If electronic record create empty content
        if (!typeQName.equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT) && dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT)) {
            writeContent(newNodeRef, nodeName, new ByteArrayInputStream("".getBytes()), false);
        }
        // Add the provided aspects if any
        List<String> aspectNames = nodeInfo.getAspectNames();
        if (aspectNames != null) {
            nodes.addCustomAspects(newNodeRef, aspectNames, ApiNodesModelFactory.EXCLUDED_ASPECTS);
        }
    } catch (InvalidTypeException ex) {
        throw new InvalidArgumentException("The given type:'" + nodeType + "' is invalid '");
    } catch (DuplicateAttributeException ex) {
        // This exception can occur when setting a custom identifier that already exists
        throw new IntegrityException(ex.getMessage(), null);
    }
    return newNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) DuplicateAttributeException(org.alfresco.service.cmr.attributes.DuplicateAttributeException) InvalidTypeException(org.alfresco.repo.model.filefolder.FileFolderServiceImpl.InvalidTypeException)

Aggregations

IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)4 QName (org.alfresco.service.namespace.QName)4 Serializable (java.io.Serializable)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 Behaviour (org.alfresco.repo.policy.annotation.Behaviour)2 Operation (org.alfresco.rest.framework.Operation)2 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)2 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)2 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 RecordMissingMetadataException (org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException)1 FormNotFoundException (org.alfresco.repo.forms.FormNotFoundException)1 InvalidTypeException (org.alfresco.repo.model.filefolder.FileFolderServiceImpl.InvalidTypeException)1 RestoreNodeReport (org.alfresco.repo.node.archive.RestoreNodeReport)1