Created
April 22, 2014 22:44
-
-
Save jpotts/11196922 to your computer and use it in GitHub Desktop.
Add a category to a document in Alfresco using CMIS 1.1 and cmis:item support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addCategory(documentPath, categoryName) { | |
println("Adding '" + categoryName + "' to the document at " + documentPath) | |
rs = session.query("select alfcmis:nodeRef from cm:category where cmis:name = '" + categoryName + "'", false) | |
if (rs.getTotalNumItems() == 0) { | |
println("Couldn't find category with name: " + categoryName) | |
return | |
} | |
catId = rs.getAt(0).getPropertyValueById("alfcmis:nodeRef") | |
testDoc = session.getObjectByPath(documentPath) | |
testDoc.refresh() //make sure we didn't get the object from the cache | |
aspects = testDoc.getPropertyValue("cmis:secondaryObjectTypeIds") | |
if (!aspects.contains("P:cm:generalclassifiable")) { | |
println("Adding aspect") | |
aspects.add("P:cm:generalclassifiable") | |
props = new HashMap<String, Object>() | |
props["cmis:secondaryObjectTypeIds"] = aspects | |
testDoc.updateProperties(props, true) | |
println("Aspects: " + testDoc.getPropertyValue("cmis:secondaryObjectTypeIds")) | |
} | |
// always want the latest version for this | |
if (!testDoc.isLatestVersion()) { | |
testDoc = testDoc.getObjectOfLatestVersion(false) | |
} | |
catIds = testDoc.getPropertyValue("cm:categories") | |
if (catIds == null) { | |
catIds = new ArrayList<Object>() | |
} | |
if (catIds.isEmpty()) { | |
catIds = new ArrayList<Object>() | |
} | |
if (!catIds.contains(catId)) { | |
println("Adding category") | |
catIds.add(catId) | |
println(catIds) | |
props = new HashMap<String, Object>() | |
props["cm:categories"] = catIds | |
testDoc.updateProperties(props, false) | |
} | |
println("Done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment