I try to update categories on folder using java CMIS api and I had a little surprise:
when I set the category I have to provide the alfcmis:nodeRef, but when I browse categories I retrieve cmis
bjectId and so in order to update categories I have to change all the list .
Isn't there a simpler way to do it? (I mean retrieving the same kind of information I provide to create)
I use apache opencmis java client version 1.1.0 and I request information upon an Alfresco community Edition 5.2.0
public String getCategoryRefByOid(String catOid){
ItemIterable<QueryResult> query = session.query(String.format("select * from cm:category where cmis:objectId = '%s'", catOid), false);
if(query.getTotalNumItems()!=0) {
QueryResult next = query.iterator().next();
String propertyValueById = next.getPropertyValueById("alfcmis:nodeRef");
return propertyValueById;
}
return null;public void addCategoryToFolder(Folder parent, String categObjectId){
List<String> catIds = parent.getPropertyValue("cm:categories");
if(catIds==null|| catIds.isEmpty())
catIds = new ArrayList<>();
if(!catIds.contains(categObjectId)){
//catIds contains cmis:objectId instead of alfcmis:nodeRef so transform
List<String> newCatIds = catIds.stream().map(oid -> getCategoryRefByOid(oid)).collect(Collectors.toList());
newCatIds.add(getCategoryRefByOid(enginOid));
HashMap<String,Object> updated = new HashMap<>();
updated.put("cm:categories", newCatIds);
parent.updateProperties(updated, true);
System.out.println("categ added");
}else{ System.out.println("categ ok");}