use of eu.esdihumboldt.hale.io.geoserver.DataStoreFile in project hale by halestudio.
the class ResourceManagerIT method testConfigArchiveUpload.
@Test
public void testConfigArchiveUpload() throws Exception {
// build mapping file resource
ContentType contentType = DataStoreFile.ZIP_CONTENT_TYPE;
InputStream is = getClass().getResourceAsStream(APP_SCHEMA_CONFIG_ARCHIVE);
DataStoreFile configArchive = ResourceBuilder.dataStoreFile(is, contentType).setAttribute(DataStoreFile.EXTENSION, "appschema").setAttribute(DataStoreFile.DATASTORE, ds.name()).setAttribute(DataStoreFile.WORKSPACE, ns.name()).build();
DataStoreFileManager dsFileMgr = new DataStoreFileManager(geoserverURL);
dsFileMgr.setCredentials(GEOSERVER_USER, GEOSERVER_PASSWORD);
dsFileMgr.setResource(configArchive);
// upload mapping configuration (datastore is created implicitly)
Map<String, String> updateParams = new HashMap<String, String>();
updateParams.put("configure", "all");
dsFileMgr.update(updateParams);
// verify datastore was created
DataStoreManager dsMgr = createDataStoreManager();
Document listDoc = dsMgr.list();
assertEquals("dataStores", listDoc.getDocumentElement().getNodeName());
NodeList dataStoreNodes = listDoc.getElementsByTagName("dataStore");
assertEquals(1, dataStoreNodes.getLength());
NodeList dataStoreChildren = dataStoreNodes.item(0).getChildNodes();
for (int i = 0; i < dataStoreChildren.getLength(); i++) {
Node child = dataStoreChildren.item(i);
if ("name".equals(child.getNodeName())) {
assertEquals(APP_SCHEMA_DATASTORE, child.getTextContent());
break;
}
}
// check feature types were created
FeatureType lcd = ResourceBuilder.featureType("LandCoverDataset").build();
FeatureType lcu = ResourceBuilder.featureType("LandCoverUnit").build();
FeatureTypeManager ftMgr = new FeatureTypeManager(geoserverURL);
ftMgr.setCredentials(GEOSERVER_USER, GEOSERVER_PASSWORD);
ftMgr.setWorkspace(ns.name());
ftMgr.setDataStore(ds.name());
ftMgr.setResource(lcd);
assertTrue(ftMgr.exists());
ftMgr.setResource(lcu);
assertTrue(ftMgr.exists());
}
use of eu.esdihumboldt.hale.io.geoserver.DataStoreFile in project hale by halestudio.
the class AppSchemaMappingUploader method publishAppSchemaDataStore.
private void publishAppSchemaDataStore(ProgressIndicator progress, IOReporter reporter) throws IOException {
Workspace ws = generator.getMainWorkspace();
// build datastore resource
DataStore dataStore = generator.getAppSchemaDataStore();
DataStoreManager dsMgr = new DataStoreManager(geoserverURL);
dsMgr.setCredentials(username, password);
dsMgr.setResource(dataStore);
dsMgr.setWorkspace(ws.name());
// remove datastore, if necessary
if (dsMgr.exists()) {
Map<String, String> deleteParams = new HashMap<String, String>();
deleteParams.put("recurse", "true");
dsMgr.delete(deleteParams);
}
// build mapping file resource
ContentType contentType = getMimeType();
byte[] content = writeContent(dataStore.name(), contentType, progress, reporter);
DataStoreFile mappingFile = ResourceBuilder.dataStoreFile(new ByteArrayInputStream(content), contentType).setAttribute(DataStoreFile.EXTENSION, "appschema").setAttribute(DataStoreFile.DATASTORE, dataStore.name()).setAttribute(DataStoreFile.WORKSPACE, ws.name()).build();
DataStoreFileManager dsFileMgr = new DataStoreFileManager(geoserverURL);
dsFileMgr.setCredentials(username, password);
dsFileMgr.setResource(mappingFile);
Map<String, String> updateParams = new HashMap<String, String>();
updateParams.put("configure", "all");
dsFileMgr.update(updateParams);
}
Aggregations