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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations