Search in sources :

Example 6 with Workspace

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();
}
Also used : HashMap(java.util.HashMap) Workspace(eu.esdihumboldt.hale.io.geoserver.Workspace)

Example 7 with Workspace

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);
}
Also used : HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Workspace(eu.esdihumboldt.hale.io.geoserver.Workspace) Test(org.junit.Test)

Example 8 with Workspace

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);
}
Also used : ContentType(org.apache.http.entity.ContentType) DataStoreFile(eu.esdihumboldt.hale.io.geoserver.DataStoreFile) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DataStore(eu.esdihumboldt.hale.io.geoserver.DataStore) DataStoreFileManager(eu.esdihumboldt.hale.io.geoserver.rest.DataStoreFileManager) DataStoreManager(eu.esdihumboldt.hale.io.geoserver.rest.DataStoreManager) Workspace(eu.esdihumboldt.hale.io.geoserver.Workspace)

Aggregations

Workspace (eu.esdihumboldt.hale.io.geoserver.Workspace)8 HashMap (java.util.HashMap)5 Test (org.junit.Test)3 Document (org.w3c.dom.Document)3 Node (org.w3c.dom.Node)3 DataStore (eu.esdihumboldt.hale.io.geoserver.DataStore)2 Namespace (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)1 DataStoreFile (eu.esdihumboldt.hale.io.geoserver.DataStoreFile)1 FeatureType (eu.esdihumboldt.hale.io.geoserver.FeatureType)1 Layer (eu.esdihumboldt.hale.io.geoserver.Layer)1 Namespace (eu.esdihumboldt.hale.io.geoserver.Namespace)1 DataStoreFileManager (eu.esdihumboldt.hale.io.geoserver.rest.DataStoreFileManager)1 DataStoreManager (eu.esdihumboldt.hale.io.geoserver.rest.DataStoreManager)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ContentType (org.apache.http.entity.ContentType)1