Search in sources :

Example 6 with Property

use of io.atlasmap.v2.Property in project polymap4-core by Polymap4.

the class StyleCompositeSerializer method handle.

protected <V> Iterable<RuleModifier<V, S>> handle(Property<StylePropertyValue<V>> prop) {
    StylePropertyValue<V> styleProp = prop.get();
    // no value -> nothing to modify
    if (styleProp == null || styleProp instanceof NoValue) {
        return singletonList(new NoValueRuleModifier());
    } else // ConstantValue
    if (styleProp instanceof ConstantValue) {
        Expression expr = ff.literal(((ConstantValue) styleProp).value());
        return singletonList(new SimpleRuleModifier(expr));
    } else // AttributeValue
    if (styleProp instanceof AttributeValue) {
        String attributeName = (String) ((AttributeValue) styleProp).attributeName.get();
        Expression expr = ff.property(attributeName);
        return singletonList(new SimpleRuleModifier(expr));
    } else // FilterMappedValues
    if (styleProp instanceof FilterMappedValues) {
        List<Mapped<Filter, Object>> values = ((FilterMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key()));
    } else // ScaleMappedValues
    if (styleProp instanceof ScaleMappedValues) {
        List<Mapped<ScaleRange, Object>> values = ((ScaleMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key().min.get(), mapped.key().max.get()));
    } else {
        throw new RuntimeException("Unhandled StylePropertyValue type: " + styleProp.getClass().getSimpleName());
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) Configurable(org.polymap.core.runtime.config.Configurable) StylePropertyValue(org.polymap.core.style.model.StylePropertyValue) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) Mandatory(org.polymap.core.runtime.config.Mandatory) StyleComposite(org.polymap.core.style.model.StyleComposite) Function(java.util.function.Function) StyleFactory(org.geotools.styling.StyleFactory) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Style(org.polymap.core.style.model.Style) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) Config2(org.polymap.core.runtime.config.Config2) FluentIterable(com.google.common.collect.FluentIterable) FilterFactory2(org.opengis.filter.FilterFactory2) ConstantValue(org.polymap.core.style.model.feature.ConstantValue) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) ScaleRange(org.polymap.core.style.model.feature.ScaleMappedValues.ScaleRange) Symbolizer(org.geotools.styling.Symbolizer) Cloner(com.rits.cloning.Cloner) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Property(org.polymap.model2.Property) Expression(org.opengis.filter.expression.Expression) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) List(java.util.List) NoValue(org.polymap.core.style.model.feature.NoValue) Rule(org.geotools.styling.Rule) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Filter(org.opengis.filter.Filter) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) FilterStyleProperty(org.polymap.core.style.model.feature.FilterStyleProperty) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) NoValue(org.polymap.core.style.model.feature.NoValue) Expression(org.opengis.filter.expression.Expression) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Filter(org.opengis.filter.Filter) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ConstantValue(org.polymap.core.style.model.feature.ConstantValue)

Example 7 with Property

use of io.atlasmap.v2.Property in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method buildAndProcessAction.

/**
 * Instantiate the field action impl class from {@link ActionProcessor} and processes it.
 * @param actionProcessor action processor
 * @param actionParameters action parameters
 * @param field field
 * @return processed field
 */
public Field buildAndProcessAction(ActionProcessor actionProcessor, Map<String, Object> actionParameters, Field field) {
    FieldType valueType = determineFieldType(field);
    try {
        Action action = actionProcessor.getActionClass().getDeclaredConstructor().newInstance();
        for (Map.Entry<String, Object> property : actionParameters.entrySet()) {
            String setter = "set" + property.getKey().substring(0, 1).toUpperCase() + property.getKey().substring(1);
            action.getClass().getMethod(setter, property.getValue().getClass()).invoke(action, property.getValue());
        }
        return processAction(action, actionProcessor, valueType, field);
    } catch (Exception e) {
        throw new IllegalArgumentException(String.format("The action '%s' cannot be processed", actionProcessor.getActionDetail().getName()), e);
    }
}
Also used : CustomAction(io.atlasmap.v2.CustomAction) AtlasFieldAction(io.atlasmap.spi.AtlasFieldAction) Action(io.atlasmap.v2.Action) Map(java.util.Map) AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasException(io.atlasmap.api.AtlasException) FieldType(io.atlasmap.v2.FieldType)

