use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class TypeImportValidation method validate.
@Override
public void validate(ModelInfo modelResource, InvocationContext context) throws ValidationException {
Collection<String> unImportedReferences = Lists.newArrayList();
ModelEMFResource emfModel = (ModelEMFResource) modelResource;
Model model = emfModel.getModel();
if (model == null)
return;
if (model instanceof Entity) {
unImportedReferences.addAll(getUnimportedProperties(((Entity) model).getProperties(), model.getReferences()));
} else if (model instanceof FunctionblockModel) {
unImportedReferences.addAll(validateFunctionBlock((FunctionblockModel) model));
} else if (model instanceof InformationModel) {
unImportedReferences.addAll(getUnimportedFunctionblocks(((InformationModel) model).getProperties(), model.getReferences()));
}
unImportedReferences.forEach(ref -> System.out.println("Missing : " + ref));
if (!unImportedReferences.isEmpty()) {
throw new ValidationException(errorMessage(unImportedReferences), modelResource);
}
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class MQTTPlatformGenerator method generate.
@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
for (FunctionblockProperty property : context.getProperties()) {
ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
if (property.getType().getFunctionblock().getStatus() != null) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new IClientHandlerTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new MqttConfigurationTemplate()));
}
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
generator.generate(property.getType(), invocationContext, outputter);
}
IGenerationResult javaResult = invocationContext.lookupGenerator(JavabeanGenerator.KEY).generate(context, invocationContext, monitor);
return GenerationResultBuilder.from(outputter).append(javaResult).build();
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class ProSystGenerator method generateForFunctionBlock.
private void generateForFunctionBlock(InformationModel infomodel, InvocationContext ctx, FunctionblockModel fbm, IGeneratedWriter outputter, String[] imports) {
ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
generator.addTask(new FunctionalItemGeneratorTask(JAVA_FILE_EXTENSION, SOURCE, fbm.getNamespace()));
generator.addTask(new FunctionalItemImplGeneratorTask(JAVA_FILE_EXTENSION, SOURCE, fbm.getNamespace(), imports));
generator.generate(fbm, ctx, outputter);
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class CodeGenerationController method generate.
@RequestMapping(value = "/{namespace}/{name}/{version:.+}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> generate(@PathVariable String namespace, @PathVariable String name, @PathVariable String version, final HttpServletRequest request) {
byte[] modelResources = downloadModelWithReferences(namespace, name, version);
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelResources))).read();
Model model = workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get();
InformationModel infomodel = null;
if (model instanceof InformationModel) {
infomodel = (InformationModel) model;
} else if (model instanceof FunctionblockModel) {
infomodel = Utils.wrapFunctionBlock((FunctionblockModel) model);
}
IGenerationResult result = null;
try {
Map<String, String> requestParams = new HashMap<>();
request.getParameterMap().entrySet().stream().forEach(x -> requestParams.put(x.getKey(), x.getValue()[0]));
result = vortoGenerator.generate(infomodel, createInvocationContext(infomodel, vortoGenerator.getServiceKey(), requestParams), null);
} catch (Exception e) {
GenerationResultZip output = new GenerationResultZip(infomodel, vortoGenerator.getServiceKey());
Generated generated = new Generated("generation_error.log", "/generated", e.getMessage());
output.write(generated);
result = output;
}
return ResponseEntity.ok().contentLength(result.getContent().length).header("content-disposition", "attachment; filename = " + result.getFileName()).contentType(MediaType.parseMediaType(result.getMediatype())).body(new InputStreamResource(new ByteArrayInputStream(result.getContent())));
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class ModelTransformer method transformProperty.
private void transformProperty(Service service, Property property) {
IMapped<Property> map = this.context.getMappedElement(property, "source");
if (map.hasAttribute("uuid")) {
String uuid = map.getAttributeValue("uuid", "");
Characteristic characteristic = null;
for (Characteristic ch : service.getCharacteristics()) {
if (ch.getUuid().equals(uuid)) {
characteristic = ch;
break;
}
}
if (characteristic == null) {
characteristic = this.factory.createCharacteristic();
characteristic.setUuid(uuid);
if (map.hasAttribute("name")) {
characteristic.setName(map.getAttributeValue("name", ""));
} else {
characteristic.setName(((FunctionblockModel) (property.eContainer().eContainer().eContainer())).getName() + property.getName());
}
service.getCharacteristics().add(characteristic);
}
if (Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")) > characteristic.getLength()) {
characteristic.setLength(Integer.valueOf(map.getAttributeValue("length", "0")) + Integer.valueOf(map.getAttributeValue("offset", "0")));
}
if (Utils.isReadable(property)) {
characteristic.setIsReadable(true);
}
if (Utils.isWritable(property)) {
characteristic.setIsWritable(true);
}
if (Utils.isEventable(property)) {
characteristic.setIsEventable(true);
}
if (map.hasAttribute("length") && map.hasAttribute("offset") && map.hasAttribute("datatype")) {
CharacteristicProperty cp = this.factory.createCharacteristicProperty();
cp.setDatatype(map.getAttributeValue("datatype", ""));
cp.setLength(Integer.parseInt(map.getAttributeValue("length", "0")));
cp.setOffset(Integer.parseInt(map.getAttributeValue("offset", "0")));
cp.setProperty(property);
characteristic.getProperties().add(cp);
}
}
}
Aggregations