use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class RecordsManagementAdminBase method readCustomContentModel.
/**
* Gets the deserialized model
*
* @param modelNodeRef The node reference of the model
* @return The deserialized model
*/
protected M2Model readCustomContentModel(NodeRef modelNodeRef) {
ContentReader reader = getContentService().getReader(modelNodeRef, ContentModel.TYPE_CONTENT);
if (!reader.exists()) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CUSTOM_MODEL_NO_CONTENT, modelNodeRef.toString()));
}
InputStream contentIn = null;
M2Model deserializedModel = null;
try {
contentIn = reader.getContentInputStream();
deserializedModel = M2Model.createModel(contentIn);
} finally {
try {
if (contentIn != null) {
contentIn.close();
}
} catch (IOException ignored) {
// Intentionally empty.
}
}
return deserializedModel;
}
use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method unmakeCustomisable.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#unmakeCustomisable(org.alfresco.service.namespace.QName)
*/
@Override
public void unmakeCustomisable(QName type) {
mandatory("type", type);
if (customisableTypes == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_SERVICE_NOT_INIT));
}
QName customAspect = getCustomAspect(type);
if (getDictionaryService().getAspect(customAspect) != null) {
// TODO need to confirm that the custom properties are not being used!
NodeRef modelRef = getCustomModelRef(customAspect.getNamespaceURI());
M2Model model = readCustomContentModel(modelRef);
try {
// Create the new aspect to hold the custom properties
model.removeAspect(customAspect.toPrefixString(getNamespaceService()));
} finally {
writeCustomContentModel(modelRef, model);
}
customisableTypes.remove(type);
}
}
use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method initCustomMap.
/**
* Initialise custom type map
*/
private void initCustomMap() {
customisableTypes = new HashMap<QName, QName>(7);
Collection<QName> aspects = getDictionaryService().getAspects(RM_CUSTOM_MODEL);
for (QName aspect : aspects) {
AspectDefinition aspectDef = getDictionaryService().getAspect(aspect);
String name = aspectDef.getName().getLocalName();
if (name.endsWith("Properties")) {
QName type = null;
String prefixString = aspectDef.getDescription(getDictionaryService());
if (prefixString == null) {
// Backward compatibility from previous RM V1.0 custom models
if (CompatibilityModel.NAME_CUSTOM_RECORD_PROPERTIES.equals(name)) {
type = RecordsManagementModel.ASPECT_RECORD;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_FOLDER_PROPERTIES.equals(name)) {
type = RecordsManagementModel.TYPE_RECORD_FOLDER;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_CATEGORY_PROPERTIES.equals(name)) {
type = RecordsManagementModel.TYPE_RECORD_CATEGORY;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_SERIES_PROPERTIES.equals(name) && // a v1.0 installation has added custom properties
aspectDef.getProperties().size() != 0) {
type = CompatibilityModel.TYPE_RECORD_SERIES;
}
} else {
type = QName.createQName(prefixString, getNamespaceService());
}
// Add the customisable type to the map
if (type != null) {
customisableTypes.put(type, aspect);
// Remove customisable type from the pending list
if (pendingCustomisableTypes != null && pendingCustomisableTypes.contains(type)) {
pendingCustomisableTypes.remove(type);
}
}
}
}
// Deal with any pending types left over
if (pendingCustomisableTypes != null && pendingCustomisableTypes.size() != 0) {
NodeRef modelRef = getCustomModelRef(RecordsManagementModel.RM_CUSTOM_URI);
M2Model model = readCustomContentModel(modelRef);
try {
for (QName customisableType : pendingCustomisableTypes) {
QName customAspect = getCustomAspectImpl(customisableType);
// Create the new aspect to hold the custom properties
M2Aspect aspect = model.createAspect(customAspect.toPrefixString(getNamespaceService()));
aspect.setDescription(customisableType.toPrefixString(getNamespaceService()));
// Make a record of the customisable type
customisableTypes.put(customisableType, customAspect);
}
} finally {
writeCustomContentModel(modelRef, model);
}
}
// indicate map is initialised
isCustomMapInit = true;
}
use of org.alfresco.repo.dictionary.M2Model 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.M2Model 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