Package it.geosolutions.geobatch.unredd.script.model

Examples of it.geosolutions.geobatch.unredd.script.model.Request


    private void executeInternal(File xmlFile) throws ActionException, GeoStoreException {

        //=== Parse input file

        Request request = null;
        try {
            request = RequestJDOMReader.parseFile(xmlFile);
        } catch (Exception e) {
            throw new ActionException(this, "Exception parsing input file " + xmlFile.getName());
        }

        String layerName = request.getLayername();
        String year = request.getYear();
        String month = request.getMonth();
        String day = request.getDay();
       
        String filename = NameUtils.buildTifFileName(layerName, year, month, day);
       
        LOGGER.info("Input parameters : [layer=" + layerName + ", year=" + year + ", month=" + month + "]");


        // ****************************************
        // Load source Layer info
        //
        // ****************************************

        LOGGER.info("Searching source Layer " + layerName);

        Resource srcLayer = srcGeostore.searchLayer(layerName);
        if(srcLayer == null) {
            throw new ActionException(this, "Source Layer not found [" + layerName+ "]");
        }

        UNREDDLayer layerResource = new UNREDDLayer(srcLayer);
        String srcPath = layerResource.getAttribute(UNREDDLayer.Attributes.MOSAICPATH);
        String dstPath = layerResource.getAttribute(UNREDDLayer.Attributes.DISSMOSAICPATH);

        LOGGER.info(layerName + " found in the Staging Area Geostore");

        // TODO ***** add layer in destination if it does not exist
        LOGGER.error("TODO: add layer in destination if it does not exist");

        // ****************************************
        // check source layer update
        //
        // ****************************************

        LOGGER.info("Searching source LayerUpdate [" + layerName + ", " + year + "," + month + "]");

        Resource srcLayerUpdatesSA = srcGeostore.searchLayerUpdate(layerName, year, month, day);
        if (srcLayerUpdatesSA == null) {
            throw new ActionException(this, "Source LayerUpdate not found [" + layerName + ", " + year + "," + month + "]");
        }

            LOGGER.info("Source LayerUpdate found [" + layerName + ", " + year + "," + month + "]");

       
        boolean isVector = request.getFormat().equals(UNREDDFormat.VECTOR);
        DataStore srcDS=null,destDS=null;
        try {
          srcDS=PostGISUtils.createDatastore(conf.getSrcPostGisConfig());
          destDS=PostGISUtils.createDatastore(conf.getDstPostGisConfig());
         
View Full Code Here


    public static Request parseFile(File xmlFile) throws JDOMException, IOException {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(xmlFile);
        Element rootElement = document.getRootElement();

        Request request = new Request();

        //=== Fetch elements
        request.setLayername(rootElement.getChildText(ELEM_layerName));
        request.setYear(rootElement.getChildText(ELEM_year));
        request.setMonth(rootElement.getChildText(ELEM_month));
        request.setDay(rootElement.getChildText(ELEM_day));

        String sFormat = rootElement.getChildText(ELEM_format);
        UNREDDFormat format = UNREDDFormat.parseName(sFormat);
        request.setFormat(format);

        //=== Check elems

        if (request.getLayername() == null) {
            throw new IllegalArgumentException("Null <"+ELEM_layerName+">");
        }

        try {
            Integer.parseInt(request.getYear());
        } catch(Exception e) {
            throw new IllegalArgumentException("Bad <"+ELEM_year+"> : " + request.getYear(), e);
        }

        try {
            if(request.getMonth() != null)
                Integer.parseInt(request.getMonth());
        } catch(Exception e) {
            throw new IllegalArgumentException("Bad <"+ELEM_month+"> : " + request.getMonth(), e);
        }
       
        try {
            if(request.getDay() != null)
                Integer.parseInt(request.getDay());
        } catch(Exception e) {
            throw new IllegalArgumentException("Bad <"+ELEM_day+"> : " + request.getDay(), e);
        }

        if (request.getFormat() == null) {
            throw new IllegalArgumentException("Bad <"+ELEM_format+"> : " + sFormat);
        }

        return request;
    }
View Full Code Here

public class XMLTest {

    @Test
    public void testCorrectVector() throws JDOMException, IOException {
        Request request = RequestJDOMReader.parseFile("src/test/resources/testXML/RequestVector.xml");
        assertEquals("layer1", request.getLayername());
        assertEquals("2010", request.getYear());
        assertEquals("10", request.getMonth());
        assertEquals(UNREDDFormat.VECTOR, request.getFormat());
    }
View Full Code Here

        assertEquals(UNREDDFormat.VECTOR, request.getFormat());
    }

    @Test
    public void testCorrectRaster() throws JDOMException, IOException {
        Request request = RequestJDOMReader.parseFile("src/test/resources/testXML/RequestRaster.xml");
        assertEquals("layer1", request.getLayername());
        assertEquals("2012", request.getYear());
        assertEquals(UNREDDFormat.RASTER, request.getFormat());
    }
View Full Code Here

        File infoXmlFile = new File(unzipDir, INFO_XML);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Reading XML parameters from " + infoXmlFile);
        }
        Request request = null;
        try {
            request = RequestJDOMReader.parseFile(infoXmlFile);
        } catch (Exception e) {
            throw new ActionException(this, "Error reading info.xml file, Are you sure to have built the input zip pkg in the right way? Note that all the content must be placed in the zip root folder, no any other subfolder are allowed..." , e);
        }

        if(request.getFormat() == null) {
            throw new ActionException(this, "the format cannot be null.");
        }

        final String layername = request.getLayername();
        if (layername==null)
            throw new ActionException(this, "the layername cannot be null.");

        final String year = request.getYear();
        if (year==null)
            throw new ActionException(this, "the year cannot be null.");

        if( ! year.matches("\\d{4}")) {
            throw new ActionException(this, "Bad format for year parameter ("+year+")");
        }

        final String month = request.getMonth();

        if(month!= null && ! month.matches("\\d\\d?") )
            throw new ActionException(this, "Bad format for month parameter ("+month+")");
       
        final String day = request.getDay();

        if(month!= null && ! month.matches("\\d\\d?") )
            throw new ActionException(this, "Bad format for month parameter ("+day+")");

        final String srcFilename = request.buildFileName();

        // build the name of the snapshot
        final String layerUpdateName = NameUtils.buildLayerUpdateName(layername, year, month, day);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Info: layername:" + layername + " year:"+year + " month:"+month + " day:"+day);
        }
        this.listenerForwarder.progressing(12, "Info from xml file: layername:" + layername + " year:"+year + " month:"+month + " day:"+day);


        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("XML parameter settings : [layer name = " + layername + "], [year = " + year + "], [month = " + month + "], [day = " + day + "], [ file name = " + srcFilename + "]");
            LOGGER.debug("XML parameter settings : [layer update name = " + layerUpdateName + "]");
        }

        File unzippedDataDir = new File(unzipDir, DATA_DIR_NAME);
        File dataFile = new File(unzippedDataDir, srcFilename);

        if( ! dataFile.isFile()) {
            throw new ActionException(this, "Could not read main data file " + dataFile);
        }

        /*****************/
        GeoStoreUtil geostore = new GeoStoreUtil(cfg.getGeoStoreConfig(), this.getTempDir());

        /******************
         *  Load Layer data
         ******************/

        this.listenerForwarder.progressing(15, "Searching layer in GeoStore");

        final Resource layerRes;
        try {
            layerRes = geostore.searchLayer(layername);
        } catch(Exception e) {
            throw new ActionException(this, "Error loading Layer "+layername, e);
        }

        if(layerRes == null)
            throw new ActionException(this, "Layer not found: "+layername);

        UNREDDLayer layer = new UNREDDLayer(layerRes);

        LOGGER.info("Layer resource found ");

        if( ! layer.getAttribute(Attributes.LAYERTYPE).equalsIgnoreCase(request.getFormat().getName()))
            throw new ActionException(this, "Bad Layer format "
                    + "(declared:"+ request.getFormat().getName()
                    + ", expected:"+layer.getAttribute(Attributes.LAYERTYPE) );

        // this attribute is read for moving the raster file to the destination directory, not for rasterization
        String mosaicDirPath = layer.getAttribute(UNREDDLayer.Attributes.MOSAICPATH);
        if( mosaicDirPath == null) {
            throw new ActionException(this, "Null mosaic directory for layer: '" + layername + "'... check the layer configuration on geostore");
        }

        File mosaicDir = new File(mosaicDirPath);
        if( ! mosaicDir.isDirectory() && ! mosaicDir.isAbsolute()) {
            throw new ActionException(this, "Bad mosaic directory for layer '" + layername + "': " + mosaicDir + " doesn't exist... create it or check the layer configuration on geostore");
        }

        // ******************
        // Check for LayerUpdate
        // ******************
        this.listenerForwarder.progressing(20, "Check for existing LayerUpdate in GeoStore");

        Resource existingLayerUpdate = null;
        try {
            existingLayerUpdate = geostore.searchLayerUpdate(layername, year, month, day);
        } catch (Exception e) {
            LOGGER.debug("Parameter : [layerSnapshot=" + layerUpdateName + "]");
            throw new ActionException(this, "Error searching for a LayerUpdate (layer:"+layername+" year:"+year+ " month:"+month+")", e);
        }

        if (existingLayerUpdate != null) {
            throw new ActionException(this, "LayerUpdate already exists (layer:"+layername+" year:"+year+ " month:"+month+")");
        }

        /********************************
         *
         * Image processing
         *
         *******************************/
        final File rasterFile;
        if (request.getFormat() == UNREDDFormat.VECTOR ) {
            rasterFile = processVector(dataFile, layername, year, month, day, layer, mosaicDir);

        } else {
            rasterFile = processRaster(dataFile, layer, mosaicDir, layername);

View Full Code Here

TOP

Related Classes of it.geosolutions.geobatch.unredd.script.model.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.