Search in sources :

Example 1 with StereoTypeTarget

use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget 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 StereoTypeTarget

use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget 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 3 with StereoTypeTarget

use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget in project vorto by eclipse.

the class ModelDtoFactory method createResource.

public static EntityModel createResource(Entity model, Optional<MappingModel> mappingModel) {
    EntityModel resource = new EntityModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Datatype);
    resource.setDescription(model.getDescription());
    resource.setDisplayName(model.getDisplayname());
    resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    resource.setProperties(model.getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
    if (mappingModel.isPresent()) {
        resource.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getEntityRule(mappingModel.get().getRules())) {
            StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
            resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
        }
    }
    return resource;
}
Also used : EntityModel(org.eclipse.vorto.repository.api.content.EntityModel) 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)

Example 4 with StereoTypeTarget

use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget 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 5 with StereoTypeTarget

use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget in project vorto by eclipse.

the class TestStereoTypeFactory method createStereoTypeTarget.

public static StereoTypeTarget createStereoTypeTarget() {
    StereoTypeTarget stereoType = MappingFactory.eINSTANCE.createStereoTypeTarget();
    Attribute typeAttribute = MappingFactory.eINSTANCE.createAttribute();
    typeAttribute.setName("DummyAttribute");
    typeAttribute.setValue("Dummy Attribute Value");
    stereoType.setName("DummyStereoType");
    stereoType.getAttributes().add(typeAttribute);
    return stereoType;
}
Also used : Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Aggregations

StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)7 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)6 ModelId (org.eclipse.vorto.repository.api.ModelId)5 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)4 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)3 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)3 Optional (java.util.Optional)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)2 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)2 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)2 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)1 EnumLiteralPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute)1 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)1