Example usage for org.joda.time DateTime getMonthOfYear

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

Introduction

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

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:com.enonic.cms.core.portal.datasource.handler.util.GetCalendarHandler.java

License:Open Source License

@Override
protected Document handle(final DataSourceRequest req, final GetCalendarParams params) throws Exception {
    final DateTime now = this.timeService.getNowAsDateTime();

    if (params.year == null) {
        params.year = now.getYear();//from  ww  w  .  j  a v  a 2 s  .  co  m
    }

    if (params.month == null) {
        params.month = now.getMonthOfYear();
    }

    final Locale locale = new Locale(params.language, params.country);
    return getCalendar(now.getMillis(), params.relative, params.year, params.month, params.count,
            params.includeWeeks, params.includeDays, locale);
}

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 {//from w  w w  .  ja  v a2s .  c  o  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.esri.geoevent.solutions.processor.geometry.QueryReportProcessor.java

License:Apache License

@Override
public GeoEvent process(GeoEvent ge) throws Exception {
    //CreateQueryMap();
    CreateQueries();/*w  w  w  .  j a v  a  2 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);

    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 {// w  w  w . j av a 2 s  . 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 w w  . j a  v  a  2 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);
    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();//from   w  w  w  .j ava 2s.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);

    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.excilys.ebi.bank.web.controller.DefaultsController.java

License:Apache License

@RequestMapping("/private/bank/account/*/operations.html")
public String displayOperationsWithDefaults() {

    DateTime now = bankService.getDefaultDateTime();

    return new StringBuilder().append("forward:year/").append(now.getYear()).append("/month/")
            .append(now.getMonthOfYear()).append("/operations.html").toString();
}

From source file:com.excilys.ebi.bank.web.controller.DefaultsController.java

License:Apache License

@RequestMapping("/private/bank/account/*/cards/*/operations.html")
public String displayCardOperationsWithDefaults() {

    DateTime now = bankService.getDefaultDateTime();

    return new StringBuilder().append("forward:year/").append(now.getYear()).append("/month/")
            .append(now.getMonthOfYear()).append("/operations.html").toString();
}

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

License:Open Source License

/** Convert millis to a date in the given timezone and then {@link #encodeDate(long, long, long)}. */
public static int encodeDate(long millis, String tz) {
    DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
    return encodeDate(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth());
}

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() };
}