Search in sources :

Example 11 with PropertyDefinition

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

the class TransientNode method initNode.

/**
 * Initialises the node.
 *
 * @param data The properties and associations to initialise the node with
 */
protected void initNode(Map<QName, Serializable> data) {
    if (logger.isDebugEnabled())
        logger.debug("Initialising transient node with data: " + data);
    DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
    // marshall the given properties and associations into the internal maps
    this.associations = new QNameNodeMap(this, this);
    this.childAssociations = new QNameNodeMap(this, this);
    if (data != null) {
        // go through all data items and allocate to the correct internal list
        for (QName item : data.keySet()) {
            PropertyDefinition propDef = ddService.getProperty(item);
            if (propDef != null) {
                this.properties.put(item, data.get(item));
            } else {
                // see if the item is either type of association
                AssociationDefinition assocDef = ddService.getAssociation(item);
                if (assocDef != null) {
                    if (assocDef.isChild()) {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef child = (NodeRef) obj;
                            // create a child association reference, add it to a list and add the list
                            // to the list of child associations for this node
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
                            ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, child);
                            assocs.add(childRef);
                            this.childAssociations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentChild = (NodeRef) target;
                                    ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, currentChild);
                                    assocs.add(childRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.childAssociations.put(item, assocs);
                            }
                        }
                    } else {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef target = (NodeRef) obj;
                            // create a association reference, add it to a list and add the list
                            // to the list of associations for this node
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
                            AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
                            assocs.add(assocRef);
                            this.associations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentTarget = (NodeRef) target;
                                    AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
                                    assocs.add(assocRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.associations.put(item, assocs);
                            }
                        }
                    }
                }
            }
        }
    }
    // show that the maps have been initialised
    this.propsRetrieved = true;
    this.assocsRetrieved = true;
    this.childAssocsRetrieved = true;
    // setup the list of aspects the node would have
    TypeDefinition typeDef = ddService.getType(this.type);
    if (typeDef == null) {
        throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
    }
    // get flat list of all aspects for the type
    List<QName> defaultAspects = new ArrayList<QName>(16);
    getMandatoryAspects(typeDef, defaultAspects);
    this.aspects = new HashSet<QName>(defaultAspects);
    // setup remaining variables
    this.path = null;
    this.locked = Boolean.FALSE;
    this.workingCopyOwner = Boolean.FALSE;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with PropertyDefinition

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

the class BaseComponentGenerator method generateAndAdd.

@SuppressWarnings("unchecked")
public UIComponent generateAndAdd(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
    UIComponent component = null;
    if (item instanceof UIProperty) {
        // get the property definition
        PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName());
        // create the component and add it to the property sheet
        component = createComponent(context, propertySheet, item);
        // setup the component for multi value editing if necessary
        component = setupMultiValuePropertyIfNecessary(context, propertySheet, item, propertyDef, component);
        // setup common aspects of the property i.e. value binding
        setupProperty(context, propertySheet, item, propertyDef, component);
        // add the component now, it needs to be added before the validations
        // are setup as we need access to the component id, which in turn needs
        // to have a parent to get the correct id
        item.getChildren().add(component);
        // setup the component for mandatory validation if necessary
        setupMandatoryPropertyIfNecessary(context, propertySheet, item, propertyDef, component);
        // setup any constraints the property has
        setupConstraints(context, propertySheet, item, propertyDef, component);
        // setup any converter the property needs
        setupConverter(context, propertySheet, item, propertyDef, component);
    } else if (item instanceof UISeparator) {
        // just create the component and add it
        component = createComponent(context, propertySheet, item);
        item.getChildren().add(component);
    } else {
        // get the association definition
        AssociationDefinition assocationDef = this.getAssociationDefinition(context, propertySheet.getNode(), item.getName());
        // create the component and add it to the property sheet
        component = createComponent(context, propertySheet, item);
        // setup common aspects of the association i.e. value binding
        setupAssociation(context, propertySheet, item, assocationDef, component);
        // add the component now, it needs to be added before the validations
        // are setup as we need access to the component id, which needs have a
        // parent to get the correct id
        item.getChildren().add(component);
        // setup the component for mandatory validation if necessary
        setupMandatoryAssociationIfNecessary(context, propertySheet, item, assocationDef, component);
        // setup any converter the association needs
        setupConverter(context, propertySheet, item, assocationDef, component);
    }
    return component;
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) UIProperty(org.alfresco.web.ui.repo.component.property.UIProperty) UIComponent(javax.faces.component.UIComponent) UISeparator(org.alfresco.web.ui.repo.component.property.UISeparator) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 13 with PropertyDefinition

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

the class TextFieldGenerator method getListOfValuesConstraint.

/**
 * Retrieves the list of values constraint for the item, if it has one
 *
 * @param context FacesContext
 * @param propertySheet The property sheet being generated
 * @param item The item being generated
 * @return The constraint if the item has one, null otherwise
 */
protected ListOfValuesConstraint getListOfValuesConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
    ListOfValuesConstraint lovConstraint = null;
    // get the property definition for the item
    PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName());
    if (propertyDef != null) {
        // go through the constaints and see if it has the
        // list of values constraint
        List<ConstraintDefinition> constraints = propertyDef.getConstraints();
        for (ConstraintDefinition constraintDef : constraints) {
            Constraint constraint = constraintDef.getConstraint();
            if (constraint instanceof ListOfValuesConstraint) {
                lovConstraint = (ListOfValuesConstraint) constraint;
                break;
            }
        }
    }
    return lovConstraint;
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 14 with PropertyDefinition

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

the class StartWorkflowWizard method getPackageActionGroup.

/**
 * Returns the action group the current task uses for the workflow package
 *
 * @return action group id
 */
public String getPackageActionGroup() {
    String actionGroup = null;
    WorkflowDefinition flowDef = this.getWorkflows().get(this.selectedWorkflow);
    WorkflowTaskDefinition taskDef = flowDef.getStartTaskDefinition();
    if (taskDef != null) {
        PropertyDefinition propDef = taskDef.metadata.getProperties().get(WorkflowModel.PROP_PACKAGE_ACTION_GROUP);
        if (propDef != null) {
            actionGroup = propDef.getDefaultValue();
        }
    }
    return actionGroup;
}
Also used : WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 15 with PropertyDefinition

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

the class RecordServiceImpl method isRecordMetadataProperty.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#isRecordMetadataProperty(org.alfresco.service.namespace.QName)
 */
@Override
public boolean isRecordMetadataProperty(QName property) {
    boolean result = false;
    PropertyDefinition propertyDefinition = dictionaryService.getProperty(property);
    if (propertyDefinition != null) {
        ClassDefinition classDefinition = propertyDefinition.getContainerClass();
        if (classDefinition != null && getRecordMetadataAspectsMap().containsKey(classDefinition.getName())) {
            result = true;
        }
    }
    return result;
}
Also used : ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

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