Example usage for org.joda.time LocalDateTime isAfter

List of usage examples for org.joda.time LocalDateTime isAfter

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime isAfter.

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:com.axelor.apps.crm.service.EventService.java

License:Open Source License

@Transactional
public void addRecurrentEventsByMonths(Event event, int periodicity, int endType, int repetitionsNumber,
        LocalDate endDate, int monthRepeatType) {
    Event lastEvent = event;/*from   w w w  . j  a v a 2  s.  c  o m*/
    if (monthRepeatType == 1) {
        int dayOfMonth = event.getStartDateTime().getDayOfMonth();
        if (endType == 1) {
            int repeated = 0;
            while (repeated != repetitionsNumber) {
                Event copy = eventRepo.copy(lastEvent, false);
                copy.setParentEvent(lastEvent);
                if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth()
                        .getMaximumValue() >= dayOfMonth) {
                    copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity));
                    copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity));
                    eventRepo.save(copy);
                    repeated++;
                    lastEvent = copy;
                }
            }
        } else {
            while (!lastEvent.getStartDateTime().plusMonths(periodicity).isAfter(endDate)) {
                Event copy = eventRepo.copy(lastEvent, false);
                copy.setParentEvent(lastEvent);
                if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth()
                        .getMaximumValue() >= dayOfMonth) {
                    copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity));
                    copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity));
                    eventRepo.save(copy);
                    lastEvent = copy;
                }
            }
        }
    }

    else {
        int dayOfWeek = event.getStartDateTime().getDayOfWeek();
        int positionInMonth = 0;
        if (event.getStartDateTime().getDayOfMonth() % 7 == 0) {
            positionInMonth = event.getStartDateTime().getDayOfMonth() / 7;
        } else {
            positionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1;
        }

        if (endType == 1) {
            int repeated = 0;
            while (repeated != repetitionsNumber) {
                Event copy = eventRepo.copy(lastEvent, false);
                copy.setParentEvent(lastEvent);
                LocalDateTime nextDateTime = new LocalDateTime(copy.getStartDateTime());
                nextDateTime.plusMonths(periodicity);
                int nextDayOfWeek = nextDateTime.getDayOfWeek();
                if (nextDayOfWeek > dayOfWeek) {
                    nextDateTime.minusDays(nextDayOfWeek - dayOfWeek);
                } else {
                    nextDateTime.plusDays(dayOfWeek - nextDayOfWeek);
                }
                int nextPositionInMonth = 0;
                if (event.getStartDateTime().getDayOfMonth() % 7 == 0) {
                    nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7;
                } else {
                    nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1;
                }
                if (nextPositionInMonth > positionInMonth) {
                    nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth);
                } else {
                    nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth);
                }
                Duration dur = new Duration(copy.getStartDateTime().toDateTime(),
                        copy.getEndDateTime().toDateTime());
                copy.setStartDateTime(nextDateTime);
                copy.setEndDateTime(nextDateTime.plus(dur));
                eventRepo.save(copy);
                repeated++;
                lastEvent = copy;
            }
        } else {
            LocalDateTime nextDateTime = new LocalDateTime(lastEvent.getStartDateTime());
            nextDateTime.plusMonths(periodicity);
            int nextDayOfWeek = nextDateTime.getDayOfWeek();
            if (nextDayOfWeek > dayOfWeek) {
                nextDateTime.minusDays(nextDayOfWeek - dayOfWeek);
            } else {
                nextDateTime.plusDays(dayOfWeek - nextDayOfWeek);
            }
            int nextPositionInMonth = 0;
            if (event.getStartDateTime().getDayOfMonth() % 7 == 0) {
                nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7;
            } else {
                nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1;
            }
            if (nextPositionInMonth > positionInMonth) {
                nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth);
            } else {
                nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth);
            }
            while (!nextDateTime.isAfter(endDate)) {
                Event copy = eventRepo.copy(lastEvent, false);
                copy.setParentEvent(lastEvent);

                Duration dur = new Duration(copy.getStartDateTime().toDateTime(),
                        copy.getEndDateTime().toDateTime());
                copy.setStartDateTime(nextDateTime);
                copy.setEndDateTime(nextDateTime.plus(dur));
                eventRepo.save(copy);
                lastEvent = copy;

                nextDateTime = new LocalDateTime(lastEvent.getStartDateTime());
                nextDateTime.plusMonths(periodicity);
                nextDayOfWeek = nextDateTime.getDayOfWeek();
                if (nextDayOfWeek > dayOfWeek) {
                    nextDateTime.minusDays(nextDayOfWeek - dayOfWeek);
                } else {
                    nextDateTime.plusDays(dayOfWeek - nextDayOfWeek);
                }
                nextPositionInMonth = 0;
                if (event.getStartDateTime().getDayOfMonth() % 7 == 0) {
                    nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7;
                } else {
                    nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1;
                }
                if (nextPositionInMonth > positionInMonth) {
                    nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth);
                } else {
                    nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth);
                }
            }
        }
    }
}

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);//from ww  w .  ja v  a  2 s.c om
    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   w w w. ja  v a  2 s.  c  om
    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.effektif.workflow.api.model.NextRelativeTime.java

