Search in sources :

Example 1 with ObjectPropertyType

use of org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType 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 2 with ObjectPropertyType

use of org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType in project vorto by eclipse.

the class DatatypeGeneratorTask method getTypesOfType.

private static Set<Type> getTypesOfType(Type type, Set<Type> container) {
    TreeIterator<EObject> iterator = type.eAllContents();
    while (iterator.hasNext()) {
        EObject current = iterator.next();
        if (current instanceof ObjectPropertyType) {
            if (!container.contains(current)) {
                container.add(((ObjectPropertyType) current).getType());
                Set<Type> moreTypes = getTypesOfType(((ObjectPropertyType) current).getType(), container);
                container.addAll(moreTypes);
            }
        }
    }
    return container;
}
Also used : ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Type(org.eclipse.vorto.core.api.model.datatype.Type) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with ObjectPropertyType

use of org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType in project vorto by eclipse.

the class DatatypeGeneratorTask method getTypes.

private static Set<Type> getTypes(FunctionblockModel model) {
    Set<Type> allTypes = new LinkedHashSet<>();
    TreeIterator<EObject> iterator = model.eAllContents();
    while (iterator.hasNext()) {
        EObject current = iterator.next();
        if (current instanceof RefParam) {
            addTypeAndReferences(((RefParam) current).getType(), allTypes);
        } else if (current instanceof ReturnObjectType) {
            addTypeAndReferences(((ReturnObjectType) current).getReturnType(), allTypes);
        } else if (current instanceof ObjectPropertyType) {
            addTypeAndReferences(((ObjectPropertyType) current).getType(), allTypes);
        }
    }
    return allTypes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Type(org.eclipse.vorto.core.api.model.datatype.Type) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) EObject(org.eclipse.emf.ecore.EObject) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)

Example 4 with ObjectPropertyType

use of org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType in project vorto by eclipse.

the class CodeGenTools method getReferencedTypes.

public static EList<Type> getReferencedTypes(Property property) {
    EList<Type> types = new BasicEList<Type>();
    if (property.getType() instanceof ObjectPropertyType) {
        ObjectPropertyType objectType = (ObjectPropertyType) property.getType();
        types.add(objectType.getType());
        if (objectType.getType() instanceof Entity) {
            types.addAll(getReferencedTypes((Entity) objectType.getType()));
        }
    }
    return types;
}
Also used : Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Type(org.eclipse.vorto.core.api.model.datatype.Type) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BasicEList(org.eclipse.emf.common.util.BasicEList)

Aggregations

ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)4 Type (org.eclipse.vorto.core.api.model.datatype.Type)3 ReturnObjectType (org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)3 EObject (org.eclipse.emf.ecore.EObject)2 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)2 RefParam (org.eclipse.vorto.core.api.model.functionblock.RefParam)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)1 EnumLiteralPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute)1 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)1 PrimitiveType (org.eclipse.vorto.core.api.model.datatype.PrimitiveType)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 PropertyAttribute (org.eclipse.vorto.core.api.model.datatype.PropertyAttribute)1 Event (org.eclipse.vorto.core.api.model.functionblock.Event)1