Search in sources :

Example 1 with WorkspaceMetadata

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);
    }
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) WorkspaceMetadata(eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) AbstractAppSchemaConfigurator(eu.esdihumboldt.hale.io.appschema.writer.AbstractAppSchemaConfigurator) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) AppSchemaMappingGenerator(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingGenerator)

Example 2 with WorkspaceMetadata

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);
}
Also used : QName(javax.xml.namespace.QName) WorkspaceMetadata(eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata)

Example 3 with WorkspaceMetadata

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;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) WorkspaceMetadata(eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata) HashSet(java.util.HashSet)

Example 4 with WorkspaceMetadata

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();
    }
}
Also used : WorkspaceMetadata(eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata) IContentType(org.eclipse.core.runtime.content.IContentType)

Aggregations

WorkspaceMetadata (eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata)4 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)1 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 AppSchemaDataAccessType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType)1 Namespace (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)1 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)1 AbstractAppSchemaConfigurator (eu.esdihumboldt.hale.io.appschema.writer.AbstractAppSchemaConfigurator)1 AppSchemaMappingGenerator (eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingGenerator)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 IContentType (org.eclipse.core.runtime.content.IContentType)1