Search in sources :

Example 1 with WFSService

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

the class TemplateResource method makeItemsFromLayer.

private List<Item> makeItemsFromLayer(Item template, String layerId, LayerManager layerMan) throws IOException {
    List<Item> items = new LinkedList<>();
    Layer layer = layerMan.load(layerId);
    WFSService wfs = (WFSService) Service.ogcHelper(Service.ServiceType.proxy_wfs, layer.getServices());
    List<String> attrs = WFSIntrospector.getAttrs(wfs);
    for (String attr : attrs) {
        if (Attributes.contains(attr)) {
            Summary summary = makeSummary(layer, attr);
            Item item = templateItem(template, attr, layer, summary);
            items.add(item);
        }
    }
    return items;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) Layer(gov.usgs.cida.coastalhazards.model.Layer) LinkedList(java.util.LinkedList)

Example 2 with WFSService

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

the class DataDomainUtility method retrieveDomainFromWFS.

public static SortedSet<String> retrieveDomainFromWFS(Item item) {
    SortedSet<String> domain = new TreeSet<>();
    WFSGetDomain client = new WFSGetDomain();
    if (item == null) {
        throw new IllegalArgumentException("Item must be valid data item");
    } else if (item.getItemType() == Item.ItemType.aggregation || item.getItemType() == Item.ItemType.template) {
        List<String> displayedIds = item.getDisplayedChildren();
        for (Item child : item.getChildren()) {
            if (displayedIds.contains(child.getId())) {
                // recurse (again, avoiding cycles is important)
                Set<String> childDomain = retrieveDomainFromWFS(child);
                domain.addAll(childDomain);
            }
        }
    } else if (item.getItemType() == Item.ItemType.data) {
        WFSService service = item.fetchWfsService();
        try {
            Set<String> domainValuesAsStrings = client.getDomainValuesAsStrings(service, item.getAttr());
            domain.addAll(domainValuesAsStrings);
        } catch (IOException e) {
            log.error("unable to get domain from wfs", e);
        }
    }
    return domain;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) TreeSet(java.util.TreeSet) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) List(java.util.List) IOException(java.io.IOException)

Example 3 with WFSService

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

the class DownloadUtility method getWfsService.

/**
 * Replaces item.getWfsService() after services were added to list
 *
 * @param item
 * @return source wfsService representing the canonical dataset
 */
private static WFSService getWfsService(Item item) {
    WFSService sourceWfs = null;
    List<Service> services = item.getServices();
    for (Service service : services) {
        if (service.getType() == ServiceType.proxy_wfs) {
            sourceWfs = new WFSService(service);
        }
    }
    return sourceWfs;
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Service(gov.usgs.cida.coastalhazards.model.Service) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with WFSService

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

the class DownloadUtility method populateDownloadMap.

private static void populateDownloadMap(Map<WFSService, SingleDownload> downloadMap, Item item) {
    SingleDownload download;
    Queue<Item> itemQueue = new LinkedList<>();
    itemQueue.add(item);
    // (i.e. an item that sees itself in the subtree throws an exception)
    while (itemQueue.peek() != null) {
        Item currentItem = itemQueue.poll();
        WFSService wfs = getWfsService(currentItem);
        if (wfs != null && wfs.checkValidity()) {
            if (downloadMap.containsKey(wfs)) {
                download = downloadMap.get(wfs);
            } else {
                download = new SingleDownload();
                download.setWfs(wfs);
                download.setName(currentItem.getName());
                try {
                    URL cswUrl = currentItem.fetchCswService().fetchUrl();
                    download.setMetadata(cswUrl);
                } catch (MalformedURLException ex) {
                    LOG.info("Invalid csw url {}", currentItem.fetchCswService());
                } catch (NullPointerException ex) {
                    LOG.info("CSW service not set");
                }
                downloadMap.put(wfs, download);
            }
            String attr = currentItem.getAttr();
            if (StringUtils.isNotBlank(attr)) {
                download.addAttr(attr);
            }
        }
        List<Item> children = currentItem.getChildren();
        if (children != null) {
            itemQueue.addAll(children);
        }
    }
}
Also used : SessionItem(gov.usgs.cida.coastalhazards.model.SessionItem) Item(gov.usgs.cida.coastalhazards.model.Item) MalformedURLException(java.net.MalformedURLException) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 5 with WFSService

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

the class SingleDownloadTest method quickStagingTest.

/**
 * Same problem with external resource, but this is good for gutcheck test
 * @throws IOException
 */
@Test
@Ignore
public void quickStagingTest() throws IOException {
    List<String> missing = new LinkedList<>();
    SingleDownload singleDownload = new SingleDownload();
    singleDownload.setName("test");
    WFSService wfs = new WFSService();
    wfs.setEndpoint("http://cidasddvascch.cr.usgs.gov:8081/geoserver/wfs");
    wfs.setTypeName("proxied:sandy_example");
    singleDownload.setWfs(wfs);
    singleDownload.addAttr("PCOL");
    singleDownload.addAttr("POVW");
    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)

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