Example usage for org.joda.time LocalDateTime parse

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

Introduction

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

Prototype

public static LocalDateTime parse(String str, DateTimeFormatter formatter) 

Source Link

Document

Parses a LocalDateTime from the specified string using a formatter.

Usage

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

License:Open Source License

@Override
public List<Result<ExecutionTimeOfAPIValues>> getExecutionTimeByAPI(String apiName, String version,
        String tenantDomain, String fromDate, String toDate, String drillDown, String mediationType)
        throws APIMgtUsageQueryServiceClientException {
    List<Result<ExecutionTimeOfAPIValues>> result = new ArrayList<Result<ExecutionTimeOfAPIValues>>();
    try {//  www  . j  a va2s  . c o m
        StringBuilder query = new StringBuilder(
                "from " + APIUsageStatisticsClientConstants.API_EXECUTION_TIME_AGG + " on("
                        + APIUsageStatisticsClientConstants.API_NAME + "=='" + apiName + "'");
        if (version != null) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_VERSION + "=='" + version + "'");
        }
        if (tenantDomain != null) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_CREATOR_TENANT_DOMAIN + "=='"
                    + tenantDomain + "'");
        }
        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;
            }
            query.append(") within " + getTimestamp(fromDate) + "L, " + getTimestamp(toDate) + "L per '"
                    + granularity + "'");
        } else {
            query.append(") within " + 0 + "L, " + new Date().getTime() + "L per 'months'");
        }
        query.append(" select " + APIUsageStatisticsClientConstants.API_NAME + ", "
                + APIUsageStatisticsClientConstants.API_CONTEXT + ", "
                + APIUsageStatisticsClientConstants.API_CREATOR + ", "
                + APIUsageStatisticsClientConstants.API_VERSION + ", "
                + APIUsageStatisticsClientConstants.TIME_STAMP + ", "
                + APIUsageStatisticsClientConstants.RESPONSE_TIME + ", "
                + APIUsageStatisticsClientConstants.SECURITY_LATENCY + ", "
                + APIUsageStatisticsClientConstants.THROTTLING_LATENCY + ", "
                + APIUsageStatisticsClientConstants.REQUEST_MEDIATION_LATENCY + ", "
                + APIUsageStatisticsClientConstants.RESPONSE_MEDIATION_LATENCY + ", "
                + APIUsageStatisticsClientConstants.BACKEND_LATENCY + ", "
                + APIUsageStatisticsClientConstants.OTHER_LATENCY + ";");
        JSONObject jsonObj = APIUtil.executeQueryOnStreamProcessor(
                APIUsageStatisticsClientConstants.APIM_ACCESS_SUMMARY_SIDDHI_APP, query.toString());
        long timeStamp;
        if (jsonObj != null) {
            JSONArray jArray = (JSONArray) jsonObj.get(APIUsageStatisticsClientConstants.RECORDS_DELIMITER);
            for (Object record : jArray) {
                JSONArray recordArray = (JSONArray) record;
                if (recordArray.size() == 12) {
                    Result<ExecutionTimeOfAPIValues> result1 = new Result<ExecutionTimeOfAPIValues>();
                    ExecutionTimeOfAPIValues executionTimeOfAPIValues = new ExecutionTimeOfAPIValues();
                    executionTimeOfAPIValues.setApi((String) recordArray.get(0));
                    executionTimeOfAPIValues.setContext((String) recordArray.get(1));
                    executionTimeOfAPIValues.setApiPublisher((String) recordArray.get(2));
                    executionTimeOfAPIValues.setVersion((String) recordArray.get(3));
                    timeStamp = (Long) recordArray.get(4);
                    DateTime time = new DateTime(timeStamp).withZone(DateTimeZone.UTC);
                    executionTimeOfAPIValues.setYear(time.getYear());
                    executionTimeOfAPIValues.setMonth(time.getMonthOfYear());
                    executionTimeOfAPIValues.setDay(time.getDayOfMonth());
                    executionTimeOfAPIValues.setHour(time.getHourOfDay());
                    executionTimeOfAPIValues.setMinutes(time.getMinuteOfHour());
                    executionTimeOfAPIValues.setSeconds(time.getSecondOfMinute());
                    executionTimeOfAPIValues.setApiResponseTime((Long) recordArray.get(5));
                    executionTimeOfAPIValues.setSecurityLatency((Long) recordArray.get(6));
                    executionTimeOfAPIValues.setThrottlingLatency((Long) recordArray.get(7));
                    executionTimeOfAPIValues.setRequestMediationLatency((Long) recordArray.get(8));
                    executionTimeOfAPIValues.setResponseMediationLatency((Long) recordArray.get(9));
                    executionTimeOfAPIValues.setBackendLatency((Long) recordArray.get(10));
                    executionTimeOfAPIValues.setOtherLatency((Long) recordArray.get(11));
                    result1.setValues(executionTimeOfAPIValues);
                    result1.setTableName(APIUsageStatisticsClientConstants.API_EXECUTION_TIME_AGG);
                    result1.setTimestamp(RestClientUtil.longToDate(new Date().getTime()));
                    result.add(result1);
                }
            }
        }
        if (!result.isEmpty() && fromDate != null && toDate != null) {
            insertZeroElementsAndSort(result, drillDown, getDateToLong(fromDate), getDateToLong(toDate));
        }
    } catch (APIManagementException e) {
        handleException("Error occurred while querying from Stream Processor ", e);
    } catch (ParseException e) {
        handleException("Couldn't parse the date", e);
    }
    return result;
}

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

