Search in sources :

Example 6 with Namespace

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

the class AppSchemaMappingUploader method publishNamespaces.

private void publishNamespaces() {
    NamespaceManager nsMgr = new NamespaceManager(geoserverURL);
    nsMgr.setCredentials(username, password);
    // check whether main namespace/workspace exists; if not, create it
    Namespace mainNs = generator.getMainNamespace();
    createNamespaceIfRequired(nsMgr, mainNs);
    // check whether secondary namespaces/workspaces exist; if not, create
    // them
    List<Namespace> secondaryNamespaces = generator.getSecondaryNamespaces();
    for (Namespace ns : secondaryNamespaces) {
        createNamespaceIfRequired(nsMgr, ns);
    }
}
Also used : NamespaceManager(eu.esdihumboldt.hale.io.geoserver.rest.NamespaceManager) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace)

Example 7 with Namespace

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

the class AppSchemaIsolatedWorkspacesMappingTest method testBothIsolated.

/**
 * Isolated attribute must be true, names must match those specified in the
 * workspace configuration, unique mapping names must be generated.
 *
 * @throws IOException
 */
@Test
public void testBothIsolated() throws IOException {
    workspaceConf.getWorkspaces().forEach(ws -> ws.setIsolated(true));
    AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, workspaceConf);
    IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
    generator.generateMapping(reporter);
    assertEquals(STATIONS_WS_RENAMED, generator.getMainNamespace().name());
    assertTrue((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
    assertEquals(STATIONS_WS_RENAMED, generator.getMainWorkspace().name());
    assertTrue((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_RENAMED, ns.name());
            assertTrue((boolean) ns.getAttribute(Namespace.ISOLATED));
            assertEquals(MEASUREMENTS_WS_RENAMED, generator.getWorkspace(ns).name());
            assertTrue((boolean) generator.getWorkspace(ns).getAttribute(Namespace.ISOLATED));
        }
    }
    assertTrue(measurementsNsFound);
    List<FeatureTypeMapping> typeMappings = generator.getGeneratedMapping().getAppSchemaMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(2, typeMappings.size());
    Set<String> mappingNames = new HashSet<String>();
    for (FeatureTypeMapping typeMapping : typeMappings) {
        assertFalse(Strings.isNullOrEmpty(typeMapping.getMappingName()));
        mappingNames.add(typeMapping.getMappingName());
    }
    assertEquals(2, mappingNames.size());
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Namespace

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

the class AppSchemaIsolatedWorkspacesMappingTest method testNonIsolatedRenamed.

/**
 * Isolated attribute must be false, names must match those specified in the
 * workspace configuration, unique mapping names must not be generated.
 *
 * @throws IOException
 */
@Test
public void testNonIsolatedRenamed() throws IOException {
    AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, workspaceConf);
    IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
    generator.generateMapping(reporter);
    assertEquals(STATIONS_WS_RENAMED, generator.getMainNamespace().name());
    assertFalse((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
    assertEquals(STATIONS_WS_RENAMED, 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_RENAMED, ns.name());
            assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
            assertEquals(MEASUREMENTS_WS_RENAMED, 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 9 with Namespace

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

the class AppSchemaIsolatedWorkspacesMappingTest method testStationsIsolated.

/**
 * Isolated attribute must be true for the stations ws and false for the
 * measurements ws, names must match those specified in the workspace
 * configuration, unique mapping names must be generated only for the
 * stations ws.
 *
 * @throws IOException
 */
@Test
public void testStationsIsolated() throws IOException {
    workspaceConf.getWorkspace(STATIONS_NS_URI).setIsolated(true);
    AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, workspaceConf);
    IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
    generator.generateMapping(reporter);
    assertEquals(STATIONS_WS_RENAMED, generator.getMainNamespace().name());
    assertTrue((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
    assertEquals(STATIONS_WS_RENAMED, generator.getMainWorkspace().name());
    assertTrue((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_RENAMED, ns.name());
            assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
            assertEquals(MEASUREMENTS_WS_RENAMED, 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());
    boolean stationsFtFound = false, measurementsFtFound = false;
    Set<String> mappingNames = new HashSet<String>();
    for (FeatureTypeMapping typeMapping : typeMappings) {
        if ((STATIONS_WS_RENAMED + ":Station_gml32").equals(typeMapping.getTargetElement())) {
            stationsFtFound = true;
            assertFalse(Strings.isNullOrEmpty(typeMapping.getMappingName()));
        }
        if ((MEASUREMENTS_WS_RENAMED + ":Measurement_gml32").equals(typeMapping.getTargetElement())) {
            measurementsFtFound = true;
            assertTrue(Strings.isNullOrEmpty(typeMapping.getMappingName()));
        }
        if (!Strings.isNullOrEmpty(typeMapping.getMappingName())) {
            mappingNames.add(typeMapping.getMappingName());
        }
    }
    assertEquals(1, mappingNames.size());
    assertTrue(stationsFtFound);
    assertTrue(measurementsFtFound);
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Namespace

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

the class NamespaceResourceTest method testSerializeDefault.

/**
 * Tests the correct serialization of a namespace resource where only
 * {@code prefix} and {@code uri} are set.
 *
 * @throws Exception if an error occurs parsing the resource as XML
 */
@Test
public void testSerializeDefault() throws Exception {
    Namespace testNamespace = ResourceBuilder.namespace(TEST_PREFIX).setAttribute(Namespace.URI, TEST_URI).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_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)

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