Skip to content

Instantly share code, notes, and snippets.

View jpotts's full-sized avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / user.properties
Created August 30, 2014 21:24
Apache JMeter user.properties that configures test settings as well as the CSV format for the test results
jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.data_type=false
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=false
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=false
@jpotts
jpotts / createSomecoClient.groovy
Created April 28, 2014 21:53
Create an instance of a custom type in Alfresco that extends sys:base using cmis:item support in CMIS 1.1
clientName = "Some Client"
folder = session.getObjectByPath('/test/testfolder1')
props = new HashMap<String, Object>()
props["cmis:objectTypeId"] = "I:sc:client"
props["sc:clientId"] = "56789"
props["sc:clientName"] = clientName
props["cmis:name"] = clientName
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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;