Posts

Update content in Webscript

private void updateContent(NodeRef nodeRef, String path, String fileName, boolean newFile)     {         // Make versionable         nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);         // Update content         InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName);         if (is != null)         {             ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);             if (newFile == true)             {                 contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);                 contentWriter.setEncoding("UTF-8");            ...

Good Practice to get response in webscript

Body requestBodyObject = JsonUtility.buildRequestBodyObject(jsonRequest); Map<String,Object> mapOfParams = requestBodyObject.getBody(); String noderef = JavaUtility.extractParameterFromMap(mapOfParams,"noderef"); NodeRef fileNodeRef = new NodeRef(noderef); public static String extractParameterFromMap(Map<String,Object> mapOfParams,String paramName) { String paramValue = ""; if(mapOfParams.containsKey(paramName)){ paramValue = (String)mapOfParams.get(paramName); } return paramValue; } public class JsonUtility { public static Body buildRequestBodyObject(String jsonRequest){ Gson gson = new GsonBuilder().create(); return gson.fromJson(jsonRequest, Body.class); } } =============================================================================== public class Response { private ResponseContainer response; public ResponseContainer getResponse() { return response; } public void setResponse...

Post WebScript

public class JsonUtility { public static Body buildRequestBodyObject(String jsonRequest){ Gson gson = new GsonBuilder().create(); return gson.fromJson(jsonRequest, Body.class); } public static Map<String,PermissionSet> convertToTypePermissionSet(String jsonRequestFromPermSet){ Type t = new TypeToken<Map<String,PermissionSet>>() {}.getType(); Map<String,PermissionSet> map = (Map<String,PermissionSet>) new Gson().fromJson(jsonRequestFromPermSet, t); return map; } } ------------------------------------------------------------------------------------------------------------------ public class JavaUtility { public static final int SUBSTR_END = 1; public static final int GROUPPREFIX_SUBSTR_END = 6; public static final String JSON_PERMSET_STR = "\"permissionSet\""; public static final String JSON_PERMCODE_STR = "\"permissionCode\""; public static final String JSON_PERMSETOBJ...

Get Global Properties

private Properties properties;     /**      *      * @method setProperties      * @param properties      */     public void setProperty(Properties properties)     {       logger.debug("setting properties");       this.properties = properties;     }     public String getGlobalProp(String propName)     {       logger.debug("getting properties");       return this.properties.getProperty(propName);     } ====================== Properties properties; public Map<String, Object> executeImpl(WebScriptRequest request, Status status) { String alf_dir =  properties.getProperty("dir.root"); } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } =========...

Alfresco log4j.properties and log after conversion JSON Log

# Set root logger level to error log4j.rootLogger=info, Console, File ###### Console appender definition ####### # All outputs currently set to be a ConsoleAppender. log4j.appender.Console=org.apache.log4j.ConsoleAppender #log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout=com.demo.logger.layout.json.SplunkJsonLayout # use log4j NDC to replace %x with tenant domain / username log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n #log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n ###### File appender definition ####### log4j.appender.File=org.apache.log4j.DailyRollingFileAppender log4j.appender.File.File=alfresco.log log4j.appender.File.Append=true log4j.appender.File.DatePattern='.'yyyy-MM-dd #log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout=com.demo.logger.layout.json.SplunkJsonLayout log4j.appender.File.layout.Conversion...

Write logs in JSON format using jackson

import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.spi.LoggingEvent; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.demo.logger.model.MyModel; public class SplunkJsonLayout extends Layout { private final Gson gson = new GsonBuilder().create();     private final String hostname = getHostname().toLowerCase();     private final String username = System.getProperty("user.name").toLowerCase();       private Level minimumLevelForSlowLogging = Level.ALL;     private List<String> mdcFieldsToLog = Collections.emptyList();     @Override public void activateOptions() { ...