Search in sources :

Example 71 with PropertyDefinition

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);
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Field(org.alfresco.repo.forms.Field) Serializable(java.io.Serializable) FieldGroup(org.alfresco.repo.forms.FieldGroup) QName(org.alfresco.service.namespace.QName) Map(java.util.Map) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 72 with PropertyDefinition

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);
    }
}
Also used : Field(org.alfresco.repo.forms.Field) FieldGroup(org.alfresco.repo.forms.FieldGroup) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 73 with PropertyDefinition

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;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 74 with PropertyDefinition

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;
    }
}
Also used : Serializable(java.io.Serializable) AccessDeniedException(net.sf.acegisecurity.AccessDeniedException) Constraint(org.alfresco.service.cmr.dictionary.Constraint) QName(org.alfresco.service.namespace.QName) MatchLogic(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint.MatchLogic) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap)

Example 75 with PropertyDefinition

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;
}
Also used : Entry(java.util.Map.Entry) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)77 QName (org.alfresco.service.namespace.QName)51 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)24 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 Map (java.util.Map)15 Serializable (java.io.Serializable)14 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)9 Collection (java.util.Collection)7 List (java.util.List)7 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 Builder (org.apache.lucene.search.BooleanQuery.Builder)7 Constraint (org.alfresco.service.cmr.dictionary.Constraint)6 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)6 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)6