use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionConstraint.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionConstraint(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
*/
public QName setCustomPropertyDefinitionConstraint(QName propQName, QName newLovConstraint) {
mandatory("propQName", propQName);
mandatory("newLovConstraint", newLovConstraint);
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 targetProp = findProperty(propQName, deserializedModel);
String dataType = targetProp.getType();
if (!dataType.equals(DataTypeDefinition.TEXT.toPrefixString(getNamespaceService()))) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(CannotApplyConstraintMetadataException.MSG_CANNOT_APPLY_CONSTRAINT, newLovConstraint, targetProp.getName(), dataType));
}
String lovConstraintQNameAsString = newLovConstraint.toPrefixString(getNamespaceService());
// Add the constraint - if it isn't already there (there should only be one constraint).
String refOfExistingConstraint = (targetProp.getConstraints().isEmpty() ? null : targetProp.getConstraints().get(0).getRef());
if (refOfExistingConstraint != null) {
targetProp.removeConstraintRef(refOfExistingConstraint);
}
targetProp.addConstraintRef(lovConstraintQNameAsString);
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("addCustomPropertyDefinitionConstraint: " + lovConstraintQNameAsString);
}
return propQName;
}
use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class ApplyDodCertModelFixesGet method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
LOGGER.info("Applying webscript-based patches to RM custom model in the repo.");
M2Model customModel = readCustomContentModel();
if (customModel == null) {
final String msg = "Custom content model could not be read";
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
M2Aspect customAssocsAspect = customModel.getAspect(customAspectName);
if (customAssocsAspect == null) {
final String msg = "Unknown aspect: " + customAspectName;
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
// MOB-1573. All custom references should have many-many multiplicity.
LOGGER.info("MOB-1573. All custom references should have many-many multiplicity.");
for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
classAssoc.setSourceMany(true);
classAssoc.setTargetMany(true);
}
// MOB-1621. Custom fields should be created as untokenized by default.
LOGGER.info("MOB-1621. Custom fields should be created as untokenized by default.");
List<String> allCustomPropertiesAspects = new ArrayList<String>(4);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_SERIES_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_CATEGORY_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_FOLDER_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_PROPERTIES);
for (String aspectName : allCustomPropertiesAspects) {
M2Aspect aspectObj = customModel.getAspect(aspectName);
List<M2Property> customProperties = aspectObj.getProperties();
for (M2Property propertyObj : customProperties) {
propertyObj.setIndexed(true);
propertyObj.setIndexedAtomically(true);
propertyObj.setStoredInIndex(false);
propertyObj.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
}
}
writeCustomContentModel(customModel);
LOGGER.info("Completed application of webscript-based patches to RM custom model in the repo.");
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("success", true);
return model;
}
use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionLabel.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionLabel(org.alfresco.service.namespace.QName, java.lang.String)
*/
public QName setCustomPropertyDefinitionLabel(QName propQName, String newLabel) {
mandatory("propQName", propQName);
PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
if (propDefn == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
}
if (newLabel == null) {
return propQName;
}
NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
M2Property targetProperty = findProperty(propQName, deserializedModel);
targetProperty.setTitle(newLabel);
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newLabel);
}
return propQName;
}
use of org.alfresco.repo.dictionary.M2Property in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method addCustomPropertyDefinition.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#addCustomPropertyDefinition(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName, java.lang.String, org.alfresco.service.namespace.QName, java.lang.String, java.lang.String, java.lang.String, boolean, boolean, boolean, org.alfresco.service.namespace.QName)
*/
public QName addCustomPropertyDefinition(QName propId, QName aspectName, String label, QName dataType, String title, String description, String defaultValue, boolean multiValued, boolean mandatory, boolean isProtected, QName lovConstraint) throws CustomMetadataException {
if (!isCustomisable(aspectName)) {
throw new NotCustomisableMetadataException(aspectName.toPrefixString(getNamespaceService()));
}
// title parameter is currently ignored. Intentionally.
if (propId == null) {
// Generate a propId
propId = this.generateQNameFor(label);
}
mandatory("aspectName", aspectName);
mandatory("label", label);
mandatory("dataType", dataType);
NodeRef modelRef = getCustomModelRef(propId.getNamespaceURI());
M2Model deserializedModel = readCustomContentModel(modelRef);
QName customAspect = getCustomAspect(aspectName);
M2Aspect customPropsAspect = deserializedModel.getAspect(customAspect.toPrefixString(getNamespaceService()));
if (customPropsAspect == null) {
throw new InvalidCustomAspectMetadataException(customAspect, aspectName.toPrefixString(getNamespaceService()));
}
String propIdAsString = propId.toPrefixString(getNamespaceService());
M2Property customProp = customPropsAspect.getProperty(propIdAsString);
if (customProp != null) {
throw new PropertyAlreadyExistsMetadataException(propIdAsString);
}
M2Property newProp = customPropsAspect.createProperty(propIdAsString);
newProp.setName(propIdAsString);
newProp.setType(dataType.toPrefixString(getNamespaceService()));
// Note that the title is used to store the RM 'label'.
newProp.setTitle(label);
newProp.setDescription(description);
newProp.setDefaultValue(defaultValue);
newProp.setMandatory(mandatory);
newProp.setProtected(isProtected);
newProp.setMultiValued(multiValued);
newProp.setIndexed(true);
newProp.setIndexedAtomically(true);
newProp.setStoredInIndex(false);
newProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
if (lovConstraint != null) {
if (!dataType.equals(DataTypeDefinition.TEXT)) {
throw new CannotApplyConstraintMetadataException(lovConstraint, propIdAsString, dataType);
}
String lovConstraintQNameAsString = lovConstraint.toPrefixString(getNamespaceService());
newProp.addConstraintRef(lovConstraintQNameAsString);
}
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("addCustomPropertyDefinition: " + label + "=" + propIdAsString + " to aspect: " + aspectName);
}
return propId;
}
Aggregations