use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomModelConstraint.
@Override
public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters) {
if (constraintName == null) {
throw new InvalidArgumentException(CONSTRAINT_NAME_NULL_ERR);
}
final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
QName constraintQname = QName.createQName(modelDef.getName().getNamespaceURI(), constraintName);
ConstraintDefinition constraintDef = customModelService.getCustomConstraint(constraintQname);
if (constraintDef == null) {
throw new EntityNotFoundException(constraintName);
}
return new CustomModelConstraint(constraintDef, dictionaryService);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method deleteCustomAspect.
@Override
public void deleteCustomAspect(String modelName, String aspectName) {
// Check the current user is authorised to delete the custom model's aspect
validateCurrentUser();
if (aspectName == null) {
throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
}
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
if (existingModelDetails.isActive()) {
throw new ConstraintViolatedException("cmm.rest_api.aspect_cannot_delete");
}
Map<String, CustomAspect> allAspects = transformToMap(existingModelDetails.getAspects(), toNameFunction());
CustomAspect aspectToBeDeleted = allAspects.get(aspectName);
if (aspectToBeDeleted == null) {
throw new EntityNotFoundException(aspectName);
}
// Validate aspect's dependency
validateTypeAspectDelete(allAspects.values(), aspectToBeDeleted.getPrefixedName());
// Remove the validated aspect
allAspects.remove(aspectName);
existingModelDetails.setAspects(new ArrayList<>(allAspects.values()));
updateModel(existingModelDetails, "cmm.rest_api.aspect_delete_failure");
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method setM2Properties.
private void setM2Properties(M2Class m2Class, List<CustomModelProperty> properties, String namespacePrefix, Set<Pair<String, String>> namespacesToImport) {
if (properties != null) {
for (CustomModelProperty prop : properties) {
validateName(prop.getName(), "cmm.rest_api.property_name_null");
M2Property m2Property = m2Class.createProperty(constructName(prop.getName(), namespacePrefix));
m2Property.setTitle(prop.getTitle());
m2Property.setDescription(prop.getDescription());
m2Property.setMandatory(prop.isMandatory());
m2Property.setMandatoryEnforced(prop.isMandatoryEnforced());
m2Property.setMultiValued(prop.isMultiValued());
String dataType = prop.getDataType();
// Default type is d:text
if (StringUtils.isBlank(dataType)) {
dataType = DEFAULT_DATA_TYPE;
} else {
if (!dataType.contains(":")) {
throw new InvalidArgumentException("cmm.rest_api.property_datatype_invalid", new Object[] { dataType });
}
}
namespacesToImport.add(resolveToUriAndPrefix(dataType));
try {
// validate default values
this.valueDataTypeValidator.validateValue(dataType, prop.getDefaultValue());
} catch (Exception ex) {
throw new InvalidArgumentException(ex.getMessage());
}
m2Property.setType(dataType);
m2Property.setDefaultValue(prop.getDefaultValue());
// Set indexing options
m2Property.setIndexed(prop.isIndexed());
// so it can support boolean data type.
if (!BOOLEAN_DATA_TYPE.equals(dataType)) {
if (Facetable.TRUE == prop.getFacetable()) {
m2Property.setFacetable(true);
} else if (Facetable.FALSE == prop.getFacetable()) {
m2Property.setFacetable(false);
}
}
m2Property.setIndexTokenisationMode(prop.getIndexTokenisationMode());
// Check for constraints
List<String> constraintRefs = prop.getConstraintRefs();
List<CustomModelConstraint> constraints = prop.getConstraints();
if (constraintRefs.size() > 0) {
for (String ref : constraintRefs) {
Pair<String, String> prefixLocalName = splitPrefixedQName(ref);
if (!namespacePrefix.equals(prefixLocalName.getFirst())) {
throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.constraint_ref_not_defined", ref));
}
m2Property.addConstraintRef(ref);
}
}
if (constraints.size() > 0) {
for (CustomModelConstraint modelConstraint : constraints) {
String constraintName = null;
if (modelConstraint.getName() != null) {
validateName(modelConstraint.getName(), CONSTRAINT_NAME_NULL_ERR);
constraintName = constructName(modelConstraint.getName(), namespacePrefix);
}
M2Constraint m2Constraint = m2Property.addConstraint(constraintName, modelConstraint.getType());
// Set title, desc and parameters
setConstraintOtherData(modelConstraint, m2Constraint, dataType);
}
}
}
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomAspect.
@Override
public CustomAspect getCustomAspect(String modelName, String aspectName, Parameters parameters) {
if (aspectName == null) {
throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
}
final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
QName aspectQname = QName.createQName(modelDef.getName().getNamespaceURI(), aspectName);
AspectDefinition customAspectDef = customModelService.getCustomAspect(aspectQname);
if (customAspectDef == null) {
throw new EntityNotFoundException(aspectName);
}
// Check if inherited properties have been requested
boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
return convertToCustomAspect(customAspectDef, includeInheritedProps);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class FavouritesImpl method addFavourite.
@Override
public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters) {
Favourite ret = null;
personId = people.validatePerson(personId, true);
Target target = favourite.getTarget();
if (target == null) {
throw new InvalidArgumentException("target is missing");
} else if (target instanceof SiteTarget) {
SiteTarget siteTarget = (SiteTarget) target;
String guid = siteTarget.getSite().getGuid();
SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
NodeRef siteNodeRef = siteInfo.getNodeRef();
String siteId = siteInfo.getShortName();
try {
PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
ret = getFavourite(personFavourite, parameters);
} catch (SiteDoesNotExistException e) {
throw new RelationshipResourceNotFoundException(personId, siteId);
}
} else if (target instanceof DocumentTarget) {
DocumentTarget documentTarget = (DocumentTarget) target;
NodeRef nodeRef = documentTarget.getFile().getGuid();
if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null)) {
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
ret = getFavourite(personFavourite, parameters);
} else if (target instanceof FolderTarget) {
FolderTarget folderTarget = (FolderTarget) target;
NodeRef nodeRef = folderTarget.getFolder().getGuid();
if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE))) {
throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
}
PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
ret = getFavourite(personFavourite, parameters);
}
return ret;
}
Aggregations