Search in sources :

Example 1 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class NestedCellRelationshipContentProvider method getElements.

/**
 * @see CellRelationshipContentProvider#getElements(Object)
 */
@Override
public Object[] getElements(Object input) {
    List<Object> elements = new ArrayList<Object>();
    entityMap.clear();
    Multimap<TypeDefinition, Type> types = HashMultimap.create();
    Collection<Property> properties = new ArrayList<Property>();
    for (Object element : super.getElements(input)) {
        if (element instanceof Type) {
            Type type = (Type) element;
            types.put(type.getDefinition().getDefinition(), type);
            elements.add(element);
        } else if (element instanceof Property) {
            properties.add((Property) element);
        } else {
            elements.add(element);
        }
    }
    // assign properties to corresponding parents
    for (Property property : properties) {
        // find association through type definition
        TypeDefinition parentType = property.getDefinition().getType();
        Collection<Type> typeList = types.get(parentType);
        for (Type type : typeList) {
            entityMap.put(type, property);
        }
    }
    return elements.toArray();
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) ArrayList(java.util.ArrayList) Property(eu.esdihumboldt.hale.common.align.model.Property) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 2 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class GroovyTransformationPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            // create a dummy type with the variables as children
            DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
            Cell cell = getWizard().getUnfinishedCell();
            boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
            for (EntityDefinition variable : getVariables()) {
                if (variable.getDefinition() instanceof PropertyDefinition) {
                    PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
                    TypeDefinition propertyType;
                    if (useInstanceValues) {
                        // use instance type
                        propertyType = prop.getPropertyType();
                    } else {
                        // use dummy type with only the
                        // binding/HasValueFlag copied
                        DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
                        propertyType = crippledType;
                    }
                    DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(getVariableName(variable)), dummy, propertyType);
                    // number of times
                    if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID))
                        dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
                }
            }
            return Collections.singleton(dummy);
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetProperty != null) {
                return Collections.singleton(targetProperty.getDefinition().getDefinition().getPropertyType());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 3 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class GroovyTransformationPage method createConfiguration.

@Override
protected SourceViewerConfiguration createConfiguration() {
    InstanceBuilderCompletions targetCompletions = new InstanceBuilderCompletions(definitionImages) {

        @Override
        protected TypeDefinition getTargetType() {
            Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetProperty != null) {
                return targetProperty.getDefinition().getDefinition().getPropertyType();
            }
            return null;
        }
    };
    HelperFunctionsCompletions functionCompletions = new HelperFunctionsCompletions(HaleUI.getServiceProvider().getService(HelperFunctionsService.class));
    return new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_BUILDER, BINDING_TARGET, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT, BINDING_HELPER_FUNCTIONS), ImmutableList.of(targetCompletions, functionCompletions));
}
Also used : HelperFunctionsService(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService) InstanceBuilderCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.InstanceBuilderCompletions) HelperFunctionsCompletions(eu.esdihumboldt.hale.ui.functions.groovy.internal.HelperFunctionsCompletions) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 4 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class UserMigration method entityReplacement.

@Override
public Optional<EntityDefinition> entityReplacement(EntityDefinition entity, SimpleLog log) {
    // use functionality from entity resolver
    if (entity instanceof TypeEntityDefinition) {
        EntityDefinition candidate = entity;
        Type type = UserFallbackEntityResolver.resolveType((TypeEntityDefinition) entity, candidate, schemaSpace);
        return Optional.ofNullable(type).map(e -> e.getDefinition());
    } else if (entity instanceof PropertyEntityDefinition) {
        EntityDefinition candidate = entity;
        candidate = EntityCandidates.find((PropertyEntityDefinition) entity);
        Property property = UserFallbackEntityResolver.resolveProperty((PropertyEntityDefinition) entity, candidate, schemaSpace);
        return Optional.ofNullable(property).map(e -> e.getDefinition());
    } else {
        log.error("Unrecognised entity type: " + entity.getClass());
        return Optional.empty();
    }
}
Also used : Property(eu.esdihumboldt.hale.common.align.model.Property) SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) Type(eu.esdihumboldt.hale.common.align.model.Type) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Optional(java.util.Optional) UserFallbackEntityResolver(eu.esdihumboldt.hale.ui.service.align.resolver.UserFallbackEntityResolver) EntityCandidates(eu.esdihumboldt.hale.ui.service.align.resolver.internal.EntityCandidates) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 5 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AppSchemaMappingTest method testAssignHandler.

@Test
public void testAssignHandler() {
    final String ASSIGN_VALUE = "LCU_1234";
    final String OCQL = "'" + ASSIGN_VALUE + "'";
    final String OCQL_BOUND = "if_then_else(isNull(" + SOURCE_UUID_V1 + "), Expression.NIL, '" + ASSIGN_VALUE + "')";
    Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(AssignFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(ASSIGN_VALUE));
    cell.setTarget(getLocalIdTargetProperty());
    cell.setTransformationParameters(parameters);
    AssignHandler assignHandler = new AssignHandler();
    AttributeMappingType attrMapping = assignHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
    // bound version of "Assign"
    DefaultCell cellCopy = new DefaultCell(cell);
    Collection<Property> anchor = getUuidSourceProperty(unitDenormType).values();
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(AssignFunction.ENTITY_ANCHOR, anchor);
    cellCopy.setSource(source);
    cellCopy.setTransformationIdentifier(AssignFunction.ID_BOUND);
    attrMapping = assignHandler.handlePropertyTransformation(typeCell, cellCopy, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL_BOUND, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) Test(org.junit.Test)

Aggregations

Property (eu.esdihumboldt.hale.common.align.model.Property)25 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)13 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)11 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 ArrayList (java.util.ArrayList)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)8 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)8 Test (org.junit.Test)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)7 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 Type (eu.esdihumboldt.hale.common.align.model.Type)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2