use of org.alfresco.repo.node.integrity.IntegrityException in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method delete.
@Override
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters) {
Version v = findVersion(nodeId, versionId);
// live (aka versioned) nodeRef
NodeRef nodeRef = v.getVersionedNodeRef();
if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
throw new PermissionDeniedException("Cannot delete version");
}
versionService.deleteVersion(nodeRef, v);
Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
if (props.get(ContentModel.PROP_VERSION_LABEL) == null) {
// note: alternatively, the client can remove the "cm:versionable" aspect (if permissions allow) to clear the version history and disable versioning
throw new IntegrityException("Cannot delete last version (did you mean to disable versioning instead ?) [" + nodeId + "," + versionId + "]", null);
/*
if (props.get(ContentModel.PROP_VERSION_TYPE) != null)
{
// minor fix up to versionable aspect - ie. remove versionType
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try
{
sr.getNodeService().removeProperty(nodeRef, ContentModel.PROP_VERSION_TYPE);
}
finally
{
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
}
*/
}
}
use of org.alfresco.repo.node.integrity.IntegrityException in project alfresco-remote-api by Alfresco.
the class ExceptionResolverTests method testMatchException.
// 04180006 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get
@Test
public void testMatchException() {
ErrorResponse response = assistant.resolveException(new ApiException(null));
assertNotNull(response);
// default to INTERNAL_SERVER_ERROR
assertEquals(500, response.getStatusCode());
response = assistant.resolveException(new InvalidArgumentException(null));
// default to STATUS_BAD_REQUEST
assertEquals(400, response.getStatusCode());
response = assistant.resolveException(new InvalidQueryException(null));
// default to STATUS_BAD_REQUEST
assertEquals(400, response.getStatusCode());
response = assistant.resolveException(new NotFoundException(null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new EntityNotFoundException(null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new RelationshipResourceNotFoundException(null, null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new PermissionDeniedException(null));
// default to STATUS_FORBIDDEN
assertEquals(403, response.getStatusCode());
response = assistant.resolveException(new UnsupportedResourceOperationException(null));
// default to STATUS_METHOD_NOT_ALLOWED
assertEquals(405, response.getStatusCode());
response = assistant.resolveException(new DeletedResourceException(null));
// default to STATUS_METHOD_NOT_ALLOWED
assertEquals(405, response.getStatusCode());
response = assistant.resolveException(new ConstraintViolatedException(null));
// default to STATUS_CONFLICT
assertEquals(409, response.getStatusCode());
response = assistant.resolveException(new StaleEntityException(null));
// default to STATUS_CONFLICT
assertEquals(409, response.getStatusCode());
// Try a random exception
response = assistant.resolveException(new FormNotFoundException(null));
// default to INTERNAL_SERVER_ERROR
assertEquals(500, response.getStatusCode());
response = assistant.resolveException(new InsufficientStorageException(null));
assertEquals(507, response.getStatusCode());
response = assistant.resolveException(new IntegrityException(null));
assertEquals(422, response.getStatusCode());
}
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;
}
use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.
the class RecordServiceImpl method validateForCompletion.
/**
* Helper method to validate whether the node is in a state suitable for completion
*
* @param nodeRef node reference
* @throws Exception if node not valid for completion
*/
private void validateForCompletion(NodeRef nodeRef) {
if (!nodeService.exists(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The record does not exist.", null);
}
if (!isRecord(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The node is not a record.", null);
}
if (freezeService.isFrozen(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The record is frozen.", null);
}
if (isDeclared(nodeRef)) {
throw new IntegrityException("The record is already completed.", null);
}
// if the record is newly created make sure the record identifier is set before completing the record
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
if (newRecords.contains(nodeRef)) {
generateRecordIdentifier(nodeService, identifierService, nodeRef);
}
// Validate that all mandatory properties, if any, are present
List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add
if (checkMandatoryPropertiesEnabled) {
Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
QName nodeRefType = nodeService.getType(nodeRef);
// check for missing mandatory metadata from type definitions
TypeDefinition typeDef = dictionaryService.getType(nodeRefType);
checkDefinitionMandatoryPropsSet(typeDef, nodeRefProps, missingProperties);
// check for missing mandatory metadata from aspect definitions
Set<QName> aspects = nodeService.getAspects(nodeRef);
for (QName aspect : aspects) {
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
}
// check for missing mandatory metadata from custom aspect definitions
QName customAspect = getCustomAspectImpl(nodeRefType);
AspectDefinition aspectDef = dictionaryService.getAspect(customAspect);
checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
if (!missingProperties.isEmpty()) {
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
throw new RecordMissingMetadataException("The record has missing mandatory properties.");
}
}
}
use of org.alfresco.repo.node.integrity.IntegrityException in project records-management by Alfresco.
the class RecordFolderType method onCreateChildAssociation.
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
*/
@Override
@Behaviour(kind = BehaviourKind.ASSOCIATION, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) {
NodeRef nodeRef = childAssocRef.getChildRef();
if (nodeService.exists(nodeRef)) {
boolean notFolderOrRmFolderSubType = !instanceOf(nodeRef, ContentModel.TYPE_FOLDER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORDS_MANAGEMENT_CONTAINER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORD_FOLDER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_TRANSFER);
if (!instanceOf(nodeRef, ContentModel.TYPE_CONTENT) && notFolderOrRmFolderSubType) {
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(nodeRef)), null);
}
// ensure nothing is being added to a closed record folder
NodeRef recordFolder = childAssocRef.getParentRef();
Boolean isClosed = (Boolean) nodeService.getProperty(recordFolder, PROP_IS_CLOSED);
if (isClosed != null && isClosed) {
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_CHILDREN_IN_CLOSED_RECORD_FOLDER), null);
}
}
}
Aggregations