Search in sources :

Example 16 with ModelProperty

use of org.eclipse.vorto.model.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());
    p.setType(createReferenceType(property.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())) {
            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 : 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) ReturnType(org.eclipse.vorto.model.ReturnType) Event(org.eclipse.vorto.core.api.model.functionblock.Event) EntityPropertySource(org.eclipse.vorto.core.api.model.mapping.EntityPropertySource) 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) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ModelInfoDto(org.eclipse.vorto.repository.web.api.v1.dto.ModelInfoDto) Map(java.util.Map) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) EnumAttributePropertyType(org.eclipse.vorto.model.EnumAttributePropertyType) Operation(org.eclipse.vorto.model.Operation) AbstractModel(org.eclipse.vorto.model.AbstractModel) EnumLiteral(org.eclipse.vorto.model.EnumLiteral) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) InfoModelPropertySource(org.eclipse.vorto.core.api.model.mapping.InfoModelPropertySource) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) List(java.util.List) DictionaryType(org.eclipse.vorto.model.DictionaryType) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) BooleanAttributeProperty(org.eclipse.vorto.model.BooleanAttributeProperty) OperationSource(org.eclipse.vorto.core.api.model.mapping.OperationSource) ModelEvent(org.eclipse.vorto.model.ModelEvent) Optional(java.util.Optional) IPropertyAttribute(org.eclipse.vorto.model.IPropertyAttribute) Constraint(org.eclipse.vorto.model.Constraint) EnumAttributeProperty(org.eclipse.vorto.model.EnumAttributeProperty) ConstraintType(org.eclipse.vorto.model.ConstraintType) Param(org.eclipse.vorto.model.Param) IUserContext(org.eclipse.vorto.repository.core.IUserContext) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Infomodel(org.eclipse.vorto.model.Infomodel) 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) IReferenceType(org.eclipse.vorto.model.IReferenceType) Property(org.eclipse.vorto.core.api.model.datatype.Property) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) EntityModel(org.eclipse.vorto.model.EntityModel) 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) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) ModelProperty(org.eclipse.vorto.model.ModelProperty) InfoModelAttributeSource(org.eclipse.vorto.core.api.model.mapping.InfoModelAttributeSource) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) EnumSource(org.eclipse.vorto.core.api.model.mapping.EnumSource) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) Source(org.eclipse.vorto.core.api.model.mapping.Source) ModelType(org.eclipse.vorto.model.ModelType) Stereotype(org.eclipse.vorto.model.Stereotype) FaultSource(org.eclipse.vorto.core.api.model.mapping.FaultSource) EnumModel(org.eclipse.vorto.model.EnumModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BooleanAttributePropertyType(org.eclipse.vorto.model.BooleanAttributePropertyType) Comment(org.eclipse.vorto.repository.domain.Comment) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) IPropertyAttribute(org.eclipse.vorto.model.IPropertyAttribute) Constraint(org.eclipse.vorto.model.Constraint) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) ModelProperty(org.eclipse.vorto.model.ModelProperty) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 17 with ModelProperty

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

Example 18 with ModelProperty

use of org.eclipse.vorto.model.ModelProperty in project vorto by eclipse.

the class ModelContentToEcoreConverter method createProperty.

private Property createProperty(ModelProperty sourceProperty, ModelBuilder<?> builder, ModelContent context) {
    Property property = DatatypeFactory.eINSTANCE.createProperty();
    property.setName(sourceProperty.getName());
    property.setType(createPropertyType(sourceProperty.getType(), builder, context));
    property.setDescription(sourceProperty.getDescription());
    Presence presence = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createPresence();
    presence.setMandatory(sourceProperty.isMandatory());
    property.setPresence(presence);
    property.setMultiplicity(sourceProperty.isMultiple());
    org.eclipse.vorto.core.api.model.datatype.ConstraintRule rule = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createConstraintRule();
    for (Constraint constraint : sourceProperty.getConstraints()) {
        org.eclipse.vorto.core.api.model.datatype.Constraint eConstraint = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createConstraint();
        eConstraint.setConstraintValues(constraint.getValue());
        eConstraint.setType(ConstraintIntervalType.valueOf(constraint.getType().name()));
        rule.getConstraints().add(eConstraint);
    }
    property.setConstraintRule(rule);
    return property;
}
Also used : Constraint(org.eclipse.vorto.model.Constraint) Presence(org.eclipse.vorto.core.api.model.datatype.Presence) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 19 with ModelProperty

