List of usage examples for javax.json Json createArrayBuilder
public static JsonArrayBuilder createArrayBuilder()
From source file:csg.files.CSGFiles.java
public void saveRecitationData(AppDataComponent recData, String filePath) throws IOException { RecitationData recDataManager = (RecitationData) recData; JsonArrayBuilder recArrayBuilder = Json.createArrayBuilder(); ObservableList<Recitation> recitations = recDataManager.getRecitations(); for (Recitation recitation : recitations) { JsonObject recitationJson = Json.createObjectBuilder().add(JSON_SECTION, recitation.getSection()) .add(JSON_INSTRUCTOR, recitation.getInstructor()).add(JSON_DAYTIME, recitation.getDayTime()) .add(JSON_LOCATION, recitation.getLocation()).add(JSON_FIRSTTA, recitation.getFirstTA()) .add(JSON_SECONDTA, recitation.getSecondTA()).build(); recArrayBuilder.add(recitationJson); }//from w ww . jav a2s .c om JsonArray recitaitonArray = recArrayBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_RECITATION, recitaitonArray).build(); Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:csg.files.CSGFiles.java
public void saveScheduleData(AppDataComponent schData, String filePath) throws IOException { ScheduleData schDataManager = (ScheduleData) schData; JsonArrayBuilder schArrayBuilder = Json.createArrayBuilder(); ObservableList<ScheduleItem> schedule = schDataManager.getSchedule(); ArrayList<ScheduleItem> holidays = new ArrayList(); ArrayList<ScheduleItem> lectures = new ArrayList(); ArrayList<ScheduleItem> references = new ArrayList(); ArrayList<ScheduleItem> recitations = new ArrayList(); ArrayList<ScheduleItem> hws = new ArrayList(); for (int i = 0; i < schedule.size(); i++) { if (schedule.get(i).getType().equals("holiday")) { holidays.add(schedule.get(i)); } else if (schedule.get(i).getType().equals("lecture")) { lectures.add(schedule.get(i)); } else if (schedule.get(i).getType().equals("reference")) { references.add(schedule.get(i)); } else if (schedule.get(i).getType().equals("recitation")) { recitations.add(schedule.get(i)); } else if (schedule.get(i).getType().equals("hw")) { hws.add(schedule.get(i));/*from w ww . j av a2s . co m*/ } } JsonArrayBuilder holidayArrayBuilder = Json.createArrayBuilder(); for (ScheduleItem scheduleItem : holidays) { JsonObject holidayJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon()) .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle()) .add(JSON_LINK, scheduleItem.getLink()).build(); holidayArrayBuilder.add(holidayJson); } JsonArray holidayArray = holidayArrayBuilder.build(); JsonArrayBuilder lectureArrayBuilder = Json.createArrayBuilder(); for (ScheduleItem scheduleItem : lectures) { JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon()) .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle()) .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink()).build(); lectureArrayBuilder.add(lecJson); } JsonArray lectureArray = lectureArrayBuilder.build(); JsonArrayBuilder referencesArrayBuilder = Json.createArrayBuilder(); for (ScheduleItem scheduleItem : references) { JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon()) .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle()) .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink()).build(); referencesArrayBuilder.add(lecJson); } JsonArray referenceArray = referencesArrayBuilder.build(); JsonArrayBuilder recitationArrayBuilder = Json.createArrayBuilder(); for (ScheduleItem scheduleItem : recitations) { JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon()) .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle()) .add(JSON_TOPIC, scheduleItem.getTopic()).build(); recitationArrayBuilder.add(lecJson); } JsonArray recitaitonArray = recitationArrayBuilder.build(); JsonArrayBuilder hwArrayBuilder = Json.createArrayBuilder(); for (ScheduleItem scheduleItem : hws) { JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon()) .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle()) .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink()) .add(JSON_TIME, scheduleItem.getTime()).add(JSON_CRITERIA, scheduleItem.getCriteria()).build(); hwArrayBuilder.add(lecJson); } JsonArray hwArray = hwArrayBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_MONDAYMON, workspace.getMonMonthDate()) .add(JSON_MONDAYDAY, workspace.getMonDayDate()).add(JSON_FRIDAYMONTH, workspace.getFriMonthDate()) .add(JSON_FRIDAYDAY, workspace.getFriDayDate()).add(JSON_HOLIDAYS, holidayArray) .add(JSON_LECTURES, lectureArray).add(JSON_REF, referenceArray) .add(JSON_RECITATION, recitaitonArray).add(JSON_HW, hwArray).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:io.bibleget.BibleGetDB.java
public JsonObject getOptions() { if (instance.connect()) { try {//from ww w .ja v a2s. c o m JsonObjectBuilder myOptionsTable; JsonArrayBuilder myRows; try (Statement stmt = instance.conn.createStatement(); ResultSet rsOps = stmt.executeQuery("SELECT * FROM OPTIONS")) { Iterator itColNames = colNames.iterator(); Iterator itDataTypes = colDataTypes.iterator(); myOptionsTable = Json.createObjectBuilder(); myRows = Json.createArrayBuilder(); while (rsOps.next()) { //System.out.println("Getting a row from the table."); JsonObjectBuilder thisRow = Json.createObjectBuilder(); while (itColNames.hasNext() && itDataTypes.hasNext()) { String colName = (String) itColNames.next(); Class dataType = (Class) itDataTypes.next(); if (dataType == String.class) { thisRow.add(colName, rsOps.getString(colName)); } if (dataType == Integer.class) { thisRow.add(colName, rsOps.getInt(colName)); } if (dataType == Boolean.class) { thisRow.add(colName, rsOps.getBoolean(colName)); } //System.out.println(colName + " <" + dataType + ">"); } thisRow.build(); myRows.add(thisRow); } rsOps.close(); stmt.close(); instance.disconnect(); myRows.build(); return myOptionsTable.add("rows", myRows).build(); } } catch (SQLException ex) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); return null; } } return null; }
From source file:csg.files.CSGFiles.java
public void saveCourseData(AppDataComponent courseData, String filePath) throws IOException { CourseData courseDataManager = (CourseData) courseData; JsonArrayBuilder courseArrayBuilder = Json.createArrayBuilder(); JsonArray courseArray = courseArrayBuilder.build(); CSGWorkspace workspace = (CSGWorkspace) app.getWorkspaceComponent(); JsonObject courseJson = Json.createObjectBuilder().add(JSON_SUBJECT, courseDataManager.getSubject()) .add(JSON_NUMBER, courseDataManager.getNumber()).add(JSON_SEMESTER, courseDataManager.getSemester()) .add(JSON_YEAR, courseDataManager.getYear()).add(JSON_TITLE, courseDataManager.getTitle()) .add(JSON_INSTRUCTORNAME, courseDataManager.getInsName()) .add(JSON_INSTRUCTORHOME, courseDataManager.getInsHome()) .add(JSON_BANNER, courseDataManager.getBannerLink()) .add(JSON_LEFTFOOTER, courseDataManager.getLeftFooterLink()) .add(JSON_RIGHTFOOTER, courseDataManager.getRightFooterLink()) .add(JSON_STYLESHEET, courseDataManager.getStyleSheet()).build(); ObservableList<CourseTemplate> templates = courseDataManager.getTemplates(); for (CourseTemplate template : templates) { JsonObject cJson = Json.createObjectBuilder().add(JSON_USE, template.isUse().getValue()) .add(JSON_NAVBAR, template.getNavbarTitle()).add(JSON_FILENAME, template.getFileName()) .add(JSON_SCRIPT, template.getScript()).build(); courseArrayBuilder.add(cJson);/*from w w w . j a v a 2 s. c o m*/ } courseArray = courseArrayBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_COURSE, courseJson) .add(JSON_COURSETEMPLATE, courseArray).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:csg.files.CSGFiles.java
public void saveTeamsAndStudentsData(AppDataComponent projectData, String filePath) throws IOException { ProjectData projectDataManager = (ProjectData) projectData; JsonArrayBuilder teamArrayBuilder = Json.createArrayBuilder(); JsonArrayBuilder studentArrayBuilder = Json.createArrayBuilder(); ObservableList<Team> teams = projectDataManager.getTeams(); ObservableList<Student> students = projectDataManager.getStudents(); for (Team team : teams) { JsonObject teamsJson = Json.createObjectBuilder().add(JSON_NAME, team.getName()) .add(JSON_RED, (Integer.parseInt(team.getColor().toString().substring(0, 2), 16))) .add(JSON_GREEN, (Integer.parseInt(team.getColor().toString().substring(2, 4), 16))) .add(JSON_BLUE, (Integer.parseInt(team.getColor().toString().substring(4, 6), 16))) .add(JSON_TEXTCOLOR, "#" + team.getTextColor()).build(); teamArrayBuilder.add(teamsJson); }//from ww w. jav a2s . c o m JsonArray teamArray = teamArrayBuilder.build(); for (Student student : students) { JsonObject studentsJson = Json.createObjectBuilder().add(JSON_LASTNAME, student.getLastName()) .add(JSON_FIRSTNAME, student.getFirstName()).add(JSON_TEAM, student.getTeam()) .add(JSON_ROLE, student.getRole()).build(); studentArrayBuilder.add(studentsJson); } JsonArray studentArray = studentArrayBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_TEAMS, teamArray) .add(JSON_STUDENTS, studentArray).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:org.kuali.student.ap.coursesearch.service.impl.CourseDetailsViewHelperServiceImpl.java
/** * @see org.kuali.student.ap.coursesearch.service.CourseDetailsViewHelperService#createAddSectionEvent(String, String, String, String, java.util.List, javax.json.JsonObjectBuilder) *//*from w w w . java 2 s .c o m*/ @Override public JsonObjectBuilder createAddSectionEvent(String termId, String courseOfferingCode, String courseOfferingId, String formatOfferingId, List<ActivityOfferingDetailsWrapper> activities, JsonObjectBuilder eventList) { JsonObjectBuilder addEvent = Json.createObjectBuilder(); addEvent.add("courseOfferingId", courseOfferingId); addEvent.add("termId", termId.replace(".", "-")); addEvent.add("courseOfferingCode", courseOfferingCode); addEvent.add("formatOfferingId", formatOfferingId); addEvent.add("uid", UUID.randomUUID().toString()); // Create json array of activity to add and add it to event String regGroupCode = ""; JsonArrayBuilder activityEvents = Json.createArrayBuilder(); for (ActivityOfferingDetailsWrapper activity : activities) { JsonObjectBuilder activityEvent = Json.createObjectBuilder(); String instructor = ""; String days = ""; String time = ""; String location = ""; String classUrl = ""; // activities in the reg group will have the same reg group code. regGroupCode = activity.getRegGroupCode(); // if activity value is null use empty string if (activity.getInstructorName() != null) instructor = activity.getInstructorName(); if (activity.getDays() != null) days = activity.getDays(); if (activity.getTime() != null) time = activity.getTime(); if (activity.getLocation() != null) location = activity.getLocation(); if (activity.getClassUrl() != null) classUrl = activity.getClassUrl(); // Add data to json for activity activityEvent.add("activityOfferingId", activity.getActivityOfferingId()); activityEvent.add("activityFormatName", activity.getActivityFormatName()); activityEvent.add("activityOfferingCode", activity.getActivityOfferingCode()); activityEvent.add("instructor", instructor); activityEvent.add("days", days); activityEvent.add("time", time); activityEvent.add("location", location); activityEvent.add("currentEnrollment", activity.getCurrentEnrollment()); activityEvent.add("maxEnrollment", activity.getMaxEnrollment()); activityEvent.add("honors", activity.isHonors()); activityEvent.add("classUrl", classUrl); JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); activityEvent.add("activityOfferingRequisites", activity.isHasActivityOfferingRequisites()); activityEvents.add(activityEvent); } addEvent.add("activities", activityEvents); addEvent.add("regGroupCode", regGroupCode); eventList.add("COURSE_SECTION_ADDED", addEvent); return eventList; }
From source file:csg.files.CSGFiles.java
public void saveProjectsData(AppDataComponent courseData, AppDataComponent projectData, String filePath) throws IOException { CourseData courseDataManager = (CourseData) courseData; ProjectData projectDataManager = (ProjectData) projectData; ObservableList<Student> students = projectDataManager.getStudents(); JsonArrayBuilder studentArrayBuilder = Json.createArrayBuilder(); JsonArrayBuilder teamArrayBuilder = Json.createArrayBuilder(); ObservableList<Team> teams = projectDataManager.getTeams(); for (Team team : teams) { for (Student student : students) { if (student.getTeam().equals(team.getName())) { studentArrayBuilder.add(student.getFirstName() + " " + student.getLastName()); }//from ww w .j a va2 s . com } JsonArray studentArray = studentArrayBuilder.build(); JsonObject teamsJson = Json.createObjectBuilder().add(JSON_NAME, team.getName()) .add(JSON_STUDENTS, studentArray).add(JSON_LINK, team.getLink()).build(); teamArrayBuilder.add(teamsJson); } JsonArray teamArray = teamArrayBuilder.build(); CSGWorkspace workspace = (CSGWorkspace) app.getWorkspaceComponent(); JsonArrayBuilder courseJsonBuilder = Json.createArrayBuilder(); JsonObject coursesJson = Json.createObjectBuilder() .add(JSON_SEMESTER, courseDataManager.getSemester() + " " + courseDataManager.getYear()) .add(JSON_PROJECTS, teamArray).build(); courseJsonBuilder.add(coursesJson); JsonArray courseJsonArr = courseJsonBuilder.build(); JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_WORK, courseJsonArr).build(); // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); StringWriter sw = new StringWriter(); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(dataManagerJSO); jsonWriter.close(); // INIT THE WRITER OutputStream os = new FileOutputStream(filePath); JsonWriter jsonFileWriter = Json.createWriter(os); jsonFileWriter.writeObject(dataManagerJSO); String prettyPrinted = sw.toString(); PrintWriter pw = new PrintWriter(filePath); pw.write(prettyPrinted); pw.close(); }
From source file:com.buffalokiwi.aerodrome.jet.orders.OrderRec.java
/** * Turn the shipments array into a JsonArray * @return /*from w w w . jav a 2s. c o m*/ */ private JsonArray shipmentsToJson() { final JsonArrayBuilder ab = Json.createArrayBuilder(); if (shipments != null) { for (final ShipmentRec s : shipments) { ab.add(s.toJSON()); } } return ab.build(); }
From source file:com.buffalokiwi.aerodrome.jet.orders.OrderRec.java
/** * Turn the shipments array into a JsonArray * @return // w w w. ja v a 2 s . c om */ private JsonArray orderItemsToJson() { final JsonArrayBuilder ab = Json.createArrayBuilder(); if (orderItems != null) { for (final OrderItemRec o : orderItems) { ab.add(o.toJSON()); } } return ab.build(); }
From source file:io.hops.hopsworks.api.jobs.JobService.java
/** * Get the log information related to a job. The return value is a JSON * object, with format logset=[{"time":"JOB * EXECUTION TIME"}, {"log":"INFORMATION LOG"}, {"err":"ERROR LOG"}] * <p>/* w w w. ja v a 2 s . c o m*/ * @param jobId * @param sc * @param req * @return */ @GET @Path("/{jobId}/showlog") @Produces(MediaType.APPLICATION_JSON) @AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST }) public Response getLogInformation(@PathParam("jobId") int jobId, @Context SecurityContext sc, @Context HttpServletRequest req) { JsonObjectBuilder builder = Json.createObjectBuilder(); JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); List<Execution> executionHistory = exeFacade.findbyProjectAndJobId(project, jobId); JsonObjectBuilder arrayObjectBuilder; if (executionHistory != null && !executionHistory.isEmpty()) { for (Execution e : executionHistory) { arrayObjectBuilder = Json.createObjectBuilder(); arrayObjectBuilder.add("jobId", e.getJob().getId()); arrayObjectBuilder.add("appId", e.getAppId() == null ? "" : e.getAppId()); arrayObjectBuilder.add("time", e.getSubmissionTime().toString()); arrayBuilder.add(arrayObjectBuilder); } } else { arrayObjectBuilder = Json.createObjectBuilder(); arrayObjectBuilder.add("jobId", ""); arrayObjectBuilder.add("appId", ""); arrayObjectBuilder.add("time", "Not available"); arrayObjectBuilder.add("log", "No log available"); arrayObjectBuilder.add("err", "No log available"); arrayBuilder.add(arrayObjectBuilder); } builder.add("logset", arrayBuilder); return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(builder.build()).build(); }