cancel
Showing results for 
Search instead for 
Did you mean: 

CML Documentation? E.G. how to add Aspect to existing node?

jasperk64
Champ in-the-making
Champ in-the-making
Is there an update on availability of CML documentation?

For example, I downloaded the 1.3 community SDK and tried to mod the Query1 to add an aspect to an *existing* node, but I can't get it to work (creating a node and adding an aspect in the same CML block with a "local id" of "1" works).

Here is the code I tried, what's wrong with my CML? I put in print statements and the code seems to execute fine (no exceptions) but after the code is done, the aspect was not added to the existing node.

  // Look string "UNIQUE" in text, multiple existing nodes have this
  Query query = new Query(QueryLanguageEnum.lucene, "TEXT:'UNIQUE'");
               
  // Execute the query
  QueryResult queryResult = repositoryService.query(storeRef, query, false);
               
  // Add aspect to first result
  ResultSet resultSet = queryResult.getResultSet();
  ResultSetRow[] rows = resultSet.getRows();
  if (rows == null)
  {
        System.out.println("No query results found.");
  }
  else
  {
   // Get the id of the first result
   String firstResultId = rows[0].getNode().getId();

   // Setting a property
  NamedValue[] specificationProps = new NamedValue[1];
                   
  // Is it possible to not set at all and still add aspect?
  specificationProps[0] = Utils.createNamedValue(PROP_MYPROP,"DDD");
        
  CMLAddAspect addAspect = new CMLAddAspect(ASPECT_MYASPECT, specificationProps, null, firstResultId);
                
                    // Construct CML Block
                    CML aspect_cml = new CML();
                    aspect_cml.setAddAspect(new CMLAddAspect[] {addAspect});
                    repositoryService.update(aspect_cml);
}
2 REPLIES 2

nimind
Champ in-the-making
Champ in-the-making
i am trying the code and i have the same code. Some solution? Thanks

rwetherall
Confirmed Champ
Confirmed Champ
Try modifying the code to …


   …

    // Get the reference of the first result
   Reference reference = rows[0].getNode().getReference();

   // Setting a property
   NamedValue[] specificationProps = new NamedValue[1];

   // Is it possible to not set at all and still add aspect?
   specificationProps[0] = Utils.createNamedValue(PROP_MYPROP,"DDD");

   CMLAddAspect addAspect = new CMLAddAspect(ASPECT_MYASPECT,    specificationProps, new Predicate(new Reference[]{reference}, null, null), "1");

   …

Basically the last parameter of the CMLAddAspect constructor is an id used internally to the CML statements, not a reference to an exisiting node.

As a note, the predicate could be build up to contain the list of all the References returned to from the query.  Then you'll only need to make one update call.  This means that the work will be done in a single transaction and with one payload sent and recieved from the server.

Hope this helps,
Roy