License:Apache License

@Override
public LocalDateTime resolve(LocalDateTime base) {
    LocalDateTime time = null;
    if (HOUR_OF_DAY.equals(indexUnit)) {
        time = base.withTime(index, 0, 0, 0);
        if (!time.isAfter(base)) {
            return time.plusDays(1);
        }//  w w  w.  jav  a 2  s . c om
    } else if (DAY_OF_WEEK.equals(indexUnit)) {
        time = base.withDayOfWeek(index).withTime(0, 0, 0, 0);
        if (!time.isAfter(base)) {
            time = time.plusWeeks(1);
        }
    } else if (DAY_OF_MONTH.equals(indexUnit)) {
        time = base.withDayOfMonth(index).withTime(0, 0, 0, 0);
        if (!time.isAfter(base)) {
            time = time.plusMonths(1);
        }
    }
    if (atHour != null) {
        time = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0);
    }
    return time;
}

From source file:com.effektif.workflow.impl.memory.MemoryWorkflowStore.java

License:Apache License

@Override
public WorkflowId findLatestWorkflowIdBySource(String workflowName) {
    if (workflowName == null) {
        return null;
    }//  ww  w.  ja  v a 2s. c  om
    ExecutableWorkflow latestWorkflow = null;
    LocalDateTime latestDeployTime = null;
    for (ExecutableWorkflow workflow : workflows.values()) {
        if (workflowName.equals(workflow.getSourceWorkflowId())
                && (latestDeployTime == null || latestDeployTime.isAfter(workflow.getCreateTime()))) {
            latestWorkflow = workflow;
            latestDeployTime = workflow.getCreateTime();
        }
    }
    return latestWorkflow != null ? latestWorkflow.getId() : null;
}

From source file:com.helger.datetime.period.LocalDateTimePeriod.java

License:Apache License

public final boolean isValidFor(@Nonnull final LocalDateTime aDate) {
    if (aDate == null)
        throw new NullPointerException("date");

    final LocalDateTime aStart = getStart();
    if (aStart != null && aStart.isAfter(aDate))
        return false;
    final LocalDateTime aEnd = getEnd();
    if (aEnd != null && aEnd.isBefore(aDate))
        return false;
    return true;/*w w  w .  j av  a  2s.  co m*/
}

From source file:com.helger.peppol.smpserver.ui.AppCommonUI.java

License:Apache License

