use of org.alfresco.rest.api.model.CustomModelProperty in project alfresco-remote-api by Alfresco.
the class BaseCustomModelApiTest method compareCustomTypesAspects.
protected void compareCustomTypesAspects(AbstractClassModel expectedDetails, AbstractClassModel actualDetails, String... excludeFields) {
List<CustomModelProperty> expectedProps = expectedDetails.getProperties();
List<CustomModelProperty> actualProps = actualDetails.getProperties();
// Sort them
sortIfnotNull(expectedProps);
sortIfnotNull(actualProps);
boolean propEqualResult = true;
if (expectedProps.size() == actualProps.size()) {
for (int i = 0, size = expectedProps.size(); i < size; i++) {
boolean equalProp = EqualsBuilder.reflectionEquals(expectedProps.get(i), actualProps.get(i), excludeFields);
if (!equalProp) {
propEqualResult = false;
break;
}
}
} else {
propEqualResult = false;
}
if (excludeFields.length > 0) {
int size = excludeFields.length;
excludeFields = Arrays.copyOf(excludeFields, size + 1);
excludeFields[size] = "properties";
}
boolean result = EqualsBuilder.reflectionEquals(expectedDetails, actualDetails, excludeFields);
String typesAspects = (expectedDetails instanceof CustomAspect) ? "aspects" : "types";
assertTrue("Two " + typesAspects + " are not equal. Expected:<" + expectedDetails.toString() + "> but was:<" + actualDetails.toString() + ">", (result && propEqualResult));
}
use of org.alfresco.rest.api.model.CustomModelProperty 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.api.model.CustomModelProperty in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method replacePrefix.
private void replacePrefix(List<? extends AbstractClassModel> existingTypesOrAspects, String modelOldNamespacePrefix, String modelNewNamespacePrefix) {
for (AbstractClassModel classModel : existingTypesOrAspects) {
// Type/Aspect's parent name
String parentName = classModel.getParentName();
if (parentName != null) {
Pair<String, String> prefixLocalNamePair = splitPrefixedQName(parentName);
// As we don't want to modify the parent name of the imported models.
if (modelOldNamespacePrefix.equals(prefixLocalNamePair.getFirst())) {
// Change the parent name prefix, to a new model namespace prefix.
String newParentName = constructName(prefixLocalNamePair.getSecond(), modelNewNamespacePrefix);
classModel.setParentName(newParentName);
}
}
// Change the property constraint ref
List<CustomModelProperty> properties = classModel.getProperties();
for (CustomModelProperty prop : properties) {
List<String> constraintRefs = prop.getConstraintRefs();
if (constraintRefs.size() > 0) {
List<String> modifiedRefs = new ArrayList<>(constraintRefs.size());
for (String ref : constraintRefs) {
// We don't need to check if the prefix is equal to the model prefix here, as it was
// done upon adding the constraint refs in the setM2Properties method.
Pair<String, String> prefixLocalNamePair = splitPrefixedQName(ref);
// Change the constraint ref prefix, to a new model namespace prefix.
String newRef = constructName(prefixLocalNamePair.getSecond(), modelNewNamespacePrefix);
modifiedRefs.add(newRef);
}
prop.setConstraintRefs(modifiedRefs);
}
}
}
}
use of org.alfresco.rest.api.model.CustomModelProperty in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method mergeProperties.
private void mergeProperties(AbstractClassModel existingDetails, AbstractClassModel newDetails, Parameters parameters, boolean isModelActive) {
validateList(newDetails.getProperties(), "cmm.rest_api.properties_empty_null");
// Transform existing properties into a map
Map<String, CustomModelProperty> existingProperties = transformToMap(existingDetails.getProperties(), toNameFunction());
// Transform new properties into a map
Map<String, CustomModelProperty> newProperties = transformToMap(newDetails.getProperties(), toNameFunction());
String propName = parameters.getParameter(PARAM_UPDATE_PROP);
// (propName == null) => property create request
if (propName == null) {
// As this is a create request, check for duplicate properties
for (String name : newProperties.keySet()) {
if (existingProperties.containsKey(name)) {
throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.property_create_name_already_in_use", name));
}
}
} else {
// Update request
CustomModelProperty existingProp = existingProperties.get(propName);
if (existingProp == null) {
throw new EntityNotFoundException(propName);
}
CustomModelProperty modifiedProp = newProperties.get(propName);
if (modifiedProp == null) {
throw new InvalidArgumentException("cmm.rest_api.property_update_prop_not_found", new Object[] { propName });
}
existingProp.setTitle(modifiedProp.getTitle());
existingProp.setDescription(modifiedProp.getDescription());
existingProp.setDefaultValue(modifiedProp.getDefaultValue());
existingProp.setConstraintRefs(modifiedProp.getConstraintRefs());
existingProp.setConstraints(modifiedProp.getConstraints());
if (isModelActive) {
validateActivePropertyUpdate(existingProp, modifiedProp);
}
existingProp.setDataType(modifiedProp.getDataType());
existingProp.setMandatory(modifiedProp.isMandatory());
existingProp.setMandatoryEnforced(modifiedProp.isMandatoryEnforced());
existingProp.setMultiValued(modifiedProp.isMultiValued());
}
// Override properties
existingProperties.putAll(newProperties);
existingDetails.setProperties(new ArrayList<>(existingProperties.values()));
}
use of org.alfresco.rest.api.model.CustomModelProperty in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method convertToCustomModelProperty.
private List<CustomModelProperty> convertToCustomModelProperty(ClassDefinition classDefinition, boolean includeInherited) {
Collection<PropertyDefinition> ownProperties = null;
ClassDefinition parentDef = classDefinition.getParentClassDefinition();
if (!includeInherited && parentDef != null) {
// Remove inherited properties
ownProperties = removeRightEntries(classDefinition.getProperties(), parentDef.getProperties()).values();
} else {
ownProperties = classDefinition.getProperties().values();
}
List<CustomModelProperty> customProperties = new ArrayList<>(ownProperties.size());
for (PropertyDefinition propDef : ownProperties) {
customProperties.add(new CustomModelProperty(propDef, dictionaryService));
}
return customProperties;
}
Aggregations