@Override public boolean reloadAccount() { { // find user name groups = new HashSet<>(); attr = new MProperties(); int cnt = 0; for (Principal principal : subject.getPrincipals()) { switch (principal.getClass().getSimpleName()) { case "UserPrincipal": userName = principal.getName(); break; case "RolePrincipal": groups.add(principal.getName()); break; } attr.put(principal.getClass().getSimpleName() + "." + cnt, principal.getName()); cnt++; } } return true; }
void indexFile(File f) throws IOException { File meta = getMetaFileFor(f); MProperties p = MProperties.load(meta); if (p == null) p = new MProperties(); String id = p.getString("_id", null); if (id == null) { id = UUID.randomUUID().toString(); p.setString("_id", id); p.save(meta); } rememberIndex(f,id); }
@Override public boolean isProperty(String name) { return properties.containsKey(name); }
public static MProperties loadOrEmpty(File f) { MProperties out = load(f); if (out == null) out = new MProperties(); return out; }
/** * This will handle the strings like properties. Means a string without separator will be * stored as value with an increasing key as integer, e.g. [val1, val2, a=b] will be 0=val1, 1=val2, a=b * @param properties * @return The MProperties */ public static MProperties explodeToMProperties(String[] properties) { if (properties == null) return new MProperties(); return explodeToMProperties(properties, '=', ':', 0, properties.length); }
public static MProperties explodeToMProperties(String[] properties, char keySeparator, char typeSeparator, int offset, int length) { MProperties p = new MProperties(); if (properties != null) { for (int i = 0; i < length; i++) { int pos = i + offset; if (pos >= properties.length) break; String item = properties[pos]; if (item != null) appendToMap(p, item, keySeparator, typeSeparator); } } return p; }
public static MProperties toMProperties(IReadProperties properties) { if (properties == null) return null; if (properties instanceof MProperties) return (MProperties)properties; return new MProperties(properties); }
@Override public Result<PNodeInfo> getFlowNodes(UUID caseId, STATE_NODE state) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; if (caseId == null && state == null) { sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_"); } else if (caseId == null) { prop.put("state", state); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE state_=$state$"); } else if (state == null) { prop.setString("case", caseId.toString()); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE case_=$case$"); } else { prop.setString("case", caseId.toString()); prop.put("state", state); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE state_=$state$ and case_=$case$"); } DbResult res = sta.executeQuery(prop); return new SqlResultNode(con,res); } catch (Exception e) { throw new IOException(e); } }
public static IProperties pojoToProperties(Object from, PojoModelFactory factory) throws IOException { MProperties out = new MProperties(); PojoModel model = factory.createPojoModel(from.getClass()); if (type == int.class) out.setInt(name, (int)value); else if (type == Integer.class) out.setInt(name, (Integer)value); else if (type == long.class) out.setLong(name, (long)value); else if (type == Long.class) out.setLong(name, (Long)value); else if (type == float.class) out.setFloat(name, (float)value); else if (type == Float.class) out.setFloat(name, (Float)value); else if (type == double.class) out.setDouble(name, (double)value); else if (type == Double.class) out.setDouble(name, (Double)value); else if (type == boolean.class) out.setBoolean(name, (boolean)value); else if (type == Boolean.class) out.setBoolean(name, (Boolean)value); else if (type == String.class) out.setString(name, (String)value); else if (type == Date.class) out.setDate(name, (Date)value); else out.setString(name, String.valueOf(value));
PojoModel modelTask = ActivityUtil.createFormPojoModel(getClass()); PojoModel modelPool = ActivityUtil.createFormPojoModel(pool.getClass()); MProperties out = new MProperties(); if (!desc.readable()) continue; if (!desc.writable()) { out.put(name + ".editable", false); out.put(name, attr.get(this)); } catch (Throwable t) { log().w(this,attr,t); if (out.containsKey(name)) continue; PropertyDescription desc = attr.getAnnotation(PropertyDescription.class); if (desc == null) continue; if (!desc.readable()) continue; if (!desc.writable()) { out.put(name + ".editable", false); out.put(name, attr.get(pool)); } catch (Throwable t) { log().w(this,attr,t); out.setString(FORM_CUSTOM_ID, caze.getCustomId()); out.setString(FORM_CUSTOMER_ID, caze.getCustomerId()); out.setString(FORM_MILESTONE, caze.getMilestone()); out.setString(FORM_CASE_ID, caze.getId().toString());
/** * This will handle the strings like options. Means a string without separator will handled * as key and set to true. e.g. [val1, val2, a=b] will be val1=true, val2=true, a=b * * @param properties * @param separator * @return The MProperties */ public static MProperties explodeToOptions(String[] properties, char separator) { MProperties p = new MProperties(); if (properties != null) { for (String i : properties) { if (i != null) { int idx = i.indexOf(separator); if (idx >= 0) { p.setProperty(i.substring(0,idx).trim(),i.substring(idx+1)); } else { p.setProperty(i, true); } } } } return p; }
private void removeIds(File file) { File meta = ((FdbCore)core).getMetaFileFor(file); MProperties p = MProperties.load(meta); if (p == null) p = new MProperties(); p.remove("_id"); try { p.save(meta); } catch (IOException e) { log().e(file,e); } }
@Override public Result<PNodeInfo> getScheduledFlowNodes(STATE_NODE state, long scheduled) throws IOException { DbConnection con = null; try { con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; if (state == null) { prop.setLong("scheduled", scheduled); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE scheduled_ <= $scheduled$"); } else { prop.setLong("scheduled", scheduled); prop.put("state", state); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE state_=$state$ and scheduled_ <= $scheduled$"); } DbResult res = sta.executeQuery(prop); return new SqlResultNode(con,res); } catch (Exception e) { try { if (con != null) con.close(); } catch (Exception e2) {} throw new IOException(e); } }
MProperties out = new MProperties(); if (activity != null) { PojoModel model = createPojoModel(activity.getClass()); for (PojoAttribute<?> attr : model) { try { out.put(attr.getName(), attr.get(activity)); } catch (Throwable t) { log.t(attr,t); PojoModel model = createPojoModel(pool.getClass()); for (PojoAttribute<?> attr : model) { if (!out.containsKey(attr.getName())) try { out.put(attr.getName(), attr.get(pool)); } catch (Throwable t) { log.t(attr,t);
@Override public OperationResult doExecuteInternal(CaoConfiguration configuration, Monitor monitor) throws CaoException { if (!canExecute(configuration)) return new NotSuccessful(getName(), "can't execute", -1); try { FsNode parent = (FsNode)configuration.getList().get(0); String rendition = configuration.getProperties().getString(UploadRenditionConfiguration.RENDITION); String path = configuration.getProperties().getString(UploadRenditionConfiguration.FILE); File file = new File(path); if (!file.exists() || !file.isFile()) throw new NotFoundException(path); File renditionFile = ((FsCore)parent.getConnection()).getContentFileFor(parent.getFile(), rendition); if (renditionFile == null) throw new MException("can't create rendition to internal file", rendition); MFile.copyFile(file, renditionFile); MProperties p = new MProperties(configuration.getProperties()); p.remove(UploadRenditionConfiguration.RENDITION); p.remove(UploadRenditionConfiguration.FILE); p.save( new File(renditionFile.getParentFile(), renditionFile.getName() + ".meta" ) ); return new Successful(getName()); } catch (Throwable t) { log().d(t); return new NotSuccessful(getName(),t.toString(),-1); } } }
} break; case "console": { final MProperties pe = new MProperties(parameters); MThread a = (MThread) session.get("__log_tail"); if (a != null) { if (sConsole == null || session.getTerminal() == null) return null; @SuppressWarnings("resource") final Console os = (Console) (pe.getString("console","ansi").equals("ansi") ? new ANSIConsole(System.in, sConsole) : new de.mhus.lib.core.console.SimpleConsole(System.in, sConsole)); final File file = new File( pe.getString("file","data/log/karaf.log") ); final boolean color = pe.getBoolean("color", true); MThread appender = new MThread(new Runnable() {
MProperties p = new MProperties(); Object res = null; Throwable t = null; p.setString(ClientObjectProxy.PROP_EXCEPION_TYPE, t.getClass().getCanonicalName()); p.setString(ClientObjectProxy.PROP_EXCEPION_TEXT, t.getMessage()); p.setString(ClientObjectProxy.PROP_EXCEPION_CLASS, act.getManagedClass().getCanonicalName()); p.setString(ClientObjectProxy.PROP_EXCEPTION_METHOD, act.getName());
public static MProperties load(InputStream inStream) throws IOException { MProperties out = new MProperties(); out.load0(new LineReader(inStream)); return out; }
@Override public OperationResult doExecuteInternal(CaoConfiguration configuration, Monitor monitor) throws CaoException { if (!canExecute(configuration)) return new NotSuccessful(getName(), "can't execute", -1); try { FdbNode parent = (FdbNode)configuration.getList().get(0); String rendition = configuration.getProperties().getString(UploadRenditionConfiguration.RENDITION); String path = configuration.getProperties().getString(UploadRenditionConfiguration.FILE); File file = new File(path); if (!file.exists() || !file.isFile()) throw new NotFoundException(path); MProperties p = new MProperties(configuration.getProperties()); p.remove(UploadRenditionConfiguration.RENDITION); p.remove(UploadRenditionConfiguration.FILE); // TODO upload rendition Changes changes = parent.adaptTo(Changes.class); if (changes != null) changes.uploadedRendition(rendition); return new Successful(getName()); } catch (Throwable t) { log().d(t); return new NotSuccessful(getName(),t.toString(),-1); } }