Search in sources :

Example 1 with EntityAccessor

use of eu.esdihumboldt.hale.common.align.groovy.accessor.EntityAccessor in project hale by halestudio.

the class AbstractTargetAction method run.

@Override
public void run() {
    // if Display not the active Thread
    if (Display.getCurrent() == null) {
        // execute in display thread
        PlatformUI.getWorkbench().getDisplay().asyncExec(this);
        return;
    }
    if (params == null || params.isEmpty()) {
        return;
    }
    // retrieve the target schema
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    SchemaSpace targetSchema = ss.getSchemas(SchemaSpaceID.TARGET);
    // find type
    QName typeName = QName.valueOf(params.get(0));
    TypeDefinition type = targetSchema.getType(typeName);
    if (type == null) {
        // check all mapping relevant types for local name only
        for (TypeDefinition candidate : targetSchema.getMappingRelevantTypes()) {
            if (candidate.getName().getLocalPart().equals(params.get(0))) {
                // use the first found
                type = candidate;
                break;
            }
        }
    }
    if (type != null) {
        EntityDefinition entity = new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null);
        if (params.size() > 1) {
            // determine property entity
            EntityAccessor accessor = new EntityAccessor(entity);
            for (int i = 1; i < params.size(); i++) {
                QName propertyName = QName.valueOf(params.get(i));
                String namespace = propertyName.getNamespaceURI();
                if (namespace != null && namespace.isEmpty()) {
                    // treat empty namespace as ignoring namespace
                    namespace = null;
                }
                accessor = accessor.findChildren(propertyName.getLocalPart(), namespace);
            }
            entity = accessor.toEntityDefinition();
        }
        if (entity != null) {
            run(entity, manager);
        } else {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", "The schema element was not found in the target schema, please make sure the correct schema is loaded.");
        }
    } else {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Schema element not found", MessageFormat.format("The type {0} was not found in the target schema, please make sure the correct schema is loaded.", typeName.getLocalPart()));
    }
}
Also used : EntityAccessor(eu.esdihumboldt.hale.common.align.groovy.accessor.EntityAccessor) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) QName(javax.xml.namespace.QName) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

EntityAccessor (eu.esdihumboldt.hale.common.align.groovy.accessor.EntityAccessor)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)1 QName (javax.xml.namespace.QName)1