Search in sources :

Example 1 with ModelProperty

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

the class ModelDtoFactory method createProperty.

private static ModelProperty createProperty(FunctionblockProperty property, Optional<MappingModel> mappingModel) {
    ModelProperty p = new ModelProperty();
    p.setDescription(property.getDescription());
    p.setName(property.getName());
    p.setType(createModelId(property.getType()));
    if (mappingModel.isPresent()) {
        p.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getPropertyRule(p.getName(), mappingModel.get().getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                p.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                p.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return p;
}
Also used : ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 2 with ModelProperty

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

the class ModelDtoFactory method createProperty.

private static ModelProperty createProperty(Property property, Optional<MappingModel> mappingModel) {
    ModelProperty p = new ModelProperty();
    p.setDescription(property.getDescription());
    p.setMandatory(property.getPresence() != null ? property.getPresence().isMandatory() : true);
    p.setMultiple(property.isMultiplicity());
    p.setName(property.getName());
    if (property.getType() instanceof PrimitivePropertyType) {
        PrimitiveType pt = ((PrimitivePropertyType) property.getType()).getType();
        p.setType(org.eclipse.vorto.repository.api.content.PrimitiveType.valueOf(pt.name()));
    } else {
        p.setType(createModelId(((ObjectPropertyType) property.getType()).getType()));
    }
    if (property.getConstraintRule() != null && property.getConstraintRule().getConstraints() != null) {
        List<Constraint> constraints = property.getConstraintRule().getConstraints().stream().map(c -> createConstraint(c)).collect(Collectors.toList());
        p.setConstraints(constraints);
    }
    if (property.getPropertyAttributes() != null) {
        List<IPropertyAttribute> attributes = property.getPropertyAttributes().stream().map(a -> createAttribute(a)).collect(Collectors.toList());
        p.setAttributes(attributes);
    }
    if (mappingModel.isPresent()) {
        p.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getPropertyRule(p.getName(), mappingModel.get().getRules())) {
            StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
            p.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
        }
    }
    return p;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) EntitySource(org.eclipse.vorto.core.api.model.mapping.EntitySource) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) Event(org.eclipse.vorto.core.api.model.functionblock.Event) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) BooleanAttributeProperty(org.eclipse.vorto.repository.api.content.BooleanAttributeProperty) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Map(java.util.Map) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) AbstractModel(org.eclipse.vorto.repository.api.AbstractModel) ModelId(org.eclipse.vorto.repository.api.ModelId) EnumAttributePropertyType(org.eclipse.vorto.repository.api.content.EnumAttributePropertyType) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) InfoModelPropertySource(org.eclipse.vorto.core.api.model.mapping.InfoModelPropertySource) EntityModel(org.eclipse.vorto.repository.api.content.EntityModel) Collectors(java.util.stream.Collectors) List(java.util.List) BooleanAttributePropertyType(org.eclipse.vorto.repository.api.content.BooleanAttributePropertyType) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ReturnType(org.eclipse.vorto.repository.api.content.ReturnType) Optional(java.util.Optional) IPropertyAttribute(org.eclipse.vorto.repository.api.content.IPropertyAttribute) EnumLiteral(org.eclipse.vorto.repository.api.content.EnumLiteral) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) EnumAttributeProperty(org.eclipse.vorto.repository.api.content.EnumAttributeProperty) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) ConstraintType(org.eclipse.vorto.repository.api.content.ConstraintType) FunctionBlockAttributeSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockAttributeSource) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) Model(org.eclipse.vorto.core.api.model.model.Model) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Property(org.eclipse.vorto.core.api.model.datatype.Property) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) Enum(org.eclipse.vorto.core.api.model.datatype.Enum) ModelType(org.eclipse.vorto.repository.api.ModelType) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) InfoModelAttributeSource(org.eclipse.vorto.core.api.model.mapping.InfoModelAttributeSource) Param(org.eclipse.vorto.repository.api.content.Param) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) Source(org.eclipse.vorto.core.api.model.mapping.Source) Operation(org.eclipse.vorto.repository.api.content.Operation) FaultSource(org.eclipse.vorto.core.api.model.mapping.FaultSource) Constraint(org.eclipse.vorto.repository.api.content.Constraint) ModelEvent(org.eclipse.vorto.repository.api.content.ModelEvent) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) EnumModel(org.eclipse.vorto.repository.api.content.EnumModel) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) IPropertyAttribute(org.eclipse.vorto.repository.api.content.IPropertyAttribute) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Constraint(org.eclipse.vorto.repository.api.content.Constraint) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 3 with ModelProperty

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

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

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

the class ModelRepositoryClientTest method testQueryModelPropertyByMappedAttribute.

@Test
public void testQueryModelPropertyByMappedAttribute() throws Exception {
    FunctionblockModel accelerometer = modelRepo.getContent(ModelId.fromPrettyFormat("com.ipso.smartobjects.Accelerometer:0.0.1"), FunctionblockModel.class, "lwm2m").get();
    List<ModelProperty> properties = mapping.newPropertyQuery(accelerometer).stereotype("Resource").attribute("ID", "5702").list();
    assertEquals(1, properties.size());
    assertEquals("x_value", properties.get(0).getName());
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Test(org.junit.Test)

Aggregations

ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)23 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)18 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)4 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)3 ArrayList (java.util.ArrayList)2 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)2 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)2 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)2 ModelId (org.eclipse.vorto.repository.api.ModelId)2 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)2 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1