Example usage for org.joda.time DateTime getHourOfDay

List of usage examples for org.joda.time DateTime getHourOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime getHourOfDay.

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:com.ephesoft.dcma.nsi.NsiExporter.java

License:Open Source License

private void transformXmlAndExportFiles(String batchInstanceID, String exportFolder, String xmlTagStyle,
        boolean isZipSwitchOn, String baseDocsFolder, InputStream xslStream)
        throws TransformerFactoryConfigurationError, DCMAApplicationException {
    String batchXmlName = batchInstanceID + ICommonConstants.UNDERSCORE_BATCH_XML;
    String sourceXMLPath = baseDocsFolder + File.separator + batchInstanceID
            + ICommonConstants.UNDERSCORE_BATCH_XML;
    String targetXmlPath = exportFolder + File.separator + batchInstanceID + xmlTagStyle;
    LOGGER.debug("Transforming XML " + sourceXMLPath + " to " + targetXmlPath);
    try {/*  w w w . java2  s. co m*/
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = null;
        try {
            // NOTE, this needs to be fixed to use the InputStream xslStream object, not a hardcoded path to the file.
            transformer = tFactory.newTransformer(new StreamSource(xslStream));
        } finally {
            if (xslStream != null) {
                try {
                    xslStream.close();
                } catch (IOException e) {
                    LOGGER.info("Error closing input stream for :" + xslResource.toString());
                }
            }
        }
        if (transformer != null) {
            DateTimeZone zone = DateTimeZone.forID(NSIExportConstant.TIME_ZONE_ID);
            DateTime dateTime = new DateTime(zone);
            String date = Integer.toString(dateTime.getYear()) + NSIExportConstant.HYPEN
                    + Integer.toString(dateTime.getMonthOfYear()) + NSIExportConstant.HYPEN
                    + Integer.toString(dateTime.getDayOfMonth());
            String time = Integer.toString(dateTime.getHourOfDay()) + NSIExportConstant.COLON
                    + Integer.toString(dateTime.getMinuteOfHour()) + NSIExportConstant.COLON
                    + Integer.toString(dateTime.getSecondOfMinute());
            transformer.setParameter(NSIExportConstant.DATE, date);
            transformer.setParameter(NSIExportConstant.HOURS, time);
            transformer.setParameter(NSIExportConstant.BASE_DOC_FOLDER_PATH, baseDocsFolder + File.separator);
            transformer.setParameter(NSIExportConstant.EXPORT_FOLDER_PATH, exportFolder + File.separator);
            File file = new File(exportFolder);
            boolean isFileCreated = false;
            if (!file.exists()) {
                isFileCreated = file.mkdir();
            } else {
                isFileCreated = true;
            }
            if (isFileCreated) {
                String imageFolderPath = exportFolder + File.separator + NSIExportConstant.IMAGE_FOLDER_NAME;
                File imageFolder = new File(imageFolderPath);
                boolean isImageFolderCreated = false;
                if (!imageFolder.exists()) {
                    isImageFolderCreated = imageFolder.mkdir();
                } else {
                    isImageFolderCreated = true;
                }
                if (isImageFolderCreated) {
                    LOGGER.info(exportFolder + " folder created");
                    Batch batch = batchSchemaService.getBatch(batchInstanceID);
                    List<Document> documentList = batch.getDocuments().getDocument();

                    transformXML(isZipSwitchOn, batchXmlName, sourceXMLPath, targetXmlPath, transformer);

                    File baseDocFolder = new File(baseDocsFolder);
                    for (Document document : documentList) {
                        if (document != null && document.getMultiPageTiffFile() != null
                                && !document.getMultiPageTiffFile().isEmpty()) {
                            String multipageTiffName = document.getMultiPageTiffFile();
                            String filePath = baseDocFolder.getAbsolutePath() + File.separator
                                    + multipageTiffName;
                            String exportFileName = multipageTiffName.replace(
                                    NSIExportConstant.TIF_WITH_DOT_EXTENSION,
                                    NSIExportConstant.DAT_WITH_DOT_EXTENSION);
                            String exportFilePath = imageFolderPath + File.separator + exportFileName;
                            File oldFile = new File(filePath);
                            File newFile = new File(exportFilePath);
                            try {
                                FileUtils.copyFile(oldFile, newFile);
                            } catch (Exception e) {
                                LOGGER.error("Error creating in file: " + newFile + "is" + e.getMessage(), e);
                            }
                        }
                    }
                }
            } else {
                LOGGER.error("Access is denied for creating: " + file.getName());
            }
        } else {
            LOGGER.error("Transformer is null due to Invalid xsl file.");
        }
    } catch (FileNotFoundException e1) {
        LOGGER.error("Could not find NSITransform.xsl file : " + e1.getMessage(), e1);
        throw new DCMAApplicationException("Could not find nsiTransform.xsl file : " + e1.getMessage(), e1);
    } catch (TransformerException e1) {
        LOGGER.error(
                "Problem occurred in transforming " + sourceXMLPath + " to " + targetXmlPath + e1.getMessage(),
                e1);
        throw new DCMAApplicationException("Could not find nsiTransform.xsl file : ", e1);
    } catch (IOException ioe) {
        LOGGER.error(
                "Problem occurred in transforming " + sourceXMLPath + " to " + targetXmlPath + ioe.getMessage(),
                ioe);
        throw new DCMAApplicationException("Could not transform ibmCMTransform.xsl file : " + ioe.getMessage(),
                ioe);
    }
}

