Search in sources :

Example 1 with Infomodel

use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.

the class ModelDtoFactory method createResource.

public static Infomodel createResource(InformationModel model, Optional<MappingModel> mappingModel) {
    Infomodel infoResource = new Infomodel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.InformationModel);
    for (FunctionblockProperty property : model.getProperties()) {
        infoResource.getFunctionblocks().add(createProperty(property, mappingModel));
    }
    infoResource.setDescription(model.getDescription());
    infoResource.setDisplayName(model.getDisplayname());
    infoResource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    if (mappingModel.isPresent()) {
        MappingModel _mappingModel = mappingModel.get();
        infoResource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
        for (MappingRule rule : getInfoModelRule(_mappingModel.getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                infoResource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                infoResource.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return infoResource;
}
Also used : Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.repository.api.ModelId) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 2 with Infomodel

use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.

the class MappingSpecificationBuilder method build.

public IMappingSpecification build() {
    try {
        Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
        DefaultMappingSpecification specification = new DefaultMappingSpecification();
        specification.setInfomodel(infomodel);
        for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
            ModelId fbModelId = (ModelId) fbProperty.getType();
            ModelId mappingId = fbProperty.getMappingReference();
            FunctionblockModel fbm;
            if (mappingId != null) {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
            } else {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
            }
            if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
                Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
                JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
                for (String functionName : functionsStereotype.getAttributes().keySet()) {
                    if (!"_namespace".equalsIgnoreCase(functionName)) {
                        functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
                    }
                }
                this.library.addFunctions(functions);
            }
            specification.getFbs().put(fbProperty.getName(), fbm);
        }
        specification.setLibrary(this.library);
        return specification;
    } catch (Exception e) {
        throw new MappingSpecificationProblem("Problem reading mapping specification", e);
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) DefaultMappingSpecification(org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification) JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 3 with Infomodel

use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.

the class DefaultMappingClient method newPropertyQuery.

@Override
public IMappingQuery<ModelProperty> newPropertyQuery(IMappedElement element) {
    final List<ModelProperty> properties = new ArrayList<ModelProperty>();
    if (element instanceof FunctionblockModel) {
        FunctionblockModel fbm = (FunctionblockModel) element;
        properties.addAll(fbm.getConfigurationProperties());
        properties.addAll(fbm.getStatusProperties());
        properties.addAll(fbm.getFaultProperties());
    } else if (element instanceof Infomodel) {
        Infomodel im = (Infomodel) element;
        properties.addAll(im.getFunctionblocks());
    } else if (element instanceof EntityModel) {
        EntityModel entity = (EntityModel) element;
        properties.addAll(entity.getProperties());
    } else {
        throw new UnsupportedOperationException();
    }
    return new MappingQueryJxPath<ModelProperty>() {

        @Override
        protected Collection<ModelProperty> getAll() {
            return properties;
        }
    };
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) ArrayList(java.util.ArrayList) EntityModel(org.eclipse.vorto.repository.api.content.EntityModel)

Example 4 with Infomodel

use of org.eclipse.vorto.repository.api.content.Infomodel 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 5 with Infomodel

use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.

the class ModelRepositoryClientTest method testGetContentOfSpecificModel.

@Test
public void testGetContentOfSpecificModel() throws Exception {
    Infomodel xdkModel = modelRepo.getContent(ModelId.fromPrettyFormat("com.bosch.devices.XDK:1.0.0"), Infomodel.class).get();
    assertNotNull(xdkModel);
    assertTrue(xdkModel.getFunctionblocks().size() > 0);
}
Also used : Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) Test(org.junit.Test)

Aggregations

Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)5 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)3 ModelId (org.eclipse.vorto.repository.api.ModelId)2 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)2 ArrayList (java.util.ArrayList)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)1 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)1 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)1 JavascriptFunctions (org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)1 DefaultMappingSpecification (org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1 InfomodelData (org.eclipse.vorto.service.mapping.normalized.InfomodelData)1 Test (org.junit.Test)1