Search in sources :

Example 6 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class UserCSVUploadPost method processSpreadsheetUpload.

/**
 * Builds user objects based on the supplied data. If a row is empty, then
 *  the child String array should be empty too. (Needs to be present so that
 *  the line number reporting works)
 */
private void processSpreadsheetUpload(String[][] data, List<Map<QName, String>> users) {
    // What we consider to be the literal string "user name" when detecting
    // if a row is an example/header one or not
    // Note - all of these want to be lower case!
    List<String> usernameIsUsername = new ArrayList<String>();
    // The English literals
    usernameIsUsername.add("username");
    usernameIsUsername.add("user name");
    // And the localised form too if found
    PropertyDefinition unPD = dictionaryService.getProperty(ContentModel.PROP_USERNAME);
    if (unPD != null) {
        if (unPD.getTitle(dictionaryService) != null)
            usernameIsUsername.add(unPD.getTitle(dictionaryService).toLowerCase());
        if (unPD.getDescription(dictionaryService) != null)
            usernameIsUsername.add(unPD.getDescription(dictionaryService).toLowerCase());
    }
    // Process the contents of the spreadsheet
    for (int lineNumber = 0; lineNumber < data.length; lineNumber++) {
        Map<QName, String> user = new HashMap<QName, String>();
        String[] userData = data[lineNumber];
        if (userData == null || userData.length == 0 || (userData.length == 1 && userData[0].trim().length() == 0)) {
            // Empty line, skip
            continue;
        }
        boolean required = true;
        for (int i = 0; i < COLUMNS.length; i++) {
            if (COLUMNS[i] == null) {
                required = false;
                continue;
            }
            String value = null;
            if (userData.length > i) {
                value = userData[i];
            }
            if (value == null || value.length() == 0) {
                if (required) {
                    throw new ResourceBundleWebScriptException(Status.STATUS_OK, getResources(), ERROR_BLANK_COLUMN, new Object[] { COLUMNS[i].getLocalName(), (i + 1), (lineNumber + 1) });
                }
            } else {
                user.put(COLUMNS[i], value);
            }
        }
        // If no password was given, use their surname
        if (!user.containsKey(ContentModel.PROP_PASSWORD)) {
            user.put(ContentModel.PROP_PASSWORD, "");
        }
        // Skip any user who looks like an example file heading
        // i.e. a username of "username" or "user name"
        String username = user.get(ContentModel.PROP_USERNAME).toLowerCase();
        if (usernameIsUsername.contains(username)) {
        // Skip
        } else {
            // Looks like a real line, keep it
            users.add(user);
        }
    }
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 7 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class AbstractClassGet method executeImpl.

/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    Map<String, Object> model = new HashMap<String, Object>(3);
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
    QName classQname = getClassQname(req);
    classdef.put(classQname, this.dictionaryservice.getClass(classQname));
    propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
    assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
    model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
    model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
    return model;
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Collection(java.util.Collection) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 8 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class AbstractClassesGet method executeImpl.

/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
    String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
    String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
    Map<String, Object> model = new HashMap<String, Object>();
    List<QName> qnames = new ArrayList<QName>();
    QName classQname = null;
    QName myModel = null;
    // if classfilter is not given, then it defaults to all
    if (classFilter == null) {
        classFilter = "all";
    }
    // validate classfilter
    if (isValidClassFilter(classFilter) == false) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
    }
    // name alone has no meaning without namespaceprefix
    if (namespacePrefix == null && name != null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
    }
    // validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
    if (namespacePrefix != null) {
        // validate name parameter if present along with the namespaceprefix
        if (name != null) {
            classQname = getClassQname(namespacePrefix, name);
            classdef.put(classQname, this.dictionaryservice.getClass(classQname));
            propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
            assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
        } else {
            // if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
            String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
            for (QName qnameObj : this.dictionaryservice.getAllModels()) {
                if (qnameObj.getNamespaceURI().equals(namespaceUri)) {
                    name = qnameObj.getLocalName();
                    myModel = getQNameForModel(namespacePrefix, name);
                    // check the classfilter to pull out either all or type or aspects
                    if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
                        qnames.addAll(this.dictionaryservice.getAspects(myModel));
                        qnames.addAll(this.dictionaryservice.getTypes(myModel));
                    } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
                        qnames.addAll(this.dictionaryservice.getTypes(myModel));
                    } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
                        qnames.addAll(this.dictionaryservice.getAspects(myModel));
                    }
                }
            }
        }
    }
    // if namespacePrefix is null, then check the classfilter to pull out either all or type or aspects
    if (myModel == null) {
        if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
            qnames.addAll(this.dictionaryservice.getAllAspects());
            qnames.addAll(this.dictionaryservice.getAllTypes());
        } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
            qnames.addAll(this.dictionaryservice.getAllTypes());
        } else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
            qnames.addAll(this.dictionaryservice.getAllAspects());
        }
    }
    if (classdef.isEmpty() == true) {
        for (QName qnameObj : qnames) {
            classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
            propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
            assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
        }
    }
    List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
    Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator(dictionaryservice));
    model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
    model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, reorderedValues(classDefinitions, propdef));
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, reorderedValues(classDefinitions, assocdef));
    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) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Collection(java.util.Collection)

