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();
}
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations