List of usage examples for javax.json JsonObject getString
String getString(String name);
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) private void builtPublicationMap(String key, Map<String, Map<String, List<String>>> map, Map<String, List<String>> current, Map<String, String> params) throws KeyNotFoundException, CoreServiceException, OrtolangException { Object object = readObject(key); if (object instanceof MetadataSource) { MetadataElement mde = ((MetadataSource) object).findMetadataByName(MetadataFormat.ACL); if (mde != null) { LOGGER.log(Level.FINE, "ACL metadata found, load json, find policy template and render it..."); MetadataObject md = (MetadataObject) readObject(mde.getKey()); try { JsonReader reader = Json.createReader(binarystore.get(md.getStream())); JsonObject json = reader.readObject(); String template = json.getString("template"); reader.close();/*w w w . j a v a2 s .co m*/ AuthorisationPolicyTemplate policy = authorisation.getPolicyTemplate(template); Map<String, List<String>> rules = authorisation.getPolicyRules(policy.getTemplate()); Map<String, List<String>> filtered = new HashMap<String, List<String>>(); for (Entry<String, List<String>> entry : rules.entrySet()) { if (params.containsKey(entry.getKey())) { filtered.put(params.get(entry.getKey()), entry.getValue()); } else { filtered.put(entry.getKey(), entry.getValue()); } } current = filtered; } catch (AuthorisationServiceException | BinaryStoreServiceException | DataNotFoundException e) { LOGGER.log(Level.SEVERE, "unable to read acl metadata", e); } } } map.put(key, current); if (object instanceof MetadataSource) { for (MetadataElement element : ((MetadataSource) object).getMetadatas()) { map.put(element.getKey(), current); } } if (object instanceof Collection) { for (CollectionElement element : ((Collection) object).getElements()) { builtPublicationMap(element.getKey(), map, current, params); } } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) private void buildHandleList(String wsalias, String tag, String key, Set<OrtolangObjectPid> pids, PathBuilder path, String apiUrlBase, String marketUrlBase) throws CoreServiceException, KeyNotFoundException, OrtolangException, InvalidPathException { try {/*from ww w. j a v a2 s .c o m*/ OrtolangObject object = findObject(key); LOGGER.log(Level.FINE, "Generating pid for key: " + key); String target = ((path.isRoot()) ? marketUrlBase : apiUrlBase) + "/" + wsalias + "/" + tag + ((path.isRoot()) ? "" : path.build()); String dynHandle = OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.HANDLE_PREFIX) + "/" + wsalias + ((path.isRoot()) ? "" : path.build()); String staticHandle = OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.HANDLE_PREFIX) + "/" + wsalias + "/" + tag + ((path.isRoot()) ? "" : path.build()); OrtolangObjectPid dpid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE, dynHandle, key, target, false); boolean adddpid = true; for (OrtolangObjectPid pid : pids) { if (pid.getName().equals(dpid.getName()) && pid.isUserbased()) { adddpid = false; break; } } if (adddpid) { pids.add(dpid); } OrtolangObjectPid spid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE, staticHandle, key, target, false); boolean addspid = true; for (OrtolangObjectPid pid : pids) { if (pid.getName().equals(spid.getName()) && pid.isUserbased()) { addspid = false; break; } } if (addspid) { pids.add(spid); } if (object instanceof MetadataSource) { MetadataElement mde = ((MetadataSource) object).findMetadataByName(MetadataFormat.PID); if (mde != null) { LOGGER.log(Level.FINE, "PID metadata found, load json and generate corresponding pids"); MetadataObject md = readMetadataObject(mde.getKey()); try { JsonReader reader = Json.createReader(binarystore.get(md.getStream())); JsonObject json = reader.readObject(); if (json.containsKey("pids")) { JsonArray jpids = json.getJsonArray("pids"); for (int i = 0; i < jpids.size(); i++) { JsonObject jpid = jpids.getJsonObject(i); LOGGER.log(Level.FINE, "Generating metadata based pid for key: " + key); String ctarget = ((path.isRoot()) ? marketUrlBase : apiUrlBase) + "/" + wsalias + "/" + tag + ((path.isRoot()) ? "" : path.build()); OrtolangObjectPid upid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE, jpid.getString("value"), key, ctarget, true); Iterator<OrtolangObjectPid> iter = pids.iterator(); while (iter.hasNext()) { OrtolangObjectPid pid = iter.next(); if (pid.getName().equals(upid.getName())) { iter.remove(); } } pids.add(upid); } } reader.close(); } catch (BinaryStoreServiceException | DataNotFoundException e) { LOGGER.log(Level.SEVERE, "unable to read pid metadata", e); } } } if (object instanceof Collection) { for (CollectionElement element : ((Collection) object).getElements()) { buildHandleList(wsalias, tag, element.getKey(), pids, path.clone().path(element.getName()), apiUrlBase, marketUrlBase); } } } catch (AccessDeniedException e) { LOGGER.log(Level.INFO, "Unable to generate a PID for an object that has been set private."); } }