Search in sources :

Example 1 with Namespace

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

the class AppSchemaIsolatedWorkspacesMappingTest method testNullWorkspaceConfiguration.

/**
 * Isolated attribute must be false, names must match the default ones,
 * unique mapping names must not be generated.
 *
 * @throws IOException
 */
@Test
public void testNullWorkspaceConfiguration() throws IOException {
    AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, null);
    IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
    generator.generateMapping(reporter);
    assertEquals(STATIONS_WS_DEFAULT, generator.getMainNamespace().name());
    assertFalse((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
    assertEquals(STATIONS_WS_DEFAULT, generator.getMainWorkspace().name());
    assertFalse((boolean) generator.getMainWorkspace().getAttribute(Namespace.ISOLATED));
    boolean measurementsNsFound = false;
    for (Namespace ns : generator.getSecondaryNamespaces()) {
        if (MEASUREMENTS_NS_URI.equals(ns.getAttribute(Namespace.URI))) {
            measurementsNsFound = true;
            assertEquals(MEASUREMENTS_WS_DEFAULT, ns.name());
            assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
            assertEquals(MEASUREMENTS_WS_DEFAULT, generator.getWorkspace(ns).name());
            assertFalse((boolean) generator.getWorkspace(ns).getAttribute(Namespace.ISOLATED));
        }
    }
    assertTrue(measurementsNsFound);
    List<FeatureTypeMapping> typeMappings = generator.getGeneratedMapping().getAppSchemaMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(2, typeMappings.size());
    for (FeatureTypeMapping typeMapping : typeMappings) {
        assertTrue(Strings.isNullOrEmpty(typeMapping.getMappingName()));
    }
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) Test(org.junit.Test)

Example 2 with Namespace

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

the class NamespaceResourceTest method testSerializeWithId.

/**
 * Tests the correct serialization of a namespace resource whose {@code id}
 * attribute is set.
 *
 * @throws Exception if an error occurs parsing the resource as XML
 */
@Test
public void testSerializeWithId() throws Exception {
    Namespace testNamespace = ResourceBuilder.namespace(TEST_PREFIX).setAttribute(Namespace.URI, TEST_URI).setAttribute(Namespace.ID, TEST_ID).build();
    Document doc = parseResource(testNamespace);
    assertEquals(1, doc.getElementsByTagName(ELEMENT_NAMESPACE).getLength());
    Node namespaceEl = doc.getElementsByTagName(ELEMENT_NAMESPACE).item(0);
    Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put(ELEMENT_ID, TEST_ID);
    expectedValues.put(ELEMENT_PREFIX, TEST_PREFIX);
    expectedValues.put(ELEMENT_URI, TEST_URI);
    expectedValues.put(ELEMENT_ISOLATED, "false");
    checkResource(namespaceEl, expectedValues);
}
Also used : HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) Test(org.junit.Test)

Example 3 with Namespace

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

the class ResourceManagerIT method waitForGeoServer.

private static void waitForGeoServer() throws Exception {
    NamespaceManager nsMgr = new NamespaceManager(geoserverURL);
    Namespace ns = ResourceBuilder.namespace("it.geosolutions").build();
    nsMgr.setResource(ns);
    nsMgr.setCredentials(GEOSERVER_USER, GEOSERVER_PASSWORD);
    int num = 0, maxAttempts = 10;
    Exception lastException = null;
    while (num < maxAttempts) {
        try {
            if (nsMgr.exists()) {
                return;
            }
        } catch (Exception e) {
            lastException = e;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore
        }
    }
    if (lastException != null) {
        throw lastException;
    }
}
Also used : Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) MalformedURLException(java.net.MalformedURLException)

Example 4 with Namespace

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

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

the class AppSchemaMappingUploader method createNamespaceIfRequired.

private void createNamespaceIfRequired(NamespaceManager nsMgr, Namespace ns) {
    nsMgr.setResource(ns);
    if (!nsMgr.exists()) {
        nsMgr.create();
    } else {
        // check whether the attributes of the existent namespace match
        // those of the one being created; throw exeption if they don't
        Namespace existing = Namespace.fromDocument(nsMgr.read());
        throwIfAttributesDontMatch(ns, existing);
    }
}
Also used : Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace)

Aggregations

Namespace (eu.esdihumboldt.hale.io.geoserver.Namespace)11 Test (org.junit.Test)7 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)4 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)4 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)4 HashMap (java.util.HashMap)3 Document (org.w3c.dom.Document)3 Node (org.w3c.dom.Node)3 HashSet (java.util.HashSet)2 DataStore (eu.esdihumboldt.hale.io.geoserver.DataStore)1 FeatureType (eu.esdihumboldt.hale.io.geoserver.FeatureType)1 Layer (eu.esdihumboldt.hale.io.geoserver.Layer)1 Workspace (eu.esdihumboldt.hale.io.geoserver.Workspace)1 NamespaceManager (eu.esdihumboldt.hale.io.geoserver.rest.NamespaceManager)1 BufferedOutputStream (java.io.BufferedOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1