License:Open Source License

@Override
public List<Result<PerGeoLocationUsageCount>> getGeoLocationsByApi(String apiName, String version,
        String tenantDomain, String fromDate, String toDate, String drillDown)
        throws APIMgtUsageQueryServiceClientException {
    List<Result<PerGeoLocationUsageCount>> result = new ArrayList<Result<PerGeoLocationUsageCount>>();
    try {/*from w ww .  j  av  a 2 s. c om*/
        StringBuilder query = new StringBuilder("from " + APIUsageStatisticsClientConstants.GEO_LOCATION_AGG
                + " on(" + APIUsageStatisticsClientConstants.API_NAME + "=='" + apiName + "'");
        if (version != null && !"ALL".equals(version)) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_VERSION + "=='" + version + "'");
        }
        if (tenantDomain != null) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_CREATOR_TENANT_DOMAIN + "=='"
                    + tenantDomain + "'");
        }
        if (!"ALL".equals(drillDown)) {
            query.append(" AND " + APIUsageStatisticsClientConstants.COUNTRY + "=='" + drillDown + "'");
        }
        if (fromDate != null && toDate != null) {
            String granularity = APIUsageStatisticsClientConstants.HOURS_GRANULARITY;//default 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_DAYS) > 0)) {
                granularity = APIUsageStatisticsClientConstants.DAYS_GRANULARITY;
            }
            query.append(") within " + getTimestamp(fromDate) + "L, " + getTimestamp(toDate) + "L per '"
                    + granularity + "' select sum(" + APIUsageStatisticsClientConstants.TOTAL_COUNT);
        } else {
            query.append(") within " + 0 + "L, " + new Date().getTime() + "L per 'months' select sum("
                    + APIUsageStatisticsClientConstants.TOTAL_COUNT);
        }
        query.append(") as count, " + APIUsageStatisticsClientConstants.COUNTRY);
        if (!"ALL".equals(drillDown)) {
            query.append(", " + APIUsageStatisticsClientConstants.CITY);
        }
        query.append(" group by " + APIUsageStatisticsClientConstants.COUNTRY);
        if (!"ALL".equals(drillDown)) {
            query.append(", " + APIUsageStatisticsClientConstants.CITY);
        }
        query.append(";");
        JSONObject jsonObj = APIUtil.executeQueryOnStreamProcessor(
                APIUsageStatisticsClientConstants.APIM_ACCESS_SUMMARY_SIDDHI_APP, query.toString());
        long count;
        String country;
        String city;
        if (jsonObj != null) {
            JSONArray jArray = (JSONArray) jsonObj.get(APIUsageStatisticsClientConstants.RECORDS_DELIMITER);
            for (Object record : jArray) {
                JSONArray recordArray = (JSONArray) record;
                if (recordArray.size() >= 2) {
                    Result<PerGeoLocationUsageCount> result1 = new Result<PerGeoLocationUsageCount>();
                    count = (Long) recordArray.get(0);
                    country = (String) recordArray.get(1);
                    List<String> facetValues = new ArrayList<String>();
                    facetValues.add(country);
                    if (!"ALL".equals(drillDown)) {
                        city = (String) recordArray.get(2);
                        facetValues.add(city);
                    }
                    PerGeoLocationUsageCount perGeoLocationUsageCount = new PerGeoLocationUsageCount(
                            (int) count, facetValues);
                    result1.setValues(perGeoLocationUsageCount);
                    result1.setTableName(APIUsageStatisticsClientConstants.GEO_LOCATION_AGG);
                    result1.setTimestamp(RestClientUtil.longToDate(new Date().getTime()));
                    result.add(result1);
                }
            }
        }
    } catch (APIManagementException e) {
        handleException("Error occurred while querying from Stream Processor ", e);
    }
    return result;

}

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

