Search in sources :

Example 1 with FunctionblockData

use of org.eclipse.vorto.service.mapping.normalized.FunctionblockData in project vorto by eclipse.

the class AbstractDataMapper method mapFunctionBlock.

private FunctionblockData mapFunctionBlock(ModelProperty fbProperty, JXPathContext context) {
    FunctionblockData fbData = new FunctionblockData(fbProperty.getName());
    FunctionblockModel fbModel = specification.getFunctionBlock(fbProperty.getName());
    for (ModelProperty statusProperty : fbModel.getStatusProperties()) {
        try {
            Object mapped = this.mapProperty(statusProperty, context);
            if (mapped != null) {
                fbData.withStatusProperty(statusProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (statusProperty.isMandatory()) {
                return null;
            }
        }
    }
    for (ModelProperty configProperty : fbModel.getConfigurationProperties()) {
        try {
            Object mapped = this.mapProperty(configProperty, context);
            if (mapped != null) {
                fbData.withConfigurationProperty(configProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (configProperty.isMandatory()) {
                return null;
            }
        }
    }
    return onlyReturnIfPopulated(fbData);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException)

Example 2 with FunctionblockData

use of org.eclipse.vorto.service.mapping.normalized.FunctionblockData in project vorto by eclipse.

the class AbstractDataMapper method map.

public MappedData map(DataInput input, MappingContext mappingContext) {
    JXPathContext context = newContext(input.getValue());
    context.setFunctions(converterLibrary);
    InfomodelData normalized = new InfomodelData();
    final Infomodel deviceInfoModel = specification.getInfoModel();
    for (ModelProperty fbProperty : deviceInfoModel.getFunctionblocks()) {
        if (mappingContext.isIncluded(fbProperty.getName())) {
            FunctionblockData mappedFb = mapFunctionBlock(fbProperty, context);
            if (mappedFb != null) {
                normalized.withFunctionblock(mappedFb);
            }
        }
    }
    return this.doMap(normalized, mappingContext);
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) InfomodelData(org.eclipse.vorto.service.mapping.normalized.InfomodelData)

Example 3 with FunctionblockData

use of org.eclipse.vorto.service.mapping.normalized.FunctionblockData in project vorto by eclipse.

the class SomePlatformMapper method doMap.

@Override
protected PlatformData doMap(InfomodelData normalized, MappingContext mappingContext) {
    PlatformData data = new PlatformData();
    State state = new State();
    Map<String, Object> status = new HashMap<>();
    for (FunctionblockData fbData : normalized.getFunctionblockData()) {
        status.put(fbData.getId(), fbData.getStatus());
    }
    state.setReported(status);
    data.setState(state);
    return data;
}
Also used : HashMap(java.util.HashMap) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData)

Example 4 with FunctionblockData

use of org.eclipse.vorto.service.mapping.normalized.FunctionblockData in project vorto by eclipse.

the class DittoMapper method doMap.

@Override
protected DittoData doMap(InfomodelData input, MappingContext mappingContext) {
    DittoData output = new DittoData();
    for (FunctionblockData fbData : input.getFunctionblockData()) {
        FeatureBuilder featureBuilder = Feature.newBuilder(fbData.getId());
        featureBuilder.withStatus(fbData.getStatus());
        output.withFeature(featureBuilder.build());
    }
    return output;
}
Also used : FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData)

Aggregations

FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)4 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)2 HashMap (java.util.HashMap)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)1 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)1 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)1 InfomodelData (org.eclipse.vorto.service.mapping.normalized.InfomodelData)1