use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method validateTypeAspectParent.
private void validateTypeAspectParent(AbstractClassModel typeAspect, CustomModel existingModel) {
String parentPrefixedName = typeAspect.getParentName();
if (StringUtils.isBlank(parentPrefixedName)) {
return;
}
Pair<String, String> prefixLocaNamePair = splitPrefixedQName(parentPrefixedName);
String parentPrefix = prefixLocaNamePair.getFirst();
String parentLocalName = prefixLocaNamePair.getSecond();
// Validate parent prefix and localName
// We know that the values are not null, we just check against the defined RegEx
validateName(parentPrefix, null);
validateName(parentLocalName, null);
final boolean isAspect = (typeAspect instanceof CustomAspect);
ClassDefinition classDefinition = null;
QName qname = null;
if (existingModel.getNamespacePrefix().equals(parentPrefix)) {
// Check for types/aspects within the model
qname = QName.createQName(existingModel.getNamespaceUri(), parentLocalName);
classDefinition = (isAspect) ? customModelService.getCustomAspect(qname) : customModelService.getCustomType(qname);
} else {
// Make sure the namespace URI and Prefix are registered
Pair<String, String> uriPrefixPair = resolveToUriAndPrefix(parentPrefixedName);
qname = QName.createQName(uriPrefixPair.getFirst(), parentLocalName);
classDefinition = (isAspect) ? dictionaryService.getAspect(qname) : dictionaryService.getType(qname);
}
if (classDefinition == null) {
String msgId = (isAspect) ? "cmm.rest_api.aspect_parent_not_exist" : "cmm.rest_api.type_parent_not_exist";
throw new ConstraintViolatedException(I18NUtil.getMessage(msgId, parentPrefixedName));
} else {
checkCircularDependency(classDefinition.getModel(), existingModel, parentPrefixedName);
}
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException 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.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class GroupsImpl method createGroupMember.
@Override
public GroupMember createGroupMember(String groupId, GroupMember groupMember) {
validateGroupId(groupId, false);
// Not allowed to modify a GROUP_EVERYONE member.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
}
validateGroupMember(groupMember);
AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
if (!authorityService.authorityExists(groupMember.getId())) {
throw new EntityNotFoundException(groupMember.getId());
}
AuthorityType existingAuthorityType = AuthorityType.getAuthorityType(groupMember.getId());
if (existingAuthorityType != authorityType) {
throw new IllegalArgumentException("Incorrect group member type, " + (AuthorityType.USER.equals(existingAuthorityType) ? Groups.PARAM_MEMBER_TYPE_PERSON : existingAuthorityType) + " exists with the given id");
}
authorityService.addAuthority(groupId, groupMember.getId());
String authority = authorityService.getName(authorityType, groupMember.getId());
return getGroupMember(authority);
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class GroupsImpl method deleteGroupMembership.
public void deleteGroupMembership(String groupId, String groupMemberId) {
validateGroupId(groupId, false);
// Not allowed to modify a GROUP_EVERYONE member.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
}
validateGroupMemberId(groupMemberId);
// Verify if groupMemberId is member of groupId
AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId);
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true);
if (!parents.contains(groupId)) {
throw new NotFoundException(groupMemberId + " is not member of " + groupId);
}
authorityService.removeAuthority(groupId, groupMemberId);
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class NodesImpl method addTargets.
public List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities) {
List<AssocTarget> result = new ArrayList<>(entities.size());
NodeRef srcNodeRef = validateNode(sourceNodeId);
for (AssocTarget assoc : entities) {
String targetNodeId = assoc.getTargetId();
if (targetNodeId == null) {
throw new InvalidArgumentException("Missing targetId");
}
String assocTypeStr = assoc.getAssocType();
QName assocTypeQName = getAssocType(assocTypeStr);
try {
NodeRef tgtNodeRef = validateNode(targetNodeId);
nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
} catch (AssociationExistsException aee) {
throw new ConstraintViolatedException("Node association '" + assocTypeStr + "' already exists from " + sourceNodeId + " to " + targetNodeId);
} catch (IllegalArgumentException iae) {
// note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
throw new InvalidArgumentException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId);
}
result.add(assoc);
}
return result;
}
Aggregations