List of usage examples for javax.json JsonArray getJsonObject
JsonObject getJsonObject(int index);
From source file:org.hyperledger.fabric_ca.sdk.HFCAAffiliation.java
private void generateResponse(JsonObject result) { if (result.containsKey("name")) { this.name = result.getString("name"); }/*from ww w . j a va2 s . c om*/ if (result.containsKey("affiliations")) { JsonArray affiliations = result.getJsonArray("affiliations"); if (affiliations != null && !affiliations.isEmpty()) { for (int i = 0; i < affiliations.size(); i++) { JsonObject aff = affiliations.getJsonObject(i); this.childHFCAAffiliations.add(new HFCAAffiliation(aff)); } } } if (result.containsKey("identities")) { JsonArray ids = result.getJsonArray("identities"); if (ids != null && !ids.isEmpty()) { for (int i = 0; i < ids.size(); i++) { JsonObject id = ids.getJsonObject(i); HFCAIdentity hfcaID = new HFCAIdentity(id); this.identities.add(hfcaID); } } } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * read retrieves a specific identity// w w w .j a v a 2s .com * * @param registrar The identity of the registrar (i.e. who is performing the registration). * @return statusCode The HTTP status code in the response * @throws IdentityException if retrieving an identity fails. * @throws InvalidArgumentException Invalid (null) argument specified */ public int read(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readIdURL = ""; try { readIdURL = HFCA_IDENTITY + "/" + enrollmentID; logger.debug(format("identity url: %s, registrar: %s", readIdURL, registrar.getName())); JsonObject result = client.httpGet(readIdURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { type = result.getString("type"); maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; logger.debug(format("identity url: %s, registrar: %s done.", readIdURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting user '%s' from url '%s': %s", enrollmentID, readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
private void getHFCAIdentity(JsonObject result) { type = result.getString("type"); if (result.containsKey("secret")) { this.secret = result.getString("secret"); }//from w w w.j a v a 2 s . c o m maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; }
From source file:org.kuali.rice.krad.uif.layout.collections.DataTablesPagingHelper.java
/** * Get the sort type string from the parsed column definitions object. * * @param jsonColumnDefs the JsonArray representation of the aoColumnDefs property from the RichTable template * options/*from ww w . ja v a 2 s .co m*/ * @param sortCol the index of the column to get the sort type for * @return the name of the sort type specified in the template options, or the default of "string" if none is * found. */ private static String getSortType(JsonArray jsonColumnDefs, int sortCol) { String sortType = "string"; // default to string if nothing is spec'd if (jsonColumnDefs != null) { JsonObject column = jsonColumnDefs.getJsonObject(sortCol); if (column.containsKey("sType")) { sortType = column.getString("sType"); } } return sortType; }
From source file:org.kuali.rice.krad.web.controller.helper.DataTablesPagingHelper.java
/** * Get the sort type string from the parsed column definitions object. * * @param jsonColumnDefs the JsonArray representation of the aoColumnDefs property from the RichTable template * options/*from w w w .ja va2s . co m*/ * @param sortCol the index of the column to get the sort type for * @return the name of the sort type specified in the template options, or the default of "string" if none is * found. */ private String getSortType(JsonArray jsonColumnDefs, int sortCol) { String sortType = "string"; // default to string if nothing is spec'd if (jsonColumnDefs != null) { JsonObject column = jsonColumnDefs.getJsonObject(sortCol); if (column.containsKey("sType")) { sortType = column.getString("sType"); } } return sortType; }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTalkTypeList() { this.talkTypeNameToTalkTypeMap = new HashMap<>(); List<TalkType> talkTypeList = new ArrayList<>(); String proposalTypeUrl = conferenceBaseUrl + "/proposalTypes"; LOGGER.debug("Sending a request to: " + proposalTypeUrl); JsonObject rootObject = readJson(proposalTypeUrl, JsonReader::readObject); JsonArray talkTypeArray = rootObject.getJsonArray("proposalTypes"); for (int i = 0; i < talkTypeArray.size(); i++) { JsonObject talkTypeObject = talkTypeArray.getJsonObject(i); String talkTypeName = talkTypeObject.getString("id"); if (talkTypeNameToTalkTypeMap.keySet().contains(talkTypeName)) { LOGGER.warn("Duplicate talk type in " + proposalTypeUrl + " at index " + i + "."); continue; }/* w ww .ja v a 2s .c o m*/ TalkType talkType = new TalkType((long) i, talkTypeName); talkType.setCompatibleRoomSet(new HashSet<>()); talkType.setCompatibleTimeslotSet(new HashSet<>()); talkTypeList.add(talkType); talkTypeNameToTalkTypeMap.put(talkTypeName, talkType); } solution.setTalkTypeList(talkTypeList); }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTrackIdSet() { this.trackIdSet = new HashSet<>(); String tracksUrl = conferenceBaseUrl + "/tracks"; LOGGER.debug("Sending a request to: " + tracksUrl); JsonObject rootObject = readJson(tracksUrl, JsonReader::readObject); JsonArray tracksArray = rootObject.getJsonArray("tracks"); for (int i = 0; i < tracksArray.size(); i++) { trackIdSet.add(tracksArray.getJsonObject(i).getString("id")); }//from w ww .j a v a 2 s. co m }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importRoomList() { this.roomIdToRoomMap = new HashMap<>(); List<Room> roomList = new ArrayList<>(); String roomsUrl = conferenceBaseUrl + "/rooms/"; LOGGER.debug("Sending a request to: " + roomsUrl); JsonObject rootObject = readJson(roomsUrl, JsonReader::readObject); JsonArray roomArray = rootObject.getJsonArray("rooms"); for (int i = 0; i < roomArray.size(); i++) { JsonObject roomObject = roomArray.getJsonObject(i); String id = roomObject.getString("id"); int capacity = roomObject.getInt("capacity"); if (!Arrays.asList(IGNORED_ROOM_IDS).contains(id)) { Room room = new Room((long) i); room.setName(id);/* w w w . j ava 2 s. c o m*/ room.setCapacity(capacity); room.setTalkTypeSet(getTalkTypeSetForCapacity(capacity)); for (TalkType talkType : room.getTalkTypeSet()) { talkType.getCompatibleRoomSet().add(room); } room.setTagSet(new HashSet<>()); room.setUnavailableTimeslotSet(new HashSet<>()); roomList.add(room); roomIdToRoomMap.put(id, room); } } roomList.sort(Comparator.comparing(Room::getName)); solution.setRoomList(roomList); }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importSpeakerList() { this.speakerNameToSpeakerMap = new HashMap<>(); this.talkUrlSet = new HashSet<>(); List<Speaker> speakerList = new ArrayList<>(); String speakersUrl = conferenceBaseUrl + "/speakers"; LOGGER.debug("Sending a request to: " + speakersUrl); JsonArray speakerArray = readJson(speakersUrl, JsonReader::readArray); for (int i = 0; i < speakerArray.size(); i++) { String speakerUrl = speakerArray.getJsonObject(i).getJsonArray("links").getJsonObject(0) .getString("href"); LOGGER.debug("Sending a request to: " + speakerUrl); JsonObject speakerObject = readJson(speakerUrl, JsonReader::readObject); String speakerId = speakerObject.getString("uuid"); String speakerName = speakerObject.getString("firstName") + " " + speakerObject.getString("lastName"); if (Arrays.asList(IGNORED_SPEAKER_NAMES).contains(speakerName)) { continue; }//from ww w . jav a 2s. c om Speaker speaker = new Speaker((long) i); speaker.setName(speakerName); speaker.withPreferredRoomTagSet(new HashSet<>()).withPreferredTimeslotTagSet(new HashSet<>()) .withProhibitedRoomTagSet(new HashSet<>()).withProhibitedTimeslotTagSet(new HashSet<>()) .withRequiredRoomTagSet(new HashSet<>()).withRequiredTimeslotTagSet(new HashSet<>()) .withUnavailableTimeslotSet(new HashSet<>()).withUndesiredRoomTagSet(new HashSet<>()) .withUndesiredTimeslotTagSet(new HashSet<>()); speakerList.add(speaker); if (speakerNameToSpeakerMap.keySet().contains(speakerName)) { throw new IllegalStateException("Speaker (" + speakerName + ") with id (" + speakerId + ") already exists in the speaker list"); } speakerNameToSpeakerMap.put(speakerName, speaker); JsonArray speakerTalksArray = speakerObject.getJsonArray("acceptedTalks"); for (int j = 0; j < speakerTalksArray.size(); j++) { String talkUrl = speakerTalksArray.getJsonObject(j).getJsonArray("links").getJsonObject(0) .getString("href"); talkUrlSet.add(talkUrl); } } speakerList.sort(Comparator.comparing(Speaker::getName)); solution.setSpeakerList(speakerList); }
From source file:org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter.java
private void importTalkList() { this.talkCodeToTalkMap = new HashMap<>(); List<Talk> talkList = new ArrayList<>(); Long talkId = 0L;// w ww . j a va2 s. c om String talksPath = getClass().getResource("devoxxBE").toString(); String[] confFiles = { "BOF", "Conf14Sept2018", "DeepDive", "HandsOnLabs", "Quickies", "ToolsInAction" }; for (String confType : confFiles) { LOGGER.debug("Sending a request to: " + talksPath + "/" + confType + ".json"); JsonArray talksArray = readJson(talksPath + "/" + confType + ".json", JsonReader::readObject) .getJsonObject("approvedTalks").getJsonArray("talks"); for (int i = 0; i < talksArray.size(); i++) { JsonObject talkObject = talksArray.getJsonObject(i); String code = talkObject.getString("id"); String title = talkObject.getString("title").substring(5); String talkTypeName = talkObject.getJsonObject("talkType").getString("id"); Set<String> themeTrackSet = extractThemeTrackSet(talkObject, code, title); String language = talkObject.getString("lang"); int audienceLevel = Integer .parseInt(talkObject.getString("audienceLevel").replaceAll("[^0-9]", "")); List<Speaker> speakerList = extractSpeakerList(confType, talkObject, code, title); Set<String> contentTagSet = extractContentTagSet(talkObject); String state = talkObject.getJsonObject("state").getString("code"); if (!Arrays.asList(IGNORED_TALK_TYPES).contains(code) && !state.equals("declined")) { Talk talk = createTalk(talkId++, code, title, talkTypeName, themeTrackSet, language, speakerList, audienceLevel, contentTagSet); talkCodeToTalkMap.put(code, talk); talkList.add(talk); talkTalkTypeToTotalMap.merge(talkTypeName, 1, Integer::sum); } } } solution.setTalkList(talkList); }