use of eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata 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.model.WorkspaceMetadata in project hale by halestudio.
the class AppSchemaMappingContext method getOrCreateFeatureTypeMapping.
/**
* Return the feature type mapping associated to the provided type.
*
* <p>
* If a feature type mapping for the provided type already exists, it is
* returned; otherwise, a new one is created.
* </p>
*
* <p>
* This method tests whether the specified type belongs to an isolated
* workspace (as indicated in the workspace configuration) and, if so,
* generates a unique mapping name to be associated with the feature type
* mapping, thus protecting it against name clashes.
*
* The implementation then delegates to
* {@link AppSchemaMappingWrapper#getOrCreateFeatureTypeMapping(TypeDefinition, String)}
* , passing {@code null} as second argument if no mapping name was
* generated.
* </p>
*
* @param targetType the target type
* @return the feature type mapping
*/
public FeatureTypeMapping getOrCreateFeatureTypeMapping(TypeDefinition targetType) {
if (targetType == null) {
return null;
}
QName typeName = new QName(targetType.getName().getNamespaceURI(), targetType.getDisplayName());
String mappingName = null;
if (mappingNames.containsKey(typeName)) {
mappingName = mappingNames.get(typeName);
} else {
if (workspaceConf != null) {
String namespaceUri = targetType.getName().getNamespaceURI();
WorkspaceMetadata workspace = workspaceConf.getWorkspace(namespaceUri);
if (workspace != null && workspace.isIsolated()) {
mappingName = mappingNameGenerator.generateUniqueMappingName(typeName);
mappingNames.put(typeName, mappingName);
}
}
}
return mappingWrapper.getOrCreateFeatureTypeMapping(targetType, mappingName);
}
use of eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata in project hale by halestudio.
the class WorkspaceConfigurationPage method updateConfiguration.
/**
* @see eu.esdihumboldt.hale.ui.io.IOWizardPage#updateConfiguration(eu.esdihumboldt.hale.common.core.io.IOProvider)
*/
@Override
public boolean updateConfiguration(AbstractAppSchemaConfigurator provider) {
boolean isValid = true;
// check for duplicates
Set<String> newNames = new HashSet<>();
for (WorkspaceMetadata workspace : workspaceConf.getWorkspaces()) {
if (newNames.contains(workspace.getName())) {
// duplicate found
setErrorMessage("Duplicated workspace name found: \"" + workspace.getName() + "\"");
isValid = false;
break;
}
newNames.add(workspace.getName());
}
if (!isValid) {
return false;
}
provider.setParameter(AppSchemaIO.PARAM_WORKSPACE, new ComplexValue(workspaceConf));
return true;
}
use of eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata in project hale by halestudio.
the class WorkspaceConfigurationPage method onShowPage.
/**
* @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
super.onShowPage(firstShow);
IContentType contentType = getWizard().getContentType();
if (!contentType.getId().equals(AppSchemaIO.CONTENT_TYPE_ARCHIVE) && !contentType.getId().equals(AppSchemaIO.CONTENT_TYPE_REST)) {
// configuration does not apply, skip page
if (!goingBack) {
getContainer().showPage(getNextPage());
} else {
getContainer().showPage(getPreviousPage());
}
return;
}
if (!firstShow) {
// empty feature type collections, since they may change
for (WorkspaceMetadata workspace : workspaceConf.getWorkspaces()) {
workspace.getFeatureTypes().clear();
}
}
if (!goingBack) {
updateWorkspaceTable();
}
}
Aggregations