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 cmisbjectId 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");}
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
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.