@Nonnull
public static BootstrapTable createCertificateDetailsTable(@Nonnull final X509Certificate aX509Cert,
        @Nonnull final LocalDateTime aNowLDT, @Nonnull final Locale aDisplayLocale) {
    final LocalDateTime aNotBefore = PDTFactory.createLocalDateTime(aX509Cert.getNotBefore());
    final LocalDateTime aNotAfter = PDTFactory.createLocalDateTime(aX509Cert.getNotAfter());
    final PublicKey aPublicKey = aX509Cert.getPublicKey();

    final BootstrapTable aCertDetails = new BootstrapTable(HCCol.star(), HCCol.star());
    aCertDetails.addBodyRow().addCell("Version:").addCell(Integer.toString(aX509Cert.getVersion()));
    aCertDetails.addBodyRow().addCell("Subject:").addCell(aX509Cert.getSubjectX500Principal().getName());
    aCertDetails.addBodyRow().addCell("Issuer:").addCell(aX509Cert.getIssuerX500Principal().getName());
    aCertDetails.addBodyRow().addCell("Serial number:").addCell(aX509Cert.getSerialNumber().toString(16));
    aCertDetails.addBodyRow().addCell("Valid from:").addCell(
            new HCTextNode(PDTToString.getAsString(aNotBefore, aDisplayLocale) + " "),
            aNowLDT.isBefore(aNotBefore)
                    ? new BootstrapLabel(EBootstrapLabelType.DANGER).addChild("!!!NOT YET VALID!!!")
                    : null);//from w  ww  . ja  v  a 2s  . com
    aCertDetails.addBodyRow().addCell("Valid to:").addCell(
            new HCTextNode(PDTToString.getAsString(aNotAfter, aDisplayLocale) + " "),
            aNowLDT.isAfter(aNotAfter)
                    ? new BootstrapLabel(EBootstrapLabelType.DANGER).addChild("!!!NO LONGER VALID!!!")
                    : new HCDiv().addChild("Valid for: " + PeriodFormatMultilingual
                            .getFormatterLong(aDisplayLocale).print(new Period(aNowLDT, aNotAfter))));

    if (aPublicKey instanceof RSAPublicKey) {
        // Special handling for RSA
        aCertDetails.addBodyRow().addCell("Public key:").addCell(aX509Cert.getPublicKey().getAlgorithm() + " ("
                + ((RSAPublicKey) aPublicKey).getModulus().bitLength() + " bits)");
    } else {
        // Usually EC or DSA key
        aCertDetails.addBodyRow().addCell("Public key:").addCell(aX509Cert.getPublicKey().getAlgorithm());
    }
    aCertDetails.addBodyRow().addCell("Signature algorithm:")
            .addCell(aX509Cert.getSigAlgName() + " (" + aX509Cert.getSigAlgOID() + ")");
    return aCertDetails;
}

From source file:com.helger.peppol.smpserver.ui.secure.PageSecureTasks.java

