Search in sources :

Example 11 with AspectDefinition

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

the class UISearchCustomProperties method createComponentsFromConfig.

/**
 * Build the components from the Advanced Search config entries
 *
 * @param context FacesContext
 */
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context) {
    DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
    AdvancedSearchConfigElement config = (AdvancedSearchConfigElement) Application.getConfigService(context).getConfig("Advanced Search").getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID);
    // create an appropriate component for each custom property
    // using the DataDictionary to look-up labels and value types
    String beanBinding = (String) getAttributes().get("bean") + '.' + (String) getAttributes().get("var");
    List<CustomProperty> props = config.getCustomProperties();
    if (props != null) {
        for (CustomProperty property : props) {
            try {
                // try to find the Property definition for the specified Type or Aspect
                PropertyDefinition propDef = null;
                if (property.Type != null) {
                    QName type = Repository.resolveToQName(property.Type);
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef == null) {
                        logger.warn("No Type Definition found for: " + property.Type + " - Was an Aspect expected?");
                        continue;
                    }
                    propDef = typeDef.getProperties().get(Repository.resolveToQName(property.Property));
                } else if (property.Aspect != null) {
                    QName aspect = Repository.resolveToQName(property.Aspect);
                    AspectDefinition aspectDef = dd.getAspect(aspect);
                    if (aspectDef == null) {
                        logger.warn("No Aspect Definition found for: " + property.Aspect + " - Was a Type expected?");
                        continue;
                    }
                    propDef = aspectDef.getProperties().get(Repository.resolveToQName(property.Property));
                }
                // if we found a def, then we can build components to represent it
                if (propDef != null) {
                    // resolve display label I18N message
                    String label;
                    if (property.LabelId != null && property.LabelId.length() != 0) {
                        label = Application.getMessage(context, property.LabelId);
                    } else {
                        // or use dictionary label or QName as last resort
                        label = propDef.getTitle(dd) != null ? propDef.getTitle(dd) : propDef.getName().getLocalName();
                    }
                    // special handling for Date and DateTime
                    DataTypeDefinition dataTypeDef = propDef.getDataType();
                    if (DataTypeDefinition.DATE.equals(dataTypeDef.getName()) || DataTypeDefinition.DATETIME.equals(dataTypeDef.getName())) {
                        getChildren().add(generateControl(context, propDef, label, beanBinding));
                    } else {
                        // add ListOfValues constraint components
                        ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
                        if (constraint != null && propDef != null && propDef.isProtected() == false) {
                            getChildren().add(generateCheck(context, propDef, beanBinding));
                            getChildren().add(generateLabel(context, label + ": "));
                        } else {
                            getChildren().add(generateLabel(context, ""));
                            getChildren().add(generateLabel(context, label + ": "));
                        }
                        getChildren().add(generateControl(context, propDef, null, beanBinding));
                    }
                }
            } catch (DictionaryException ddErr) {
                logger.warn("Error building custom properties for Advanced Search: " + ddErr.getMessage());
            }
        }
    }
}
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) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) AdvancedSearchConfigElement(org.alfresco.web.config.AdvancedSearchConfigElement) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 12 with AspectDefinition

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

the class TransientNode method createNew.

/**
 * Construct a transient node for an item yet to be created in the Repository.
 *
 * This will apply any one-time initialisation required upon creation of the node
 * e.g. assignment of default values.
 *
 * @param dictionaryService dictionary service
 * @param typeDef The type definition this node will represent
 * @param name The name of the node
 * @param data The properties and associations this node will have
 * @return  transient node
 */
public static TransientNode createNew(DictionaryService dictionaryService, TypeDefinition typeDef, String name, Map<QName, Serializable> data) {
    // build a complete anonymous type for the start task
    List<AspectDefinition> aspects = typeDef.getDefaultAspects();
    List<QName> aspectNames = new ArrayList<QName>(aspects.size());
    getMandatoryAspects(typeDef, aspectNames);
    ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames);
    // initialise start task values
    Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
    if (data != null) {
        startValues.putAll(data);
    }
    // apply default values
    Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
    for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet()) {
        String defaultValue = entry.getValue().getDefaultValue();
        if (defaultValue != null) {
            if (startValues.get(entry.getKey()) == null) {
                startValues.put(entry.getKey(), (Serializable) DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue));
            }
        }
    }
    return new TransientNode(typeDef.getName(), name, startValues);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with AspectDefinition

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

the class TransientNode method getMandatoryAspects.

/**
 * Gets a flattened list of all mandatory aspects for a given class
 *
 * @param classDef  the class
 * @param aspects  a list to hold the mandatory aspects
 */
private static void getMandatoryAspects(ClassDefinition classDef, List<QName> aspects) {
    for (AspectDefinition aspect : classDef.getDefaultAspects()) {
        QName aspectName = aspect.getName();
        if (!aspects.contains(aspectName)) {
            aspects.add(aspect.getName());
            getMandatoryAspects(aspect, aspects);
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Example 14 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project SearchServices by Alfresco.

the class Solr4QueryParser method createAspectQuery.

protected Query createAspectQuery(String queryText, boolean exactOnly) {
    AspectDefinition target = QueryParserUtils.matchAspectDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
    if (target == null) {
        return new TermQuery(new Term(FIELD_ASPECT, "_unknown_"));
    }
    if (exactOnly) {
        QName targetQName = target.getName();
        TermQuery termQuery = new TermQuery(new Term(FIELD_ASPECT, targetQName.toString()));
        return termQuery;
    } else {
        Collection<QName> subclasses = dictionaryService.getSubAspects(target.getName(), true);
        BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
        for (QName qname : subclasses) {
            AspectDefinition current = dictionaryService.getAspect(qname);
            if (target.getName().equals(current.getName()) || current.getIncludedInSuperTypeQuery()) {
                TermQuery termQuery = new TermQuery(new Term(FIELD_ASPECT, qname.toString()));
                if (termQuery != null) {
                    booleanQuery.add(termQuery, Occur.SHOULD);
                }
            }
        }
        return booleanQuery.build();
    }
}
Also used : MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) QName(org.alfresco.service.namespace.QName) Builder(org.apache.lucene.search.BooleanQuery.Builder) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) Term(org.apache.lucene.index.Term) Builder(org.apache.lucene.search.BooleanQuery.Builder)

Example 15 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.

the class RecordsManagementAdminBase method getCustomAssociations.

/**
 * Gets all the custom associations
 *
 * @return All custom associations
 */
protected Map<QName, AssociationDefinition> getCustomAssociations() {
    Map<QName, AssociationDefinition> customAssociations = new HashMap<QName, AssociationDefinition>();
    AspectDefinition aspectDefn = getDictionaryService().getAspect(ASPECT_CUSTOM_ASSOCIATIONS);
    if (aspectDefn != null) {
        customAssociations.putAll(aspectDefn.getAssociations());
    }
    return customAssociations;
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Aggregations

AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)22 QName (org.alfresco.service.namespace.QName)21 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 Map (java.util.Map)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 Serializable (java.io.Serializable)3 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)3 HashSet (java.util.HashSet)2 ParameterDefinitionImpl (org.alfresco.repo.action.ParameterDefinitionImpl)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)2 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 CustomProperty (org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 SelectItem (javax.faces.model.SelectItem)1