I'm doing some work with Node Categories through CWS - to locate the specific information I need to manipulate I'm currently iterating through all of the Category data until I arrive at the attribute of interest, which seems inelegant at best (see code fragment below).
So, given the methods available today with CS10.5 what's the better way to do this? I sense what I should be doing is pulling an empty reference object based on the definition of the category of interest, 'locating' the matching object within the Category object(s) associated with the node, updating the attribute of interest through the reference object, and merging the resulting modified Category data back into the node.
Any suggestions would be most welcome (bonus karma for Java samples).
------------------------
// pull the Metadata associated with this Node Metadata thisNodeMetadata = docManClient.getNode(thisNode.getID()).getMetadata();// so long as there is something to look throughif ((thisNodeMetadata.getAttributeGroups()).size() > 0) { List<AttributeGroup> thisNodeAttributeGroups = thisNodeMetadata.getAttributeGroups(); // walk the sets of Attributes for (AttributeGroup thisNodeAttributeGroup : thisNodeAttributeGroups) { // until we find the set of interest if (thisNodeAttributeGroup.getDisplayName().equals("Legacy Document Info")) { List<DataValue> thisNodeAttributeGroupDataValues = thisNodeAttributeGroup.getValues(); // then walk the attributes within the set of interest for (DataValue thisNodeAttributeGroupDataValue : thisNodeAttributeGroupDataValues){ // until we find the attribute of interest if (thisNodeAttributeGroupDataValue.getDescription().equals("Legacy Path")) { // only change it if it's not the same so we don't waste cycles if (!(((StringValue)thisNodeAttributeGroupDataValue).getValues()).toString().equals(targetPath)) { // clear out the attribute if it isn't already empty if (!((StringValue)thisNodeAttributeGroupDataValue).getValues().isEmpty()) ((StringValue)thisNodeAttributeGroupDataValue).getValues().clear(); // and add in the new value ((StringValue)thisNodeAttributeGroupDataValue).getValues().add(targetPath); // now go and update the List of AttributeGroupDataValues with the modified AttributeGroupDataValue int indexOfAGDV = thisNodeAttributeGroupDataValues.indexOf(thisNodeAttributeGroupDataValue); thisNodeAttributeGroupDataValues.set(indexOfAGDV, thisNodeAttributeGroupDataValue); // finally go and update the List of AttributeGroups with the modified AttributeGroup int indexOfAG = thisNodeAttributeGroups.indexOf(thisNodeAttributeGroup); thisNodeMetadata.getAttributeGroups().set(indexOfAG, thisNodeAttributeGroup); // and commit the change back to the database docManClient.setNodeMetadata(thisNode.getID(), thisNodeMetadata); } } } } }}