Example 8 with Property

use of io.atlasmap.v2.Property in project atlasmap by atlasmap.

the class AtlasField method readProperty.

/**
 * Reads the source property.
 * @param scope scope
 * @param name name
 * @return read field
 * @throws AtlasException unexpected error
 */
public AtlasField readProperty(String scope, String name) throws AtlasException {
    PropertyModule module = session.getSourcePropertyModule();
    PropertyField sourceField = module.createField();
    sourceField.setScope(scope);
    sourceField.setName(name);
    session.head().setSourceField(sourceField);
    module.readSourceValue(session);
    setRawField(sourceField);
    return this;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) PropertyModule(io.atlasmap.core.PropertyModule)

Example 9 with Property

use of io.atlasmap.v2.Property in project atlasmap by atlasmap.

the class BaseMarshallerTest method generateProperties.

private void generateProperties(AtlasMapping atlasMapping) {
    Property p = new Property();
    p.setName("foo");
    p.setValue("bar");
    p.setFieldType(FieldType.INTEGER);
    atlasMapping.setProperties(new Properties());
    atlasMapping.getProperties().getProperty().add(p);
}
Also used : Properties(io.atlasmap.v2.Properties) Property(io.atlasmap.v2.Property)

Example 10 with Property

use of io.atlasmap.v2.Property in project atlasmap by atlasmap.

the class DefaultAtlasContext method init.

/**
 * TODO: For dynamic re-load. This needs lock()
 *
 * @throws AtlasException failed to initialize
 */
