use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class NodesImpl method createNodeImpl.
private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props, QName assocTypeQName) {
NodeRef newNode = null;
if (props == null) {
props = new HashMap<>(1);
}
props.put(ContentModel.PROP_NAME, nodeName);
validatePropValues(props);
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
try {
newNode = nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, nodeTypeQName, props).getChildRef();
} catch (DuplicateChildNodeNameException dcne) {
// duplicate - name clash
throw new ConstraintViolatedException(dcne.getMessage());
}
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
postActivity(Activity_Type.ADDED, activityInfo, false);
return newNode;
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class NodesImpl method addChildren.
public List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities) {
NodeRef parentNodeRef = validateNode(parentNodeId);
List<AssocChild> result = new ArrayList<>(entities.size());
for (AssocChild assoc : entities) {
String childId = assoc.getChildId();
if (childId == null) {
throw new InvalidArgumentException("Missing childId");
}
QName assocTypeQName = getAssocType(assoc.getAssocType());
try {
NodeRef childNodeRef = validateNode(childId);
String nodeName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
} catch (AssociationExistsException aee) {
throw new ConstraintViolatedException(aee.getMessage());
} catch (DuplicateChildNodeNameException dcne) {
throw new ConstraintViolatedException(dcne.getMessage());
}
result.add(assoc);
}
return result;
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class PeopleImpl method create.
@Override
public Person create(Person person) {
validateCreatePersonData(person);
if (!isAdminAuthority()) {
// hence next block would cause 409 to be returned)
throw new PermissionDeniedException();
}
// no sensible way to know that it was thrown due to the user already existing - hence this check here.
if (personService.personExists(person.getUserName())) {
throw new ConstraintViolatedException("Person '" + person.getUserName() + "' already exists.");
}
// set enabled default value true
if (person.isEnabled() == null) {
person.setEnabled(true);
}
Map<QName, Serializable> props = person.toProperties();
MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
mas.createAuthentication(person.getUserName(), person.getPassword().toCharArray());
mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());
// Add custom properties
if (person.getProperties() != null) {
Map<String, Object> customProps = person.getProperties();
props.putAll(nodes.mapToNodeProperties(customProps));
}
NodeRef nodeRef = personService.createPerson(props);
// Add custom aspects
nodes.addCustomAspects(nodeRef, person.getAspectNames(), EXCLUDED_ASPECTS);
// and store the content URL in ContentModel.PROP_PERSONDESC
if (person.getDescription() != null) {
savePersonDescription(person.getDescription(), nodeRef);
}
// Return a fresh retrieval
return getPerson(person.getUserName());
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method create.
/**
* Create quick share.
* <p>
* Requires authenticated access.
*
* @param nodeIds
* @param parameters
* @return
*/
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
checkEnabled();
List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
for (QuickShareLink qs : nodeIds) {
String nodeId = qs.getNodeId();
if (nodeId == null) {
throw new InvalidArgumentException("A valid nodeId must be specified !");
}
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
try {
// Note: will throw InvalidNodeRefException (=> 404) if node does not exist
String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (sharedId != null) {
throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
}
// Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
try {
QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
} catch (InvalidNodeRefException inre) {
throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
} catch (QuickShareLinkExpiryActionException ex) {
throw new InvalidArgumentException(ex.getMessage());
}
} catch (AccessDeniedException ade) {
throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
} catch (InvalidNodeRefException inre) {
logger.warn("Unable to create shared link: [" + nodeRef + "]");
throw new EntityNotFoundException(nodeId);
}
}
return result;
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class SitesImpl method createSite.
/**
* Create default/fixed preset (Share) site - with DocLib container/component
*
* @param site
* @return
*/
public Site createSite(Site site, Parameters parameters) {
// note: if site id is null then will be generated from the site title
site = validateSite(site);
SiteInfo siteInfo = null;
try {
siteInfo = createSite(site);
} catch (SiteServiceException sse) {
if (sse.getMsgId().equals("site_service.unable_to_create")) {
throw new ConstraintViolatedException(sse.getMessage());
} else {
throw sse;
}
}
String siteId = siteInfo.getShortName();
NodeRef siteNodeRef = siteInfo.getNodeRef();
// default false (if not provided)
boolean skipShareSurfConfig = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_SURF_CONFIGURATION));
if (skipShareSurfConfig == false) {
// import default/fixed preset Share surf config
importSite(siteId, siteNodeRef);
}
// pre-create doclib
siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
// default false (if not provided)
boolean skipAddToFavorites = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_ADDTOFAVORITES));
if (skipAddToFavorites == false) {
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
// ignore result
favouritesService.addFavourite(personId, siteNodeRef);
}
return getSite(siteInfo, true);
}
Aggregations