From source file:com.esofthead.mycollab.vaadin.AppContext.java

License:Open Source License

/**
 * @param date is the UTC date value//from   w ww.j  av  a2s.  c o  m
 * @return
 */
public static String formatDateTime(Date date) {
    //        return date == null ? "" : DateTimeUtils.formatDate(date, AppContext.getDateTimeFormat(), AppContext.getUserTimeZone());
    if (date == null) {
        return "";
    } else {
        DateTime jodaDate = new DateTime(date)
                .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone()));
        if (jodaDate.getHourOfDay() > 0 || jodaDate.getMinuteOfHour() > 0) {
            DateTimeFormatter formatter = DateTimeFormat.forPattern(AppContext.getDateTimeFormat());
            return formatter.print(jodaDate);
        } else {
            DateTimeFormatter formatter = DateTimeFormat.forPattern(AppContext.getDateFormat());
            return formatter.print(jodaDate);
        }
    }
}

From source file:com.esofthead.mycollab.vaadin.web.ui.field.DateTimeOptionField.java

License:Open Source License

@Override
public void setPropertyDataSource(Property newDataSource) {
    Date value = (Date) newDataSource.getValue();
    if (value != null) {
        DateTime jodaTime = new DateTime(value);
        jodaTime = jodaTime.toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone()));
        int hrs = jodaTime.getHourOfDay();
        int min = jodaTime.getMinuteOfHour();
        String timeFormat = "AM";
        if (hrs > 12) {
            hrs -= 12;/*from ww  w .j a  va  2  s  .  c om*/
            timeFormat = "PM";
        }

        if ((hrs > 0 || min > 0) && hideTimeOption) {
            toggleHideTimeOption(false);
        }

        popupDateField.setPropertyDataSource(new ObjectProperty(jodaTime.toDate()));
        if (!hideTimeOption) {
            hourPickerComboBox.setPropertyDataSource(new ObjectProperty((hrs < 10) ? "0" + hrs : "" + hrs));
            minutePickerComboBox.setPropertyDataSource(new ObjectProperty((min < 10) ? "0" + min : "" + min));
            timeFormatComboBox.setPropertyDataSource(new ObjectProperty(timeFormat));
        }
    }
    super.setPropertyDataSource(newDataSource);
}

