CML Documentation? E.G. how to add Aspect to existing node?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2007 05:26 PM
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);
}
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);
}
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2007 03:35 AM
i am trying the code and i have the same code. Some solution? Thanks

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2007 08:21 AM
Try modifying the code to …
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
… // 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
