Example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeNoMillis

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTimeNoMillis.

Prototype

public static DateTimeFormatter dateTimeNoMillis() 

Source Link

Document

Returns a formatter that combines a full date and time without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).

Usage

From source file:it.geosolutions.geobatch.destination.ingestion.ObuIngestionProcess.java

License:Open Source License

public static void main(String[] args) throws IOException, ParseException {
    File importFile = new File("D:\\Develop\\destination\\OBU\\OBU.csv");
    BufferedReader reader = null;
    TimeZone tz = TimeZone.getTimeZone("UTC");
    DateTimeFormatter dateFormat = ISODateTimeFormat.dateTimeNoMillis();
    DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {//from   www  .  j a va 2 s  .co m
        reader = new BufferedReader(new FileReader(importFile));
        String line = null;
        int count = 0;
        while ((line = reader.readLine()) != null) {
            String[] parts = line.split(";");
            int idSorgente = Integer.parseInt(parts[0]);
            Date dataTrasmissione = dateFormat.parseDateTime(parts[1]).toDate();
            Date dataRicezione = dateFormat.parseDateTime(parts[2]).toDate();
            Date dataCreazione = dateFormat.parseDateTime(parts[3]).toDate();
            String autista = parts[4];
            String trattore = parts[5];
            String semirimorchio = parts[6];
            String cim = parts[7];
            String ultimoMsg = parts[8];
            Double latitude = Double.parseDouble(parts[9]);
            if (latitude > 90.0) {
                latitude = null;
            }
            Double longitude = Double.parseDouble(parts[10]);
            if (longitude > 900.0) {
                longitude = null;
            }
            String type = parts[11];
            String value = parts[12];
            String originalValue = value;
            Map<String, Object> values = new HashMap<String, Object>();

            if (type.equals("01")) {
                int n = Integer.parseInt(value.substring(0, 2), 16);
                value = value.substring(2);
                List<String> subcodes = new ArrayList<String>();
                for (int i = 0; i < n; i++) {
                    subcodes.add(value.substring(0, 2));
                    value = value.substring(2);
                }
                for (String subcode : subcodes) {
                    if (subcode.equals("01")) {
                        values.put("velocita_gps", Integer.parseInt(value.substring(0, 2), 16));
                        value = value.substring(2);
                    } else if (subcode.equals("02")) {
                        values.put("direzione_gps", Integer.parseInt(value.substring(0, 3), 16));
                        value = value.substring(3);
                    } else if (subcode.equals("03")) {
                        values.put("pressione_sospensioni", Integer.parseInt(value.substring(0, 4), 16));
                        value = value.substring(4);
                    } else if (subcode.equals("04")) {
                        values.put("distanza", Long.parseLong(value.substring(0, 8), 16));
                        value = value.substring(8);
                    } else if (subcode.equals("05")) {
                        values.put("velocita_odometro", Integer.parseInt(value.substring(0, 2), 16));
                        value = value.substring(2);
                    } else if (subcode.equals("06")) {
                        values.put("inclinazione_longitudinale", Integer.parseInt(value.substring(0, 2), 16));
                        value = value.substring(2);
                    } else if (subcode.equals("07")) {
                        values.put("inclinazione_trasversale", Integer.parseInt(value.substring(0, 2), 16));
                        value = value.substring(2);
                    } else if (subcode.equals("0D")) {
                        // TODO: Dati CAN bus trattore
                        String prefix = value.substring(0, 18);
                        value = value.substring(18);
                        int len = Integer.parseInt(prefix.substring(16, 18));
                        int globallen = 3 * len;
                        for (int j = 1; j <= len; j++) {
                            globallen += 2 * (Integer.parseInt(value.substring(3 * j - 1, 3 * j)));
                        }
                        value = value.substring(globallen + 2);
                    } else if (subcode.equals("0F")) {
                        // TODO: quantita prodotto negli scomparti
                        int len = Integer.parseInt(value.substring(0, 2), 16);
                        value = value.substring(2);
                        value = value.substring(5 * len);
                    } else if (subcode.equals("10")) {
                        // TODO: pressione prodotto
                        int len = Integer.parseInt(value.substring(0, 2), 16);
                        value = value.substring(2 + 5 * len);
                    } else if (subcode.equals("11")) {
                        // TODO: temperatura prodotto
                        int len = Integer.parseInt(value.substring(0, 2), 16);
                        value = value.substring(2 + 5 * len);
                    } else if (subcode.equals("14")) {
                        // TODO: tipo prodotto negli scomparti
                        int len = Integer.parseInt(value.substring(0, 2), 16);
                        value = value.substring(2);
                        value = value.substring(3 * len);
                    } else if (subcode.equals("16")) {
                        values.put("distanza_grezza", Long.parseLong(value.substring(0, 8), 16));
                        value = value.substring(8);
                    } else {
                        value = "";
                    }
                }
            }
            //0;2012-11-20T07:50:09+01:00;2012-11-20T07:50:09+01:00;2012-11-20T07:46:44+01:00;
            //UNKNOWNA;UNKNOWNT;LOM1406;UNKNOWNCIM;0;+47.9977;+011.6758;01;020F140412CB320F943181B42CAF04100200300400

            count++;
            int velocita = 0;
            int direzione = 0;
            if (values.containsKey("velocita_gps")) {
                velocita = (Integer) values.get("velocita_gps");
            } else if (values.containsKey("velocita_odometro")) {
                velocita = (Integer) values.get("velocita_odometro");
            }
            if (values.containsKey("direzione_gps")) {
                direzione = (Integer) values.get("direzione_gps");
            }
            System.out.print(
                    "insert into siig_geo_obu(id,source,data_trasmissione,data_ricezione,data_creazione,autista,trattore,semirimorchio,cim,geometria,tipo,valore,velocita,direzione) ");
            if (longitude == null) {
                System.out.println(
                        "values(" + count + "," + idSorgente + ",'" + outputDateFormat.format(dataTrasmissione)
                                + "','" + outputDateFormat.format(dataRicezione) + "','"
                                + outputDateFormat.format(dataCreazione) + "','" + autista + "','" + trattore
                                + "','" + semirimorchio + "','" + cim + "',null,'" + type + "','" + value + "',"
                                + velocita + "," + direzione + ");");
            } else {
                System.out.println("values(" + count + "," + idSorgente + ",'"
                        + outputDateFormat.format(dataTrasmissione) + "','"
                        + outputDateFormat.format(dataRicezione) + "','"
                        + outputDateFormat.format(dataCreazione) + "','" + autista + "','" + trattore + "','"
                        + semirimorchio + "','" + cim + "',ST_GeomFromText('POINT(" + longitude + " " + latitude
                        + ")',4326),'" + type + "','" + value + "'," + velocita + "," + direzione + ");");
            }

        }
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:joachimeichborn.geotag.io.writer.kml.AbstractKmlWriter.java

License:Open Source License

/**
 * Add a placemark for each position/*from   ww  w  .j  a v  a 2 s.co  m*/
 * 
 * @param aDocument
 *            The KML document that is build
 * @param aTrack
 */
private void addPlacemarkFolder(final Document aDocument, final Track aTrack) {
    final Folder pinFolder = new Folder().withName("Places").withOpen(false);
    for (final PositionData position : aTrack.getPositions()) {
        final Placemark place = new Placemark();
        place.setName(position.getName());
        place.createAndSetTimeStamp()
                .withWhen(position.getTimeStamp().toString(ISODateTimeFormat.dateTimeNoMillis()));
        place.createAndSetPoint().addToCoordinates(position.getCoordinates().getLongitude(),
                position.getCoordinates().getLatitude(), position.getCoordinates().getAltitude());
        place.setStyleUrl("#" + PIN_STYLE);
        place.setVisibility(false);
        final ExtendedData extendedData = place.createAndSetExtendedData();
        extendedData.createAndAddData(position.getTimeStamp().toString(ISODateTimeFormat.yearMonthDay()))
                .withName(EXTENDED_DATA_DATE);
        extendedData.createAndAddData(position.getTimeStamp().toString(ISODateTimeFormat.hourMinuteSecond()))
                .withName(EXTENDED_DATA_TIME);
        extendedData.createAndAddData(Float.toString(position.getAccuracy())).withName(EXTENDED_DATA_ACCURACY);
        pinFolder.getFeature().add(place);
    }
    aDocument.getFeature().add(pinFolder);
}

From source file:joachimeichborn.geotag.io.writer.kml.AbstractKmlWriter.java

License:Open Source License

/**
 * Add for each position a circle that displays it's accuracy
 * /*from   w w w .j  av  a  2s  . c o  m*/
 * @param aDocument
 *            The KML document that is build
 */
private void addAccuracyCircles(final Document aDocument, final Track aTrack) {
    final Folder accuraciesFolder = new Folder().withName("Accuracies").withOpen(false);
    for (final PositionData position : aTrack.getPositions()) {
        if (position.getAccuracy() > 0f) {
            final LineString circle = new LineString().withTessellate(true);

            for (final Radian point : CirclePolygon.calculateCirclePoints(
                    position.getCoordinates().getLatitude(), position.getCoordinates().getLongitude(),
                    position.getAccuracy())) {
                circle.addToCoordinates(point.getLongitude(), point.getLatitude());
            }
            accuraciesFolder.createAndAddPlacemark().withName(String.valueOf(position.getAccuracy()))
                    .withStyleUrl("#" + ACCURACY_STYLE).withVisibility(false).withGeometry(circle)
                    .createAndSetTimeStamp()
                    .withWhen(position.getTimeStamp().toString(ISODateTimeFormat.dateTimeNoMillis()));
        }
    }
    aDocument.getFeature().add(accuraciesFolder);
}

From source file:ke.co.tawi.babblesms.server.sendsms.tawismsgw.PostSMS.java

License:Open Source License

/**
 * //  w w  w.ja v  a  2 s. c  o m
 */
@Override
public void run() {
    HttpEntity responseEntity = null;
    Map<String, String> params;

    if (urlValidator.isValid(smsGateway.getUrl())) {

        // Prepare the parameters to send
        params = new HashMap<>();

        params.put("username", smsGateway.getUsername());
        params.put("password", smsGateway.getPasswd());
        params.put("source", smsSource.getSource());
        params.put("message", message);

        switch (smsSource.getNetworkuuid()) {
        case Network.SAFARICOM_KE:
            params.put("network", "safaricom_ke");
            break;

        case Network.AIRTEL_KE:
            params.put("network", "safaricom_ke"); // TODO: change to airtel_ke
            break;
        }

        // When setting the destination, numbers beginning with '07' are edited
        // to begin with '254'
        phoneMap = new HashMap<>();
        StringBuffer phoneBuff = new StringBuffer();
        String phoneNum;

        for (Phone phone : phoneList) {
            phoneNum = phone.getPhonenumber();

            if (StringUtils.startsWith(phoneNum, "07")) {
                phoneNum = "254" + StringUtils.substring(phoneNum, 1);
            }

            phoneMap.put(phoneNum, phone);
            phoneBuff.append(phoneNum).append(";");
        }

        params.put("destination", StringUtils.removeEnd(phoneBuff.toString(), ";"));

        // Push to the URL
        try {
            URL url = new URL(smsGateway.getUrl());

            if (StringUtils.equalsIgnoreCase(url.getProtocol(), "http")) {
                responseEntity = doPost(smsGateway.getUrl(), params, retry);

            }
            //            else if(StringUtils.equalsIgnoreCase(url.getProtocol(), "https")) {
            //               doPostSecure(smsGateway.getUrl(), params, retry);
            //            }

        } catch (MalformedURLException e) {
            logger.error("MalformedURLException for URL: '" + smsGateway.getUrl() + "'");
            logger.error(ExceptionUtils.getStackTrace(e));
        }
    } // end 'if(urlValidator.isValid(urlStr))'

    // Process the response from the SMS Gateway
    // Assuming all is ok, it would have the following pattern:
    // requestStatus=ACCEPTED&messageIds=254726176878:b265ce23;254728932844:367941a36d2e4ef195;254724300863:11fca3c5966d4d
    if (responseEntity != null) {

        OutgoingLog outgoingLog;

        try {
            String response = EntityUtils.toString(responseEntity);
            GatewayDAO.getInstance().logResponse(account, response, new Date());

            String[] strTokens = StringUtils.split(response, '&');
            String tmpStr = "", dateStr = "";
            for (String str : strTokens) {
                if (StringUtils.startsWith(str, "messageIds")) {
                    tmpStr = StringUtils.removeStart(str, "messageIds=");
                } else if (StringUtils.startsWith(str, "datetime")) {
                    dateStr = StringUtils.removeStart(str, "datetime=");
                }
            }

            strTokens = StringUtils.split(tmpStr, ';');
            String phoneStr, uuid;
            Phone phone;
            DateTimeFormatter timeFormatter = ISODateTimeFormat.dateTimeNoMillis();

            for (String str : strTokens) {
                phoneStr = StringUtils.split(str, ':')[0];
                uuid = StringUtils.split(str, ':')[1];
                phone = phoneMap.get(phoneStr);

                outgoingLog = new OutgoingLog();
                outgoingLog.setUuid(uuid);
                outgoingLog.setOrigin(smsSource.getSource());
                outgoingLog.setMessage(message);
                outgoingLog.setDestination(phone.getPhonenumber());
                outgoingLog.setNetworkUuid(phone.getNetworkuuid());
                outgoingLog.setMessagestatusuuid(MsgStatus.SENT);
                outgoingLog.setSender(account.getUuid());
                outgoingLog.setPhoneUuid(phone.getUuid());

                // Set the date of the OutgoingLog to match the SMS Gateway time

                LocalDateTime datetime = timeFormatter.parseLocalDateTime(dateStr);
                outgoingLog.setLogTime(datetime.toDate());

                outgoingLogDAO.put(outgoingLog);
            }

        } catch (ParseException e) {
            logger.error("ParseException when reading responseEntity");
            logger.error(ExceptionUtils.getStackTrace(e));

        } catch (IOException e) {
            logger.error("IOException when reading responseEntity");
            logger.error(ExceptionUtils.getStackTrace(e));
        }
    }
}

From source file:ke.co.tawi.babblesms.server.servlet.sms.callback.Callback.java

License:Open Source License

/**     
 * @param request //  w  ww  .j a va  2  s  .  com
 * @param response 
 * @throws ServletException, IOException     
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    DateTimeFormatter timeFormatter = ISODateTimeFormat.dateTimeNoMillis();

    String callbackType = request.getParameter("callbackType");
    String messageId;
    LocalDateTime datetime;

    switch (callbackType) {

    case "status": // A notification of an SMS Status change
        messageId = request.getParameter("messageId");

        datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime"));
        String status = request.getParameter("status");

        OutgoingLog log = outgoingLogDAO.get(messageId);
        log.setLogTime(datetime.toDate());
        log.setMessagestatusuuid(dlrstatusMap.get(status));

        outgoingLogDAO.put(log);

        break;

    case "incomingSms":
        String network = request.getParameter("network").toLowerCase();
        datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime"));

        IncomingLog incomingLog = new IncomingLog();
        incomingLog.setDestination(request.getParameter("destination"));
        incomingLog.setUuid(request.getParameter("messageId"));
        incomingLog.setMessage(request.getParameter("message"));
        incomingLog.setLogTime(datetime.toDate());
        incomingLog.setNetworkUuid(networkMap.get(network));

        // The source saved in the address book may begin with "07"
        // but the one received for Kenya would begin with "254"
        // We have to reconcile the two
        String source = request.getParameter("source");

        String phoneNum = "";
        if (StringUtils.startsWith(source, "254")) {
            phoneNum = "07" + StringUtils.substring(source, 4);
        }

        if (phoneDAO.getPhones(phoneNum).size() > 0) {
            incomingLog.setOrigin(phoneNum);

        } else {
            incomingLog.setOrigin(source);
        }

        // Determine the account that it is destined for
        // This assumes that the same shortcode number cannot
        // be owned by multiple accounts
        for (Shortcode shortcode : shortcodeList) {
            if (shortcode.getCodenumber().equals(incomingLog.getDestination())) {
                incomingLog.setRecipientUuid(shortcode.getAccountuuid());
                break;
            }
        }

        incomingLogDAO.putIncomingLog(incomingLog);
        break;
    }

}

From source file:MWC.TacticalData.GND.GDataset.java

License:Open Source License

@Override
public Date[] getTimes() {

    if (_times == null) {
        // have a look at the types
        final ArrayList<String> types = getDataTypes();
        if (types.contains(TIME)) {
            final JsonNode node = getNode();
            if (node != null) {
                final JsonNode data = node.get(TIME);
                if (data != null) {
                    final int len = data.size();
                    _times = new Date[len];
                    for (int i = 0; i < len; i++) {
                        final String thisVal = data.get(i).asText();
                        _times[i] = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(thisVal).toDate();
                    }/*  ww w  . j a  v a  2s .c  o  m*/
                }
            }
        }
    }
    return _times;
}

