cancel
Showing results for 
Search instead for 
Did you mean: 

Create node with mandatory associations

csering
Champ in-the-making
Champ in-the-making
Hi all,

I am trying to create a node using nodeService.createNode() in Java, but get an IntegrityException error because a mandatory association is not present. Anyone done this before? I've tried setting the association in property map and setting
<mandatory enforced="false">true</mandatory>
in the content model. Currently using Alfresco 4.1.4 (super old I know - client requirement.)

I've included the basic code, model, and error message for reference. Thanks for your assistance.

Christy


Java:

Map<QName, Serializable> props = new HashMap<QName, Serializable>();

props.put(ContentModel.PROP_NAME, id);
props.put(MyModel.PROP_ID, id);
props.put(MyModel.PROP_PERIOD, "period");
props.put(MyModel.ASSOC_BUSINESS, myBusinessNodeRef);

ChildAssociationRef createdNodeChildRef = nodeService.createNode(
   parentFolderNodeRef,
   ContentModel.ASSOC_CONTAINS,
   QName.createQName((String) props.get(ContentModel.PROP_NAME)),
   MyModel.TYPE_MY_FOLDER,
   props
);


Model:

<association name="myModel:business">
   <title>Business</title>
   <source>
      <mandatory>false</mandatory>
      <many>true</many>
   </source>
   <target>
      <class>myOtherModel:BusinessClient</class>
      <mandatory enforced="false">true</mandatory>
      <many>false</many>
   </target>
</association>


Error:
The association target multiplicity has been violated:
   Source Node: workspace://SpacesStore/386a0725-f46d-414b-8ee7-dbb80b1b256f
   Association: Association[ class=ClassDef[name={my.model}requestAttributes], name={my.model}business, target class={my.other.model}BusinessClient, source role=null, target role=null]
   Required target Multiplicity: 1..1
   Actual target Multiplicity: 0

2 REPLIES 2

lutz_horn
Champ in-the-making
Champ in-the-making
This is a known issue (https://issues.alfresco.com/jira/browse/MNT-12367). Even though you set

<blockcode>
<mandatory enforced="false">true</mandatory>
</blockcode>

the association is enforced <strong>on node creation</strong>. You don't get a chance to set the association.

Don't use a mandatory association until this bug is fixed in Alfresco.

csering
Champ in-the-making
Champ in-the-making
This an existing client model that cannot be changed, as is usually the case in these forums. Answers like 'Don't use a mandatory association until this bug is fixed in Alfresco' are not helpful or productive. Thank you however, for the JIRA link.

Anyone else come up with a workaround? Thanks.