use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType in project hale by halestudio.
the class WorkspaceConfigurationPage method updateWorkspaceTable.
private void updateWorkspaceTable() {
AbstractAppSchemaConfigurator configurator = getWizard().getProvider();
DefaultIOReporter reporter = new DefaultIOReporter(configurator.getTarget(), "Generate Temporary App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, true);
AppSchemaMappingGenerator generator;
try {
configurator.generateMapping(reporter);
generator = configurator.getMappingGenerator();
AppSchemaDataAccessType appSchemaMapping = generator.getGeneratedMapping().getAppSchemaMapping();
List<FeatureTypeMapping> typeMappings = appSchemaMapping.getTypeMappings().getFeatureTypeMapping();
for (FeatureTypeMapping typeMapping : typeMappings) {
String[] workspaceAndType = typeMapping.getTargetElement().split(":");
String workspaceName = workspaceAndType[0];
String typeName = workspaceAndType[1];
List<Namespace> namespaces = appSchemaMapping.getNamespaces().getNamespace();
for (Namespace namespace : namespaces) {
if (workspaceName.equals(namespace.getPrefix())) {
String uri = namespace.getUri();
if (workspaceConf.hasWorkspace(uri)) {
workspaceConf.getWorkspace(uri).getFeatureTypes().add(typeName);
} else {
WorkspaceMetadata workspace = new WorkspaceMetadata(workspaceName, uri);
workspace.getFeatureTypes().add(typeName);
workspaceConf.addWorkspace(workspace);
}
}
}
}
// remove workspaces that contain no features
workspaceConf.getWorkspaces().forEach((ws) -> {
if (ws.getFeatureTypes().isEmpty()) {
workspaceConf.removeWorkspace(ws.getNamespaceUri());
}
});
workspaceTableViewer.setInput(workspaceConf.getWorkspaces());
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType in project hale by halestudio.
the class AppSchemaMappingGenerator method generateMapping.
/**
* Generates the app-schema mapping configuration.
*
* @param reporter status reporter
* @return the generated app-schema mapping configuration
* @throws IOException if an error occurs loading the mapping template file
*/
public AppSchemaMappingWrapper generateMapping(IOReporter reporter) throws IOException {
// reset wrapper
resetMappingState();
try {
AppSchemaDataAccessType mapping = loadMappingTemplate();
mappingWrapper = new AppSchemaMappingWrapper(mapping);
context = new AppSchemaMappingContext(mappingWrapper, alignment, targetSchema.getMappingRelevantTypes(), chainingConf, workspaceConf);
// create namespace objects for all target types / properties
// TODO: this removes all namespaces that were defined in the
// template file, add code to cope with pre-configured namespaces
// instead
mapping.getNamespaces().getNamespace().clear();
createNamespaces();
// apply datastore configuration, if any
// TODO: for now, only a single datastore is supported
applyDataStoreConfig();
// populate targetTypes element
createTargetTypes();
// populate typeMappings element
createTypeMappings(context, reporter);
// cache mainMapping and includedTypesMapping for performance
mainMapping = mappingWrapper.getMainMapping();
includedTypesMapping = mappingWrapper.getIncludedTypesMapping();
return mappingWrapper;
} catch (Exception e) {
// making sure state is reset in case an exception is thrown
resetMappingState();
throw e;
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType in project hale by halestudio.
the class AppSchemaMappingGenerator method loadMappingTemplate.
private AppSchemaDataAccessType loadMappingTemplate() throws IOException {
InputStream is = getClass().getResourceAsStream(AppSchemaIO.MAPPING_TEMPLATE);
JAXBElement<AppSchemaDataAccessType> templateElement = null;
try {
JAXBContext context = createJaxbContext();
Unmarshaller unmarshaller = context.createUnmarshaller();
templateElement = unmarshaller.unmarshal(new StreamSource(is), AppSchemaDataAccessType.class);
} catch (JAXBException e) {
throw new IOException(e);
}
return templateElement.getValue();
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType in project hale by halestudio.
the class AppSchemaMappingWrapper method getMainMapping.
/**
* Returns the mapping configuration for the main mapping file.
*
* <p>
* If the mapping does not require multiple files, this method is equivalent
* to {@link #getAppSchemaMapping()}.
* </p>
*
* @return a copy of the main mapping configuration
*/
public AppSchemaDataAccessType getMainMapping() {
AppSchemaDataAccessType mainMapping = cloneMapping(appSchemaMapping);
if (requiresMultipleFiles()) {
// add included types configuration
mainMapping.getIncludedTypes().getInclude().add(AppSchemaIO.INCLUDED_TYPES_MAPPING_FILE);
Set<FeatureTypeMapping> toBeRemoved = new HashSet<FeatureTypeMapping>();
Set<FeatureTypeMapping> toBeKept = new HashSet<FeatureTypeMapping>();
groupTypeMappings(toBeKept, toBeRemoved);
purgeTypeMappings(mainMapping, toBeRemoved);
}
return mainMapping;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType in project hale by halestudio.
the class AppSchemaMappingWrapper method cloneMapping.
static AppSchemaDataAccessType cloneMapping(AppSchemaDataAccessType mapping) {
AppSchemaDataAccessType clone = new AppSchemaDataAccessType();
initMapping(clone);
clone.setCatalog(mapping.getCatalog());
clone.getIncludedTypes().getInclude().addAll(mapping.getIncludedTypes().getInclude());
for (Namespace ns : mapping.getNamespaces().getNamespace()) {
clone.getNamespaces().getNamespace().add(cloneNamespace(ns));
}
for (DataStore ds : mapping.getSourceDataStores().getDataStore()) {
clone.getSourceDataStores().getDataStore().add(cloneDataStore(ds));
}
clone.getTargetTypes().getFeatureType().getSchemaUri().addAll(mapping.getTargetTypes().getFeatureType().getSchemaUri());
for (FeatureTypeMapping ftMapping : mapping.getTypeMappings().getFeatureTypeMapping()) {
clone.getTypeMappings().getFeatureTypeMapping().add(cloneFeatureTypeMapping(ftMapping));
}
return clone;
}
Aggregations