From source file:com.esri.geoevent.solutions.processor.geometry.QueryReportProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    //CreateQueryMap();
    CreateQueries();//from   w ww.j a  va2 s  . c  o  m
    double radius = (Double) properties.get("radius").getValue();
    String units = properties.get("units").getValue().toString();
    int inwkid = (Integer) properties.get("wkidin").getValue();
    int outwkid = (Integer) properties.get("wkidout").getValue();
    int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    srIn = SpatialReference.create(inwkid);
    srBuffer = SpatialReference.create(bufferwkid);
    srOut = SpatialReference.create(outwkid);

    com.esri.ges.spatial.Geometry geo = ge.getGeometry();
    com.esri.ges.spatial.Geometry inGeo = null;
    if (properties.get("geosrc").getValueAsString().equals("Buffer")) {
        inGeometry = constructGeometry(geo);
        Unit u = queryUnit(units);
        inGeo = constructBuffer(geo, radius, u);
    } else if (properties.get("geosrc").getValueAsString().equals("Event Definition")) {

        String eventfld = properties.get("geoeventdef").getValue().toString();
        String[] arr = eventfld.split(":");
        String geostr = (String) ge.getField(arr[1]);
        com.esri.ges.spatial.Geometry g = constructGeometryFromString(geostr);
        com.esri.core.geometry.Geometry polyGeo = constructGeometry(g);
        Envelope env = new Envelope();
        polyGeo.queryEnvelope(env);
        inGeometry = env.getCenter();
        com.esri.core.geometry.Geometry projGeo = GeometryEngine.project(polyGeo, srBuffer, srOut);
        String json = GeometryEngine.geometryToJson(srOut, projGeo);
        inGeo = spatial.fromJson(json);
    } else {

        com.esri.core.geometry.Geometry polyGeo = constructGeometry(geo);
        Envelope env = new Envelope();
        polyGeo.queryEnvelope(env);
        inGeometry = env.getCenter();
        com.esri.core.geometry.Geometry projGeo = GeometryEngine.project(polyGeo, srBuffer, srOut);
        String json = GeometryEngine.geometryToJson(srOut, projGeo);
        inGeo = spatial.fromJson(json);

    }
    String jsonGeo = inGeo.toJson();
    String geotype = GeometryUtility.parseGeometryType(inGeo.getType());
    ExecuteRestQueries(jsonGeo, geotype);
    String timestamp = "";
    if ((Boolean) properties.get("usetimestamp").getValue()) {
        String eventfld = properties.get("timestamp").getValueAsString();
        String[] arr = eventfld.split(":");
        timestamp = ge.getField(arr[1]).toString();
    }
    DateTime dt = DateTime.now();
    String ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    String file = properties.get("filename").getValueAsString() + ts + ".html";

    ParseResponses(timestamp, file);
    String host = properties.get("host").getValueAsString();
    if (host.contains("http://")) {
        host.replace("http://", "");
    }
    String url = "http://" + host + ":6180/geoevent/assets/reports/" + file;
    GeoEventDefinition geoDef = ge.getGeoEventDefinition();
    String outDefName = geoDef.getName() + "_out";
    GeoEventDefinition edOut;
    if ((edOut = manager.searchGeoEventDefinition(outDefName, getId())) == null) {
        List<FieldDefinition> fds = Arrays
                .asList(((FieldDefinition) new DefaultFieldDefinition("url", FieldType.String)));
        edOut = geoDef.augment(fds);
        edOut.setOwner(getId());
        edOut.setName(outDefName);
        manager.addGeoEventDefinition(edOut);
    }
    GeoEventCreator geoEventCreator = messaging.createGeoEventCreator();
    GeoEvent geOut = geoEventCreator.create(edOut.getGuid(), new Object[] { ge.getAllFields(), url });
    geOut.setProperty(GeoEventPropertyName.TYPE, "message");
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, getId());
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, definition.getUri());

    for (Map.Entry<GeoEventPropertyName, Object> property : ge.getProperties())
        if (!geOut.hasProperty(property.getKey()))
            geOut.setProperty(property.getKey(), property.getValue());
    queries.clear();
    responseMap.clear();
    return geOut;

}

From source file:com.esri.geoevent.solutions.processor.queryreport.QueryReportProcessor.java

License:Apache License

