cancel
Showing results for 
Search instead for 
Did you mean: 

Aspect and association

vince20151
Champ in-the-making
Champ in-the-making
Hello,

We have a document type that we like to add an aspect to it. The aspect is project id. A document can have no project or multiple projects associated with it. So I thought it is best to add project as an aspect. Also because project aspect will be used in many other types of documents, folders and workflow.

What is the best way to define this aspect in the model. I have defined it as stand alone and then in some action code, attach the project aspect to the document. This seems to work fine but it only work for one project ID. I need to be able to associate multiple project to the document.

I need to make change to my model and code but not sure what is the best approach/design of the aspect. Should I be using associations in defining the aspect. How would the model look after the change and the corresponding java code.
Below is snippet of the model and the java code. It only works for one project but not multiple.

/* Model */

<aspect name="myCoSmiley TonguerojectAspect">
            <properties>
                <property name="MyCoSmiley TonguerojectId">
                    <description>Project Id</description>
                    <type>d:text</type>
                    <multiple>true</multiple> <!– this setting does not seem to have any effect –>
                </property>
            </properties>
</aspect>

/* java code */
/* add project IDs to a map */
Map <QName,Serializable> aspectValuesMap = new HashMap <QName,Serializable>();
QName QNameProjectId = QName.createQName(MYCO_NAMESPACE,"ProjectId");
aspectValuesMap .put(QNameProjectId , projId1);
aspectValuesMap .put(QNameProjectId , projId2); // This code does not add a second proj ID since the key is the same so it will displace the first ID

/* add the map to the node of an existing document */
QName QNameProjectAspect = QName.createQName(MYCO_NAMESPACE,"projectAspect");
nodeService.addAspect(myDocNodeRef, QNameProjectAspect , aspectValuesMap );

1 REPLY 1

mitpatoliya
Star Collaborator
Star Collaborator
You need to convert "projectid" property as multivalue property,So that it can accomodate more then one project id.I see you have already added <multiple>true</multiple> to make it multivalue.

So I think missing piece is java code.
For a multivalue property you need to create list of values and set it into property.

Map <QName,Serializable> aspectValuesMap = new HashMap <QName,Serializable>();
QName QNameProjectId = QName.createQName(MYCO_NAMESPACE,"ProjectId");
List pids=new ArrayList();
pids.add(10);
pids.add(20);
aspectValuesMap .put(QNameProjectId , pids);

something like this.* Note this is just roughly typed code make sure to correct it syntactically.