protected synchronized void init() throws AtlasException {
    if (this.initialized) {
        return;
    }
    registerJmx(this);
    if (this.atlasMappingUri != null) {
        this.admHandler = new ADMArchiveHandler(factory.getClassLoader());
        this.admHandler.setIgnoreLibrary(true);
        this.admHandler.load(Paths.get(this.atlasMappingUri));
        this.dataSourceMetadataMap = this.admHandler.getDataSourceMetadataMap();
    }
    if (this.admHandler == null || this.admHandler.getMappingDefinition() == null) {
        LOG.warn("AtlasMap context cannot initialize without mapping definition, ignoring:" + " Mapping URI={}", this.atlasMappingUri);
        return;
    }
    sourceModules.clear();
    ConstantModule constant = new ConstantModule();
    constant.setConversionService(factory.getConversionService());
    constant.setFieldActionService(factory.getFieldActionService());
    sourceModules.put(AtlasConstants.CONSTANTS_DOCUMENT_ID, constant);
    PropertyModule property = new PropertyModule(factory.getPropertyStrategy());
    property.setConversionService(factory.getConversionService());
    property.setFieldActionService(factory.getFieldActionService());
    property.setMode(AtlasModuleMode.SOURCE);
    sourceModules.put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, property);
    targetModules.clear();
    property = new PropertyModule(factory.getPropertyStrategy());
    property.setConversionService(factory.getConversionService());
    property.setFieldActionService(factory.getFieldActionService());
    property.setMode(AtlasModuleMode.TARGET);
    targetModules.put(AtlasConstants.PROPERTIES_TARGET_DOCUMENT_ID, property);
    lookupTables.clear();
    if (admHandler.getMappingDefinition().getLookupTables() != null && admHandler.getMappingDefinition().getLookupTables().getLookupTable() != null) {
        for (LookupTable table : admHandler.getMappingDefinition().getLookupTables().getLookupTable()) {
            lookupTables.put(table.getName(), table);
        }
    }
    AtlasModuleInfoRegistry moduleInfoRegistry = factory.getModuleInfoRegistry();
    for (DataSource ds : admHandler.getMappingDefinition().getDataSource()) {
        AtlasModuleInfo moduleInfo = moduleInfoRegistry.lookupByUri(ds.getUri());
        if (moduleInfo == null) {
            LOG.error("Cannot find module info for the DataSource uri '{}'", ds.getUri());
            continue;
        }
        if (ds.getDataSourceType() != DataSourceType.SOURCE && ds.getDataSourceType() != DataSourceType.TARGET) {
            LOG.error("Unsupported DataSource type '{}'", ds.getDataSourceType());
            continue;
        }
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            docId = ds.getDataSourceType() == DataSourceType.SOURCE ? AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID : AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID;
        }
        if (ds.getDataSourceType() == DataSourceType.SOURCE && sourceModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), ds.getId());
            continue;
        }
        if (ds.getDataSourceType() == DataSourceType.TARGET && targetModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), docId);
            continue;
        }
        try {
            AtlasModule module = moduleInfo.getModuleClass().getDeclaredConstructor().newInstance();
            module.setClassLoader(factory.getClassLoader());
            module.setConversionService(factory.getConversionService());
            module.setFieldActionService(factory.getFieldActionService());
            module.setDataSource(ds);
            if (ds.getDataSourceType() == DataSourceType.SOURCE) {
                getSourceModules().put(docId, module);
            } else if (ds.getDataSourceType() == DataSourceType.TARGET) {
                getTargetModules().put(docId, module);
            }
            if (this.dataSourceMetadataMap != null) {
                DataSourceKey dskey = new DataSourceKey(ds.getDataSourceType() == DataSourceType.SOURCE, docId);
                DataSourceMetadata meta = this.dataSourceMetadataMap.get(dskey);
                if (meta != null) {
                    module.setDataSourceMetadata(meta);
                }
            }
            module.init();
        } catch (Exception t) {
            LOG.error("Unable to initialize {} module: {}", ds.getDataSourceType(), moduleInfo);
            LOG.error(t.getMessage(), t);
            throw new AtlasException(String.format("Unable to initialize %s module: %s", ds.getDataSourceType(), moduleInfo.toString()), t);
        }
    }
    initialized = true;
}
Also used : AtlasException(io.atlasmap.api.AtlasException) AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasException(io.atlasmap.api.AtlasException) DataSource(io.atlasmap.v2.DataSource) AtlasModule(io.atlasmap.spi.AtlasModule) AtlasModuleInfo(io.atlasmap.spi.AtlasModuleInfo) DataSourceKey(io.atlasmap.v2.DataSourceKey) DataSourceMetadata(io.atlasmap.v2.DataSourceMetadata) AtlasModuleInfoRegistry(io.atlasmap.spi.AtlasModuleInfoRegistry) LookupTable(io.atlasmap.v2.LookupTable)

Aggregations

Property (org.eclipse.bpmn2.Property)21 Property (io.atlasmap.v2.Property)7 AtlasMapping (io.atlasmap.v2.AtlasMapping)6 ArrayList (java.util.ArrayList)6 Process (org.eclipse.bpmn2.Process)6 Test (org.junit.Test)6 DataObject (org.eclipse.bpmn2.DataObject)5 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)5 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)5 RootElement (org.eclipse.bpmn2.RootElement)5 Properties (io.atlasmap.v2.Properties)4 DataInput (org.eclipse.bpmn2.DataInput)4 DeclarationList (org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.DeclarationList)4 PropertyField (io.atlasmap.v2.PropertyField)3 List (java.util.List)3 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)3 DataOutput (org.eclipse.bpmn2.DataOutput)3 FlowElement (org.eclipse.bpmn2.FlowElement)3 SubProcess (org.eclipse.bpmn2.SubProcess)3 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2