Example usage for org.joda.time LocalDateTime isBefore

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

Introduction

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

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java

License:Open Source License

@Override
public List<Result<APIUsageByApplication>> getAPIUsageByApplications(String apiName, String apiVersion,
        String fromDate, String toDate, String providerName) throws APIMgtUsageQueryServiceClientException {
    String tenantDomain = null;//from   www .  j av a2s.  c o  m
    if (providerName != null) {
        tenantDomain = MultitenantUtils.getTenantDomain(providerName);
    }
    List<Result<APIUsageByApplication>> apiUsageByApplicationsResultList = new ArrayList<Result<APIUsageByApplication>>();
    try {
        // Build the query.
        StringBuilder apiUsageByAppQuery = new StringBuilder(
                "from " + APIUsageStatisticsClientConstants.API_VERSION_PER_APP_AGG + " on("
                        + APIUsageStatisticsClientConstants.API_CREATOR_TENANT_DOMAIN + "=='" + tenantDomain
                        + "' AND " + APIUsageStatisticsClientConstants.API_NAME + "=='" + apiName);

        if (!APIUsageStatisticsClientConstants.FOR_ALL_API_VERSIONS.equals(apiVersion)) {
            apiUsageByAppQuery
                    .append("' AND " + APIUsageStatisticsClientConstants.API_VERSION + "=='" + apiVersion);
        }
        if (fromDate != null && toDate != null) {
            String granularity = APIUsageStatisticsClientConstants.SECONDS_GRANULARITY;
            Map<String, Integer> durationBreakdown = this.getDurationBreakdown(fromDate, toDate);
            LocalDateTime currentDate = LocalDateTime.now(DateTimeZone.UTC);
            DateTimeFormatter formatter = DateTimeFormat
                    .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN);
            LocalDateTime fromLocalDateTime = LocalDateTime.parse(fromDate, formatter);//GMT time

            if (fromLocalDateTime.isBefore(currentDate.minusYears(1))) {
                granularity = APIUsageStatisticsClientConstants.MONTHS_GRANULARITY;
            } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_MONTHS) > 0
                    || durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_WEEKS) > 0) {
                granularity = APIUsageStatisticsClientConstants.DAYS_GRANULARITY;
            } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_DAYS) > 0) {
                granularity = APIUsageStatisticsClientConstants.HOURS_GRANULARITY;
            } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_HOURS) > 0) {
                granularity = APIUsageStatisticsClientConstants.MINUTES_GRANULARITY;
            }
            apiUsageByAppQuery.append("') within " + getTimestamp(fromDate) + "L, " + getTimestamp(toDate)
                    + "L per '" + granularity + "' select " + APIUsageStatisticsClientConstants.API_NAME + ", "
                    + APIUsageStatisticsClientConstants.API_VERSION + ", "
                    + APIUsageStatisticsClientConstants.APPLICATION_NAME + ", sum("
                    + APIUsageStatisticsClientConstants.TOTAL_REQUEST_COUNT
                    + ") as total_request_count group by " + APIUsageStatisticsClientConstants.API_NAME + ", "
                    + APIUsageStatisticsClientConstants.API_VERSION + ", "
                    + APIUsageStatisticsClientConstants.APPLICATION_NAME + ";");
        }
        // Invoke the rest api and get the results.
        JSONObject apiUsageByAppResult = APIUtil.executeQueryOnStreamProcessor(
                APIUsageStatisticsClientConstants.APIM_ACCESS_SUMMARY_SIDDHI_APP,
                apiUsageByAppQuery.toString());

        // Create the api usage object and return.
        long requestCount;
        String api;
        String version;
        String appName;
        if (apiUsageByAppResult != null) {
            JSONArray jArray = (JSONArray) apiUsageByAppResult
                    .get(APIUsageStatisticsClientConstants.RECORDS_DELIMITER);
            for (Object record : jArray) {
                JSONArray recordArray = (JSONArray) record;
                if (recordArray.size() == 4) {
                    Result<APIUsageByApplication> result = new Result<APIUsageByApplication>();
                    api = (String) recordArray.get(0);
                    version = (String) recordArray.get(1);
                    appName = (String) recordArray.get(2);
                    requestCount = (Long) recordArray.get(3);

                    APIUsageByApplication apiUsageByApplication = new APIUsageByApplication();
                    apiUsageByApplication.setApiName(api);
                    apiUsageByApplication.setApiVersion(version);
                    apiUsageByApplication.setApplicationName(appName);
                    apiUsageByApplication.setRequstCount(requestCount);

                    result.setValues(apiUsageByApplication);
                    result.setTableName(APIUsageStatisticsClientConstants.API_VERSION_PER_APP_AGG);
                    result.setTimestamp(RestClientUtil.longToDate(new Date().getTime()));
                    apiUsageByApplicationsResultList.add(result);
                }
            }
        }
        return apiUsageByApplicationsResultList;
    } catch (APIManagementException e) {
        handleException("Error occurred while querying from Stream Processor.", e);
    }
    return new ArrayList<Result<APIUsageByApplication>>();
}