use of org.eclipse.vorto.model.ModelProperty in project vorto by eclipse.

the class ModelContentToEcoreConverter method convertFunctionblock.

private org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel convertFunctionblock(FunctionblockModel model, ModelContent context) {
    FunctionblockBuilder builder = BuilderUtils.newFunctionblock(new ModelId(ModelType.Functionblock, model.getId().getName(), model.getId().getNamespace(), model.getId().getVersion()));
    builder.withCategory(model.getCategory());
    builder.withDescription(model.getDescription());
    builder.withDisplayName(model.getDisplayName());
    builder.withVortolang(model.getVortolang());
    if (model.getSuperType() != null)
        builder.withSuperType(convertSupertype(model.getSuperType(), model, context));
    for (ModelProperty sourceProperty : model.getStatusProperties()) {
        Property property = createProperty(sourceProperty, builder, context);
        builder.withStatusProperty(property);
    }
    for (ModelProperty sourceProperty : model.getConfigurationProperties()) {
        Property property = createProperty(sourceProperty, builder, context);
        builder.withConfiguration(property);
    }
    for (Operation operation : model.getOperations()) {
        builder.withOperation(operation.getName(), createReturnTypeOrNull(operation.getResult(), builder, context), operation.getDescription(), operation.isBreakable(), createParams(operation.getParams(), builder, context));
    }
    for (ModelEvent event : model.getEvents()) {
        EventBuilder eventBuilder = BuilderUtils.newEvent(event.getName());
        for (ModelProperty sourceProperty : event.getProperties()) {
            Property property = createProperty(sourceProperty, builder, context);
            eventBuilder.withProperty(property);
        }
        builder.withEvent(eventBuilder.build());
    }
    return builder.build();
}
Also used : EventBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EventBuilder) FunctionblockBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.FunctionblockBuilder) ModelProperty(org.eclipse.vorto.model.ModelProperty) Operation(org.eclipse.vorto.model.Operation) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelEvent(org.eclipse.vorto.model.ModelEvent) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 20 with ModelProperty

use of org.eclipse.vorto.model.ModelProperty in project vorto by eclipse.

the class ModelContentToEcoreConverter method convertEntity.

private Entity convertEntity(EntityModel entity, ModelContent context) {
    EntityBuilder builder = BuilderUtils.newEntity(new ModelId(ModelType.Datatype, entity.getId().getName(), entity.getId().getNamespace(), entity.getId().getVersion()));
    builder.withCategory(entity.getCategory());
    builder.withDescription(entity.getDescription());
    builder.withDisplayName(entity.getDisplayName());
    builder.withVortolang(entity.getVortolang());
    builder.withReferences(entity.getReferences().stream().map(r -> new ModelId(ModelType.Datatype, r.getName(), r.getNamespace(), r.getVersion())).collect(Collectors.toList()));
    for (ModelProperty sourceProperty : entity.getProperties()) {
        Property property = createProperty(sourceProperty, builder, context);
        builder.withProperty(property);
    }
    return builder.build();
}
Also used : ModelProperty(org.eclipse.vorto.model.ModelProperty) EntityBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EntityBuilder) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Aggregations

ModelProperty (org.eclipse.vorto.model.ModelProperty)39 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)30 Property (org.eclipse.vorto.core.api.model.datatype.Property)5 EntityModel (org.eclipse.vorto.model.EntityModel)5 Infomodel (org.eclipse.vorto.model.Infomodel)5 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)4 Constraint (org.eclipse.vorto.model.Constraint)4 EnumModel (org.eclipse.vorto.model.EnumModel)4 ModelEvent (org.eclipse.vorto.model.ModelEvent)3 ModelId (org.eclipse.vorto.model.ModelId)3 Operation (org.eclipse.vorto.model.Operation)3 Stereotype (org.eclipse.vorto.model.Stereotype)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)2 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)2 EntityBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.EntityBuilder)2 EventBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.EventBuilder)2