Search in sources :

Example 6 with WFSService

use of gov.usgs.cida.coastalhazards.util.ogc.WFSService in project coastal-hazards by USGS-CIDA.

the class DownloadUtility method stageSessionDownload.

/**
 * TODO stage all the items with some smarts about naming and such
 *
 * @param stageThis
 * @param stagingDir
 * @return
 * @throws java.io.IOException
 */
public static boolean stageSessionDownload(Session stageThis, File stagingDir) throws IOException, ConcurrentModificationException {
    boolean success = false;
    lock(stagingDir);
    List<String> missing = new LinkedList<>();
    try {
        Map<WFSService, SingleDownload> downloadMap = new HashMap<>(stageThis.getItems().size());
        for (SessionItem sessionItem : stageThis.getItems()) {
            Item item;
            try (ItemManager itemManager = new ItemManager()) {
                item = itemManager.load(sessionItem.getItemId());
            }
            populateDownloadMap(downloadMap, item);
        }
        List<String> namesUsed = new ArrayList<>(downloadMap.size());
        for (SingleDownload stagedDownload : downloadMap.values()) {
            while (namesUsed.contains(stagedDownload.getName())) {
                stagedDownload.incrementName();
            }
            namesUsed.add(stagedDownload.getName());
            // TODO try/catch this to isolate/retry problem downloads?
            boolean stage = stagedDownload.stage(stagingDir, missing);
            success = success || stage;
        }
    } finally {
        writeMissingFile(stagingDir, missing);
        writeReadmeFile(stagingDir);
        unlock(stagingDir);
    }
    return success;
}
Also used : SessionItem(gov.usgs.cida.coastalhazards.model.SessionItem) Item(gov.usgs.cida.coastalhazards.model.Item) SessionItem(gov.usgs.cida.coastalhazards.model.SessionItem) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 7 with WFSService

use of gov.usgs.cida.coastalhazards.util.ogc.WFSService in project coastal-hazards by USGS-CIDA.

the class WFSGetDomainTest method testGetDomainValuesAsStrings.

/**
 * Test of getDomainValuesAsStrings method, of class WFSGetDomain.
 */
@Test
// ignoring until I can actually mock this sort of thing out
@Ignore
public void testGetDomainValuesAsStrings() throws Exception {
    WFSService service = new WFSService();
    service.setEndpoint("https://marine.usgs.gov/coastalchangehazardsportal/geoserver/proxied/ows");
    service.setTypeName("proxied:MauiK_shorelines");
    WFSGetDomain instance = new WFSGetDomain();
    Set<String> result = instance.getDomainValuesAsStrings(service, "DATE_");
    assertThat(19, is(equalTo(result.size())));
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with WFSService

use of gov.usgs.cida.coastalhazards.util.ogc.WFSService in project coastal-hazards by USGS-CIDA.

the class SingleDownloadTest method testRemoveSHAPELEN.

@Test
@Ignore
public void testRemoveSHAPELEN() throws IOException {
    List<String> missing = new LinkedList<>();
    SingleDownload singleDownload = new SingleDownload();
    singleDownload.setName("test");
    WFSService wfs = new WFSService();
    wfs.setEndpoint("http://olga.er.usgs.gov/stpgis/services/Vulnerability/GOM_erosion_hazards/MapServer/WFSServer");
    wfs.setTypeName("Vulnerability_GOM_erosion_hazards:Gulf_of_Mexico_Erosion_Hazards");
    singleDownload.setWfs(wfs);
    singleDownload.stage(DownloadUtility.createDownloadStagingArea(), missing);
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) LinkedList(java.util.LinkedList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with WFSService

use of gov.usgs.cida.coastalhazards.util.ogc.WFSService in project coastal-hazards by USGS-CIDA.

the class LayerResource method createVectorLayer.

@POST
@Path("/")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response createVectorLayer(@Context HttpServletRequest req, InputStream postBody) {
    Response response = null;
    String newId = IdGenerator.generate();
    List<Service> added = null;
    try {
        log.info("Vector layer upload - about to parseRequest");
        byte[] inmemory = IOUtils.toByteArray(postBody);
        try (ByteArrayInputStream bais = new ByteArrayInputStream(inmemory)) {
            log.info("Vector layer create - about to doCSWInsertFromString");
            String metadataId = MetadataUtil.doCSWInsertFromString(MetadataUtil.extractMetadataFromShp(bais));
            bais.reset();
            log.info("Vector layer create - about to do GeoserverUtil.addVectorLayer with Id: " + newId);
            added = GeoserverUtil.addVectorLayer(bais, newId);
            log.info("Vector layer create - about to makeCSWServiceForUrl with metadataId: " + metadataId);
            added.add(MetadataUtil.makeCSWServiceForUrl(MetadataUtil.getMetadataByIdUrl(metadataId)));
        } finally {
            // just in case
            inmemory = null;
        }
    } catch (IOException | ParserConfigurationException | SAXException | IllegalArgumentException e) {
        log.error("Problem creating services from input", e);
    }
    if (added != null && !added.isEmpty()) {
        WFSService wfs = (WFSService) Service.ogcHelper(Service.ServiceType.proxy_wfs, added);
        Bbox bbox = null;
        try {
            bbox = WFSIntrospector.getBbox(wfs);
        } catch (IOException ex) {
            log.debug("Error determining bounding box", ex);
        }
        Layer layer = new Layer();
        layer.setId(newId);
        layer.setServices(added);
        layer.setBbox(bbox);
        try (LayerManager manager = new LayerManager()) {
            manager.save(layer);
        }
        response = Response.created(layerURI(layer)).build();
    } else {
        response = Response.serverError().entity("Unable to create layer").build();
    }
    return response;
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Service(gov.usgs.cida.coastalhazards.model.Service) IOException(java.io.IOException) Layer(gov.usgs.cida.coastalhazards.model.Layer) SAXException(org.xml.sax.SAXException) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LayerManager(gov.usgs.cida.coastalhazards.jpa.LayerManager) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 10 with WFSService

use of gov.usgs.cida.coastalhazards.util.ogc.WFSService in project coastal-hazards by USGS-CIDA.

the class Item method fetchWfsService.

public WFSService fetchWfsService() {
    WFSService wfsService = null;
    OGCService ogc = fetchOgcService(ServiceType.proxy_wfs);
    if (ogc instanceof WFSService) {
        wfsService = (WFSService) ogc;
    }
    return wfsService;
}
Also used : OGCService(gov.usgs.cida.coastalhazards.util.ogc.OGCService) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService)

Aggregations

WFSService (gov.usgs.cida.coastalhazards.util.ogc.WFSService)10 LinkedList (java.util.LinkedList)5 Item (gov.usgs.cida.coastalhazards.model.Item)4 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 Layer (gov.usgs.cida.coastalhazards.model.Layer)2 Service (gov.usgs.cida.coastalhazards.model.Service)2 SessionItem (gov.usgs.cida.coastalhazards.model.SessionItem)2 IOException (java.io.IOException)2 ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)1 LayerManager (gov.usgs.cida.coastalhazards.jpa.LayerManager)1 Bbox (gov.usgs.cida.coastalhazards.model.Bbox)1 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)1 OGCService (gov.usgs.cida.coastalhazards.util.ogc.OGCService)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1