use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RecordsManagementFormFilter method addPropertyFieldsToGroup.
/**
* Add property fields to group
*
* @param form
* @param props
* @param setId
*/
protected void addPropertyFieldsToGroup(Form form, Map<QName, PropertyDefinition> props, String setId, String setLabel) {
if (props != null) {
for (Map.Entry<QName, PropertyDefinition> entry : props.entrySet()) {
PropertyDefinition prop = entry.getValue();
String id = form.getItem().getId();
id = id.replaceFirst("/", "://");
NodeRef nodeRef = new NodeRef(id);
Serializable value = nodeService.getProperty(nodeRef, entry.getKey());
FieldGroup group = new FieldGroup(setId, setLabel, false, false, null);
Field field = FieldUtils.makePropertyField(prop, value, group, namespaceService, dictionaryService);
form.addField(field);
if (logger.isDebugEnabled()) {
logger.debug("Adding custom property .. " + prop.getName().toString() + " .. with value " + value + ".. to group .. " + setId);
}
}
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RecordsManagementTypeFormFilter method addCustomRMProperties.
/**
* Adds a property definition for each of the custom properties for the
* given RM type to the given form.
*
* @param rmTypeCustomAspect Enum representing the RM type to add custom
* properties for
* @param form The form to add the properties to
*/
protected void addCustomRMProperties(QName customisableType, Form form) {
ParameterCheck.mandatory("customisableType", customisableType);
ParameterCheck.mandatory("form", form);
Map<QName, PropertyDefinition> customProps = rmAdminService.getCustomPropertyDefinitions(customisableType);
if (customProps != null && !customProps.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("Found " + customProps.size() + " custom properties for customisable type " + customisableType);
}
// setup field definition for each custom property
Collection<PropertyDefinition> properties = customProps.values();
FieldGroup group = new FieldGroup(CUSTOM_RM_FIELD_GROUP_ID, null, false, false, null);
List<Field> fields = FieldUtils.makePropertyFields(properties, group, namespaceService, dictionaryService);
form.addFields(fields);
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RmPropertiesGet method executeImpl.
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, boolean isRM) {
QName classQName = null;
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
if (className != null && className.length() != 0) {
classQName = createClassQName(className);
if (classQName == null) {
// Error
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
}
}
String[] names = req.getParameterValues(PARAM_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String namespaceURI = null;
if (namespacePrefix != null) {
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
}
Map<QName, PropertyDefinition> propMap = null;
if (classQName == null) {
if (names != null) {
propMap = new HashMap<QName, PropertyDefinition>(names.length);
for (String name : names) {
QName propQName = QName.createQName(name, namespaceService);
PropertyDefinition propDef = dictionaryservice.getProperty(propQName);
if (propDef != null) {
propMap.put(propQName, propDef);
}
}
} else {
Collection<QName> propQNames = getProperties(isRM);
propMap = new HashMap<QName, PropertyDefinition>(propQNames.size());
for (QName propQName : propQNames) {
propMap.put(propQName, dictionaryservice.getProperty(propQName));
}
}
} else {
// Get all the property definitions for the class
propMap = dictionaryservice.getClass(classQName).getProperties();
}
// Filter the properties by URI
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet()) {
if ((namespaceURI != null && namespaceURI.equals(entry.getKey().getNamespaceURI())) || namespaceURI == null) {
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator(dictionaryservice));
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
return model;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method hasAccess.
/**
* Check whether access to 'record component' node is vetoed for current user due to caveat(s)
*
* @param nodeRef
* @return false, if caveat(s) veto access otherwise return true
*/
@SuppressWarnings("unchecked")
public boolean hasAccess(NodeRef nodeRef) {
try {
if ((!nodeService.exists(nodeRef)) || (caveatAspectQNames.size() == 0)) {
return true;
}
boolean found = false;
for (QName caveatAspectQName : caveatAspectQNames) {
if (nodeService.hasAspect(nodeRef, caveatAspectQName)) {
found = true;
break;
}
}
if (!found) {
// no caveat aspect
return true;
} else {
// check for caveats
String userName = AuthenticationUtil.getRunAsUser();
if (userName != null) {
// check all text properties
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
for (Map.Entry<QName, Serializable> entry : props.entrySet()) {
QName propName = entry.getKey();
PropertyDefinition propDef = dictionaryService.getProperty(propName);
if ((propDef != null) && (propDef.getDataType().getName().equals(DATATYPE_TEXT))) {
List<ConstraintDefinition> conDefs = propDef.getConstraints();
for (ConstraintDefinition conDef : conDefs) {
Constraint con = conDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
RMListOfValuesConstraint rmCon = ((RMListOfValuesConstraint) con);
String conName = rmCon.getShortName();
MatchLogic matchLogic = rmCon.getMatchLogicEnum();
Map<String, List<String>> caveatConstraintDef = caveatConfig.get(conName);
if (caveatConstraintDef == null) {
continue;
} else {
Set<String> userGroupNames = authorityService.getAuthoritiesForUser(userName);
List<String> allowedValues = getRMAllowedValues(userName, userGroupNames, conName);
List<String> propValues = null;
Object val = entry.getValue();
if (val instanceof String) {
propValues = new ArrayList<String>(1);
propValues.add((String) val);
} else if (val instanceof List) {
propValues = (List<String>) val;
}
if (propValues != null && !isAllowed(propValues, allowedValues, matchLogic)) {
if (logger.isDebugEnabled()) {
logger.debug("Veto access: caveat=" + conName + ", userName=" + userName + ", nodeRef=" + nodeRef + ", propName=" + propName + ", propValues=" + propValues + ", allowedValues=" + allowedValues);
}
return false;
}
}
}
}
}
}
}
return true;
}
} catch (AccessDeniedException ade) {
return false;
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project records-management by Alfresco.
the class CustomPropertyDefinitionsGet method executeImpl.
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String propId = templateVars.get(PROP_ID);
String elementName = req.getParameter(ELEMENT);
if (logger.isDebugEnabled() && elementName != null) {
logger.debug("Getting custom property definitions for elementName " + elementName);
} else if (logger.isDebugEnabled() && propId != null) {
logger.debug("Getting custom property definition for propId " + propId);
}
// If propId has been provided then this is a request for a single custom-property-defn.
// else it is a request for all defined on the specified element.
List<PropertyDefinition> propData = new ArrayList<PropertyDefinition>();
if (propId != null) {
QName propQName = rmAdminService.getQNameForClientId(propId);
PropertyDefinition propDefn = rmAdminService.getCustomPropertyDefinitions().get(propQName);
if (propQName == null || propDefn == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Property definition for " + propId + " not found.");
}
propData.add(propDefn);
} else if (elementName != null) {
QName customisableType = mapToTypeQName(elementName);
Map<QName, PropertyDefinition> currentCustomProps = rmAdminService.getCustomPropertyDefinitions(customisableType);
if (currentCustomProps != null) {
for (Entry<QName, PropertyDefinition> entry : currentCustomProps.entrySet()) {
propData.add(entry.getValue());
}
}
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Either elementName or propId must be specified.");
}
if (logger.isDebugEnabled()) {
logger.debug("Retrieved custom property definitions: " + propData);
}
model.put("customProps", propData);
return model;
}
Aggregations