List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:org.openiot.gsn.utils.Helpers.java
License:Open Source License
public static String convertTimeFromLongToIso(long timestamp) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dt = new DateTime(timestamp); return fmt.print(dt); }
From source file:org.openiot.gsn.wrappers.JDBCWrapper.java
License:Open Source License
public boolean initialize() { setName(getWrapperName() + "-" + (++threadCounter)); AddressBean addressBean = getActiveAddressBean(); table_name = addressBean.getPredicateValue("table-name"); databaseURL = addressBean.getPredicateValue("jdbc-url"); username = addressBean.getPredicateValue("username"); password = addressBean.getPredicateValue("password"); driver = addressBean.getPredicateValue("driver"); if ((databaseURL != null) && (username != null) && (password != null) && (driver != null)) { useDefaultStorageManager = false; sm = StorageManagerFactory.getInstance(driver, username, password, databaseURL, 8); logger.warn("Using specified storage manager: " + databaseURL); } else {// w ww. ja v a 2s . c om sm = Main.getDefaultStorage(); logger.warn("Using default storage manager"); } if (table_name == null) { logger.warn("The > table-name < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } ////////////////// boolean usePreviousCheckPoint = true; String time = addressBean.getPredicateValue("start-time"); if (time == null) { logger.warn("The > start-time < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } if (time.equalsIgnoreCase("continue")) { latest_timed = getLatestProcessed(); usePreviousCheckPoint = false; logger.warn("Mode: continue => " + latest_timed); } else if (isISOFormat(time)) { try { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); start_time = fmt.parseDateTime(time).getMillis(); latest_timed = start_time; logger.warn("Mode: ISO => " + latest_timed); } catch (IllegalArgumentException e) { logger.warn("The > start-time < parameter is malformed (looks like ISO8601) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else if (isLong(time)) { try { latest_timed = Long.parseLong(time); logger.warn("Mode: epoch => " + latest_timed); } catch (NumberFormatException e) { logger.warn("The > start-time < parameter is malformed (looks like epoch) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else { logger.warn( "Incorrectly formatted > start-time < accepted values are: 'continue' (from latest element in destination table), iso-date (e.g. 2009-11-02T00:00:00.000+00:00), or epoch (e.g. 1257946505000)"); return false; } ////////////////// checkPointDir = addressBean.getPredicateValueWithDefault("check-point-directory", "jdbc-check-points"); checkPointFile = checkPointDir + "/" + table_name + "-" + this.getActiveAddressBean().getVirtualSensorName(); new File(checkPointDir).mkdirs(); if (usePreviousCheckPoint) { logger.warn("trying to read latest timestamp from chekpoint file ... " + checkPointFile); try { if (getLatestTimeStampFromCheckPoint() != 0) { latest_timed = getLatestTimeStampFromCheckPoint(); logger.warn("latest ts => " + latest_timed); } else logger.warn("wrong value for latest ts (" + getLatestTimeStampFromCheckPoint() + "), ignored"); } catch (IOException e) { logger.warn("Checkpoints couldn't be used due to IO exception."); logger.warn(e.getMessage(), e); } } ////////////////// Connection connection = null; try { logger.info("Initializing the structure of JDBCWrapper with : " + table_name); connection = sm.getConnection(); outputFormat = sm.tableToStructureByString(table_name, connection); } catch (SQLException e) { logger.error(e.getMessage(), e); return false; } finally { sm.close(connection); } dataFieldsLength = outputFormat.length; dataFieldNames = new String[dataFieldsLength]; dataFieldTypes = new Byte[dataFieldsLength]; for (int i = 0; i < outputFormat.length; i++) { dataFieldNames[i] = outputFormat[i].getName(); dataFieldTypes[i] = outputFormat[i].getDataTypeID(); } return true; }
From source file:org.openiot.gsn.wrappers.TetraedreFluoWrapper.java
License:Open Source License
public boolean initialize() { setName(getWrapperName() + "-" + (++threadCounter)); AddressBean addressBean = getActiveAddressBean(); table_name = addressBean.getPredicateValue("table-name"); physical_input = addressBean.getPredicateValue("physical-input"); databaseURL = addressBean.getPredicateValue("jdbc-url"); username = addressBean.getPredicateValue("username"); password = addressBean.getPredicateValue("password"); driver = addressBean.getPredicateValue("driver"); if ((databaseURL != null) && (username != null) && (password != null) && (driver != null)) { useDefaultStorageManager = false; sm = StorageManagerFactory.getInstance(driver, username, password, databaseURL, 8); logger.warn("Using specified storage manager: " + databaseURL); } else {/*from w w w. ja va 2 s . c o m*/ sm = Main.getDefaultStorage(); logger.warn("Using default storage manager"); } if (table_name == null) { logger.warn("The > table-name < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } ////////////////// boolean usePreviousCheckPoint = true; String time = addressBean.getPredicateValue("start-time"); if (time == null) { logger.warn("The > start-time < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } if (time.equalsIgnoreCase("continue")) { latest_timed = getLatestProcessed(); usePreviousCheckPoint = false; logger.warn("Mode: continue => " + latest_timed); } else if (isISOFormat(time)) { try { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); start_time = fmt.parseDateTime(time).getMillis(); latest_timed = start_time; logger.warn("Mode: ISO => " + latest_timed); } catch (IllegalArgumentException e) { logger.warn("The > start-time < parameter is malformed (looks like ISO8601) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else if (isLong(time)) { try { latest_timed = Long.parseLong(time); logger.warn("Mode: epoch => " + latest_timed); } catch (NumberFormatException e) { logger.warn("The > start-time < parameter is malformed (looks like epoch) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else { logger.warn( "Incorrectly formatted > start-time < accepted values are: 'continue' (from latest element in destination table), iso-date (e.g. 2009-11-02T00:00:00.000+00:00), or epoch (e.g. 1257946505000)"); return false; } ////////////////// checkPointDir = addressBean.getPredicateValueWithDefault("check-point-directory", "jdbc-check-points"); checkPointFile = checkPointDir + "/" + table_name + "-" + this.getActiveAddressBean().getVirtualSensorName(); new File(checkPointDir).mkdirs(); if (usePreviousCheckPoint) { logger.warn("trying to read latest timestamp from chekpoint file ... " + checkPointFile); try { if (getLatestTimeStampFromCheckPoint() != 0) { latest_timed = getLatestTimeStampFromCheckPoint(); logger.warn("latest ts => " + latest_timed); } else logger.warn("wrong value for latest ts (" + getLatestTimeStampFromCheckPoint() + "), ignored"); } catch (IOException e) { logger.warn("Checkpoints couldn't be used due to IO exception."); logger.warn(e.getMessage(), e); } } ////////////////// Connection connection = null; try { logger.info("Initializing the structure of JDBCWrapper with : " + table_name); connection = sm.getConnection(); outputFormat = sm.tableToStructureByString(table_name, connection); } catch (SQLException e) { logger.error(e.getMessage(), e); return false; } finally { sm.close(connection); } dataFieldsLength = outputFormat.length; dataFieldNames = new String[dataFieldsLength]; dataFieldTypes = new Byte[dataFieldsLength]; for (int i = 0; i < outputFormat.length; i++) { dataFieldNames[i] = outputFormat[i].getName(); dataFieldTypes[i] = outputFormat[i].getDataTypeID(); } return true; }
From source file:org.openiot.gsn.wrappers.TetraedreNMCWrapper.java
License:Open Source License
public boolean initialize() { setName(getWrapperName() + "-" + (++threadCounter)); AddressBean addressBean = getActiveAddressBean(); table_name = addressBean.getPredicateValue("table-name"); databaseURL = addressBean.getPredicateValue("jdbc-url"); username = addressBean.getPredicateValue("username"); password = addressBean.getPredicateValue("password"); driver = addressBean.getPredicateValue("driver"); if ((databaseURL != null) && (username != null) && (password != null) && (driver != null)) { useDefaultStorageManager = false; sm = StorageManagerFactory.getInstance(driver, username, password, databaseURL, 8); logger.warn("Using specified storage manager: " + databaseURL); } else {//from w ww .j a v a 2 s . c o m sm = Main.getDefaultStorage(); logger.warn("Using default storage manager"); } if (table_name == null) { logger.warn("The > table-name < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } ////////////////// boolean usePreviousCheckPoint = true; String time = addressBean.getPredicateValue("start-time"); if (time == null) { logger.warn("The > start-time < parameter is missing from the wrapper for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } if (time.equalsIgnoreCase("continue")) { latest_timed = getLatestProcessed(); usePreviousCheckPoint = false; logger.warn("Mode: continue => " + latest_timed); } else if (isISOFormat(time)) { try { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); start_time = fmt.parseDateTime(time).getMillis(); latest_timed = start_time; logger.warn("Mode: ISO => " + latest_timed); } catch (IllegalArgumentException e) { logger.warn("The > start-time < parameter is malformed (looks like ISO8601) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else if (isLong(time)) { try { latest_timed = Long.parseLong(time); logger.warn("Mode: epoch => " + latest_timed); } catch (NumberFormatException e) { logger.warn("The > start-time < parameter is malformed (looks like epoch) for VS " + this.getActiveAddressBean().getVirtualSensorName()); return false; } } else { logger.warn( "Incorrectly formatted > start-time < accepted values are: 'continue' (from latest element in destination table), iso-date (e.g. 2009-11-02T00:00:00.000+00:00), or epoch (e.g. 1257946505000)"); return false; } ////////////////// checkPointDir = addressBean.getPredicateValueWithDefault("check-point-directory", "jdbc-check-points"); checkPointFile = checkPointDir + "/" + table_name + "-" + this.getActiveAddressBean().getVirtualSensorName(); new File(checkPointDir).mkdirs(); if (usePreviousCheckPoint) { logger.warn("trying to read latest timestamp from chekpoint file ... " + checkPointFile); try { if (getLatestTimeStampFromCheckPoint() != 0) { latest_timed = getLatestTimeStampFromCheckPoint(); logger.warn("latest ts => " + latest_timed); } else logger.warn("wrong value for latest ts (" + getLatestTimeStampFromCheckPoint() + "), ignored"); } catch (IOException e) { logger.warn("Checkpoints couldn't be used due to IO exception."); logger.warn(e.getMessage(), e); } } ////////////////// Connection connection = null; try { logger.info("Initializing the structure of JDBCWrapper with : " + table_name); connection = sm.getConnection(); outputFormat = sm.tableToStructureByString(table_name, connection); } catch (SQLException e) { logger.error(e.getMessage(), e); return false; } finally { sm.close(connection); } dataFieldsLength = outputFormat.length; dataFieldNames = new String[dataFieldsLength]; dataFieldTypes = new Byte[dataFieldsLength]; for (int i = 0; i < outputFormat.length; i++) { dataFieldNames[i] = outputFormat[i].getName(); dataFieldTypes[i] = outputFormat[i].getDataTypeID(); } return true; }
From source file:org.openmrs.module.chaiui.ChaiUiUtils.java
License:Open Source License
/** * Formats a date as ISO 8601 for use as a query parameter * @param date the date/*ww w. j a v a 2 s. co m*/ * @return the string value * @should format null date as empty string */ public String formatDateParam(Date date) { if (date == null) { return ""; } if (!dateHasTime(date)) { // don't include time if there isn't any return iso8601Formatter.format(date); } else { // return a full ISO8601 representation DateTime dt = new DateTime(date); return ISODateTimeFormat.dateTime().print(dt); } }
From source file:org.opensaml.core.xml.schema.impl.XSDateTimeImpl.java
License:Open Source License
/** * Constructor./*from w w w .j ava 2 s .c o m*/ * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected XSDateTimeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) { super(namespaceURI, elementLocalName, namespacePrefix); formatter = ISODateTimeFormat.dateTime().withChronology(ISOChronology.getInstanceUTC()); }
From source file:org.opensaml.saml.ext.saml2mdrpi.impl.PublicationInfoMarshaller.java
License:Open Source License
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { PublicationInfo info = (PublicationInfo) samlObject; if (info.getPublisher() != null) { domElement.setAttributeNS(null, PublicationInfo.PUBLISHER_ATTRIB_NAME, info.getPublisher()); }//w ww . j ava 2 s . c om if (info.getPublicationId() != null) { domElement.setAttributeNS(null, PublicationInfo.PUBLICATION_ID_ATTRIB_NAME, info.getPublicationId()); } if (info.getCreationInstant() != null) { String creationInstant = ISODateTimeFormat.dateTime().print(info.getCreationInstant()); domElement.setAttributeNS(null, PublicationInfo.CREATION_INSTANT_ATTRIB_NAME, creationInstant); } }
From source file:org.opensaml.saml.ext.saml2mdrpi.impl.PublicationMarshaller.java
License:Open Source License
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { Publication info = (Publication) samlObject; if (info.getPublisher() != null) { domElement.setAttributeNS(null, Publication.PUBLISHER_ATTRIB_NAME, info.getPublisher()); }/*www . jav a 2s . c om*/ if (info.getPublicationId() != null) { domElement.setAttributeNS(null, Publication.PUBLICATION_ID_ATTRIB_NAME, info.getPublicationId()); } if (info.getCreationInstant() != null) { String creationInstant = ISODateTimeFormat.dateTime().print(info.getCreationInstant()); domElement.setAttributeNS(null, Publication.CREATION_INSTANT_ATTRIB_NAME, creationInstant); } }
From source file:org.opensaml.saml.ext.saml2mdrpi.impl.RegistrationInfoMarshaller.java
License:Open Source License
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { RegistrationInfo info = (RegistrationInfo) samlObject; if (info.getRegistrationAuthority() != null) { domElement.setAttributeNS(null, RegistrationInfo.REGISTRATION_AUTHORITY_ATTRIB_NAME, info.getRegistrationAuthority()); }// ww w . j a va 2 s . c o m if (info.getRegistrationInstant() != null) { String registrationInstant = ISODateTimeFormat.dateTime().print(info.getRegistrationInstant()); domElement.setAttributeNS(null, RegistrationInfo.REGISTRATION_INSTANT_ATTRIB_NAME, registrationInstant); } }
From source file:org.opensaml.saml.saml1.core.impl.AssertionMarshaller.java
License:Open Source License
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException { Assertion assertion = (Assertion) samlElement; if (assertion.getID() != null) { domElement.setAttributeNS(null, Assertion.ID_ATTRIB_NAME, assertion.getID()); if (assertion.getMinorVersion() != 0) { domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true); }/*from w w w . j a v a 2 s . c o m*/ } if (assertion.getIssuer() != null) { domElement.setAttributeNS(null, Assertion.ISSUER_ATTRIB_NAME, assertion.getIssuer()); } if (assertion.getIssueInstant() != null) { String date = ISODateTimeFormat.dateTime().print(assertion.getIssueInstant()); domElement.setAttributeNS(null, Assertion.ISSUEINSTANT_ATTRIB_NAME, date); } domElement.setAttributeNS(null, Assertion.MAJORVERSION_ATTRIB_NAME, "1"); if (assertion.getMinorVersion() == 0) { domElement.setAttributeNS(null, Assertion.MINORVERSION_ATTRIB_NAME, "0"); } else { domElement.setAttributeNS(null, Assertion.MINORVERSION_ATTRIB_NAME, "1"); } }