@Override
public void afterPropertiesSet() {
    radius = (Double) properties.get("radius").getValue();
    units = properties.get("units").getValue().toString();
    //inwkid = (Integer) properties.get("wkidin").getValue();
    outwkid = (Integer) properties.get("wkidout").getValue();
    bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    geoSrc = properties.get("geosrc").getValueAsString();
    useCentroid = (Boolean) properties.get("usecentroid").getValue();
    eventfld = properties.get("geoeventdef").getValue().toString();
    useTimeStamp = (Boolean) properties.get("usetimestamp").getValue();

    DateTime dt = DateTime.now();
    ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    time = ((Integer) dt.getYear()).toString() + "/" + ((Integer) dt.getMonthOfYear()).toString() + "/"
            + ((Integer) dt.getDayOfMonth()).toString() + " " + ((Integer) dt.getHourOfDay()).toString() + ":"
            + ((Integer) dt.getMinuteOfHour()).toString() + ":" + ((Integer) dt.getSecondOfMinute()).toString();
    file = properties.get("filename").getValueAsString() + ts + ".html";
    host = properties.get("host").getValueAsString();
    outDefName = properties.get("gedname").getValueAsString();
    connName = properties.get("connection").getValueAsString();
    folder = properties.get("folder").getValueAsString();
    service = properties.get("service").getValueAsString();
    lyrName = properties.get("layer").getValueAsString();
    try {/*from   w w  w  . jav  a 2s . c o m*/
        conn = connectionManager.getArcGISServerConnection(connName);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        ValidationException ve = new ValidationException("Unable to make connection to ArcGIS Server");
        LOG.error(ve.getMessage());
        try {
            throw ve;
        } catch (ValidationException e1) {

            e1.printStackTrace();
        }
    }
    layer = conn.getLayer(folder, service, lyrName, ArcGISServerType.FeatureServer);
    layerId = ((Integer) layer.getId()).toString();
    field = properties.get("field").getValueAsString();
    sortField = properties.get("sortfield").getValueAsString();
    if (!properties.get("endpoint").getValueAsString().isEmpty()) {
        endpoint = properties.get("endpoint").getValueAsString();
    }
    try {
        token = conn.getDecryptedToken();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //fields = conn.getFields(folder, service, layer.getId(), ArcGISServerType.FeatureServer);
    calcDist = (Boolean) properties.get("calcDistance").getValue();
    wc = properties.get("wc").getValueAsString();
    lyrHeaderCfg = properties.get("lyrheader").getValueAsString();
    sortByDist = false;
    if (calcDist) {
        sortByDist = (Boolean) properties.get("sortdist").getValue();
        distToken = "${distance.value}";
        distUnits = properties.get("dist_units").getValueAsString();
    }
    //token = properties.get("field-token").getValueAsString();
    itemConfig = properties.get("item-config").getValueAsString();
    title = properties.get("title").getValueAsString();
    Object objHeader = properties.get("header");
    header = null;
    if (objHeader != null) {
        header = properties.get("header").getValueAsString();
    }
}

From source file:com.esri.ges.solutions.processor.geometry.QueryProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    CreateQueryMap();//w ww  .  j  a v a 2 s  . co  m
    double radius = (Double) properties.get("radius").getValue();
    String units = properties.get("units").getValue().toString();
    int inwkid = (Integer) properties.get("wkidin").getValue();
    int outwkid = (Integer) properties.get("wkidout").getValue();
    int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    srIn = SpatialReference.create(inwkid);
    srBuffer = SpatialReference.create(bufferwkid);
    srOut = SpatialReference.create(outwkid);
    com.esri.ges.spatial.Point eventGeo = (com.esri.ges.spatial.Point) ge.getGeometry();
    double x = eventGeo.getX();
    double y = eventGeo.getY();
    com.esri.ges.spatial.Geometry buffer = constructBuffer(x, y, radius, units);
    String jsonGeo = buffer.toJson();
    String geotype = GeometryUtility.parseGeometryType(buffer.getType());
    ExecuteRestQueries(jsonGeo, geotype);
    String timestamp = "";
    if ((Boolean) properties.get("usetimestamp").getValue()) {
        String eventfld = properties.get("timestamp").getValueAsString();
        String[] arr = eventfld.split(":");
        timestamp = ge.getField(arr[1]).toString();
    }
    DateTime dt = DateTime.now();
    String ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    String file = properties.get("filename").getValueAsString() + ts + ".html";

    ParseResponses(timestamp, file);
    String host = properties.get("host").getValueAsString();
    String url = "http://" + host + ":6180/geoevent/assets/reports/" + file;
    GeoEventDefinition geoDef = ge.getGeoEventDefinition();
    List<FieldDefinition> fds = Arrays
            .asList(((FieldDefinition) new DefaultFieldDefinition("url", FieldType.String)));
    GeoEventDefinition edOut = geoDef.augment(fds);
    edOut.setOwner(getId());
    manager.addTemporaryGeoEventDefinition(edOut, true);
    GeoEventCreator geoEventCreator = messaging.createGeoEventCreator();
    GeoEvent geOut = geoEventCreator.create(edOut.getGuid(), new Object[] { ge.getAllFields(), url });
    geOut.setProperty(GeoEventPropertyName.TYPE, "message");
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, getId());
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, definition.getUri());
    for (Map.Entry<GeoEventPropertyName, Object> property : ge.getProperties())
        if (!geOut.hasProperty(property.getKey()))
            geOut.setProperty(property.getKey(), property.getValue());
    queries.clear();
    responseMap.clear();
    return geOut;

}

