Skip to content

Instantly share code, notes, and snippets.

View jpotts's full-sized avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / AspectExample.java
Last active July 18, 2023 14:54
Creating aspect-defined properties in CMIS with Alfresco
package com.someco.cmis.examples;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.chemistry.opencmis.client.api.Document;
@jpotts
jpotts / dumpVersions.groovy
Created August 2, 2013 01:07
Using CMIS to dump an object's versions
document = session.getObjectByPath('/versionableExample.txt')
println("Checked out?" + document.versionSeriesCheckedOut)
versions = document.getAllVersions()
for (version in versions) {
println ("Version:" + version.versionLabel + " PWC?:" + version.privateWorkingCopy)
}
@jpotts
jpotts / gist:6542996
Created September 12, 2013 19:59
Hitting the Public API of a local Alfresco 4.2.d server using the Google HTTP Client
package com.someco;
import java.io.IOException;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
@jpotts
jpotts / query-aspect.groovy
Last active December 24, 2015 14:09
This is the query example from the OpenCMIS Workbench modified with a query string that shows how to query for properties defined in an Alfresco aspect using a join.
import org.apache.chemistry.opencmis.commons.*
import org.apache.chemistry.opencmis.commons.data.*
import org.apache.chemistry.opencmis.commons.enums.*
import org.apache.chemistry.opencmis.client.api.*
String cql = "SELECT D.cmis:name, T.cm:title FROM cmis:document as D join cm:titled as T on D.cmis:objectId = T.cmis:objectId"
ItemIterable<QueryResult> results = session.query(cql, false)
results.each { hit ->
@jpotts
jpotts / addSecondaryType.java
Last active January 16, 2024 10:45
Adding an aspect (known in CMIS 1.1 as a "secondary type") by modifying cmis:secondaryObjectTypeIds. This requires that you connect using the CMIS 1.1 service URL. You do not need the Alfresco OpenCMIS Extension when using this approach. Works with Alfresco 4.2.e Community Edition and higher.
List<Object> aspects = doc.getProperty("cmis:secondaryObjectTypeIds").getValues();
if (!aspects.contains("P:cm:geographic")) {
aspects.add("P:cm:geographic");
HashMap<String, Object> props = new HashMap<String, Object>();
props.put("cmis:secondaryObjectTypeIds", aspects);
doc.updateProperties(props);
System.out.println("Added aspect");
} else {
System.out.println("Doc already had aspect");
}
@jpotts
jpotts / gist:10878584
Created April 16, 2014 13:50
Remove an aspect from every node in the repository
var results = search.luceneSearch("ASPECT:\"ASPECT NAME HERE\"");
for each (var doc in results) {
doc.removeAspect("ASPECT NAME HERE");
}
@jpotts
jpotts / getCats.groovy
Created April 22, 2014 19:44
Retrieve the list of categories for a node using CMIS 1.1 cmis:item support
testDoc = session.getObjectByPath("/test/testfolder1/test1.txt")
catIds = testDoc.getPropertyValue("cm:categories")
for (catId in catIds) {
cat = session.getObject(catId)
println(cat.name)
}
@jpotts
jpotts / addCategory.groovy
Created April 22, 2014 22:44
Add a category to a document in Alfresco using CMIS 1.1 and cmis:item support
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")
@jpotts
jpotts / updatePerson.groovy
Created April 22, 2014 23:18
Update a person object in Alfresco using CMIS 1.1 and cmis:item support
rs = session.query("select cmis:objectId FROM cm:person where cm:firstName like 'Te%' and cm:organization like 'Green%' and cm:location like 'Dallas%' and (cm:companypostcode <> '75070' or cm:companypostcode is null)", false)
if (rs.getTotalNumItems() == 0) {
println("Couldn't find person that matched query")
return
}
for (res in rs) {
personId = res.getPropertyValueById("cmis:objectId")
person = session.getObject(personId)
@jpotts
jpotts / updateRule.groovy
Created April 23, 2014 22:24
Enable a rule and set it to run on sub-folders in Alfresco through CMIS by leveraging cmis:item support in CMIS 1.1
rs = session.query("select R.cmis:objectId from rule:rule as R join cm:titled as T on R.cmis:objectId = T.cmis:objectId where T.cm:title = 'add classifiable aspect'", false)
if (rs.getTotalNumItems() == 0) {
println("Couldn't find a rule that matched your query")
return
}
for (res in rs) {
ruleId = res.getPropertyValueById('cmis:objectId')
rule = session.getObject(ruleId)