use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelContentToEcoreConverter method convertFunctionblockMapping.
private Model convertFunctionblockMapping(FunctionblockModel model, ModelContent context, String platformKey) {
MappingBuilder builder = BuilderUtils.newMapping(new ModelId(ModelType.InformationModel, model.getId().getName() + "Mapping", model.getId().getNamespace() + ".mapping." + platformKey, model.getId().getVersion()), platformKey);
builder.withVortolang("1.0");
builder.withDescription("Mapping that contains " + platformKey + " specific meta data");
builder.withReference(ModelIdFactory.newInstance(ModelType.Functionblock, model.getId().getNamespace(), model.getId().getVersion(), model.getId().getVersion()));
org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel eFbm = convertFunctionblock(model, context);
for (Stereotype stereotype : model.getStereotypes()) {
MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
FunctionBlockSource source = MappingFactory.eINSTANCE.createFunctionBlockSource();
source.setModel(eFbm);
ruleBuilder.withSource(source);
builder.addRule(ruleBuilder.build());
}
for (ModelProperty statusProperty : model.getStatusProperties()) {
for (Stereotype stereotype : statusProperty.getStereotypes()) {
MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
StatusSource source = MappingFactory.eINSTANCE.createStatusSource();
source.setModel(eFbm);
source.setProperty(eFbm.getFunctionblock().getStatus().getProperties().stream().filter(property -> property.getName().equals(statusProperty.getName())).findAny().get());
ruleBuilder.withSource(source);
builder.addRule(ruleBuilder.build());
}
}
for (ModelProperty configProperty : model.getConfigurationProperties()) {
for (Stereotype stereotype : configProperty.getStereotypes()) {
MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
ConfigurationSource source = MappingFactory.eINSTANCE.createConfigurationSource();
source.setModel(eFbm);
source.setProperty(eFbm.getFunctionblock().getConfiguration().getProperties().stream().filter(property -> property.getName().equals(configProperty.getName())).findAny().get());
ruleBuilder.withSource(source);
builder.addRule(ruleBuilder.build());
}
}
return builder.build();
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class GeneratorExecutionHandler method handleRequest.
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ObjectMapper mapper = ObjectMapperFactory.getInstance();
ApiGatewayRequest request = ApiGatewayRequest.createFromJson(input);
Optional<ICodeGenerator> generator = generators.stream().filter(gen -> gen.getMeta().getKey().equals(request.getPathParam(PLUGINKEY))).findAny();
if (!generator.isPresent()) {
objectMapper.writeValue(output, createHttpReponse(404));
}
ModelContent modelContent = mapper.readValue(request.getInput(), ModelContent.class);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
Model converted = converter.convert(modelContent, Optional.empty());
InvocationContext invocationContext = InvocationContext.simpleInvocationContext(request.getQueryParams());
InformationModel infomodel = org.eclipse.vorto.plugin.utils.Utils.toInformationModel(converted);
try {
IGenerationResult generatorResult = generator.get().generate(infomodel, invocationContext);
ApiGatewayResponse validResponse = createResponse(generatorResult);
OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8");
writer.write(objectMapper.writeValueAsString(validResponse));
writer.close();
} catch (GeneratorException e) {
ApiGatewayResponse response = createHttpReponse(500);
objectMapper.writeValue(output, response);
}
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertWithTargetPlatform.
@Test
public void testConvertWithTargetPlatform() throws Exception {
importModel("Color.type");
importModel("sample.mapping");
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), Optional.of("ios"));
assertNotNull(content);
assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), content.getModels().get(content.getRoot()).getId());
assertEquals("colortype", ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().get(0).getName());
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelContentDeserializationTest method testDeserializeWithDictionaryType.
@Test
public void testDeserializeWithDictionaryType() throws Exception {
ModelContent content = ObjectMapperFactory.getInstance().readValue(new ClassPathResource("json/TestModelContent_dictionary.json").getInputStream(), ModelContent.class);
assertNotNull(content);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
FunctionblockModel model = (FunctionblockModel) converter.convert(content, Optional.empty());
assertNotNull(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
}
use of org.eclipse.vorto.model.ModelContent in project vorto by eclipse.
the class ModelContentDeserializationTest method testDeserializeWithPrimitiveType.
@Test
public void testDeserializeWithPrimitiveType() throws Exception {
ModelContent content = ObjectMapperFactory.getInstance().readValue(new ClassPathResource("json/TestModelContent_primitive.json").getInputStream(), ModelContent.class);
assertNotNull(content);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
FunctionblockModel model = (FunctionblockModel) converter.convert(content, Optional.empty());
assertNotNull(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof PrimitivePropertyType);
}
Aggregations