Package it.geosolutions.geostore.services.rest.model

Examples of it.geosolutions.geostore.services.rest.model.RESTResource


     *
     * @param resource the source Resource
     * @return
     */
    public static RESTResource copyResource(Resource resource) {
        RESTResource ret = new RESTResource();
        ret.setName(resource.getName());
        ret.setDescription(resource.getDescription());
        ret.setMetadata(resource.getMetadata());
        if(resource.getData() != null)
            ret.setData(resource.getData().getData());
        ret.setCategory(new RESTCategory(resource.getCategory().getName()));
        copyResourceAttribs(resource, ret);
        return ret;
    }
View Full Code Here


        //=== COPY LAYER

        Resource dstLayer = dstGeostore.searchLayer(layerName);
        if( dstLayer == null) {
            LOGGER.info("Copying Layer into destination: " + srcLayer);
            RESTResource layer = FlowUtil.copyResource(srcLayer);
            dstGeostore.insert(layer);
        }

        //==================================================
        //=== LAYERUPDATE
        //===
        //=== Insert LayerUpdate if it does not exist

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

        //=== COPY LAYERUPDATE

        Resource dstLayerUpdate = dstGeostore.searchLayerUpdate(layerName, year, month, day);
        if ( dstLayerUpdate == null ) {
            LOGGER.info("Copying LayerUpdate " + layerName+":"+year+":"+month);

            RESTResource layerUpdate = FlowUtil.copyResource(srcLayerUpdate);
            dstGeostore.insert(layerUpdate);
        }

        //==================================================
        //=== STATS
        //===
        //=== loop on all the statistics associated with the layer

        Map<Long, Resource> srcChartScripts = new HashMap<Long, Resource>();

        List<ShortResource> statsDefList = srcGeostore.searchStatsDefByLayer(layerName, true); // may be empty, is always not null

        for (ShortResource statDef : statsDefList) {
            String statsDefName = statDef.getName();
            LOGGER.info("Found stats def :" + statsDefName);

            //=== OVERWRITE STATSDEF

            Resource dstStatsDef = dstGeostore.searchStatsDefByName(statsDefName);
            if(dstStatsDef != null) {
                LOGGER.info("Removing previous StatsDef " + statsDefName);
                dstGeostore.delete(dstStatsDef.getId());
            }

            LOGGER.info("Copying StatsDef " + statsDefName);
            Resource srcStatsDef = srcGeostore.searchStatsDefByName(statsDefName);
            RESTResource statsDef = FlowUtil.copyResource(srcStatsDef);
            dstGeostore.insert(statsDef);

            //=== OVERWRITE STATSDATA

            Resource dstStatsData = dstGeostore.searchStatsData(statsDefName, year, month, day);
            if(dstStatsData != null) {
                LOGGER.info("Removing previous StatsData [statsdef:"+statsDefName+" year:"+year+" month:"+month+"]");
                dstGeostore.delete(dstStatsData.getId());
            }

            Resource srcStatsData = srcGeostore.searchStatsData(statsDefName, year, month, day);
            if (srcStatsData == null) {
                LOGGER.warn("No StatsData found for [statsdef:"+statsDefName+" year:"+year+" month:"+month+"]");
            } else {
                LOGGER.info("Copying StatsData " + srcStatsData.getName());
                RESTResource statsData = FlowUtil.copyResource(srcStatsData);
                dstGeostore.insert(statsData);
               
                // Add attribute Published=true to srcGeostore, usefull for staging admin application
              LOGGER.info("Adding attribute published=true to resource " + srcStatsData.getName());
              RESTResource statsDataTmp = FlowUtil.copyResource(srcStatsData);
              ShortAttribute published = new ShortAttribute(UNREDDLayerUpdate.Attributes.PUBLISHED.getName(), "true", DataType.STRING);
             
              //DamianoG workaround for search in list due to ShortAttribute don't override equals method
              boolean flag = true;
              for(ShortAttribute el : statsDataTmp.getAttribute()){
                if(el.toString().equals(published.toString())){
                  flag = false;
                  break;
                }
              }
             
            //if(!statsDataTmp.getAttribute().contains(published)){
              if(flag){
                List<ShortAttribute> l = new ArrayList<ShortAttribute>();
                l.add(published);
                l.addAll(statsDataTmp.getAttribute());
                statsDataTmp.setAttribute(l);
                srcGeostore.delete(srcStatsData.getId());
                srcGeostore.insert(statsDataTmp);
              }
            }

            // Collect dependant chartscript to be copied
            List<Resource> csList = srcGeostore.searchChartScriptByStatsDef(statsDefName);
            for (Resource cs : csList) {
                LOGGER.info("Collecting ChartScript: adding " + cs.getName());
                srcChartScripts.put(cs.getId(), cs);
            }
          
           
        }

        //==================================================
        //=== CHARTS
        //===
        //=== loop on all the collected charts

        for (Resource srcChartScript : srcChartScripts.values()) {
            String chartScriptName = srcChartScript.getName();
            LOGGER.info("Removing previous charts stuff: " + chartScriptName);

            //== remove chartScript
            Resource dstChartScript = dstGeostore.searchChartScript(chartScriptName);
            if(dstChartScript != null) {
                LOGGER.info("Removing previous ChartScript :"+ chartScriptName);
                dstGeostore.delete(dstChartScript.getId());
            }

            //== remove chartData
            List<ShortResource> dstChartDataList = dstGeostore.searchChartDataByChartScript(chartScriptName);
            for (ShortResource dstChartData : dstChartDataList) {
                LOGGER.info("Removing previous ChartData :"+ dstChartData.getName() + " [cscript:" + chartScriptName+ ']');
                dstGeostore.delete(dstChartData.getId());
            }

            //== Insert chartScript
            LOGGER.info("Copying ChartScript " + chartScriptName);
            RESTResource chartScript = FlowUtil.copyResource(srcChartScript);
            dstGeostore.insert(chartScript);

            //DamianoG commented due to chartData must be recalculated not copyed from staging
            //== Insert chartData
//            List<Resource> srcChartDataList = srcGeostore.searchChartDataPublished(chartScriptName);
View Full Code Here

    @Ignore
    public void testBadFormat() throws GeoStoreException, FlowException, ActionException {
        clearPlayfield();
        UNREDDLayer layer = buildRasterLayer();
        layer.setAttribute(UNREDDLayer.Attributes.LAYERTYPE, UNREDDFormat.VECTOR.getName());
        RESTResource layerResource = layer.createRESTResource();
        layerResource.setName("layer1");
        gstcu.insert(layerResource);

        //=== Data is set, prepare flow
        LOGGER.info("===== Run the code!");
        File inputFile = loadFile("context/Request.zip");
View Full Code Here

    @Ignore
    public void testBadSize() throws GeoStoreException, FlowException, ActionException {
        clearPlayfield();
        UNREDDLayer layer = buildRasterLayer();
        layer.setAttribute(UNREDDLayer.Attributes.RASTERPIXELWIDTH, "42");
        RESTResource layerResource = layer.createRESTResource();
        layerResource.setName("layer1");
        gstcu.insert(layerResource);

        //=== Data is set, prepare flow
        LOGGER.info("===== Run the code!");
        File inputFile = loadFile("context/Request.zip");
View Full Code Here

    @Test
    @Ignore
    public void testBadExistingLayerUpdate() throws GeoStoreException, FlowException, ActionException {
        clearPlayfield();
        UNREDDLayer layer = buildRasterLayer();
        RESTResource layerResource = layer.createRESTResource();
        layerResource.setName("layer1");
        gstcu.insert(layerResource);

        UNREDDLayerUpdate layerUpdate = new UNREDDLayerUpdate();
        layerUpdate.setAttribute(Attributes.YEAR, "2012");
        layerUpdate.setAttribute(Attributes.LAYER, "layer1");
        RESTResource luResource = layerUpdate.createRESTResource();
        luResource.setName(NameUtils.buildLayerUpdateName("layer1", "2012", null, null));
        gstcu.insert(luResource);

        //=== Data is set, prepare flow
        LOGGER.info("===== Run the code!");
        File inputFile = loadFile("context/Request.zip");
View Full Code Here

    @Test
    public void testProperIngestRaster() throws GeoStoreException, FlowException, ActionException {

        clearPlayfield();
        UNREDDLayer layer = buildRasterLayer();
        RESTResource layerResource = layer.createRESTResource();
        layerResource.setName("layer1");
        gstcu.insert(layerResource);
       
        //=== Data is set, prepare flow
        LOGGER.info("===== Run the code!");
        File inputFile = loadFile("context/Request.zip");
View Full Code Here

    @Test
    public void testProperIngestVector() throws GeoStoreException, FlowException, ActionException {

        clearPlayfield();
        UNREDDLayer layer = buildVectorLayer();
        RESTResource layerResource = layer.createRESTResource();
        layerResource.setName("layer1");
        gstcu.insert(layerResource);

        //=== Data is set, prepare flow
        LOGGER.info("===== Run the code!");
        File inputFile = loadFile("context/RequestSHP.zip");
View Full Code Here

    return ret;
  }


    protected void doDelete(File xmlResourceFile) throws JAXBException, IOException {
        RESTResource restResource = (RESTResource) unmarshaller.unmarshal(xmlResourceFile);
        geostore.deleteResource(restResource.getId());       
    }
View Full Code Here

    }
 

    protected File doInsert(File xmlResourceFile) throws JAXBException, IOException {

        RESTResource restResource = (RESTResource) unmarshaller.unmarshal(xmlResourceFile);
        long resourceId = geostore.insert(restResource);
       
        Resource resource = geostore.getResource(resourceId);
        File outputInsertFile = File.createTempFile("gstinsert_", xmlResourceFile.getName(), getTempDir());
       
View Full Code Here

        return outputInsertFile;
    }
       
    protected File doUpdateData(File xmlResourceFile) throws JAXBException, IOException {

        RESTResource restResource = (RESTResource) unmarshaller.unmarshal(xmlResourceFile);
        long id = restResource.getId();
        String data = restResource.getStore().getData();
        geostore.setData(id, data);
        Resource resource = geostore.getResource(id);
        File outputInsertFile = File.createTempFile("gstupdate_", xmlResourceFile.getName(), getTempDir());
        Marshaller m = JAXBMarshallerBuilder.getJAXBMarshaller(resource.getClass());
        m.marshal(resource, outputInsertFile);
View Full Code Here

TOP

Related Classes of it.geosolutions.geostore.services.rest.model.RESTResource

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.