Search in sources :

Example 1 with FeatureType

use of eu.esdihumboldt.hale.io.geoserver.FeatureType 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 FeatureType

use of eu.esdihumboldt.hale.io.geoserver.FeatureType in project hale by halestudio.

the class AppSchemaMappingFileWriter method writeArchive.

private void writeArchive(ProgressIndicator progress, IOReporter reporter) throws IOException {
    Workspace ws = generator.getMainWorkspace();
    Namespace mainNs = generator.getMainNamespace();
    DataStore ds = generator.getAppSchemaDataStore();
    // save to archive
    final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(getTarget().getOutput()));
    // add workspace folder
    ZipEntry workspaceFolder = new ZipEntry(ws.getAttribute(Workspace.NAME) + "/");
    zip.putNextEntry(workspaceFolder);
    // add workspace file
    zip.putNextEntry(new ZipEntry(workspaceFolder.getName() + WORKSPACE_FILE));
    copyAndCloseInputStream(ws.asStream(), zip);
    zip.closeEntry();
    // add namespace file
    zip.putNextEntry(new ZipEntry(workspaceFolder.getName() + NAMESPACE_FILE));
    copyAndCloseInputStream(mainNs.asStream(), zip);
    zip.closeEntry();
    // add datastore folder
    ZipEntry dataStoreFolder = new ZipEntry(workspaceFolder.getName() + ds.getAttribute(DataStore.NAME) + "/");
    zip.putNextEntry(dataStoreFolder);
    // add datastore file
    zip.putNextEntry(new ZipEntry(dataStoreFolder.getName() + DATASTORE_FILE));
    copyAndCloseInputStream(ds.asStream(), zip);
    zip.closeEntry();
    // add target schema to zip
    if (getIncludeSchemaParameter()) {
        addTargetSchemaToZip(zip, dataStoreFolder, progress, reporter);
    }
    // add main mapping file
    Map<String, String> connectionParams = ds.getConnectionParameters();
    zip.putNextEntry(new ZipEntry(dataStoreFolder.getName() + connectionParams.get("mappingFileName")));
    generator.writeMappingConf(zip);
    zip.closeEntry();
    // add included types mapping file, if necessary
    if (generator.getGeneratedMapping().requiresMultipleFiles()) {
        zip.putNextEntry(new ZipEntry(dataStoreFolder.getName() + AppSchemaIO.INCLUDED_TYPES_MAPPING_FILE));
        generator.writeIncludedTypesMappingConf(zip);
        zip.closeEntry();
    }
    // add feature type entries
    List<FeatureType> featureTypes = generator.getFeatureTypes();
    for (FeatureType ft : featureTypes) {
        Layer layer = generator.getLayer(ft);
        // add feature type folder
        ZipEntry featureTypeFolder = new ZipEntry(dataStoreFolder.getName() + ft.getAttribute(FeatureType.NAME) + "/");
        zip.putNextEntry(featureTypeFolder);
        // add feature type file
        zip.putNextEntry(new ZipEntry(featureTypeFolder.getName() + FEATURETYPE_FILE));
        copyAndCloseInputStream(ft.asStream(), zip);
        zip.closeEntry();
        // add layer file
        zip.putNextEntry(new ZipEntry(featureTypeFolder.getName() + LAYER_FILE));
        copyAndCloseInputStream(layer.asStream(), zip);
        zip.closeEntry();
    }
    // add secondary namespaces
    List<Namespace> secondaryNamespaces = generator.getSecondaryNamespaces();
    for (Namespace secNs : secondaryNamespaces) {
        Workspace secWs = generator.getWorkspace(secNs);
        // add workspace folder
        ZipEntry secondaryWorkspaceFolder = new ZipEntry(secWs.name() + "/");
        zip.putNextEntry(secondaryWorkspaceFolder);
        // add workspace file
        zip.putNextEntry(new ZipEntry(secondaryWorkspaceFolder.getName() + WORKSPACE_FILE));
        copyAndCloseInputStream(secWs.asStream(), zip);
        zip.closeEntry();
        // add namespace file
        zip.putNextEntry(new ZipEntry(secondaryWorkspaceFolder.getName() + NAMESPACE_FILE));
        copyAndCloseInputStream(secNs.asStream(), zip);
        zip.closeEntry();
    }
    zip.close();
}
Also used : FeatureType(eu.esdihumboldt.hale.io.geoserver.FeatureType) ZipOutputStream(java.util.zip.ZipOutputStream) DataStore(eu.esdihumboldt.hale.io.geoserver.DataStore) ZipEntry(java.util.zip.ZipEntry) BufferedOutputStream(java.io.BufferedOutputStream) Layer(eu.esdihumboldt.hale.io.geoserver.Layer) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) Workspace(eu.esdihumboldt.hale.io.geoserver.Workspace)

Example 3 with FeatureType

use of eu.esdihumboldt.hale.io.geoserver.FeatureType in project hale by halestudio.

the class AppSchemaMappingGenerator method getFeatureTypes.

/**
 * Returns the generated feature type configuration for all mapped feature
 * types.
 *
 * @return the generated feature type configuration
 */
public List<FeatureType> getFeatureTypes() {
    checkMappingGenerated();
    eu.esdihumboldt.hale.io.geoserver.DataStore dataStore = getAppSchemaDataStore();
    List<FeatureType> featureTypes = new ArrayList<FeatureType>();
    // .getFeatureTypeMapping()) {
    for (FeatureTypeMapping ftMapping : mainMapping.getTypeMappings().getFeatureTypeMapping()) {
        featureTypes.add(getFeatureType(dataStore, ftMapping));
    }
    return featureTypes;
}
Also used : FeatureType(eu.esdihumboldt.hale.io.geoserver.FeatureType) ArrayList(java.util.ArrayList) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Aggregations

FeatureType (eu.esdihumboldt.hale.io.geoserver.FeatureType)3 AbstractDockerTest (eu.esdihumboldt.hale.common.test.docker.AbstractDockerTest)1 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)1 DataStore (eu.esdihumboldt.hale.io.geoserver.DataStore)1 DataStoreFile (eu.esdihumboldt.hale.io.geoserver.DataStoreFile)1 Layer (eu.esdihumboldt.hale.io.geoserver.Layer)1 Namespace (eu.esdihumboldt.hale.io.geoserver.Namespace)1 Workspace (eu.esdihumboldt.hale.io.geoserver.Workspace)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ContentType (org.apache.http.entity.ContentType)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1