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