License:Open Source License

@Override
public List<Result<UserAgentUsageCount>> getUserAgentUsageByAPI(String apiName, String version,
        String tenantDomain, String fromDate, String toDate, String drillDown)
        throws APIMgtUsageQueryServiceClientException {
    List<Result<UserAgentUsageCount>> result = new ArrayList<Result<UserAgentUsageCount>>();
    try {/*from   w w  w  .  j  a  v a 2s. c  om*/
        StringBuilder query = new StringBuilder("from " + APIUsageStatisticsClientConstants.API_USER_BROWSER_AGG
                + " on(" + APIUsageStatisticsClientConstants.API_NAME + "=='" + apiName + "'");
        if (version != null && !"ALL".equals(version)) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_VERSION + "=='" + version + "'");
        }
        if (tenantDomain != null) {
            query.append(" AND " + APIUsageStatisticsClientConstants.API_CREATOR_TENANT_DOMAIN + "=='"
                    + tenantDomain + "'");
        }
        if (!"ALL".equals(drillDown)) {
            query.append(
                    " AND " + APIUsageStatisticsClientConstants.OPERATING_SYSTEM + "=='" + drillDown + "'");
        }
        if (fromDate != null && toDate != null) {
            String granularity = APIUsageStatisticsClientConstants.HOURS_GRANULARITY;//default 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_DAYS) > 0)) {
                granularity = APIUsageStatisticsClientConstants.DAYS_GRANULARITY;
            }
            query.append(") within " + getTimestamp(fromDate) + "L, " + getTimestamp(toDate) + "L per '"
                    + granularity + "' select sum(" + APIUsageStatisticsClientConstants.TOTAL_REQUEST_COUNT);
        } else {
            query.append(") within " + 0 + "L, " + new Date().getTime() + "L per 'months' select sum("
                    + APIUsageStatisticsClientConstants.TOTAL_REQUEST_COUNT);
        }
        query.append(") as count, " + APIUsageStatisticsClientConstants.OPERATING_SYSTEM + ", "
                + APIUsageStatisticsClientConstants.BROWSER + " group by "
                + APIUsageStatisticsClientConstants.OPERATING_SYSTEM + ", "
                + APIUsageStatisticsClientConstants.BROWSER + ";");

        JSONObject jsonObj = APIUtil.executeQueryOnStreamProcessor(
                APIUsageStatisticsClientConstants.APIM_ACCESS_SUMMARY_SIDDHI_APP, query.toString());
        long count;
        String operatingSystem;
        String browser;
        if (jsonObj != null) {
            JSONArray jArray = (JSONArray) jsonObj.get(APIUsageStatisticsClientConstants.RECORDS_DELIMITER);
            for (Object record : jArray) {
                JSONArray recordArray = (JSONArray) record;
                if (recordArray.size() == 3) {
                    Result<UserAgentUsageCount> result1 = new Result<UserAgentUsageCount>();
                    count = (Long) recordArray.get(0);
                    operatingSystem = (String) recordArray.get(1);
                    browser = (String) recordArray.get(2);
                    List<String> facetValues = new ArrayList<String>();
                    facetValues.add(operatingSystem);
                    facetValues.add(browser);
                    UserAgentUsageCount perUserAgentUsageCount = new UserAgentUsageCount((int) count,
                            facetValues);
                    result1.setValues(perUserAgentUsageCount);
                    result1.setTableName(APIUsageStatisticsClientConstants.API_USER_BROWSER_AGG);
                    result1.setTimestamp(RestClientUtil.longToDate(new Date().getTime()));
                    result.add(result1);
                }
            }
        }
    } catch (APIManagementException e) {
        handleException("Error occurred while querying from Stream Processor ", e);
    }
    return result;
}

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  w  ww.  java  2 s . 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:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java

License:Open Source License

/**
 * This method is used to get the breakdown of the duration between 2 days/timestamps in terms of years,
 * months, days, hours, minutes and seconds
 *
 * @param fromDate Start timestamp of the duration
 * @param toDate   End timestamp of the duration
 * @return A map containing the breakdown
 * @throws APIMgtUsageQueryServiceClientException when there is an error during date parsing
 *///  w  w w .  ja v  a2 s .c  om
