use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class WorkspaceResourceTest method testSerializeWithId.
/**
* Tests the correct serialization of a workspace resource whose {@code id}
* attribute is set.
*
* @throws Exception if an error occurs parsing the resource as XML
*/
@Test
public void testSerializeWithId() throws Exception {
Workspace testWorkspace = ResourceBuilder.workspace(TEST_NAME).setAttribute(Workspace.ID, TEST_ID).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_ID, TEST_ID);
expectedValues.put(ELEMENT_NAME, TEST_NAME);
expectedValues.put(ELEMENT_ISOLATED, "false");
checkResource(workspaceEl, expectedValues);
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class WorkspaceResourceTest method testSerializeIsolated.
/**
* Tests the correct serialization of a workspace resource whose
* {@code isolated} attribute is set to {@code true}.
*
* @throws Exception if an error occurs parsing the resource as XML
*/
@Test
public void testSerializeIsolated() throws Exception {
Workspace testWorkspace = ResourceBuilder.workspace(TEST_NAME).setAttribute(Workspace.ISOLATED, true).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, "true");
checkResource(workspaceEl, expectedValues);
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace 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();
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class AppSchemaMappingGenerator method getMainWorkspace.
/**
* Returns the generated workspace configuration for the main workspace.
*
* @return the main workspace configuration
* @throws IllegalStateException if the no app-schema mapping configuration
* has been generated yet or if no target schema is available
*/
public Workspace getMainWorkspace() {
checkMappingGenerated();
checkTargetSchemaAvailable();
Namespace ns = context.getOrCreateNamespace(targetSchema.getNamespace(), null);
Workspace ws = getWorkspace(ns.getPrefix(), ns.getUri());
return ws;
}
use of eu.esdihumboldt.hale.io.geoserver.Workspace in project hale by halestudio.
the class AppSchemaMappingGenerator method getWorkspace.
/**
* Returns the configuration of the workspace associated to the provided
* namespace.
*
* @param ns the namespace
* @return the configuration of the workspace associated to <code>ns</code>
*/
public Workspace getWorkspace(eu.esdihumboldt.hale.io.geoserver.Namespace ns) {
Object namespaceUri = ns.getAttribute(eu.esdihumboldt.hale.io.geoserver.Namespace.URI);
Workspace ws = getWorkspace(ns.name(), String.valueOf(namespaceUri));
return ws;
}
Aggregations