List of usage examples for javax.json JsonObjectBuilder add
JsonObjectBuilder add(String name, JsonArrayBuilder builder);
From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java
public AcademicTermWrapper populateTermWrapper(TermInfo termInfo, boolean isCopy, boolean calculateInstrDays) throws Exception { getLog().debug("Populating Term - {}", termInfo.getId()); TypeInfo type = getAcalService().getTermType(termInfo.getTypeKey(), createContextInfo()); AcademicTermWrapper termWrapper = new AcademicTermWrapper(termInfo, isCopy); termWrapper.setTypeInfo(type);/*w ww. jav a 2 s .c om*/ termWrapper.setTermNameForUI(type.getName()); if (isCopy) { termWrapper.setName(type.getName()); } //Populate examdates List<ExamPeriodInfo> examPeriodInfos = getAcalService().getExamPeriodsForTerm(termInfo.getId(), createContextInfo()); if (examPeriodInfos != null && examPeriodInfos.size() > 0) { //only one or none for (ExamPeriodInfo examPeriodInfo : examPeriodInfos) { ExamPeriodWrapper examPeriodWrapper = new ExamPeriodWrapper(examPeriodInfo, isCopy); examPeriodWrapper.setExcludeSaturday(Boolean.parseBoolean(examPeriodInfo .getAttributeValue(AcademicCalendarServiceConstants.EXAM_PERIOD_EXCLUDE_SATURDAY_ATTR))); examPeriodWrapper.setExcludeSunday(Boolean.parseBoolean(examPeriodInfo .getAttributeValue(AcademicCalendarServiceConstants.EXAM_PERIOD_EXCLUDE_SUNDAY_ATTR))); termWrapper.getExamdates().add(examPeriodWrapper); } } //Populate keydates List<KeyDateInfo> keydateList = getAcalService().getKeyDatesForTerm(termInfo.getId(), createContextInfo()); List<TypeInfo> keyDateTypes = getTypeService().getAllowedTypesForType(termInfo.getTypeKey(), createContextInfo()); Map<String, KeyDatesGroupWrapper> keyDateGroup = new HashMap<String, KeyDatesGroupWrapper>(); for (KeyDateInfo keyDateInfo : keydateList) { KeyDateWrapper keyDateWrapper = new KeyDateWrapper(keyDateInfo, isCopy); type = getTypeService().getType(keyDateInfo.getTypeKey(), createContextInfo()); keyDateWrapper.setTypeInfo(type); keyDateWrapper.setKeyDateNameUI(type.getName()); addKeyDateGroup(keyDateTypes, keyDateWrapper, keyDateGroup); } for (KeyDatesGroupWrapper group : keyDateGroup.values()) { if (!group.getKeydates().isEmpty()) { //KSENROLL-12648: workaround for rice 2.4 upgrade issue. //Construct key date types JSON string for js to populate key date type dropdown in key date add blank line if (StringUtils.isBlank(group.getKeyDateTypesJSON())) { List<TypeInfo> types = getTypeService().getTypesForGroupType(group.getKeyDateGroupType(), createContextInfo()); JsonObjectBuilder keyDateTypesJsonBuilder = Json.createObjectBuilder(); for (TypeInfo typeInfo : types) { if (!group.isKeyDateExists(typeInfo.getKey())) { keyDateTypesJsonBuilder.add(typeInfo.getKey(), typeInfo.getName().replace("\"", "\\\"")); } } group.setKeyDateTypesJSON(keyDateTypesJsonBuilder.build().toString()); } termWrapper.getKeyDatesGroupWrappers().add(group); } } if (calculateInstrDays) { populateInstructionalDays(termWrapper); } return termWrapper; }
From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java
/** * Process before adding a term, key date group, holiday calendar or event * *///w w w . ja v a 2 s . co m @Override public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath) { processAddBlankLines(model); if (addLine instanceof AcademicTermWrapper) { AcademicTermWrapper newLine = (AcademicTermWrapper) addLine; AcademicCalendarForm acalForm = (AcademicCalendarForm) model; //need to handle Term vs subTerm in different way try { if (newLine.getTermType() != null && !StringUtils.isBlank(newLine.getTermType())) { TypeInfo termType = getAcalService().getTermType(newLine.getTermType(), createContextInfo()); // check if term is subterm vs parent term getParentTermType(newLine); if (newLine.getParentTerm() == null || StringUtils.isBlank(newLine.getParentTerm())) { //try to add a term newLine.setTermNameForUI(termType.getName()); newLine.setName(termType.getName() + " " + DateFormatters.DEFULT_YEAR_FORMATTER.format(newLine.getStartDate())); newLine.setTypeInfo(termType); newLine.setSubTerm(false); } else { //try to add a subterm newLine.setTermNameForUI(termType.getName()); newLine.setName(termType.getName() + " " + DateFormatters.DEFULT_YEAR_FORMATTER.format(newLine.getStartDate())); newLine.setTypeInfo(termType); newLine.setSubTerm(true); AcademicTermWrapper parentTermWrapper = getParentTermInForm(newLine.getParentTerm(), acalForm.getTermWrapperList()); if (parentTermWrapper != null) { populateParentTermToSubterm(parentTermWrapper, newLine); } parentTermWrapper.setHasSubterm(true); parentTermWrapper.getSubterms().add(newLine); } } } catch (Exception e) { throw new RuntimeException(e); } } else if (addLine instanceof KeyDatesGroupWrapper) { KeyDatesGroupWrapper group = (KeyDatesGroupWrapper) addLine; if (StringUtils.isNotEmpty(group.getKeyDateGroupType())) { try { TypeInfo termType = getTypeInfo(group.getKeyDateGroupType()); group.setKeyDateGroupNameUI(termType.getName()); group.setTypeInfo(termType); KeyDateWrapper keyDate = new KeyDateWrapper(); group.getKeydates().add(keyDate); ((AcademicCalendarForm) model).getAddedCollectionItems().add(keyDate); //KSENROLL-12648: workaround for rice 2.4 upgrade issue. //Construct key date types JSON string for js to populate key date type dropdown in key date add blank line if (StringUtils.isBlank(group.getKeyDateTypesJSON())) { List<TypeInfo> types = getTypeService().getTypesForGroupType(group.getKeyDateGroupType(), createContextInfo()); JsonObjectBuilder keyDateTypesJsonBuilder = Json.createObjectBuilder(); for (TypeInfo typeInfo : types) { if (!group.isKeyDateExists(typeInfo.getKey())) { keyDateTypesJsonBuilder.add(typeInfo.getKey(), typeInfo.getName().replace("\"", "\\\"")); } } group.setKeyDateTypesJSON(keyDateTypesJsonBuilder.build().toString()); } } catch (Exception e) { throw new RuntimeException(e); } } } else if (addLine instanceof HolidayCalendarInfo) { HolidayCalendarInfo inputLine = (HolidayCalendarInfo) addLine; try { System.out.println("HC id =" + inputLine.getId()); HolidayCalendarInfo exists = getAcalService().getHolidayCalendar(inputLine.getId(), createContextInfo()); inputLine.setName(exists.getName()); inputLine.setId(exists.getId()); inputLine.setTypeKey(exists.getTypeKey()); inputLine.setAdminOrgId(exists.getAdminOrgId()); inputLine.setStartDate(exists.getStartDate()); inputLine.setEndDate(exists.getEndDate()); } catch (Exception e) { throw new RuntimeException(e); } } else if (addLine instanceof HolidayCalendarWrapper) { HolidayCalendarWrapper inputLine = (HolidayCalendarWrapper) addLine; List<HolidayWrapper> holidays = new ArrayList<HolidayWrapper>(); try { String holidayCalendarId = inputLine.getId(); if (!StringUtils.isEmpty(holidayCalendarId)) { HolidayCalendarInfo hcInfo = getAcalService().getHolidayCalendar(inputLine.getId(), createContextInfo()); inputLine.setHolidayCalendarInfo(hcInfo); inputLine.setAdminOrgName(AcalCommonUtils.getAdminOrgNameById(hcInfo.getAdminOrgId())); StateInfo hcState = getAcalService().getHolidayCalendarState(hcInfo.getStateKey(), createContextInfo()); inputLine.setStateName(hcState.getName()); List<HolidayInfo> holidayInfoList = getAcalService() .getHolidaysForHolidayCalendar(hcInfo.getId(), createContextInfo()); for (HolidayInfo holidayInfo : holidayInfoList) { HolidayWrapper holiday = new HolidayWrapper(holidayInfo); TypeInfo typeInfo = getAcalService().getHolidayType(holidayInfo.getTypeKey(), createContextInfo()); holiday.setTypeName(typeInfo.getName()); holidays.add(holiday); } inputLine.setHolidays(holidays); } } catch (Exception e) { throw new RuntimeException(e); } } else if (addLine instanceof HolidayWrapper) { HolidayWrapper holiday = (HolidayWrapper) addLine; try { holiday.setTypeName(getTypeInfo(holiday.getTypeKey()).getName()); } catch (Exception e) { throw new RuntimeException(e); } if (!AcalCommonUtils.isValidDateRange(holiday.getStartDate(), holiday.getEndDate())) { GlobalVariables.getMessageMap().putWarningForSectionId("KS-HolidayCalendar-HolidaySection", CalendarConstants.MessageKeys.ERROR_INVALID_DATE_RANGE, holiday.getTypeName(), AcalCommonUtils.formatDate(holiday.getStartDate()), AcalCommonUtils.formatDate(holiday.getEndDate())); } } else { super.processBeforeAddLine(model, addLine, collectionId, collectionPath); } }
From source file:com.buffalokiwi.aerodrome.jet.orders.OrderRec.java
/** * Turn this object into Jet json // w w w . jav a2 s .c o m * @return json */ @Override public JsonObject toJSON() { final JsonObject shipTo = Json.createObjectBuilder().add("recipient", shippingTo.toJSON()) .add("address", shippingToAddress.toJSON()).build(); final JsonObjectBuilder b = Json.createObjectBuilder().add("merchant_order_id", merchantOrderId) .add("reference_order_id", referenceOrderId) .add("customer_reference_order_id", customerReferenceOrderId) .add("fulfillment_node", fulfillmentNode).add("alt_order_id", altOrderId) .add("hash_email", hashEmail).add("status", status.getText()) .add("exception_state", exceptionState.getText()) .add("order_placed_date", orderPlacedDate.getDateString(JetDate.FMT_ZULU)) .add("order_transmission_date", orderTransmissionDate.getDateString(JetDate.FMT_ZULU)) //.add( "jet_request_directed_cancel", (( jetRequestDirectedCancel ) ? "true" : "false" )) .add("order_detail", orderDetail.toJSON()).add("buyer", buyer.toJSON()).add("shipping_to", shipTo) .add("order_totals", orderTotals.toJSON()).add("has_shipments", hasShipments) .add("acknowledgement_status", ackStatus.getText()); if (orderReadyDate != null) b.add("order_ready_date", orderReadyDate.getDateString(JetDate.FMT_ZULU_ZERO)); if (orderAckDate != null) b.add("order_acknowledge_date", orderAckDate.getDateString(JetDate.FMT_LOCAL_MICRO)); if (shipments != null) b.add("shipments", shipmentsToJson()); if (orderItems != null) b.add("order_items", orderItemsToJson()); return b.build(); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public String snapshotWorkspace(String wskey) throws CoreServiceException, KeyNotFoundException, AccessDeniedException, WorkspaceReadOnlyException, WorkspaceUnchangedException { LOGGER.log(Level.FINE, "snapshoting workspace [" + wskey + "]"); try {//from w ww . j a v a 2 s . c om String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier identifier = registry.lookup(wskey); checkObjectType(identifier, Workspace.OBJECT_TYPE); authorisation.checkPermission(wskey, subjects, "update"); Workspace workspace = em.find(Workspace.class, identifier.getId()); if (workspace == null) { throw new CoreServiceException( "unable to load workspace with id [" + identifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, workspace)) { throw new WorkspaceReadOnlyException( "unable to snapshot workspace with key [" + wskey + "] because it is read only"); } String name = String.valueOf(workspace.getClock()); if (!workspace.hasChanged()) { throw new WorkspaceUnchangedException( "unable to snapshot because workspace has no pending modifications since last snapshot"); } try { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("wskey", wskey); builder.add("snapshotName", name); builder.add("wsalias", workspace.getAlias()); JsonObject jsonObject = builder.build(); String hash = binarystore.put(new ByteArrayInputStream(jsonObject.toString().getBytes())); List<String> mds = findMetadataObjectsForTargetAndName(workspace.getHead(), MetadataFormat.WORKSPACE); if (mds.isEmpty()) { LOGGER.log(Level.INFO, "creating workspace metadata for root collection"); createMetadataObject(wskey, "/", MetadataFormat.WORKSPACE, hash, null, false); } else { LOGGER.log(Level.INFO, "updating workspace metadata for root collection"); updateMetadataObject(wskey, "/", MetadataFormat.WORKSPACE, hash, null, false); } } catch (BinaryStoreServiceException | DataCollisionException | CoreServiceException | KeyNotFoundException | InvalidPathException | AccessDeniedException | MetadataFormatException | PathNotFoundException | KeyAlreadyExistsException e) { throw new CoreServiceException( "cannot create workspace metadata for collection root : " + e.getMessage()); } workspace.setKey(wskey); workspace.incrementClock(); OrtolangObjectIdentifier hidentifier = registry.lookup(workspace.getHead()); checkObjectType(hidentifier, Collection.OBJECT_TYPE); Collection collection = em.find(Collection.class, hidentifier.getId()); if (collection == null) { throw new CoreServiceException( "unable to load head collection with id [" + hidentifier.getId() + "] from storage"); } collection.setKey(workspace.getHead()); Collection clone = cloneCollection(workspace.getHead(), collection, workspace.getClock()); workspace.addSnapshot(new SnapshotElement(name, collection.getKey())); workspace.setHead(clone.getKey()); workspace.setChanged(false); em.merge(workspace); registry.update(wskey); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(2).addArgument("ws-alias", workspace.getAlias()) .addArgument("snapshot-name", name); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Workspace.OBJECT_TYPE, "snapshot"), argsBuilder.build()); return name; } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | CloneException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred while snapshoting workspace", e); throw new CoreServiceException("unable to snapshot workspace with key [" + wskey + "]", e); } }