List of usage examples for org.joda.time LocalDate getYear
public int getYear()
From source file:de.sub.goobi.helper.tasks.ExportNewspaperBatchTask.java
License:Open Source License
/** * Inserts a reference (METS pointer (mptr) URL) for an issue on a given * date into an act.//from w w w . ja va2 s. com * * @param act * act in whose logical structure the pointer is to create * @param ruleset * rule set the act is based on * @param date * date of the issue to create a pointer to * @param metsPointerURL * URL of the issue * @throws TypeNotAllowedForParentException * is thrown, if this DocStruct is not allowed for a parent * @throws MetadataTypeNotAllowedException * if the DocStructType of this DocStruct instance does not * allow the MetadataType or if the maximum number of Metadata * (of this type) is already available * @throws TypeNotAllowedAsChildException * if a child should be added, but it's DocStruct type isn't * member of this instance's DocStruct type */ private void insertIssueReference(DigitalDocument act, Prefs ruleset, LocalDate date, String metsPointerURL) throws TypeNotAllowedForParentException, TypeNotAllowedAsChildException, MetadataTypeNotAllowedException { DocStruct year = getOrCreateChild(act.getLogicalDocStruct(), yearLevelName, MetsModsImportExport.CREATE_LABEL_ATTRIBUTE_TYPE, Integer.toString(date.getYear()), MetsModsImportExport.CREATE_ORDERLABEL_ATTRIBUTE_TYPE, act, ruleset); DocStruct month = getOrCreateChild(year, monthLevelName, MetsModsImportExport.CREATE_ORDERLABEL_ATTRIBUTE_TYPE, Integer.toString(date.getMonthOfYear()), MetsModsImportExport.CREATE_LABEL_ATTRIBUTE_TYPE, act, ruleset); DocStruct day = getOrCreateChild(month, dayLevelName, MetsModsImportExport.CREATE_ORDERLABEL_ATTRIBUTE_TYPE, Integer.toString(date.getDayOfMonth()), MetsModsImportExport.CREATE_LABEL_ATTRIBUTE_TYPE, act, ruleset); DocStruct issue = day.createChild(issueLevelName, act, ruleset); issue.addMetadata(MetsModsImportExport.CREATE_MPTR_ELEMENT_TYPE, metsPointerURL); }
From source file:divconq.lang.BigDateTime.java
License:Open Source License
/** * @param date translates into BigDateTime, assumes ISOChronology *///from w ww .j a v a 2 s . c o m public BigDateTime(LocalDate date) { if (date == null) return; this.year = 50000000000L + date.getYear(); // ISO says 1 BCE = 0, 2 BCE = -1, etc this.month = date.getMonthOfYear(); this.day = date.getDayOfMonth(); }
From source file:edu.harvard.med.iccbl.screensaver.reports.icbg.AssayInfoProducer.java
License:Open Source License
public AssayInfo getAssayInfoForScreen(Screen screen) throws FileNotFoundException { AssayInfo assayInfo = new AssayInfo(); assayInfo.setAssayName("ICCBL" + screen.getFacilityId()); assayInfo.setProtocolDescription(screen.getTitle()); assayInfo.setPNote(screen.getSummary()); assayInfo.setInvestigator(//from ww w .j av a2 s .c om screen.getLabHead() == null ? "" : screen.getLabHead().getLastName().toUpperCase()); String assayCategoryText = ""; for (String keyword : screen.getKeywords()) { assayCategoryText += keyword.toUpperCase() + " "; } if (assayCategories != null) { assayInfo.setAssayCategory(assayCategories.get(screen.getFacilityId())); } else { assayCategoryText += screen.getSummary().toUpperCase(); setAssayCategory(assayInfo, assayCategoryText); } LocalDate assayDate = screen.getDateCreated().toLocalDate(); for (StatusItem statusItem : screen.getStatusItems()) { LocalDate statusItemDate = statusItem.getStatusDate(); if (assayDate == null || assayDate.compareTo(statusItemDate) < 0) { assayDate = statusItemDate; } } assayInfo.setAssayDate( assayDate.getMonthOfYear() + "/" + assayDate.getDayOfMonth() + "/" + (assayDate.getYear())); assert assayDate.getYear() >= 1900 : "year should include century"; return assayInfo; }
From source file:edu.uic.apk.APKBuilder.java
License:Open Source License
protected static double getDateDifference(LocalDate c1, LocalDate c2) { //like c1 - c2 in years assert c2 != null; if (c1 == null) { c1 = getSimulationDate();/*from w ww .j a v a 2 s . c om*/ } LocalDate dt = c1.minusDays(c2.getDayOfYear()).minusYears(c2.getYear()); return dt.getYear() + (dt.getDayOfYear() / 365.0); //year is 365 ticks throughout }
From source file:edu.uic.apk.IDUbuilder1.java
License:Open Source License
public IDU generate_SynthNEP(HashMap<String, Object> generator_params) throws Exception { DrugUser modelDU = null;/*ww w . ja va 2 s.c om*/ Integer max_trials = 50; if (generator_params.containsKey("max_trials")) { max_trials = (Integer) generator_params.get("max_trials"); } for (int trial = 0; trial < max_trials; trial++) { try { modelDU = pg.generate(generator_params); assert modelDU != null; break; } catch (Exception e) { System.out.println("x"); modelDU = null; } } if (modelDU == null) { throw new Exception("failed to generate"); } IDU idu = new IDU(); idu.setAgeStarted(modelDU.getAgeStarted()); LocalDate b_day = modelDU.getBirthDate(); LocalDate age_at_survey = modelDU.getSurveyDate(); LocalDate sim_date = APKBuilder.getSimulationDate(); b_day = b_day.plusYears(sim_date.getYear() - age_at_survey.getYear()); b_day = b_day.plusDays(sim_date.getDayOfYear() - age_at_survey.getDayOfYear()); b_day = b_day.plusDays((int) (0.05 * 365 * (RandomHelper.nextDouble() - 0.5))); //some slight jitter (0.05 of a year) idu.setBirthDate(b_day); //System.out.println("Age:" + idu.getAge() + "Model age:" + modelDU.getAge()); idu.setDatabaseLabel(modelDU.getDatabaseLabel()); idu.setEntryDate(LocalDate.now()); idu.setDrugGivingDegree(modelDU.getDrugGivingDegree()); idu.setDrugReceptDegree(modelDU.getDrugReceptDegree()); idu.setFractionReceptSharing(modelDU.getFractionReceptSharing()); idu.setGender(modelDU.getGender()); if (modelDU.getHcvState() == HCV_state.ABPOS) { double roll = RandomHelper.nextDouble() - ab_prob_chronic; if (roll < 0) { idu.setHcvInitialState(HCV_state.chronic); } else if (roll - ab_prob_acute < 0) { idu.setHcvInitialState(HCV_state.infectiousacute); } else { idu.setHcvInitialState(HCV_state.recovered); } } else { idu.setHcvInitialState(HCV_state.susceptible); } idu.setInjectionIntensity(modelDU.getInjectionIntensity()); if (idu.getName() == null) { if (idu.getGender() == Gender.Male) { idu.setName(IDU.male_names[RandomHelper.nextIntFromTo(0, IDU.male_names.length - 1)]); } else { idu.setName(IDU.female_names[RandomHelper.nextIntFromTo(0, IDU.female_names.length - 1)]); } } idu.setPreliminaryZip(modelDU.getPreliminaryZip()); idu.setRace(modelDU.getRace()); idu.setSyringe_source(modelDU.getSyringe_source()); return idu; }
From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java
License:Open Source License
public void seekField(Granulaarsus field, int direction, int soughtValue, boolean excludingCurrent) { // --------------------------------- // DAY_OF_MONTH // --------------------------------- if (field == Granulaarsus.DAY_OF_MONTH && direction != 0 && soughtValue == 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir); ajaFookus = nihutatudFookus;/*w w w. jav a 2s. c om*/ this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // DAY_OF_WEEK // --------------------------------- if (field == Granulaarsus.DAY_OF_WEEK && soughtValue >= DateTimeConstants.MONDAY && soughtValue <= DateTimeConstants.SUNDAY && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne p2ev ehk p2ev, millest tahame tingimata m66duda int algneNadalapaev = (excludingCurrent) ? (ajaFookus.getDayOfWeek()) : (-1); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale ajaFookus = ajaFookus.plusDays(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir); ajaFookus = nihutatudFookus; int uusNadalapaev = ajaFookus.getDayOfWeek(); if (algneNadalapaev != -1) { if (algneNadalapaev == uusNadalapaev) { continue; } else { algneNadalapaev = -1; } } if (uusNadalapaev == soughtValue) { algneNadalapaev = uusNadalapaev; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // WEEK OF YEAR // --------------------------------- if (field == Granulaarsus.WEEK_OF_YEAR && soughtValue == 0 && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne n2dal ehk n2dal, millest tahame m88duda int algneNadal = (excludingCurrent) ? (ajaFookus.getWeekOfWeekyear()) : (-1); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale ajaFookus = ajaFookus.plusDays(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir); ajaFookus = nihutatudFookus; int uusNadal = nihutatudFookus.getWeekOfWeekyear(); if (algneNadal != -1) { if (algneNadal == uusNadal) { continue; } else { algneNadal = -1; } } if (soughtValue == 0) { algneNadal = uusNadal; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.WEEK_OF_YEAR, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // MONTH // --------------------------------- if (field == Granulaarsus.MONTH && (soughtValue == 0 || DateTimeConstants.JANUARY <= soughtValue && soughtValue <= DateTimeConstants.DECEMBER) && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne kuu ehk kuu, millest tahame m88duda int algneKuu = (excludingCurrent) ? (ajaFookus.getMonthOfYear()) : (-1); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule ajaFookus = ajaFookus.plusMonths(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir); ajaFookus = nihutatudFookus; int uusKuu = nihutatudFookus.getMonthOfYear(); if (algneKuu != -1) { if (algneKuu == uusKuu) { continue; } else { algneKuu = -1; } } if (soughtValue == 0 || (soughtValue != 0 && uusKuu == soughtValue)) { algneKuu = uusKuu; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // YEAR // --------------------------------- if (field == Granulaarsus.YEAR && soughtValue == 0 && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne aasta ehk aasta, millest tahame m88duda int algneAasta = (excludingCurrent) ? (ajaFookus.getYear()) : (-1); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule ajaFookus = ajaFookus.plusMonths(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir); ajaFookus = nihutatudFookus; int uusAasta = nihutatudFookus.getYear(); if (algneAasta != -1) { if (algneAasta == uusAasta) { continue; } else { algneAasta = -1; } } if (soughtValue == 0) { algneAasta = uusAasta; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // YEAR_OF_CENTURY // --------------------------------- if (field == Granulaarsus.YEAR_OF_CENTURY && direction != 0) { int minValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate, DateTimeFieldType.yearOfCentury(), false); int maxValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate, DateTimeFieldType.yearOfCentury(), true); if (minValue <= soughtValue && soughtValue <= maxValue) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne aasta ehk aasta, millest tahame m88duda int algneAasta = (excludingCurrent) ? (ajaFookus.getYearOfCentury()) : (-1); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale ajaFookus = ajaFookus.plusYears(dir * (-1)); } int count = 0; int cycleCount = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusYears(1 * dir); cycleCount++; ajaFookus = nihutatudFookus; int uusAasta = nihutatudFookus.getYearOfCentury(); if (algneAasta != -1) { if (algneAasta == uusAasta) { continue; } else { algneAasta = -1; } } if (uusAasta == soughtValue) { algneAasta = uusAasta; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } } // --------------------------------- // CENTURY_OF_ERA // --------------------------------- if (field == Granulaarsus.CENTURY_OF_ERA && soughtValue == 0 && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne saj ehk sajand, millest tahame m88duda int algneSajand = (excludingCurrent) ? (ajaFookus.getCenturyOfEra()) : (Integer.MIN_VALUE); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale ajaFookus = ajaFookus.plusYears(dir * (-10)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusYears(10 * dir); ajaFookus = nihutatudFookus; int uusSajand = nihutatudFookus.getCenturyOfEra(); if (algneSajand != Integer.MIN_VALUE) { if (algneSajand == uusSajand) { continue; } else { algneSajand = Integer.MIN_VALUE; } } if (soughtValue == 0) { algneSajand = uusSajand; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; updateDateRepresentation(Granulaarsus.CENTURY_OF_ERA, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } }
From source file:energy.usef.brp.workflow.settlement.initiate.BrpInitiateSettlementCoordinator.java
License:Apache License
/** * Preparation of the Initiate Settlement process for the first day of the previous month until the last day of the previous * month. The initiating of settlements will stop if there are no flex orders in the selected period. * * @param event The {@link CollectSmartMeterDataEvent} triggering the process. *//*from w w w. ja v a2s .c o m*/ @Asynchronous @Lock(LockType.WRITE) public void handleCollectSmartMeterDataEvent( @Observes(during = TransactionPhase.AFTER_COMPLETION) CollectSmartMeterDataEvent event) { LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, event); LocalDate dayOneMonthBefore = event.getPeriodInMonth(); if (dayOneMonthBefore == null) { dayOneMonthBefore = DateTimeUtil.getCurrentDate().minusMonths(1); } LocalDate startDate = dayOneMonthBefore.withDayOfMonth(1); LocalDate endDate = dayOneMonthBefore.dayOfMonth().withMaximumValue(); // retrieve a distinct list of all connections valid in given time frame and map them to a string list. Map<LocalDate, Map<ConnectionGroup, List<Connection>>> connectionGroupsWithConnections = corePlanboardBusinessService .findConnectionGroupWithConnectionsWithOverlappingValidity(startDate, endDate); List<LocalDate> daysWithOrders = corePlanboardBusinessService .findPlanboardMessages(DocumentType.FLEX_ORDER, startDate, endDate, DocumentStatus.ACCEPTED) .stream().map(PlanboardMessage::getPeriod).distinct().collect(Collectors.toList()); if (daysWithOrders.isEmpty()) { checkInitiateSettlementDoneEvent .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear())); LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); return; } // loop through all the MDCs for (MeterDataCompany meterDataCompany : brpBusinessService.findAllMDCs()) { // query meter data company (MDC) for all connections LOGGER.info("Preparing sending MeterDataQuery to Meter Data Company {}", meterDataCompany.getDomain()); for (LocalDate period : connectionGroupsWithConnections.keySet()) { if (!daysWithOrders.contains(period)) { continue; } LocalDateTime expirationDateTime = DateTimeUtil.getCurrentDateTime().plusHours( configBrp.getIntegerProperty(ConfigBrpParam.BRP_METER_DATA_QUERY_EXPIRATION_IN_HOURS)); MessageMetadata messageMetadata = MessageMetadataBuilder .build(meterDataCompany.getDomain(), USEFRole.MDC, config.getProperty(ConfigParam.HOST_DOMAIN), USEFRole.BRP, TRANSACTIONAL) .validUntil(expirationDateTime).build(); // fill the MeterDataQuery message MeterDataQuery meterDataQuery = new MeterDataQuery(); meterDataQuery.setMessageMetadata(messageMetadata); meterDataQuery.setDateRangeStart(period); meterDataQuery.setDateRangeEnd(period); meterDataQuery.getConnections() .addAll(buildConnectionGroups(connectionGroupsWithConnections.get(period))); MeterDataQueryMessageUtil.populateConnectionsInConnectionGroups(meterDataQuery, connectionGroupsWithConnections.get(period)); // Store in PlanboardMessage, no connectionGroup available because query is for the whole grid. // the period should be the startDate of the month. PlanboardMessage meterDataQueryPlanboardMessage = new PlanboardMessage( DocumentType.METER_DATA_QUERY_USAGE, sequenceGeneratorService.next(), DocumentStatus.SENT, meterDataCompany.getDomain(), period, null, null, expirationDateTime); corePlanboardBusinessService.updatePlanboardMessage(meterDataQueryPlanboardMessage); // send the message jmsHelperService.sendMessageToOutQueue(XMLUtil.messageObjectToXml(meterDataQuery)); } } LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); }
From source file:energy.usef.brp.workflow.settlement.initiate.BrpInitiateSettlementCoordinator.java
License:Apache License
/** * Handles the event triggering the initiation of the settlement. * * @param finalizeInitiateSettlementEvent {@link FinalizeInitiateSettlementEvent}. *//* w ww . j a v a2 s. c om*/ @SuppressWarnings("unchecked") @Asynchronous public void handleBrpInitiateSettlement( @Observes(during = TransactionPhase.AFTER_COMPLETION) FinalizeInitiateSettlementEvent finalizeInitiateSettlementEvent) { LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, finalizeInitiateSettlementEvent); // variables final LocalDate startDate = finalizeInitiateSettlementEvent.getStartDate(); final LocalDate endDate = finalizeInitiateSettlementEvent.getEndDate(); // creation of the context and call to the PBC. WorkflowContext inContext = initiateWorkflowContext(startDate, endDate); inContext.setValue(BrpInitiateSettlementParameter.IN.SMART_METER_DATA.name(), MeterDataTransformer.transform(finalizeInitiateSettlementEvent.getConnectionGroupList())); SettlementDto settlementDto = invokeInitiateSettlementPbc(inContext); // Add the settlement prices to the SettlementDto settlementDto = calculateSettlementPrice(settlementDto, inContext.get(FLEX_OFFER_DTO_LIST.name(), List.class)); // invoke the PBC to add penalty data to the ptuSettlementList settlementDto = addPenaltyData(settlementDto); // save the settlement dtos. saveSettlement(settlementDto); LOGGER.info("Settlements are stored in the DB."); checkInitiateSettlementDoneEvent .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear())); LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, finalizeInitiateSettlementEvent); }
From source file:energy.usef.dso.workflow.settlement.initiate.DsoInitiateSettlementCoordinator.java
License:Apache License
/** * Preparation of the Initiate Settlement process. * * @param event the {@link CollectSmartMeterDataEvent} that triggers the process. *//* ww w .jav a 2s . c o m*/ @Asynchronous @Lock(LockType.WRITE) public void handleCollectSmartMeterDataEvent( @Observes(during = TransactionPhase.AFTER_COMPLETION) CollectSmartMeterDataEvent event) { LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, event); LocalDate dayOneMonthBefore = event.getPeriodInMonth(); if (dayOneMonthBefore == null) { dayOneMonthBefore = DateTimeUtil.getCurrentDate().minusMonths(1); } LocalDate startDate = dayOneMonthBefore.withDayOfMonth(1); LocalDate endDate = dayOneMonthBefore.dayOfMonth().withMaximumValue(); LOGGER.info("Preparing Initiate Settlement workflow for the start day {} and end day {}.", startDate, endDate); // retrieve a distinct list of all connections valid in given time frame and map them to a string list. Map<LocalDate, Map<ConnectionGroup, List<Connection>>> connectionGroupsWithConnections = corePlanboardBusinessService .findConnectionGroupWithConnectionsWithOverlappingValidity(startDate, endDate); List<LocalDate> daysWithOrders = corePlanboardBusinessService .findPlanboardMessages(DocumentType.FLEX_ORDER, startDate, endDate, DocumentStatus.ACCEPTED) .stream().map(PlanboardMessage::getPeriod).distinct().collect(toList()); if (daysWithOrders.isEmpty()) { checkInitiateSettlementDoneEvent .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear())); LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); return; } // loop through all the MDCs for (MeterDataCompany meterDataCompany : dsoPlanboardBusinessService.findAllMDCs()) { // query meter data company (MDC) for all connections LOGGER.info("Preparing sending MeterDataQuery to Meter Data Company {}", meterDataCompany.getDomain()); for (LocalDate period : connectionGroupsWithConnections.keySet()) { if (!daysWithOrders.contains(period)) { continue; } LocalDateTime expirationDateTime = DateTimeUtil.getCurrentDateTime().plusHours( configDso.getIntegerProperty(ConfigDsoParam.DSO_METER_DATA_QUERY_EXPIRATION_IN_HOURS)); MessageMetadata messageMetadata = MessageMetadataBuilder .build(meterDataCompany.getDomain(), USEFRole.MDC, config.getProperty(ConfigParam.HOST_DOMAIN), USEFRole.DSO, TRANSACTIONAL) .validUntil(expirationDateTime).build(); // fill the MeterDataQuery message MeterDataQuery meterDataQuery = new MeterDataQuery(); meterDataQuery.setMessageMetadata(messageMetadata); meterDataQuery.setDateRangeStart(period); meterDataQuery.setDateRangeEnd(period); meterDataQuery.getConnections() .addAll(buildConnectionGroups(connectionGroupsWithConnections.get(period))); MeterDataQueryMessageUtil.populateConnectionsInConnectionGroups(meterDataQuery, connectionGroupsWithConnections.get(period)); // Store in PlanboardMessage, no connectionGroup available because query is for the whole grid. // the period should be the startDate of the month. PlanboardMessage meterDataQueryPlanboardMessage = new PlanboardMessage( DocumentType.METER_DATA_QUERY_USAGE, sequenceGeneratorService.next(), DocumentStatus.SENT, meterDataCompany.getDomain(), period, null, null, null); meterDataQueryPlanboardMessage.setExpirationDate(expirationDateTime); corePlanboardBusinessService.updatePlanboardMessage(meterDataQueryPlanboardMessage); // send the message jmsHelperService.sendMessageToOutQueue(XMLUtil.messageObjectToXml(meterDataQuery)); } } LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); }
From source file:energy.usef.dso.workflow.settlement.initiate.DsoInitiateSettlementCoordinator.java
License:Apache License
/** * Handles the event triggering the initiation of the settlement. * * @param finalizeInitiateSettlementEvent {@link CollectSmartMeterDataEvent}. *//*from ww w .j ava2s.c o m*/ @SuppressWarnings("unchecked") @Asynchronous public void handleDsoInitiateSettlement( @Observes(during = TransactionPhase.AFTER_COMPLETION) FinalizeInitiateSettlementEvent finalizeInitiateSettlementEvent) { LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, finalizeInitiateSettlementEvent); final LocalDate startDate = finalizeInitiateSettlementEvent.getStartDate(); final LocalDate endDate = finalizeInitiateSettlementEvent.getEndDate(); // creation of the context and call to the PBC. WorkflowContext inContext = initiateWorkflowContext(startDate, endDate); if (!finalizeInitiateSettlementEvent.getMeterDataPerCongestionPoint().isEmpty()) { inContext.setValue(DsoInitiateSettlementParameter.IN.SMART_METER_DATA.name(), MeterDataTransformer .transform(finalizeInitiateSettlementEvent.getMeterDataPerCongestionPoint())); } else { inContext.setValue(DsoInitiateSettlementParameter.IN.GRID_MONITORING_DATA.name(), buildGridMonitoringDtos(startDate, endDate)); } SettlementDto settlementDto = invokeInitiateSettlementPbc(inContext); // Add the settlement prices to the SettlementDto settlementDto = calculateSettlementPrice(settlementDto, inContext.get(FLEX_OFFER_DTO_LIST.name(), List.class)); // invoke the PBC to add penalty data to the ptuSettlementList settlementDto = addPenaltyData(settlementDto); // save the settlement dtos. saveSettlement(settlementDto); checkInitiateSettlementDoneEvent .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear())); LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, finalizeInitiateSettlementEvent); }