Search in sources :

Example 1 with FieldData

use of org.alfresco.repo.forms.FormData.FieldData in project alfresco-repository by Alfresco.

the class TypeAndAspectsFormProcessor method persistNode.

@Override
protected void persistNode(NodeRef nodeRef, FormData data) {
    super.persistNode(nodeRef, data);
    QName type = this.nodeService.getType(nodeRef);
    Set<QName> aspectNames = getAspectNames(getTypedItem(typeItem));
    TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, aspectNames);
    Map<QName, PropertyDefinition> propDefs = typeDef.getProperties();
    Map<QName, Serializable> propsToPersist = new HashMap<QName, Serializable>();
    for (FieldData fieldData : data) {
        String fieldName = fieldData.getName();
        if (fieldName.startsWith(PROP_DATA_PREFIX)) {
            processPropertyPersist(nodeRef, propDefs, fieldData, propsToPersist, data);
        }
    }
    this.nodeService.addProperties(nodeRef, propsToPersist);
}
Also used : FieldData(org.alfresco.repo.forms.FormData.FieldData) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 2 with FieldData

use of org.alfresco.repo.forms.FormData.FieldData in project alfresco-repository by Alfresco.

the class RemoveChildAssocCommand method persistNode.

/**
 * Persists the given FormData on the given NodeRef
 *
 * @param nodeRef The NodeRef to persist the form data on
 * @param data The FormData to persist
 */
protected void persistNode(NodeRef nodeRef, FormData data) {
    // get the property definitions for the type of node being persisted
    QName type = this.nodeService.getType(nodeRef);
    TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService.getAspects(nodeRef));
    Map<QName, AssociationDefinition> assocDefs = typeDef.getAssociations();
    Map<QName, ChildAssociationDefinition> childAssocDefs = typeDef.getChildAssociations();
    Map<QName, PropertyDefinition> propDefs = typeDef.getProperties();
    Map<QName, Serializable> propsToPersist = new HashMap<QName, Serializable>(data.getNumberOfFields());
    List<AbstractAssocCommand> assocsToPersist = new ArrayList<AbstractAssocCommand>();
    for (FieldData fieldData : data) {
        // NOTE: ignore file fields for now, not supported yet!
        if (fieldData.isFile() == false) {
            String fieldName = fieldData.getName();
            if (fieldName.startsWith(PROP_DATA_PREFIX)) {
                processPropertyPersist(nodeRef, propDefs, fieldData, propsToPersist, data);
            } else if (fieldName.startsWith(ASSOC_DATA_PREFIX)) {
                processAssociationPersist(nodeRef, assocDefs, childAssocDefs, fieldData, assocsToPersist);
            } else if (getLogger().isWarnEnabled()) {
                getLogger().warn("Ignoring unrecognised field '" + fieldName + "'");
            }
        }
    }
    // persist the properties using addProperties as this changes the repo
    // values of
    // those properties included in the Map, but leaves any other property
    // values unchanged,
    // whereas setProperties causes the deletion of properties that are not
    // included in the Map.
    this.nodeService.addProperties(nodeRef, propsToPersist);
    for (AbstractAssocCommand cmd : assocsToPersist) {
        // TODO If there is an attempt to add and remove the same assoc in
        // one request,
        // we could drop each request and do nothing.
        cmd.updateAssociations(nodeService);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) FieldData(org.alfresco.repo.forms.FormData.FieldData) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)

Example 3 with FieldData

use of org.alfresco.repo.forms.FormData.FieldData in project alfresco-repository by Alfresco.

the class ActionFormProcessor method getActionedUponNodeRef.

/**
 * This method returns the actionedUponNodeRef based on the submitted form data.
 */
private NodeRef getActionedUponNodeRef(ActionDefinition item, FormData data) {
    FieldData actionedUponNodeRef = data.getFieldData(DESTINATION);
    NodeRef result = null;
    // executer implementations will throw an exception on execution.
    if (actionedUponNodeRef != null) {
        String nodeRefString = (String) actionedUponNodeRef.getValue();
        if (NodeRef.isNodeRef(nodeRefString)) {
            result = new NodeRef(nodeRefString);
        } else {
            // We will disallow a malformed actionedUponNodeRef string
            throw new FormException("Illegal actionedUponNodeRef: " + nodeRefString);
        }
    }
    return result;
}
Also used : FieldData(org.alfresco.repo.forms.FormData.FieldData) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FormException(org.alfresco.repo.forms.FormException)

Example 4 with FieldData

use of org.alfresco.repo.forms.FormData.FieldData in project alfresco-repository by Alfresco.

the class ScriptFormData method getData.

public ScriptableHashMap<String, ScriptFieldData> getData() {
    ScriptableHashMap<String, ScriptFieldData> result = new ScriptableHashMap<String, ScriptFieldData>();
    if (this.formData != null) {
        for (FieldData fieldData : formData) {
            ScriptFieldData wrappedFieldData = new ScriptFieldData(fieldData);
            result.put(fieldData.getName(), wrappedFieldData);
        }
    }
    return result;
}
Also used : FieldData(org.alfresco.repo.forms.FormData.FieldData) ScriptableHashMap(org.alfresco.repo.jscript.ScriptableHashMap)

Example 5 with FieldData

use of org.alfresco.repo.forms.FormData.FieldData in project alfresco-repository by Alfresco.

the class TaskFormProcessorTest method checkPackageActionGroups.

private void checkPackageActionGroups(FormData formData) {
    FieldData pckgActionData = formData.getFieldData("prop_bpm_packageActionGroup");
    assertNotNull(pckgActionData);
    assertEquals("", pckgActionData.getValue());
    FieldData pckgItemActionData = formData.getFieldData("prop_bpm_packageItemActionGroup");
    assertNotNull(pckgItemActionData);
    assertEquals("read_package_item_actions", pckgItemActionData.getValue());
}
Also used : FieldData(org.alfresco.repo.forms.FormData.FieldData)

Aggregations

FieldData (org.alfresco.repo.forms.FormData.FieldData)12 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 QName (org.alfresco.service.namespace.QName)6 ArrayList (java.util.ArrayList)4 FormException (org.alfresco.repo.forms.FormException)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 List (java.util.List)3 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 Collection (java.util.Collection)1 StringTokenizer (java.util.StringTokenizer)1 FieldDefinition (org.alfresco.repo.forms.FieldDefinition)1 ScriptableHashMap (org.alfresco.repo.jscript.ScriptableHashMap)1 Action (org.alfresco.service.cmr.action.Action)1 ParameterDefinition (org.alfresco.service.cmr.action.ParameterDefinition)1 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)1 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)1 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)1