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;
}
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())));
}
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);
}
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;
}
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;
}
Aggregations