License:Apache License

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    final LocalDateTime aNowDT = PDTFactory.getCurrentLocalDateTime();
    final LocalDateTime aNowPlusDT = aNowDT.plusMonths(3);

    aNodeList.addChild(new BootstrapInfoBox().addChild(
            "This page tries to identify upcoming tasks and potential problems in the SMP configuration. It is meant to highlight immediate and upcoming action items as well as potential misconfiguration."));

    final HCOL aOL = new HCOL();

    // check certificate configuration
    {/*from   w  w w .ja v  a  2 s  . c o m*/
        final KeyLoadingResult aKeyLoadingResult = KeyLoadingResult.loadConfiguredKey();
        if (aKeyLoadingResult.isFailure())
            aOL.addItem(_createError("Problem with the certificate configuration"),
                    new HCDiv().addChild(aKeyLoadingResult.getErrorMessage()));
    }

    // Check SML configuration
    {
        if (!RegistrationHookFactory.isSMLConnectionActive())
            aOL.addItem(_createWarning("The connection to the SML is not active."), new HCDiv().addChild(
                    "All creations and deletions of service groups needs to be repeated when the SML connection is active!"));
    }

    // check service groups and redirects
    {
        final Collection<? extends ISMPServiceGroup> aServiceGroups = aServiceGroupMgr.getAllSMPServiceGroups();
        final Collection<? extends ISMPRedirect> aRedirects = aRedirectMgr.getAllSMPRedirects();
        if (aServiceGroups.isEmpty() && aRedirects.isEmpty()) {
            aOL.addItem(_createWarning(
                    "Neither a service group nor a redirect is configured. This SMP is currently empty."));
        } else {
            // For all service groups
            for (final ISMPServiceGroup aServiceGroup : CollectionHelper.getSorted(aServiceGroups,
                    new ComparatorSMPServiceGroup())) {
                final HCUL aULPerSG = new HCUL();
                final Collection<? extends ISMPServiceInformation> aServiceInfos = aServiceInfoMgr
                        .getAllSMPServiceInformationsOfServiceGroup(aServiceGroup);
                if (aServiceInfos.isEmpty()) {
                    aULPerSG.addItem(_createWarning("No endpoint is configured for this service group."));
                } else {
                    for (final ISMPServiceInformation aServiceInfo : aServiceInfos) {
                        final HCUL aULPerDocType = new HCUL();
                        final Collection<? extends ISMPProcess> aProcesses = aServiceInfo.getAllProcesses();
                        for (final ISMPProcess aProcess : aProcesses) {
                            final HCUL aULPerProcess = new HCUL();
                            final Collection<? extends ISMPEndpoint> aEndpoints = aProcess.getAllEndpoints();
                            for (final ISMPEndpoint aEndpoint : aEndpoints) {
                                final HCUL aULPerEndpoint = new HCUL();

                                final ESMPTransportProfile eTransportProfile = ESMPTransportProfile
                                        .getFromIDOrNull(aEndpoint.getTransportProfile());
                                if (eTransportProfile == null)
                                    aULPerEndpoint.addItem(_createWarning(
                                            "The endpoint uses the non-standard transport profile '"
                                                    + aEndpoint.getTransportProfile() + "'."));

                                if (aEndpoint.getServiceActivationDateTime() != null) {
                                    if (aEndpoint.getServiceActivationDateTime().isAfter(aNowDT))
                                        aULPerEndpoint.addItem(_createWarning(
                                                "The endpoint is not yet active. It will be active from "
                                                        + PDTToString.getAsString(
                                                                aEndpoint.getServiceActivationDateTime(),
                                                                aDisplayLocale)
                                                        + "."));
                                }

                                if (aEndpoint.getServiceExpirationDateTime() != null) {
                                    if (aEndpoint.getServiceExpirationDateTime().isBefore(aNowDT))
                                        aULPerEndpoint.addItem(_createError(
                                                "The endpoint is not longer active. It was valid until "
                                                        + PDTToString.getAsString(
                                                                aEndpoint.getServiceExpirationDateTime(),
                                                                aDisplayLocale)
                                                        + "."));
                                    else if (aEndpoint.getServiceExpirationDateTime().isBefore(aNowPlusDT))
                                        aULPerEndpoint.addItem(_createWarning(
                                                "The endpoint will be inactive soon. It is only valid until "
                                                        + PDTToString.getAsString(
                                                                aEndpoint.getServiceExpirationDateTime(),
                                                                aDisplayLocale)
                                                        + "."));
                                }

                                X509Certificate aX509Cert = null;
                                try {
                                    aX509Cert = CertificateHelper
                                            .convertStringToCertficate(aEndpoint.getCertificate());
                                } catch (final CertificateException ex) {
                                    // Ignore
                                }
                                if (aX509Cert == null)
                                    aULPerEndpoint.addItem(_createError(
                                            "The X.509 certificate configured at the endpoint is invalid and could not be interpreted as a certificate."));
                                else {
                                    final LocalDateTime aNotBefore = PDTFactory
                                            .createLocalDateTime(aX509Cert.getNotBefore());
                                    if (aNotBefore.isAfter(aNowDT))
                                        aULPerEndpoint.addItem(_createError(
                                                "The endpoint certificate is not yet active. It will be active from "
                                                        + PDTToString.getAsString(aNotBefore, aDisplayLocale)
                                                        + "."));

                                    final LocalDateTime aNotAfter = PDTFactory
                                            .createLocalDateTime(aX509Cert.getNotAfter());
                                    if (aNotAfter.isBefore(aNowDT))
                                        aULPerEndpoint.addItem(_createError(
                                                "The endpoint certificate is already expired. It was valid until "
                                                        + PDTToString.getAsString(aNotAfter, aDisplayLocale)
                                                        + "."));
                                    else if (aNotAfter.isBefore(aNowPlusDT))
                                        aULPerEndpoint.addItem(_createWarning(
                                                "The endpoint certificate will expire soon. It is only valid until "
                                                        + PDTToString.getAsString(aNotAfter, aDisplayLocale)
                                                        + "."));
                                }

                                // Show per endpoint errors
                                if (aULPerEndpoint.hasChildren())
                                    aULPerProcess
                                            .addItem(
                                                    new HCDiv().addChild("Transport profile ")
                                                            .addChild(new HCCode()
                                                                    .addChild(aEndpoint.getTransportProfile())),
                                                    aULPerEndpoint);
                            }
                            // Show per process errors
                            if (aULPerProcess.hasChildren())
                                aULPerDocType.addItem(new HCDiv().addChild("Process ")
                                        .addChild(new HCCode().addClass(CUICoreCSS.CSS_CLASS_NOWRAP)
                                                .addChild(aProcess.getProcessIdentifier().getURIEncoded())),
                                        aULPerProcess);
                        }
                        // Show per document type errors
                        if (aULPerDocType.hasChildren())
                            aULPerSG.addItem(new HCDiv().addChild("Document type ")
                                    .addChild(new HCCode().addClass(CUICoreCSS.CSS_CLASS_NOWRAP).addChild(
                                            aServiceInfo.getDocumentTypeIdentifier().getURIEncoded())),
                                    aULPerDocType);
                    }
                }

                // Show per service group errors
                if (aULPerSG.hasChildren())
                    aOL.addItem(
                            new HCDiv().addChild("Service group ")
                                    .addChild(new HCCode()
                                            .addChild(aServiceGroup.getParticpantIdentifier().getURIEncoded())),
                            aULPerSG);
            }
        }
    }

    // Show results
    if (aOL.hasChildren()) {
        aNodeList.addChild(
                new BootstrapWarnBox().addChild("The following list of tasks and problems were identified:"));
        aNodeList.addChild(aOL);
    } else
        aNodeList.addChild(new BootstrapSuccessBox().addChild("Great job, no tasks or problems identified!"));
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    final String METHOD = "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + "): ";
    if (resultCode == Activity.RESULT_OK) {
        // Figure out which Result code we are dealing with. This method
        /// handles the results of all dialog fragments used to set the
        /// model data.
        switch (requestCode) {
        case REQUEST_BEGIN_DATE_PICKER:
            Date beginDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
            LocalDateTime ldtBeginDate = new LocalDateTime(beginDate.getTime());
            if (ldtBeginDate.isBefore(new LocalDateTime(mHours.getEnd().getTime()))) {
                mHours.setBegin(beginDate);
                updateUI();/* w w  w.j a  v  a2 s  .  com*/
            } else {
                String message = "End date must be after begin date";
                Log.e(TAG, METHOD + message);
                Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
            }
            break;
        case REQUEST_END_DATE_PICKER:
            Date endDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
            LocalDateTime ldtEndDate = new LocalDateTime(endDate.getTime());
            if (ldtEndDate.isAfter(new LocalDateTime(mHours.getBegin().getTime()))) {
                mHours.setEnd(endDate);
                updateUI();
            } else {
                String message = "End date must be after begin date";
                Log.e(TAG, METHOD + message);
                Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
            }
            break;
        case REQUEST_BREAK:
            Integer breakTimeInMinutes = (Integer) data
                    .getSerializableExtra(NumberPickerFragment.RESULT_MINUTES);
            mHours.setBreak(renderBreakForStorage(breakTimeInMinutes));
            updateUI();
            break;
        case REQUEST_CODE_MANAGE_PROJECTS:
            Project project = (Project) data.getSerializableExtra(ProjectListActivity.RESULT_PROJECT);
            mHours.setProject(project);
            updateUI();
            break;
        default:
            break;
        }
    }
}

From source file:control.Xray.java

/**
 * Tjekker om en given dato er i en given tidsperiode.
 *
 * @param dateTime metoden returnerer sand, hvis denne parameter ligger i
 * den givne periode.//  w w w.  j ava2  s  . c o m
 * @param periodStart definerer periodens start.
 * @param periodEnd definerer periodens slutning.
 * @return
 */
public boolean isDateInPeriod(LocalDateTime dateTime, LocalDateTime periodStart, LocalDateTime periodEnd) {
    boolean inPeriod = false;

    if (dateTime.isEqual(periodStart) || (dateTime.isBefore(periodEnd) && dateTime.isAfter(periodStart))) {
        inPeriod = true;
    }

    return inPeriod;
}