From source file:todolist.ui.controllers.SettingsController.java

/**
 * isWithinWeek/*from w  w w.  jav a  2 s . c  o m*/
 * 
 * @param startOfWeek
 * @param endOfWeek
 * @param endTime
 * @return boolean
 */
private boolean isWithinWeek(LocalDateTime startOfWeek, LocalDateTime endOfWeek,
        java.time.LocalDateTime endTime) {

    int millis = 0;
    int seconds = endTime.getSecond();
    int minutes = endTime.getMinute();
    int hours = endTime.getHour();
    int day = endTime.getDayOfMonth();
    int month = endTime.getMonthValue();
    int year = endTime.getYear();

    LocalDateTime endTimeFormatted = new LocalDateTime();
    endTimeFormatted = endTimeFormatted.withDate(year, month, day);
    endTimeFormatted = endTimeFormatted.withTime(hours, minutes, seconds, millis);

    return endTimeFormatted.isAfter(startOfWeek) && endTimeFormatted.isBefore(endOfWeek);
}

From source file:view.popups.shift.ShiftManualPopup.java

public ArrayList<LocalDateTime> getTwelveMondays() {
    ArrayList<LocalDateTime> mondays = new ArrayList<>();
    LocalDateTime monday;

    //Denne her uges mandag
    LocalDateTime thisMonday = today.withDayOfWeek(DateTimeConstants.MONDAY);

    //Starter monday p denne her uges mandag
    monday = thisMonday;//from www . j a  v a  2s  . c  o  m

    //En lkke der tller alle mandage op 12 uger frem og stter dem i arrayListen
    for (int i = 0; i < 13; i++) {
        mondays.add(monday);

        if (monday.isBefore(twelveWeeks)) {
            monday = thisMonday.plusWeeks(i);

            System.out.println(monday);
        }
    }

    return mondays;
}

From source file:view.schema.ShiftTile.java

private Paint getColorOnShiftStart(LocalDateTime shiftTime) {
    //hours/*from  ww w . j a  va 2  s  .com*/
    LocalDateTime tempShiftEveningStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.EVENING_SHIFT_HOURS_START.getHours());
    LocalDateTime tempShiftNightStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.NIGHT_SHIFT_HOURS_START.getHours());
    LocalDateTime tempShiftDayStart = shiftTime.withField(DateTimeFieldType.hourOfDay(),
            ShiftPeriodConstants.DAY_SHIFT_HOURS_START.getHours());
    //Minutes.
    tempShiftEveningStart = tempShiftEveningStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.EVENING_SHIFT_MINUTES_START.getMinutes());
    tempShiftNightStart = tempShiftNightStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.NIGHT_SHIFT_MINUTES_START.getMinutes());
    tempShiftDayStart = tempShiftDayStart.withField(DateTimeFieldType.minuteOfHour(),
            ShiftPeriodConstants.DAY_SHIFT_MINUTES_START.getMinutes());

    if (shiftTime.isEqual(tempShiftDayStart)
            || (shiftTime.isBefore(tempShiftEveningStart) && shiftTime.isAfter(tempShiftDayStart))) {
        return BLUE;
    } else if (shiftTime.isEqual(tempShiftEveningStart)
            || (shiftTime.isBefore(tempShiftNightStart) && shiftTime.isAfter(tempShiftEveningStart))) {
        return GREEN;
    } else {
        return RED;
    }
}