Example 9 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project acs-community-packaging by Alfresco.

the class LinkPropertiesDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    try {
        NodeRef nodeRef = getEditableNode().getNodeRef();
        Map<String, Object> props = getEditableNode().getProperties();
        // get the name and move the node as necessary
        String name = (String) props.get(ContentModel.PROP_NAME);
        if (name != null) {
            getFileFolderService().rename(nodeRef, name);
        }
        Map<QName, Serializable> properties = this.getNodeService().getProperties(nodeRef);
        // we need to put all the properties from the editable bag back into
        // the format expected by the repository
        // deal with adding the "titled" aspect if required
        String title = (String) props.get(ContentModel.PROP_TITLE);
        String description = (String) props.get(ContentModel.PROP_DESCRIPTION);
        if (title != null || description != null) {
            // add the aspect to be sure it's present
            getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
        // other props will get added later in setProperties()
        }
        // add the remaining properties
        Iterator<String> iterProps = props.keySet().iterator();
        while (iterProps.hasNext()) {
            String propName = iterProps.next();
            QName qname = QName.createQName(propName);
            // make sure the property is represented correctly
            Serializable propValue = (Serializable) props.get(propName);
            // check for empty strings when using number types, set to null in this case
            if ((propValue != null) && (propValue instanceof String) && (propValue.toString().length() == 0)) {
                PropertyDefinition propDef = this.getDictionaryService().getProperty(qname);
                if (propDef != null) {
                    if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
                        propValue = null;
                    }
                }
            }
            properties.put(qname, propValue);
        }
        // send the properties back to the repository
        this.getNodeService().setProperties(nodeRef, properties);
    } catch (InvalidNodeRefException err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() }));
        // this failure means the node no longer exists - we cannot show the doc properties screen
        outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
        outcome = null;
        ReportedException.throwIfNecessary(e);
    }
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 10 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getCustomPropertyLookup.

/**
 * Helper map to lookup custom property QName strings against a DataTypeDefinition
 *
 * @return custom property lookup Map
 */
private Map<String, DataTypeDefinition> getCustomPropertyLookup() {
    if ((properties.getCustomPropertyLookup() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        properties.setCustomPropertyLookup(new HashMap<String, DataTypeDefinition>(7, 1.0f));
        List<CustomProperty> customProps = getSearchConfig().getCustomProperties();
        if (customProps != null) {
            DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
            for (CustomProperty customProp : customProps) {
                PropertyDefinition propDef = null;
                QName propQName = Repository.resolveToQName(customProp.Property);
                if (customProp.Type != null) {
                    QName type = Repository.resolveToQName(customProp.Type);
                    TypeDefinition typeDef = dd.getType(type);
                    propDef = typeDef.getProperties().get(propQName);
                } else if (customProp.Aspect != null) {
                    QName aspect = Repository.resolveToQName(customProp.Aspect);
                    AspectDefinition aspectDef = dd.getAspect(aspect);
                    propDef = aspectDef.getProperties().get(propQName);
                }
                if (propQName != null && propDef != null) {
                    properties.getCustomPropertyLookup().put(propQName.toString(), propDef.getDataType());
                }
            }
        }
    }
    return properties.getCustomPropertyLookup();
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

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