List of usage examples for org.joda.time LocalDateTime parse
public static LocalDateTime parse(String str, DateTimeFormatter formatter)
From source file:com.act.lcms.db.model.ScanFile.java
License:Open Source License
/** * This function parses the date from a given scan file's name. * @return a local date time// www. java2 s . com */ public LocalDateTime getDateFromScanFileTitle() throws Exception { for (Pair<Pattern, Map<SCAN_NAME_COMPONENT, Integer>> scan : NAME_EXTRACTION_PATTERNS) { Pattern p = scan.getLeft(); Map<SCAN_NAME_COMPONENT, Integer> groupMap = scan.getRight(); Matcher m = p.matcher(this.fileName); if (m.matches() && groupMap.containsKey(SCAN_NAME_COMPONENT.DATE)) { DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT); LocalDateTime dateTime = LocalDateTime.parse(m.group(groupMap.get(SCAN_NAME_COMPONENT.DATE)), formatter); if (dateTime.getYear() < TWENTYN_INCEPTION) { throw new RuntimeException("The date parsed from the file name is malformed."); } return dateTime; } } // We assume a date will appear in every file name format. throw new RuntimeException(String.format("Unable to extract date from scan file name: %s", this.fileName)); }
From source file:com.axelor.apps.production.web.OperationOrderController.java
License:Open Source License
public void chargeByMachineHours(ActionRequest request, ActionResponse response) throws AxelorException { List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>(); DateTimeFormatter parser = ISODateTimeFormat.dateTime(); LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(), parser);/* w w w .jav a 2s .c o m*/ LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser); LocalDateTime itDateTime = new LocalDateTime(fromDateTime); if (Days.daysBetween( new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()), new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth())) .getDays() > 20) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)), IException.CONFIGURATION_ERROR); } List<OperationOrder> operationOrderListTemp = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime) .fetch(); Set<String> machineNameList = new HashSet<String>(); for (OperationOrder operationOrder : operationOrderListTemp) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) { machineNameList.add(operationOrder.getWorkCenter().getMachine().getName()); } } } while (!itDateTime.isAfter(toDateTime)) { List<OperationOrder> operationOrderList = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)) .fetch(); Map<String, BigDecimal> map = new HashMap<String, BigDecimal>(); for (OperationOrder operationOrder : operationOrderList) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { String machine = operationOrder.getWorkCenter().getMachine().getName(); int numberOfMinutes = 0; if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) { numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT()) .getMinutes(); } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) { numberOfMinutes = Minutes .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)) .getMinutes(); } else { numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).getMinutes(); } if (numberOfMinutes > 60) { numberOfMinutes = 60; } BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)) .divide(new BigDecimal(60), 2, RoundingMode.HALF_UP); if (map.containsKey(machine)) { map.put(machine, map.get(machine).add(percentage)); } else { map.put(machine, percentage); } } } Set<String> keyList = map.keySet(); for (String key : machineNameList) { if (keyList.contains(key)) { Map<String, Object> dataMap = new HashMap<String, Object>(); if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) { dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm")); } else { dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm")); } dataMap.put("charge", (Object) map.get(key)); dataMap.put("machine", (Object) key); dataList.add(dataMap); } else { Map<String, Object> dataMap = new HashMap<String, Object>(); if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) { dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm")); } else { dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm")); } dataMap.put("charge", (Object) BigDecimal.ZERO); dataMap.put("machine", (Object) key); dataList.add(dataMap); } } itDateTime = itDateTime.plusHours(1); } response.setData(dataList); }
From source file:com.axelor.apps.production.web.OperationOrderController.java
License:Open Source License
public void chargeByMachineDays(ActionRequest request, ActionResponse response) throws AxelorException { List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>(); DateTimeFormatter parser = ISODateTimeFormat.dateTime(); LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(), parser);/*from www . j a v a 2s . com*/ fromDateTime = fromDateTime.withHourOfDay(0).withMinuteOfHour(0); LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser); toDateTime = toDateTime.withHourOfDay(23).withMinuteOfHour(59); LocalDateTime itDateTime = new LocalDateTime(fromDateTime); if (Days.daysBetween( new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()), new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth())) .getDays() > 500) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)), IException.CONFIGURATION_ERROR); } List<OperationOrder> operationOrderListTemp = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime) .fetch(); Set<String> machineNameList = new HashSet<String>(); for (OperationOrder operationOrder : operationOrderListTemp) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) { machineNameList.add(operationOrder.getWorkCenter().getMachine().getName()); } } } while (!itDateTime.isAfter(toDateTime)) { List<OperationOrder> operationOrderList = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)) .fetch(); Map<String, BigDecimal> map = new HashMap<String, BigDecimal>(); for (OperationOrder operationOrder : operationOrderList) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { String machine = operationOrder.getWorkCenter().getMachine().getName(); int numberOfMinutes = 0; if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) { numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT()) .getMinutes(); } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) { numberOfMinutes = Minutes .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)) .getMinutes(); } else { numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).getMinutes(); } if (numberOfMinutes > 60) { numberOfMinutes = 60; } int numberOfMinutesPerDay = 0; if (operationOrder.getWorkCenter().getMachine().getWeeklyPlanning() != null) { DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning( operationOrder.getWorkCenter().getMachine().getWeeklyPlanning(), new LocalDate(itDateTime)); numberOfMinutesPerDay = Minutes .minutesBetween(dayPlanning.getMorningFrom(), dayPlanning.getMorningTo()) .getMinutes(); numberOfMinutesPerDay += Minutes .minutesBetween(dayPlanning.getAfternoonFrom(), dayPlanning.getAfternoonTo()) .getMinutes(); } else { numberOfMinutesPerDay = 60 * 8; } BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)) .divide(new BigDecimal(numberOfMinutesPerDay), 2, RoundingMode.HALF_UP); if (map.containsKey(machine)) { map.put(machine, map.get(machine).add(percentage)); } else { map.put(machine, percentage); } } } Set<String> keyList = map.keySet(); for (String key : machineNameList) { if (keyList.contains(key)) { int found = 0; for (Map<String, Object> mapIt : dataList) { if (mapIt.get("dateTime").equals((Object) itDateTime.toString("dd/MM/yyyy")) && mapIt.get("machine").equals((Object) key)) { mapIt.put("charge", new BigDecimal(mapIt.get("charge").toString()).add(map.get(key))); found = 1; break; } } if (found == 0) { Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy")); dataMap.put("charge", (Object) map.get(key)); dataMap.put("machine", (Object) key); dataList.add(dataMap); } } } itDateTime = itDateTime.plusHours(1); } response.setData(dataList); }
From source file:com.axelor.controller.ConnectionToPrestashop.java
License:Open Source License
@Transactional @SuppressWarnings("finally") public String syncCustomer() { String message = ""; try {/* w w w . java 2s . c om*/ List<Integer> prestashopIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Partner> erpList = Partner.all().fetch(); for (Partner prestahopCustomer : erpList) { erpIdList.add(prestahopCustomer.getPrestashopid()); } System.out.println("API KEY :: " + apiKey); URL url = new URL("http://localhost/client-lib/crud/action.php?resource=customers&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); prestashopIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop :: " + prestashopIdList.size()); System.out.println("From ERP :: " + erpIdList.size()); scan.close(); // Check new entries in the prestshop Iterator<Integer> prestaListIterator = prestashopIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current prestaid for operation ::" + tempId); if (erpIdList.contains(tempId)) { Customer tempCustomer = getCustomer(tempId); String dateUpdate = tempCustomer.getDate_upd(); LocalDateTime dt1 = LocalDateTime.parse(dateUpdate, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); Partner pCust = Partner.all().filter("prestashopId=?", tempId).fetchOne(); LocalDateTime dt2 = pCust.getUpdatedOn(); if (dt2 != null) { int diff = Seconds.secondsBetween(dt2, dt1).getSeconds(); if (diff > 1) updateCustomer(tempCustomer, tempId); } else { updateCustomer(tempCustomer, tempId); } erpIdList.remove(tempId); } else { System.out.println("Current prestaid for insertion operation ::" + tempId); // insert new data in ERP Database insertCustomer(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { System.out.println("Currently in Erp ::" + tempId); Partner customerDelete = Partner.all().filter("prestashopid=?", tempId).fetchOne(); String firstName = customerDelete.getFirstName(); customerDelete.setArchived(Boolean.TRUE); System.out.println("customer deleted ::" + firstName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:com.axelor.controller.ConnectionToPrestashop.java
License:Open Source License
@SuppressWarnings("finally") @Transactional//from ww w .j a v a2 s. c o m public String syncAddress() { String message = ""; try { List<Integer> prestashopIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Address> erpList = Address.all().fetch(); for (Address prestahopAddress : erpList) { erpIdList.add(prestahopAddress.getPrestashopid()); } URL url = new URL("http://localhost/client-lib/crud/action.php?resource=addresses&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); prestashopIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop Addresses :: " + prestashopIdList.size()); System.out.println("From ERP Addresses :: " + erpIdList.size()); scan.close(); // Check new entries in the prestashop Iterator<Integer> prestaListIterator = prestashopIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current AddressPrestashopId for operation ::" + tempId); if (erpIdList.contains(tempId)) { com.axelor.pojo.Address tempAddress = getAddress(tempId); String dateUpdate = tempAddress.getDate_upd(); LocalDateTime dt1 = LocalDateTime.parse(dateUpdate, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); Address pAddress = Address.all().filter("prestashopid=?", tempId).fetchOne(); LocalDateTime dt2 = pAddress.getUpdatedOn(); if (dt2 != null) { int diff = Seconds.secondsBetween(dt2, dt1).getSeconds(); if (diff > 1) updateAddress(tempAddress, tempId); } else { updateAddress(tempAddress, tempId); } erpIdList.remove(tempId); } else { System.out.println("Current AddressPrestashopId for insertion operation ::" + tempId); // insert new data in ERP Database insertAddress(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { Address addressDelete = Address.all().filter("prestashopid=?", tempId).fetchOne(); String fullName = addressDelete.getFullName(); // addressDelete.remove(); addressDelete.setArchived(Boolean.TRUE); System.out.println("Address deleted ::" + fullName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:com.constellio.app.conf.RegisteredLicense.java
private LocalDateTime parse(String dateYYYYMMDD) { if (dateYYYYMMDD == null) { return null; } else {/*from w w w . j a v a 2 s . c o m*/ DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd"); return LocalDateTime.parse(dateYYYYMMDD.replace("-", "").replace("_", "").replace("/", ""), formatter); } }
From source file:com.constellio.model.packaging.custom.CustomPluginsPackagingService.java
public LocalDateTime extractLicenseDateAttribute(File licenseFile, String theLicenseContent, String method) { String value = extractLicenseAttribute(licenseFile, theLicenseContent, method); try {/*from w w w . j a v a 2 s. c om*/ DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd"); return LocalDateTime.parse(value.replace("-", ""), formatter); } catch (IllegalArgumentException e) { throw new CustomPluginsPackagingServiceException.InvalidDate(licenseFile, method, e); } }
From source file:com.creditcloud.interestbearing.ta.utils.CustomLocalDateTimeDeserializer.java
@Override public LocalDateTime deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException { String text = jp.getText();//ww w .j ava 2 s . c o m return LocalDateTime.parse(text, formatter); }
From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java
License:Apache License
public static SmsCampaign instance(final AppUser submittedBy, final Report report, final JsonCommand command) { final String campaignName = command.stringValueOfParameterNamed(SmsCampaignValidator.campaignName); final Long campaignType = command.longValueOfParameterNamed(SmsCampaignValidator.campaignType); final Long triggerType = command.longValueOfParameterNamed(SmsCampaignValidator.triggerType); final Long providerId = command.longValueOfParameterNamed(SmsCampaignValidator.providerId); final String paramValue = command.jsonFragment(SmsCampaignValidator.paramValue); final String message = command.stringValueOfParameterNamed(SmsCampaignValidator.message); LocalDate submittedOnDate = new LocalDate(); if (command.hasParameter(SmsCampaignValidator.submittedOnDateParamName)) { submittedOnDate = command.localDateValueOfParameterNamed(SmsCampaignValidator.submittedOnDateParamName); }/* ww w.ja v a 2 s .com*/ String recurrence = null; LocalDateTime recurrenceStartDate = new LocalDateTime(); if (SmsCampaignTriggerType.fromInt(triggerType.intValue()).isSchedule()) { final Locale locale = command.extractLocale(); String dateTimeFormat = null; if (command.hasParameter(SmsCampaignValidator.dateTimeFormat)) { dateTimeFormat = command.stringValueOfParameterNamed(SmsCampaignValidator.dateTimeFormat); final DateTimeFormatter fmt = DateTimeFormat.forPattern(dateTimeFormat).withLocale(locale); if (command.hasParameter(SmsCampaignValidator.recurrenceStartDate)) { recurrenceStartDate = LocalDateTime.parse( command.stringValueOfParameterNamed(SmsCampaignValidator.recurrenceStartDate), fmt); } recurrence = constructRecurrence(command); } } else { recurrenceStartDate = null; } return new SmsCampaign(campaignName, campaignType.intValue(), triggerType.intValue(), report, providerId, paramValue, message, submittedOnDate, submittedBy, recurrence, recurrenceStartDate); }
From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java
License:Apache License
public Map<String, Object> update(JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(5); if (command.isChangeInStringParameterNamed(SmsCampaignValidator.campaignName, this.campaignName)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.campaignName); actualChanges.put(SmsCampaignValidator.campaignName, newValue); this.campaignName = StringUtils.defaultIfEmpty(newValue, null); }/*from w ww . ja v a 2 s . c om*/ if (command.isChangeInStringParameterNamed(SmsCampaignValidator.message, this.message)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.message); actualChanges.put(SmsCampaignValidator.message, newValue); this.message = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(SmsCampaignValidator.paramValue, this.paramValue)) { final String newValue = command.jsonFragment(SmsCampaignValidator.paramValue); actualChanges.put(SmsCampaignValidator.paramValue, newValue); this.paramValue = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInIntegerParameterNamed(SmsCampaignValidator.campaignType, this.campaignType)) { final Integer newValue = command.integerValueOfParameterNamed(SmsCampaignValidator.campaignType); actualChanges.put(SmsCampaignValidator.campaignType, CampaignType.fromInt(newValue)); this.campaignType = CampaignType.fromInt(newValue).getValue(); } if (command.isChangeInIntegerParameterNamed(SmsCampaignValidator.triggerType, this.triggerType)) { final Integer newValue = command.integerValueOfParameterNamed(SmsCampaignValidator.triggerType); actualChanges.put(SmsCampaignValidator.triggerType, SmsCampaignTriggerType.fromInt(newValue)); this.triggerType = SmsCampaignTriggerType.fromInt(newValue).getValue(); } if (command.isChangeInLongParameterNamed(SmsCampaignValidator.runReportId, (this.businessRuleId != null) ? this.businessRuleId.getId() : null)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.runReportId); actualChanges.put(SmsCampaignValidator.runReportId, newValue); } if (command.isChangeInStringParameterNamed(SmsCampaignValidator.recurrenceParamName, this.recurrence)) { final String newValue = command.stringValueOfParameterNamed(SmsCampaignValidator.recurrenceParamName); actualChanges.put(SmsCampaignValidator.recurrenceParamName, newValue); this.recurrence = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInLongParameterNamed(SmsCampaignValidator.providerId, this.providerId)) { final Long newValue = command.longValueOfParameterNamed(SmsCampaignValidator.providerId); actualChanges.put(SmsCampaignValidator.providerId, newValue); } if (SmsCampaignTriggerType.fromInt(this.triggerType).isSchedule()) { final String dateFormatAsInput = command.dateFormat(); final String dateTimeFormatAsInput = command .stringValueOfParameterNamed(SmsCampaignValidator.dateTimeFormat); final String localeAsInput = command.locale(); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(dateTimeFormatAsInput).withLocale(locale); final String valueAsInput = command .stringValueOfParameterNamed(SmsCampaignValidator.recurrenceStartDate); actualChanges.put(SmsCampaignValidator.recurrenceStartDate, valueAsInput); actualChanges.put(SmsCampaignValidator.dateFormatParamName, dateFormatAsInput); actualChanges.put(SmsCampaignValidator.dateTimeFormat, dateTimeFormatAsInput); actualChanges.put(SmsCampaignValidator.localeParamName, localeAsInput); final LocalDateTime newValue = LocalDateTime.parse(valueAsInput, fmt); this.recurrenceStartDate = newValue.toDate(); } return actualChanges; }