use of org.eclipse.vorto.model.ReturnType in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockOperationWithPrimitiveTypes.
@Test
public void testConvertFunctionblockOperationWithPrimitiveTypes() {
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).operation(Operation.Builder("op").description("some operation").withParam(Param.Builder("p1", PrimitiveType.INT).build()).build()).operation(Operation.Builder("op2").withResult(new ReturnType(PrimitiveType.BOOLEAN, false)).build()).build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
assertEquals(2, model.getFunctionblock().getOperations().size());
org.eclipse.vorto.core.api.model.functionblock.Operation op1 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op")).findAny().get();
assertEquals("some operation", op1.getDescription());
assertEquals(1, op1.getParams().size());
assertEquals("p1", op1.getParams().get(0).getName());
assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.INT, ((PrimitiveParam) op1.getParams().get(0)).getType());
org.eclipse.vorto.core.api.model.functionblock.Operation op2 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op2")).findAny().get();
assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.BOOLEAN, ((ReturnPrimitiveType) op2.getReturnType()).getReturnType());
}
use of org.eclipse.vorto.model.ReturnType in project vorto by eclipse.
the class ModelDtoFactory method createOperation.
private static Operation createOperation(org.eclipse.vorto.core.api.model.functionblock.Operation o, Optional<MappingModel> mappingModel) {
Operation operation = new Operation(o.getName());
operation.setBreakable(o.isBreakable());
operation.setDescription(o.getDescription());
operation.setParams(o.getParams().stream().map(p -> createParam(p, mappingModel)).collect(Collectors.toList()));
if (o.getReturnType() != null) {
ReturnType returnType = new ReturnType();
returnType.setMultiple(o.getReturnType().isMultiplicity());
if (o.getReturnType() instanceof ReturnPrimitiveType) {
returnType.setPrimitive(true);
PrimitiveType pt = ((ReturnPrimitiveType) o.getReturnType()).getReturnType();
returnType.setType(org.eclipse.vorto.model.PrimitiveType.valueOf(pt.name()));
} else if (o.getReturnType() instanceof ReturnObjectType) {
returnType.setPrimitive(false);
returnType.setType(createModelId(((ReturnObjectType) o.getReturnType()).getReturnType()));
} else if (o.getReturnType() instanceof ReturnDictonaryType) {
returnType.setPrimitive(false);
returnType.setMultiple(true);
DictionaryPropertyType dt = ((ReturnDictonaryType) o.getReturnType()).getReturnType();
returnType.setType(new DictionaryType(createReferenceType(dt.getKeyType()), createReferenceType(dt.getValueType())));
}
operation.setResult(returnType);
}
if (mappingModel.isPresent()) {
operation.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
for (MappingRule rule : getOperationRule(operation.getName(), mappingModel.get().getRules())) {
if (rule.getTarget() instanceof StereoTypeTarget) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
operation.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
} else if (rule.getTarget() instanceof ReferenceTarget) {
ReferenceTarget target = (ReferenceTarget) rule.getTarget();
operation.setMappingReference(createModelId(target.getMappingModel()));
}
}
}
return operation;
}
use of org.eclipse.vorto.model.ReturnType in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockOperationWithObjectTypes.
@Test
public void testConvertFunctionblockOperationWithObjectTypes() {
EnumModel enumModel = EnumModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Unit:1.0.0")).literal("celcius", null).literal("kg", null).build();
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).operation(Operation.Builder("op").withParam(Param.Builder("p1", enumModel.getId()).build()).build()).operation(Operation.Builder("op2").withResult(new ReturnType(enumModel.getId(), false)).build()).build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).withDependency(enumModel).build(), Optional.empty());
assertEquals(2, model.getFunctionblock().getOperations().size());
assertEquals(1, model.getReferences().size());
org.eclipse.vorto.core.api.model.functionblock.Operation op1 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op")).findAny().get();
assertEquals(1, op1.getParams().size());
assertEquals("Unit", ((Enum) ((RefParam) op1.getParams().get(0)).getType()).getName());
assertEquals(2, ((Enum) ((RefParam) op1.getParams().get(0)).getType()).getEnums().size());
org.eclipse.vorto.core.api.model.functionblock.Operation op2 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op2")).findAny().get();
assertEquals("Unit", ((Enum) (((ReturnObjectType) op2.getReturnType()).getReturnType())).getName());
assertEquals(2, ((Enum) (((ReturnObjectType) op2.getReturnType()).getReturnType())).getEnums().size());
}
Aggregations