package org.gcube.application.cms.sdi.model; import freemarker.core.PlainTextOutputFormat; import lombok.Getter; import org.bson.Document; import org.gcube.application.geoportal.common.model.document.filesets.GCubeSDILayer; import sun.misc.GC; import javax.print.Doc; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class GCubeSDILayerBuilder { public static enum OGC_TYPE{ wms,wfs,wcs,csw } public static final String EPSG_4326="EPSG:4326"; public static final String WGS84_FULL="GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],"+ "AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295],"+ "AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]]"; public static final String GS_PLATFORM="Geoserver"; GCubeSDILayer theObject = new GCubeSDILayer(); @Getter Document platformInfo= new Document(GCubeSDILayer.PLATFORM_INFO,GS_PLATFORM); @Getter GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.WORLD; @Getter Map ogcLinks = new HashMap<>(); public GCubeSDILayerBuilder(){ } public GCubeSDILayer getLayer(){ theObject.put(GCubeSDILayer.PLATFORM_INFO,platformInfo); theObject.put(GCubeSDILayer.B_BOX,bbox); prepareOGCLinks(); theObject.put(GCubeSDILayer.OGC_LINKS,ogcLinks); return theObject; } // @@@@@@@@@@@@@@@@@@ Platform info public GCubeSDILayerBuilder setWorkspace(String ws){ platformInfo.put("workspace",ws); return this; } public GCubeSDILayerBuilder setHost(String ws){ platformInfo.put("host",ws); return this; } public GCubeSDILayerBuilder setEngineVersion(String ws){ platformInfo.put("engineVersion",ws); return this; } public GCubeSDILayerBuilder setLayerName(String ws){ platformInfo.put("layerName",ws); return this; } public GCubeSDILayerBuilder setPersistencePath(String ws){ platformInfo.put("persistencePath",ws); return this; } public GCubeSDILayerBuilder setStoreName(String ws){ platformInfo.put("storeName",ws); return this; } public GCubeSDILayerBuilder setFiles(List ws){ platformInfo.put("files",ws); return this; } private void prepareOGCLinks(){ if(!ogcLinks.containsKey(OGC_TYPE.wms)){ addLink(OGC_TYPE.wms,String.format("https://%1$s/geoserver/%2$s/wms?" + "service=WMS&version=1.1.0&request=GetMap&layers=%2$s:%3$s&" + "styles=&bbox=%4$f,%5$f,%6$f,%7$f&srs=%8$s&format=application/openlayers&width=%9$d&height=%10$d", platformInfo.get("host"), platformInfo.get("workspace"), platformInfo.get("layerName"), bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), EPSG_4326, 400, 400)); } } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@ OGC public GCubeSDILayerBuilder addLink(OGC_TYPE type,String link){ ogcLinks.put(type,new Document(type.name(),link)); return this; } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@ BBOX }