List of usage examples for javax.json JsonObject isNull
boolean isNull(String name);
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2transmart.I2B2TranSMARTResourceImplementation.java
public List<Entity> searchObservationOnly(String searchTerm, String strategy, SecureSession session, String onlObs) {/*from w w w .j a v a 2 s . co m*/ List<Entity> entities = new ArrayList<Entity>(); try { URI uri = new URI(this.transmartURL.split("://")[0], this.transmartURL.split("://")[1].split("/")[0], "/" + this.transmartURL.split("://")[1].split("/")[1] + "/textSearch/findPaths", "oblyObs=" + onlObs + "&term=" + searchTerm, null); HttpClient client = createClient(session); HttpGet get = new HttpGet(uri); HttpResponse response = client.execute(get); JsonReader reader = Json.createReader(response.getEntity().getContent()); JsonArray arrayResults = reader.readArray(); for (JsonValue val : arrayResults) { JsonObject returnObject = (JsonObject) val; Entity returnedEntity = new Entity(); returnedEntity .setPui("/" + this.resourceName + converti2b2Path(returnObject.getString("conceptPath"))); if (!returnObject.isNull("text")) { returnedEntity.getAttributes().put("text", returnObject.getString("text")); } entities.add(returnedEntity); } } catch (URISyntaxException | JsonException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return entities; }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
private String revokeInternal(User revoker, String serial, String aki, String reason, boolean genCRL) throws RevocationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); }/* w w w.ja va2s. c o m*/ if (Utils.isNullOrEmpty(serial)) { throw new IllegalArgumentException("Serial number id required to revoke ceritificate"); } if (Utils.isNullOrEmpty(aki)) { throw new IllegalArgumentException("AKI is required to revoke certificate"); } if (revoker == null) { throw new InvalidArgumentException("revoker is not set"); } logger.debug(format("revoke revoker: %s, reason: %s, url: %s", revoker.getName(), reason, url)); try { setUpSSL(); // build request body RevocationRequest req = new RevocationRequest(caName, null, serial, aki, reason, genCRL); String body = req.toJson(); // send revoke request JsonObject resp = httpPost(url + HFCA_REVOKE, body, revoker); logger.debug("revoke done"); if (genCRL) { if (resp.isEmpty()) { throw new RevocationException("Failed to return CRL, revoke response is empty"); } if (resp.isNull("CRL")) { throw new RevocationException("Failed to return CRL"); } return resp.getString("CRL"); } return null; } catch (CertificateException e) { logger.error("Cannot validate certificate. Error is: " + e.getMessage()); throw new RevocationException("Error while revoking cert. " + e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e); throw new RevocationException("Error while revoking the user. " + e.getMessage(), e); } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
private String revokeInternal(User revoker, Enrollment enrollment, String reason, boolean genCRL) throws RevocationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); }/*ww w .ja v a 2 s . com*/ if (enrollment == null) { throw new InvalidArgumentException("revokee enrollment is not set"); } if (revoker == null) { throw new InvalidArgumentException("revoker is not set"); } logger.debug(format("revoke revoker: %s, reason: %s, url: %s", revoker.getName(), reason, url)); try { setUpSSL(); // get cert from to-be-revoked enrollment BufferedInputStream pem = new BufferedInputStream( new ByteArrayInputStream(enrollment.getCert().getBytes())); CertificateFactory certFactory = CertificateFactory .getInstance(Config.getConfig().getCertificateFormat()); X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(pem); // get its serial number String serial = DatatypeConverter.printHexBinary(certificate.getSerialNumber().toByteArray()); // get its aki // 2.5.29.35 : AuthorityKeyIdentifier byte[] extensionValue = certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId()); ASN1OctetString akiOc = ASN1OctetString.getInstance(extensionValue); String aki = DatatypeConverter .printHexBinary(AuthorityKeyIdentifier.getInstance(akiOc.getOctets()).getKeyIdentifier()); // build request body RevocationRequest req = new RevocationRequest(caName, null, serial, aki, reason, genCRL); String body = req.toJson(); // send revoke request JsonObject resp = httpPost(url + HFCA_REVOKE, body, revoker); logger.debug("revoke done"); if (genCRL) { if (resp.isEmpty()) { throw new RevocationException("Failed to return CRL, revoke response is empty"); } if (resp.isNull("CRL")) { throw new RevocationException("Failed to return CRL"); } return resp.getString("CRL"); } return null; } catch (CertificateException e) { logger.error("Cannot validate certificate. Error is: " + e.getMessage()); throw new RevocationException("Error while revoking cert. " + e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e); throw new RevocationException("Error while revoking the user. " + e.getMessage(), e); } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
private String revokeInternal(User revoker, String revokee, String reason, boolean genCRL) throws RevocationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); }//from w w w. ja v a2s . c o m logger.debug(format("revoke revoker: %s, revokee: %s, reason: %s", revoker, revokee, reason)); if (Utils.isNullOrEmpty(revokee)) { throw new InvalidArgumentException("revokee user is not set"); } if (revoker == null) { throw new InvalidArgumentException("revoker is not set"); } try { setUpSSL(); // build request body RevocationRequest req = new RevocationRequest(caName, revokee, null, null, reason, genCRL); String body = req.toJson(); // send revoke request JsonObject resp = httpPost(url + HFCA_REVOKE, body, revoker); logger.debug(format("revoke revokee: %s done.", revokee)); if (genCRL) { if (resp.isEmpty()) { throw new RevocationException("Failed to return CRL, revoke response is empty"); } if (resp.isNull("CRL")) { throw new RevocationException("Failed to return CRL"); } return resp.getString("CRL"); } return null; } catch (Exception e) { logger.error(e.getMessage(), e); throw new RevocationException("Error while revoking the user. " + e.getMessage(), e); } }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTimeslotList() { List<Timeslot> timeslotList = new ArrayList<>(); Map<Timeslot, List<Room>> timeslotToAvailableRoomsMap = new HashMap<>(); Map<Pair<LocalDateTime, LocalDateTime>, Timeslot> startAndEndTimeToTimeslotMap = new HashMap<>(); Long timeSlotId = 0L;//w ww . java2 s. c o m String schedulesUrl = conferenceBaseUrl + "/schedules/"; LOGGER.debug("Sending a request to: " + schedulesUrl); JsonArray daysArray = readJson(schedulesUrl, JsonReader::readObject).getJsonArray("links"); for (int i = 0; i < daysArray.size(); i++) { JsonObject dayObject = daysArray.getJsonObject(i); String dayUrl = dayObject.getString("href"); LOGGER.debug("Sending a request to: " + dayUrl); JsonArray daySlotsArray = readJson(dayUrl, JsonReader::readObject).getJsonArray("slots"); for (int j = 0; j < daySlotsArray.size(); j++) { JsonObject timeslotObject = daySlotsArray.getJsonObject(j); LocalDateTime startDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("fromTimeMillis").longValue()), ZoneId.of(ZONE_ID)); LocalDateTime endDateTime = LocalDateTime.ofInstant( Instant.ofEpochMilli(timeslotObject.getJsonNumber("toTimeMillis").longValue()), ZoneId.of(ZONE_ID)); Room room = roomIdToRoomMap.get(timeslotObject.getString("roomId")); if (room == null) { throw new IllegalStateException("The timeslot (" + timeslotObject.getString("slotId") + ") has a roomId (" + timeslotObject.getString("roomId") + ") that does not exist in the rooms list"); } // Assuming slotId is of format: tia_room6_monday_12_.... take only "tia" String talkTypeName = timeslotObject.getString("slotId").split("_")[0]; TalkType timeslotTalkType = talkTypeNameToTalkTypeMap.get(talkTypeName); if (Arrays.asList(IGNORED_TALK_TYPES).contains(talkTypeName)) { continue; } Timeslot timeslot; if (startAndEndTimeToTimeslotMap.keySet().contains(Pair.of(startDateTime, endDateTime))) { timeslot = startAndEndTimeToTimeslotMap.get(Pair.of(startDateTime, endDateTime)); timeslotToAvailableRoomsMap.get(timeslot).add(room); if (timeslotTalkType != null) { timeslot.getTalkTypeSet().add(timeslotTalkType); } } else { timeslot = new Timeslot(timeSlotId++); timeslot.withStartDateTime(startDateTime).withEndDateTime(endDateTime) .withTalkTypeSet(timeslotTalkType == null ? new HashSet<>() : new HashSet<>(Arrays.asList(timeslotTalkType))); timeslot.setTagSet(new HashSet<>()); timeslotList.add(timeslot); timeslotToAvailableRoomsMap.put(timeslot, new ArrayList<>(Arrays.asList(room))); startAndEndTimeToTimeslotMap.put(Pair.of(startDateTime, endDateTime), timeslot); } if (!timeslotObject.isNull("talk")) { scheduleTalk(timeslotObject, room, timeslot); } for (TalkType talkType : timeslot.getTalkTypeSet()) { talkType.getCompatibleTimeslotSet().add(timeslot); } timeslotTalkTypeToTotalMap.merge(talkTypeName, 1, Integer::sum); } } for (Room room : solution.getRoomList()) { room.setUnavailableTimeslotSet(timeslotList.stream() .filter(timeslot -> !timeslotToAvailableRoomsMap.get(timeslot).contains(room)) .collect(Collectors.toSet())); } solution.setTimeslotList(timeslotList); }