Search in sources :

Example 1 with DataStoreFile

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());
}
Also used : FeatureType(eu.esdihumboldt.hale.io.geoserver.FeatureType) ContentType(org.apache.http.entity.ContentType) DataStoreFile(eu.esdihumboldt.hale.io.geoserver.DataStoreFile) HashMap(java.util.HashMap) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) AbstractDockerTest(eu.esdihumboldt.hale.common.test.docker.AbstractDockerTest) Test(org.junit.Test)

Example 2 with DataStoreFile

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

DataStoreFile (eu.esdihumboldt.hale.io.geoserver.DataStoreFile)2 HashMap (java.util.HashMap)2 ContentType (org.apache.http.entity.ContentType)2 AbstractDockerTest (eu.esdihumboldt.hale.common.test.docker.AbstractDockerTest)1 DataStore (eu.esdihumboldt.hale.io.geoserver.DataStore)1 FeatureType (eu.esdihumboldt.hale.io.geoserver.FeatureType)1 Workspace (eu.esdihumboldt.hale.io.geoserver.Workspace)1 DataStoreFileManager (eu.esdihumboldt.hale.io.geoserver.rest.DataStoreFileManager)1 DataStoreManager (eu.esdihumboldt.hale.io.geoserver.rest.DataStoreManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1