Open CMIS cm:category not consistent?

cancel
Showing results for 
Search instead for 
Did you mean: 
frenout
Member II

Open CMIS cm:category not consistent?

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 cmisSmiley SurprisedbjectId 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");}
1 Reply
andy1
Senior Member

Re: Open CMIS cm:category not consistent?

Hi

That is an interesting one. Clearly the repository is mapping node references to cmis objectIds  for that particular property type. It should do the reverse mapping at set time. This sounds like a bug to me. Please raise this as an ALF issue in Jira.

Andy