use of org.eclipse.vorto.model.DictionaryType in project vorto by eclipse.
the class ModelContentToEcoreConverter method createReturnTypeOrNull.
private ReturnType createReturnTypeOrNull(org.eclipse.vorto.model.ReturnType result, FunctionblockBuilder builder, ModelContent context) {
if (result == null) {
return null;
} else {
if (result.getType() instanceof PrimitiveType) {
ReturnPrimitiveType type = FunctionblockFactory.eINSTANCE.createReturnPrimitiveType();
type.setMultiplicity(result.isMultiple());
type.setReturnType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) result.getType()).name()));
return type;
} else if (result.getType() instanceof org.eclipse.vorto.model.ModelId) {
ReturnObjectType type = FunctionblockFactory.eINSTANCE.createReturnObjectType();
type.setMultiplicity(result.isMultiple());
Type convertedType = ((Type) convert(context.getModels().get((org.eclipse.vorto.model.ModelId) result.getType()), context, Optional.empty()));
builder.withReference(ModelIdFactory.newInstance(convertedType));
type.setReturnType(convertedType);
return type;
} else if (result.getType() instanceof DictionaryType) {
ReturnDictonaryType type = FunctionblockFactory.eINSTANCE.createReturnDictonaryType();
type.setMultiplicity(result.isMultiple());
type.setReturnType((DictionaryPropertyType) createPropertyType(result.getType(), builder, context));
return type;
} else {
return null;
}
}
}
use of org.eclipse.vorto.model.DictionaryType in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithoutParameters.
@Test
public void testConvertFunctionblockWithDictionaryTypeWithoutParameters() {
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(null, null)).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(1, model.getFunctionblock().getStatus().getProperties().size());
assertTrue(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
}
use of org.eclipse.vorto.model.DictionaryType 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.DictionaryType in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters.
@Test
public void testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters() {
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(PrimitiveType.STRING, PrimitiveType.INT)).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(1, model.getFunctionblock().getStatus().getProperties().size());
assertTrue(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getKeyType() instanceof PrimitivePropertyType);
assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getValueType() instanceof PrimitivePropertyType);
}
use of org.eclipse.vorto.model.DictionaryType in project vorto by eclipse.
the class ModelContentToEcoreConverter method createPropertyType.
private PropertyType createPropertyType(IReferenceType referenceType, ModelBuilder<?> builder, ModelContent context) {
if (referenceType instanceof PrimitiveType) {
PrimitivePropertyType primitive = DatatypeFactory.eINSTANCE.createPrimitivePropertyType();
primitive.setType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) referenceType).name()));
return primitive;
} else if (referenceType instanceof org.eclipse.vorto.model.ModelId) {
IModel referencedModel = context.getModels().get((org.eclipse.vorto.model.ModelId) referenceType);
Type convertedReference = (Type) convert(referencedModel, context, Optional.empty());
builder.withReference(ModelIdFactory.newInstance(convertedReference));
ObjectPropertyType objType = DatatypeFactory.eINSTANCE.createObjectPropertyType();
objType.setType(convertedReference);
return objType;
} else if (referenceType instanceof DictionaryType) {
DictionaryType dictionaryType = (DictionaryType) referenceType;
DictionaryPropertyType dictionary = DatatypeFactory.eINSTANCE.createDictionaryPropertyType();
if (dictionaryType.getKey() != null) {
dictionary.setKeyType(createPropertyType(dictionaryType.getKey(), builder, context));
}
if (dictionaryType.getValue() != null) {
dictionary.setValueType(createPropertyType(dictionaryType.getValue(), builder, context));
}
return dictionary;
} else {
throw new UnsupportedOperationException("Reference type is not valie");
}
}
Aggregations