From source file:com.esri.ges.solutions.processor.geometry.QueryReportProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    CreateQueryMap();//  w ww  .  j  a  va2 s .c  om
    double radius = (Double) properties.get("radius").getValue();
    String units = properties.get("units").getValue().toString();
    int inwkid = (Integer) properties.get("wkidin").getValue();
    int outwkid = (Integer) properties.get("wkidout").getValue();
    int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
    srIn = SpatialReference.create(inwkid);
    srBuffer = SpatialReference.create(bufferwkid);
    srOut = SpatialReference.create(outwkid);

    Geometry geo = ge.getGeometry();

    Geometry inGeo = null;
    if (properties.get("geosrc").getValueAsString().equals("Buffer")) {
        inGeo = constructBuffer(geo, radius, units);
    } else if (properties.get("geosrc").getValueAsString().equals("Event Definition")) {

        String eventfld = properties.get("geoeventdef").getValue().toString();
        String[] arr = eventfld.split(":");
        String geostr = (String) ge.getField(arr[1]);
        inGeo = constructGeometryFromString(geostr);
    } else {
        inGeo = geo;
    }
    String jsonGeo = inGeo.toJson();
    String geotype = GeometryUtility.parseGeometryType(inGeo.getType());
    ExecuteRestQueries(jsonGeo, geotype);
    String timestamp = "";
    if ((Boolean) properties.get("usetimestamp").getValue()) {
        String eventfld = properties.get("timestamp").getValueAsString();
        String[] arr = eventfld.split(":");
        timestamp = ge.getField(arr[1]).toString();
    }
    DateTime dt = DateTime.now();
    String ts = ((Integer) dt.getYear()).toString() + ((Integer) dt.getMonthOfYear()).toString()
            + ((Integer) dt.getDayOfMonth()).toString() + ((Integer) dt.getHourOfDay()).toString()
            + ((Integer) dt.getMinuteOfHour()).toString() + ((Integer) dt.getSecondOfMinute()).toString();
    String file = properties.get("filename").getValueAsString() + ts + ".html";

    ParseResponses(timestamp, file);
    String host = properties.get("host").getValueAsString();
    String url = "http://" + host + ":6180/geoevent/assets/reports/" + file;
    GeoEventDefinition geoDef = ge.getGeoEventDefinition();
    List<FieldDefinition> fds = Arrays
            .asList(((FieldDefinition) new DefaultFieldDefinition("url", FieldType.String)));
    GeoEventDefinition edOut = geoDef.augment(fds);
    edOut.setOwner(getId());
    manager.addTemporaryGeoEventDefinition(edOut, true);
    GeoEventCreator geoEventCreator = messaging.createGeoEventCreator();
    GeoEvent geOut = geoEventCreator.create(edOut.getGuid(), new Object[] { ge.getAllFields(), url });
    geOut.setProperty(GeoEventPropertyName.TYPE, "message");
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, getId());
    geOut.setProperty(GeoEventPropertyName.OWNER_ID, definition.getUri());
    for (Map.Entry<GeoEventPropertyName, Object> property : ge.getProperties())
        if (!geOut.hasProperty(property.getKey()))
            geOut.setProperty(property.getKey(), property.getValue());
    queries.clear();
    responseMap.clear();
    return geOut;

}

From source file:com.example.android.sunshine.wear.Utility.java

License:Apache License

static public String getTimeForDisplay(DateTime dateTime) {
    return dateTime.getHourOfDay() + ":" + dateTime.getMinuteOfHour();
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Convert {@code millis} to a DateTime and {@link #encodeTime(long, long, long, TExecutionContext)}. */
public static int encodeTime(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeTime(dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), null);
}

From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java

License:Open Source License

/** Decode {@code encodedTimestamp} using the {@code tz} timezone. */
public static long[] decodeTimestamp(long encodedTimestamp, String tz) {
    DateTime dt = new DateTime(encodedTimestamp * 1000L, DateTimeZone.forID(tz));
    return new long[] { dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(),
            dt.getMinuteOfHour(), dt.getSecondOfMinute() };
}