use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class AppSchemaMappingGenerator method getAppSchemaDataStore.
/**
* Returns the generated app-schema datastore configuration.
*
* @return the generated datastore configuration
* @throws IllegalStateException if no app-schema mapping configuration has
* been generated yet or if no target schema is available
*/
public eu.esdihumboldt.hale.io.geoserver.DataStore getAppSchemaDataStore() {
checkMappingGenerated();
checkTargetSchemaAvailable();
eu.esdihumboldt.hale.io.geoserver.Namespace ns = getMainNamespace();
Workspace ws = getMainWorkspace();
String workspaceId = (String) ws.getAttribute(Workspace.ID);
String dataStoreName = extractSchemaName(targetSchema.getLocation());
String dataStoreId = dataStoreName + "_datastore";
String mappingFileName = dataStoreName + ".xml";
Map<String, String> connectionParameters = new HashMap<String, String>();
connectionParameters.put("uri", (String) ns.getAttribute(eu.esdihumboldt.hale.io.geoserver.Namespace.URI));
connectionParameters.put("workspaceName", ws.name());
connectionParameters.put("mappingFileName", mappingFileName);
return ResourceBuilder.dataStore(dataStoreName, AppSchemaDataStore.class).setAttribute(eu.esdihumboldt.hale.io.geoserver.DataStore.ID, dataStoreId).setAttribute(eu.esdihumboldt.hale.io.geoserver.DataStore.WORKSPACE_ID, workspaceId).setAttribute(eu.esdihumboldt.hale.io.geoserver.DataStore.CONNECTION_PARAMS, connectionParameters).build();
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class WorkspaceResourceTest method testSerializeDefault.
/**
* Tests the correct serialization of a workspace resource where only
* {@code name} is set.
*
* @throws Exception if an error occurs parsing the resource as XML
*/
@Test
public void testSerializeDefault() throws Exception {
Workspace testWorkspace = ResourceBuilder.workspace(TEST_NAME).build();
Document doc = parseResource(testWorkspace);
assertEquals(1, doc.getElementsByTagName(ELEMENT_WORKSPACE).getLength());
Node workspaceEl = doc.getElementsByTagName(ELEMENT_WORKSPACE).item(0);
Map<String, String> expectedValues = new HashMap<>();
expectedValues.put(ELEMENT_NAME, TEST_NAME);
expectedValues.put(ELEMENT_ISOLATED, "false");
checkResource(workspaceEl, expectedValues);
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace 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