private Map<String, Integer> getDurationBreakdown(String fromDate, String toDate)
        throws APIMgtUsageQueryServiceClientException {
    Map<String, Integer> durationBreakdown = new HashMap<String, Integer>();

    DateTimeFormatter formatter = DateTimeFormat
            .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN);
    LocalDateTime startDate = LocalDateTime.parse(fromDate, formatter);
    LocalDateTime endDate = LocalDateTime.parse(toDate, formatter);
    Period period = new Period(startDate, endDate);
    int numOfYears = period.getYears();
    int numOfMonths = period.getMonths();
    int numOfWeeks = period.getWeeks();
    int numOfDays = period.getDays();
    if (numOfWeeks > 0) {
        numOfDays += numOfWeeks * 7;
    }
    int numOfHours = period.getHours();
    int numOfMinutes = period.getMinutes();
    int numOfSeconds = period.getSeconds();
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_YEARS, numOfYears);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MONTHS, numOfMonths);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_DAYS, numOfDays);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_WEEKS, numOfWeeks);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_HOURS, numOfHours);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MINUTES, numOfMinutes);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_SECONDS, numOfSeconds);
    return durationBreakdown;
}

From source file:pl.porannajava.javnysejm.support.StringConverter.java

License:Apache License

public static LocalDateTime getDateTime(String input) {

    return LocalDateTime.parse(normalizeString(input), DATETIME_FORMATTER);
}

From source file:py.com.palermo.servicioarthy.impl.gestioncomercial.PortalGeneralService.java

public void setRespuestaEncuesta(RespuestaEncuesta r) {
    if (r.getFechaCadena() != null) {
        LocalDateTime localDateTime = LocalDateTime.parse(r.getFechaCadena(),
                DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
        r.setFecha(localDateTime.toDate());
    }/*from  w ww. j a v a 2s.  c  o  m*/
    guarda(r);
}

From source file:py.com.palermo.servicioarthy.impl.gestioncomercial.PortalGeneralService.java

public String setFactura(Factura f) {

    if (f.getFechaCadena() != null) {
        LocalDateTime localDateTime = LocalDateTime.parse(f.getFechaCadena(),
                DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
        f.setFecha(localDateTime.toDate());
    }/*from   ww w.j  a  v  a  2 s. c om*/

    Factura vivo = em.find(Factura.class, f.getId());
    if (vivo != null && vivo.getEstadoDescarga().compareToIgnoreCase("T") == 0) {
        return f.getId();
    }

    for (FacturaCobro c : f.getCobros()) {
        if (c.getDocumentoId() != null && c.getDocumentoId().compareToIgnoreCase("0") == 0) {
            c.setDocumentoId(null);
        }
    }
    f.setEstadoDescarga("N");
    em.merge(f);
    return f.getId();
}

From source file:py.com.palermo.servicioarthy.impl.gestioncomercial.PortalGeneralService.java

public String setLog(LogOperacion l) {

    if (l.getFechaCadena() != null) {
        LocalDateTime localDateTime = LocalDateTime.parse(l.getFechaCadena(),
                DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
        l.setFecha(localDateTime.toDate());
    }//  w w w .j  a  v  a  2s .  c  o m

    String R = l.getId() + "";
    l.setId(null);
    em.persist(l);
    return R;
}

From source file:py.com.palermo.servicioarthy.impl.gestioncomercial.PortalGeneralService.java

public String setRelevamiento(Relevamiento r) {

    if (r.getFechaCadena() != null) {
        LocalDateTime localDateTime = LocalDateTime.parse(r.getFechaCadena(),
                DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
        r.setFecha(localDateTime.toDate());
    }// w w w.j  a  v a 2 s.  c o m

    String R = r.getId() + "";
    Relevamiento rbd = null;
    try {
        rbd = (Relevamiento) em.createQuery("SELECT r FROM Relevamiento r where r.hashKey = ?1")
                .setParameter(1, r.getHashKey()).getSingleResult();
    } catch (Exception e) {

    }

    if (rbd != null && rbd.getEstadoDescarga().compareToIgnoreCase("T") == 0) {
        return R;
    }

    if (rbd == null) {
        r.setId(null);
        r.setEstadoDescarga("N");
        em.persist(r);
    } else {
        rbd.setMotivoNoVentaId(r.getMotivoNoVentaId());
        rbd.setEstadoAnulacion(r.getEstadoAnulacion());
        rbd.setEstadoDescarga("N");
        em.merge(rbd);
    }

    return R;
}