@Override public void addTemplate(CallingContext context, String name, String template, Boolean overwrite) { if (templates.containsKey(name) && !templates.get(name).isEmpty() && !overwrite) { log.info(Messages.getString("Admin.NoOverwriteTemplate") + name); // $NON-NLS-1$ } else { log.info( Messages.getString("Admin.AddingTemplate") + name + Messages.getString("Admin.Value") + template); //$NON-NLS-1$ //$NON-NLS-2$ templates.put(name, template); } }
public AdminApiImpl(Kernel raptureKernel) { super(raptureKernel); // Update templates from the command line (Environment and Defines) for (Map.Entry<String, String> entry : System.getenv().entrySet()) { if (entry.getKey().startsWith(TEMPLATE)) { String templateName = entry.getKey().substring(TEMPLATE.length() + 1); templates.put(templateName, entry.getValue()); } } Enumeration<Object> e = System.getProperties().keys(); while (e.hasMoreElements()) { String name = e.nextElement().toString(); if (name.startsWith(TEMPLATE)) { String templateName = name.substring(TEMPLATE.length() + 1); templates.put(templateName, System.getProperty(name)); } } }
@Override public Map<String, String> getSystemProperties(CallingContext context, List<String> keys) { Map<String, String> ret = new TreeMap<String, String>(); if (keys.isEmpty()) { ret.putAll(System.getenv()); Properties p = System.getProperties(); for (Map.Entry<Object, Object> prop : p.entrySet()) { ret.put(prop.getKey().toString(), prop.getValue().toString()); } } else { for (String k : keys) { String val = System.getenv(k); if (val != null) { ret.put(k, System.getenv(k)); } else { String prop = System.getProperty(k); if (prop != null) { ret.put(k, prop); } } } } return ret; }
@Override public String runTemplate(CallingContext context, String name, String params) { String template = templates.get(name); if (template == null) { log.info( "Null template execution - " + name + Messages.getString("Admin.NoExist")); // $NON-NLS-1$ //$NON-NLS-2$ return null; } log.info( Messages.getString("Admin.RunTemplate") + template + Messages.getString("Admin.Params") + params); //$NON-NLS-1$ //$NON-NLS-2$ String ret = TemplateF.parseTemplate(template, params); log.info(Messages.getString("Admin.TemplateOutput") + ret); // $NON-NLS-1$ return ret; }
@Override public void addMetadata(CallingContext context, Map<String, String> values, Boolean overwrite) { if ((values == null) || values.isEmpty()) return; Map<String, String> metadata = context.getMetadata(); if (metadata == null) metadata = new HashMap<String, String>(); for (String key : values.keySet()) { if (!overwrite && metadata.containsKey(key)) { throw RaptureExceptionFactory.create( HttpURLConnection.HTTP_BAD_REQUEST, key + " exists and overwrite was disallowed"); } metadata.put(key, values.get(key)); } context.setMetadata(metadata); getEphemeralRepo() .addToStage( RaptureConstants.OFFICIAL_STAGE, "session/" + context.getContext(), JacksonUtil.jsonFromObject(context), false); }
@Override public String getTemplate(CallingContext context, String name) { return templates.get(name); }