use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method getCustomPropertyDefinitions.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#getCustomPropertyDefinitions(org.alfresco.module.org_alfresco_module_rm.CustomisableRmElement)
*/
public Map<QName, PropertyDefinition> getCustomPropertyDefinitions(QName customisableType) {
mandatory("customisableType", customisableType);
Map<QName, PropertyDefinition> propDefns = null;
QName relevantAspectQName = getCustomAspect(customisableType);
AspectDefinition aspectDefn = getDictionaryService().getAspect(relevantAspectQName);
if (aspectDefn != null) {
propDefns = aspectDefn.getProperties();
}
return propDefns;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition 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.service.cmr.dictionary.PropertyDefinition 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;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition 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.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RecordsManagementAuditServiceImpl method writeAuditTrailEntry.
/**
* Writes an audit trail entry to the given writer
*
* @param writer The writer to write to
* @param entry The entry to write
* @param reportFormat The format to write the header in
* @throws IOException
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void writeAuditTrailEntry(Writer writer, RecordsManagementAuditEntry entry, ReportFormat reportFormat) throws IOException {
if (writer == null) {
return;
}
if (reportFormat == ReportFormat.HTML) {
writer.write("<div class=\"audit-entry\">\n");
writer.write("<div class=\"audit-entry-header\">");
writer.write("<span class=\"label\">Timestamp:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(entry.getTimestamp().toString()));
writer.write("</span>");
writer.write("<span class=\"label\">User:</span>");
writer.write("<span class=\"value\">");
writer.write(entry.getFullName() != null ? StringEscapeUtils.escapeHtml(entry.getFullName()) : StringEscapeUtils.escapeHtml(entry.getUserName()));
writer.write("</span>");
if (entry.getUserRole() != null && entry.getUserRole().length() > 0) {
writer.write("<span class=\"label\">Role:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(entry.getUserRole()));
writer.write("</span>");
}
if (entry.getEvent() != null && entry.getEvent().length() > 0) {
writer.write("<span class=\"label\">Event:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(getAuditEventLabel(entry.getEvent())));
writer.write("</span>\n");
}
writer.write("</div>\n");
writer.write("<div class=\"audit-entry-node\">");
if (entry.getIdentifier() != null && entry.getIdentifier().length() > 0) {
writer.write("<span class=\"label\">Identifier:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(entry.getIdentifier()));
writer.write("</span>");
}
if (entry.getNodeType() != null && entry.getNodeType().length() > 0) {
writer.write("<span class=\"label\">Type:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(entry.getNodeType()));
writer.write("</span>");
}
if (entry.getPath() != null && entry.getPath().length() > 0) {
// we need to strip off the first part of the path
String path = entry.getPath();
String displayPath = path;
int idx = path.indexOf('/', 1);
if (idx != -1) {
displayPath = "/File Plan" + path.substring(idx);
}
writer.write("<span class=\"label\">Location:</span>");
writer.write("<span class=\"value\">");
writer.write(StringEscapeUtils.escapeHtml(displayPath));
writer.write("</span>");
}
writer.write("</div>\n");
if (entry.getChangedProperties() != null) {
writer.write("<table class=\"changed-values-table\" cellspacing=\"0\">");
writer.write("<tr><th>Property</th><th>Previous Value</th><th>New Value</th></tr>");
// create an entry for each property that changed
for (QName valueName : entry.getChangedProperties().keySet()) {
Pair<Serializable, Serializable> values = entry.getChangedProperties().get(valueName);
writer.write("<tr><td>");
writer.write(getPropertyLabel(valueName));
writer.write("</td><td>");
// inspect the property to determine it's data type
QName propDataType = DataTypeDefinition.TEXT;
PropertyDefinition propDef = dictionaryService.getProperty(valueName);
if (propDef != null) {
propDataType = propDef.getDataType().getName();
}
if (DataTypeDefinition.MLTEXT.equals(propDataType)) {
writer.write(values.getFirst() == null ? "<none>" : StringEscapeUtils.escapeHtml(convertToMlText((Map) values.getFirst()).getDefaultValue()));
writer.write("</td><td>");
writer.write(values.getSecond() == null ? "<none>" : StringEscapeUtils.escapeHtml(convertToMlText((Map) values.getSecond()).getDefaultValue()));
} else {
Serializable oldValue = values.getFirst();
writer.write(oldValue == null ? "<none>" : StringEscapeUtils.escapeHtml(oldValue.toString()));
writer.write("</td><td>");
Serializable newValue = values.getSecond();
writer.write(newValue == null ? "<none>" : StringEscapeUtils.escapeHtml(newValue.toString()));
}
writer.write("</td></tr>");
}
writer.write("</table>\n");
}
writer.write("</div>");
} else {
try {
JSONObject json = new JSONObject();
json.put("timestamp", entry.getTimestampString());
json.put("userName", entry.getUserName());
json.put("userRole", entry.getUserRole() == null ? "" : entry.getUserRole());
json.put("fullName", entry.getFullName() == null ? "" : entry.getFullName());
json.put("nodeRef", entry.getNodeRef() == null ? "" : entry.getNodeRef());
// TODO: Find another way for checking the event
if (entry.getEvent().equals("Create Person") && entry.getNodeRef() != null) {
NodeRef nodeRef = entry.getNodeRef();
String userName = null;
if (nodeService.exists(nodeRef)) {
userName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
}
json.put("nodeName", userName == null ? "" : userName);
json.put("createPerson", true);
} else if (entry.getEvent().equals("Delete Person") && entry.getNodeRef() != null) {
if (entry.getBeforeProperties() != null) {
String userName = (String) entry.getBeforeProperties().get(ContentModel.PROP_USERNAME);
json.put("nodeName", userName == null ? "" : userName);
}
json.put("deletePerson", true);
} else {
json.put("nodeName", entry.getNodeName() == null ? "" : entry.getNodeName());
}
// TODO: Find another way for checking the event
if (entry.getEvent().equals("Delete RM Object")) {
json.put("deleteObject", true);
}
json.put("nodeType", entry.getNodeType() == null ? "" : entry.getNodeType());
json.put("event", entry.getEvent() == null ? "" : getAuditEventLabel(entry.getEvent()));
json.put("identifier", entry.getIdentifier() == null ? "" : entry.getIdentifier());
json.put("path", entry.getPath() == null ? "" : entry.getPath());
JSONArray changedValues = new JSONArray();
if (entry.getChangedProperties() != null) {
// create an entry for each property that changed
for (QName valueName : entry.getChangedProperties().keySet()) {
Pair<Serializable, Serializable> values = entry.getChangedProperties().get(valueName);
JSONObject changedValue = new JSONObject();
changedValue.put("name", getPropertyLabel(valueName));
// inspect the property to determine it's data type
QName propDataType = DataTypeDefinition.TEXT;
PropertyDefinition propDef = dictionaryService.getProperty(valueName);
if (propDef != null) {
propDataType = propDef.getDataType().getName();
}
// handle output of mltext properties
if (DataTypeDefinition.MLTEXT.equals(propDataType)) {
changedValue.put("previous", values.getFirst() == null ? "" : convertToMlText((Map) values.getFirst()).getDefaultValue());
changedValue.put("new", values.getSecond() == null ? "" : convertToMlText((Map) values.getSecond()).getDefaultValue());
} else {
changedValue.put("previous", values.getFirst() == null ? "" : values.getFirst().toString());
changedValue.put("new", values.getSecond() == null ? "" : values.getSecond().toString());
}
changedValues.put(changedValue);
}
}
json.put("changedValues", changedValues);
writer.write(json.toString());
} catch (JSONException je) {
writer.write("{}");
}
}
}
Aggregations