Skip to content

Instantly share code, notes, and snippets.

View jpotts's full-sized avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / blog-post.json
Created November 3, 2014 00:38
Snippet of prismic.io blog post document mask
{
"Blog Post" : {
"body" : {
"type" : "StructuredText",
"config" : {
"placeholder" : "Start writing your blog post here...",
"minHeight" : "400px",
"imageConstraint" : {
"width" : 640.0
}
@jpotts
jpotts / GetDocumentExample.java
Created November 25, 2014 04:53
Showing how to grab a document, either by ID or by path, from an Alfresco 5.0.a repository, even when the user does not have access to the enclosing folders
package com.alfresco.api.example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Session;
public class GetDocumentExample extends BaseOnPremExample {
@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();
@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 / 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 / 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 / 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)
}