Skip to content

Instantly share code, notes, and snippets.

View jpotts's full-sized avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / Reindexer.java
Created January 19, 2015 15:20
Use a scroll and the bulk api to reindex docs in an Elasticsearch index within the same cluster
public class Reindexer extends BaseElasticsearchUtility {
private static Log logger = LogFactory.getLog(Reindexer.class);
public static void main(String[] args) {
if (args.length != 5) {
doUsage();
System.exit(-1);
}
@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 / 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)
@jpotts
jpotts / example-object.json
Last active June 30, 2016 01:59
Example content service object and response
{
"id": "someid",
"name": "globalNavSpecialOffersPromo",
"description": "",
"crDate": 1452112197971,
"modDate": 1457469890414,
"pubDate": 1457469840000,
"metadata": {
"pageId": [
"air-flight-some-other-page",
@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 / 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 / SearchExample.java
Last active August 29, 2015 14:11
Elasticsearch function score query
public List<Content> fetchContentForPlacements(Date curDate, String relString, String pageId, Metadata meta) throws ContentServiceException {
// check for required parameters
if (pageId == null) {
throw new MissingParameterException(Constants.MSG_PAGE_ID_REQUIRED);
}
// default the current date to now if it wasn't provided
if (curDate == null) {
curDate = new Date();