From source file:net.shibboleth.idp.StatusServlet.java

License:Open Source License

/** {@inheritDoc} */
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    allowedIPs = new LazyList<IPRange>();

    String cidrBlocks = StringSupport.trimOrNull(config.getInitParameter(IP_PARAM_NAME));
    if (cidrBlocks != null) {
        for (String cidrBlock : cidrBlocks.split(" ")) {
            allowedIPs.add(IPRange.parseCIDRBlock(cidrBlock));
        }/*w  ww. j  av a  2 s.  c  o  m*/
    }

    dateFormat = ISODateTimeFormat.dateTimeNoMillis();
    startTime = new DateTime(ISOChronology.getInstanceUTC());
    // TODO incomplete v2 port
    // attributeResolver = HttpServletHelper.getAttributeResolver(config.getServletContext());
    // rpConfigManager = HttpServletHelper.getRelyingPartyConfirmationManager(config.getServletContext());
}

From source file:net.simonvt.cathode.api.util.TimeUtils.java

License:Apache License

public static long getMillis(String iso) {
    if (iso != null) {
        final int length = iso.length();
        DateTimeFormatter fmt;//  w  w w. j av a  2  s  .  c o m

        if (length <= 20) {
            fmt = ISODateTimeFormat.dateTimeNoMillis();
        } else {
            fmt = ISODateTimeFormat.dateTime();
        }

        return fmt.parseDateTime(iso).getMillis();
    }

    return 0L;
}

From source file:org.apache.rave.portal.util.ModelUtil.java

License:Apache License

public static Date stringToDate(String dateString) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    return fmt.parseDateTime(dateString).toDate();
}

From source file:org.apache.rave.portal.util.ModelUtil.java

License:Apache License

public static String dateToString(Date date) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dateTime = new DateTime(date);
    return fmt.print(dateTime);
}