use of org.alfresco.repo.dictionary.M2Property in project alfresco-remote-api by Alfresco.
the class AbstractEnterpriseOpenCMISTCKTest method overrideVersionableAspectProperties.
protected void overrideVersionableAspectProperties(ApplicationContext ctx) {
final DictionaryDAO dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
dictionaryDAO.removeModel(QName.createQName("cm:contentmodel"));
M2Model contentModel = M2Model.createModel(getClass().getClassLoader().getResourceAsStream("alfresco/model/contentModel.xml"));
M2Aspect versionableAspect = contentModel.getAspect("cm:versionable");
M2Property prop = versionableAspect.getProperty("cm:initialVersion");
prop.setDefaultValue(Boolean.FALSE.toString());
prop = versionableAspect.getProperty("cm:autoVersion");
prop.setDefaultValue(Boolean.FALSE.toString());
prop = versionableAspect.getProperty("cm:autoVersionOnUpdateProps");
prop.setDefaultValue(Boolean.FALSE.toString());
dictionaryDAO.putModel(contentModel);
}
use of org.alfresco.repo.dictionary.M2Property 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.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinition.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinition(org.alfresco.service.namespace.QName)
*/
public void removeCustomPropertyDefinition(QName propQName) {
mandatory("propQName", propQName);
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
String propQNameAsString = propQName.toPrefixString(getNamespaceService());
String aspectName = null;
boolean found = false;
// attempt to delete the property definition.
for (QName customisableType : getCustomisable()) {
aspectName = getCustomAspect(customisableType).toPrefixString(getNamespaceService());
M2Aspect customPropsAspect = deserializedModel.getAspect(aspectName);
if (customPropsAspect == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
}
M2Property prop = customPropsAspect.getProperty(propQNameAsString);
if (prop != null) {
if (logger.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Attempting to delete custom property: ");
msg.append(propQNameAsString);
logger.debug(msg.toString());
}
found = true;
customPropsAspect.removeProperty(propQNameAsString);
break;
}
}
if (!found) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQNameAsString));
}
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("deleteCustomPropertyDefinition: " + propQNameAsString + " from aspect: " + aspectName);
}
}
use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method updateCustomPropertyDefinitionName.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#updateCustomPropertyDefinitionName(org.alfresco.service.namespace.QName, java.lang.String)
*/
public QName updateCustomPropertyDefinitionName(QName propQName, String newName) throws CustomMetadataException {
mandatory("propQName", propQName);
PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
if (propDefn == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
}
if (newName == null) {
return propQName;
}
QName newPropQName = getQNameForClientId(newName);
if (newPropQName != null) {
PropertyDefinition newPropDefn = getDictionaryService().getProperty(newPropQName);
if (newPropDefn != null && !propDefn.equals(newPropDefn)) {
// The requested QName is already in use
String propIdAsString = newPropQName.toPrefixString(getNamespaceService());
throw new PropertyAlreadyExistsMetadataException(propIdAsString);
}
}
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
M2Property targetProperty = findProperty(propQName, deserializedModel);
targetProperty.setName(new StringBuilder().append(RecordsManagementCustomModel.RM_CUSTOM_PREFIX).append(QName.NAMESPACE_PREFIX).append(newName).toString());
targetProperty.setTitle(URLDecoder.decode(newName));
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newName);
}
return propQName;
}
use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinitionConstraints.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinitionConstraints(org.alfresco.service.namespace.QName)
*/
public QName removeCustomPropertyDefinitionConstraints(QName propQName) {
mandatory("propQName", propQName);
PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
if (propDefn == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
}
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
M2Property targetProperty = findProperty(propQName, deserializedModel);
// Need to count backwards to remove constraints
for (int i = targetProperty.getConstraints().size() - 1; i >= 0; i--) {
String ref = targetProperty.getConstraints().get(i).getRef();
targetProperty.removeConstraintRef(ref);
}
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("removeCustomPropertyDefinitionConstraints: " + propQName);
}
return propQName;
}
Aggregations