Search in sources :

Example 16 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class SitesImpl method addSiteMember.

public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
    String personId = people.validatePerson(siteMember.getPersonId());
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        logger.debug("addSiteMember:  site does not exist " + siteId + " person " + personId);
        throw new EntityNotFoundException(siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    String role = siteMember.getRole();
    if (role == null) {
        logger.debug("addSiteMember:  Must provide a role " + siteMember);
        throw new InvalidArgumentException("Must provide a role");
    }
    if (siteService.isMember(siteId, personId)) {
        logger.debug("addSiteMember:  " + personId + " is already a member of site " + siteId);
        throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
    }
    if (!siteService.canAddMember(siteId, personId, role)) {
        logger.debug("addSiteMember:  PermissionDeniedException " + siteId + " person " + personId + " role " + role);
        throw new PermissionDeniedException();
    }
    try {
        siteService.setMembership(siteId, personId, role);
    } catch (UnknownAuthorityException e) {
        logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
        throw new InvalidArgumentException("Unknown role '" + role + "'");
    }
    return siteMember;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 17 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method updateTransferContainer.

/**
 * Utility method that updates a transfer container's name and properties
 *
 * @param nodeRef  the node to update
 * @param transferContainerInfo  information to update the transfer container with
 * @param parameters  request parameters
 */
public void updateTransferContainer(NodeRef nodeRef, TransferContainer transferContainerInfo, Parameters parameters) {
    Map<QName, Serializable> props = new HashMap<>(0);
    if (transferContainerInfo.getProperties() != null) {
        props = mapToNodeProperties(transferContainerInfo.getProperties());
    }
    String name = transferContainerInfo.getName();
    if ((name != null) && (!name.isEmpty())) {
        // update node name if needed
        props.put(ContentModel.PROP_NAME, name);
    }
    try {
        // update node properties - note: null will unset the specified property
        nodeService.addProperties(nodeRef, props);
    } catch (DuplicateChildNodeNameException dcne) {
        throw new ConstraintViolatedException(dcne.getMessage());
    }
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 18 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method updateNode.

/**
 * Utility method that updates a node's name and properties
 * @param nodeRef  the node to update
 * @param updateInfo  information to update the record with
 * @param parameters  request parameters
 */
public void updateNode(NodeRef nodeRef, RMNode updateInfo, Parameters parameters) {
    Map<QName, Serializable> props = new HashMap<>(0);
    if (updateInfo.getProperties() != null) {
        props = mapToNodeProperties(updateInfo.getProperties());
    }
    String name = updateInfo.getName();
    if ((name != null) && (!name.isEmpty())) {
        // update node name if needed
        props.put(ContentModel.PROP_NAME, name);
    }
    try {
        // update node properties - note: null will unset the specified property
        nodeService.addProperties(nodeRef, props);
    } catch (DuplicateChildNodeNameException dcne) {
        throw new ConstraintViolatedException(dcne.getMessage());
    }
    // update aspects
    List<String> aspectNames = updateInfo.getAspectNames();
    nodes.updateCustomAspects(nodeRef, aspectNames, ApiNodesModelFactory.EXCLUDED_ASPECTS);
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 19 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method updateCustomModel.

@Override
public CustomModel updateCustomModel(String modelName, CustomModel model, Parameters parameters) {
    // Check the current user is authorised to update the custom model
    validateCurrentUser();
    // Check to see if the model exists
    ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
    CustomModel existingModel = existingModelDetails.getModel();
    // the other properties should be untouched)
    if (hasSelectProperty(parameters, SELECT_STATUS)) {
        ModelStatus status = model.getStatus();
        if (status == null) {
            throw new InvalidArgumentException("cmm.rest_api.model_status_null");
        }
        try {
            if (ModelStatus.ACTIVE.equals(status)) {
                customModelService.activateCustomModel(modelName);
            } else {
                customModelService.deactivateCustomModel(modelName);
            }
            // update the model's status
            existingModel.setStatus(status);
            return existingModel;
        } catch (CustomModelConstraintException mce) {
            throw new ConstraintViolatedException(mce.getMessage());
        } catch (Exception ex) {
            throw new ApiException(ex.getMessage(), ex);
        }
    } else {
        if (model.getName() != null && !(existingModel.getName().equals(model.getName()))) {
            throw new InvalidArgumentException("cmm.rest_api.model_name_cannot_update");
        }
        existingModel.setNamespaceUri(model.getNamespaceUri());
        final boolean isNamespacePrefixChanged = !(existingModel.getNamespacePrefix().equals(model.getNamespacePrefix()));
        if (isNamespacePrefixChanged) {
            // Change types' and aspects' parents as well as the property constraint's Ref namespace prefix
            replacePrefix(existingModelDetails.getTypes(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
            replacePrefix(existingModelDetails.getAspects(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
        }
        existingModel.setNamespacePrefix(model.getNamespacePrefix());
        existingModel.setAuthor(model.getAuthor());
        existingModel.setDescription(model.getDescription());
        CustomModelDefinition modelDef = updateModel(existingModelDetails, "cmm.rest_api.model_update_failure");
        return new CustomModel(modelDef);
    }
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModelStatus(org.alfresco.rest.api.model.CustomModel.ModelStatus) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 20 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method validateImportedM2Model.

private void validateImportedM2Model(M2Model m2Model) {
    List<M2Namespace> namespaces = m2Model.getNamespaces();
    if (namespaces.size() > 1) {
        throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.model.import_namespace_multiple_found", namespaces.size()));
    } else if (namespaces.isEmpty()) {
        throw new ConstraintViolatedException("cmm.rest_api.model.import_namespace_undefined");
    }
    checkUnsupportedModelElements(m2Model.getTypes());
    checkUnsupportedModelElements(m2Model.getAspects());
}
Also used : M2Namespace(org.alfresco.repo.dictionary.M2Namespace) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Aggregations

ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)31 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)20 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)12 QName (org.alfresco.service.namespace.QName)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)7 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)7 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)7 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)4 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)4 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)4 AssociationExistsException (org.alfresco.service.cmr.repository.AssociationExistsException)4 ArrayList (java.util.ArrayList)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3 CustomModel (org.alfresco.rest.api.model.CustomModel)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 InsufficientStorageException (org.alfresco.rest.framework.core.exceptions.InsufficientStorageException)3