Skip to content

Instantly share code, notes, and snippets.

View jpotts's full-sized avatar

Jeff Potts jpotts

View GitHub Profile
@jpotts
jpotts / team_member.json
Created March 2, 2018 20:53
Example Team Member JSON
{
"data": {
"type": "node--team_member",
"id": "d56fd5ed-65f8-4f31-b4c0-29f33ea67bfb",
"attributes": {
"nid": 16,
"uuid": "d56fd5ed-65f8-4f31-b4c0-29f33ea67bfb",
"vid": 17,
"langcode": "en",
"status": true,
@jpotts
jpotts / headshot.json
Last active March 2, 2018 20:53
Example Team Member and Headshot JSON
{
"data": {
"type": "file--file",
"id": "311f36ae-b233-4db9-84ba-803525307e42",
"attributes": {
"fid": 2,
"uuid": "311f36ae-b233-4db9-84ba-803525307e42",
"langcode": "en",
"filename": "gravatar.png",
"uri": "public://2018-03/gravatar.png",
@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 / InvokeSearchTemplate.java
Last active August 22, 2020 01:39
Code snippets that go along with an ecmarchitect.com blog post on Elasticsearch search templates.
Map<String, Object> params = new HashMap<String, Object>();
params.put("search_term", "elasticsearch");
params.put("since", "now-30d");
Template template = new Template("tweets", ScriptService.ScriptType.FILE, MustacheScriptEngineService.NAME, null, params);
SearchRequestBuilder request = client.prepareSearch(INDEX).setTemplate(template);
SearchResponse response = request.execute().actionGet();
@jpotts
jpotts / MemberOfGroupFromProperty.java
Last active September 29, 2021 07:52
This is a custom Share evaluator that checks if the current user is a member of a group. The group to check is grabbed from a property on the node. The node is specified in the evaluator config. If you know the group to check at compile time, there is already an OOTB evaluator for that.
import java.util.ArrayList;
p
import org.alfresco.web.evaluator.BaseEvaluator;
import org.alfresco.web.extensibility.SlingshotEvaluatorUtil;
import org.json.simple.JSONObject;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
public class MemberOfGroupFromProperty extends BaseEvaluator {
protected SlingshotEvaluatorUtil util = null;
@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 / 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 / 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 / example.sh
Created November 13, 2014 15:39
Need a better approach to sorting semantic version strings in Elasticsearch
# Delete the example index
curl -XDELETE "http://localhost:9200/sortable-version-test?pretty=true"
# Create a new example index
curl -X POST "http://localhost:9200/sortable-version-test?pretty=true"
# Set the mapping. Assumes version.groovy resides in $ES_HOME/config/scripts
curl -XPOST "http://localhost:9200/sortable-version-test/version/_mapping?pretty=true" -d'
{
"version": {
@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
}