Skip to content

Commit

Permalink
Feature/vorto 459 (#479)
Browse files Browse the repository at this point in the history
* Remove unused imports.

Signed-off-by: Erle Czar Mantos <[email protected]>

* Change the directory structure of the Bosch IoT Things Generator.

Signed-off-by: Erle Czar Mantos <[email protected]>

* Change the directory structure of the Bosch IoT Things Generator.

Signed-off-by: Erle Czar Mantos <[email protected]>

* Modified based on comments from the issue tracker.

Signed-off-by: Erle Czar Mantos <[email protected]>

* Reformatting. But previous 5 commits Fixes #459

Signed-off-by: Erle Czar Mantos <[email protected]>
  • Loading branch information
Erle Czar Mantos authored and aedelmann committed Jan 10, 2017
1 parent 8f11ddd commit c885803
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@

import org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask;
import org.eclipse.vorto.codegen.api.GenerationResultZip;
import org.eclipse.vorto.codegen.api.ICodeGeneratorTask;
import org.eclipse.vorto.codegen.api.IGeneratedWriter;
import org.eclipse.vorto.codegen.api.IGenerationResult;
import org.eclipse.vorto.codegen.api.IVortoCodeGenerator;
import org.eclipse.vorto.codegen.api.InvocationContext;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.ConfigurationValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.EventValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.FaultValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.OperationParametersValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.OperationReturnTypeValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.StatusValidationTask;
import org.eclipse.vorto.codegen.examples.bosch.things.tasks.ValidationTaskFactory;
import org.eclipse.vorto.core.api.model.functionblock.Configuration;
import org.eclipse.vorto.core.api.model.functionblock.Event;
import org.eclipse.vorto.core.api.model.functionblock.Fault;
Expand All @@ -38,119 +34,81 @@
public class BoschIoTThingsGenerator implements IVortoCodeGenerator {

public static final String JSON_SCHEMA_FILE_EXTENSION = ".schema.json";
public static final String TARGET_PATH = "json";
public static final String TARGET_PATH = "feature";

public IGenerationResult generate(InformationModel infomodel,
InvocationContext invocationContext) {

GenerationResultZip zipOutputter = new GenerationResultZip(infomodel,
getServiceKey());
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());

for (FunctionblockProperty fbp : infomodel.getProperties()) {
FunctionBlock fb = fbp.getType().getFunctionblock();

generateForFunctionblock(
fb,
invocationContext,
TARGET_PATH + "/"
+ fbp.getType().getNamespace() + "."
+ fbp.getType().getName() + "_"
+ fbp.getType().getVersion(),
fb, invocationContext,
TARGET_PATH + "/" + fbp.getType().getNamespace() + "." + fbp.getType().getName() + "_" + fbp.getType().getVersion(),
JSON_SCHEMA_FILE_EXTENSION,
zipOutputter);
}
return zipOutputter;
}

@SuppressWarnings("unchecked")
public void generateForFunctionblock(
FunctionBlock fb,
InvocationContext context,
String targetPath,
String jsonFileExtension,
String jsonFileExt,
IGeneratedWriter outputter) {
if (fb == null) {
throw new RuntimeException("fb is null");
}

if (fb.getOperations() != null) {
for (Operation op : fb.getOperations()) {
generateForOperation(
op,
context,
targetPath,
jsonFileExtension,
outputter);
}
}
String stateTargetPath = targetPath + "/state";
String operationTargetPath = targetPath + "/operations";
String eventTargetPath = targetPath + "/events";

Configuration configuration = fb.getConfiguration();
if (configuration != null) {
generateForConfiguration(configuration, context, targetPath, jsonFileExtension, outputter);
generateTask(configuration, context, outputter, ValidationTaskFactory.getConfigurationValidationTask(jsonFileExt, stateTargetPath));
}

Status status = fb.getStatus();
if (status != null) {
generateForStatus(status, context, targetPath, jsonFileExtension, outputter);
generateTask(status, context, outputter, ValidationTaskFactory.getStatusValidationTask(jsonFileExt, stateTargetPath));
}

Fault fault = fb.getFault();
if (fault != null) {
generateForFault(fault, context, targetPath, jsonFileExtension, outputter);
generateTask(fault, context, outputter, ValidationTaskFactory.getFaultValidationTask(jsonFileExt, stateTargetPath));
}

if (configuration != null || status != null || fault != null) {
generateTask(fb, context, outputter, ValidationTaskFactory.getStateValidationTask(jsonFileExt, stateTargetPath));
}

if (fb.getEvents() != null) {
for (Event event : fb.getEvents()) {
generateForEvent(
event,
context,
targetPath,
jsonFileExtension,
outputter);
generateTask(event, context, outputter, ValidationTaskFactory.getEventValidationTask(jsonFileExt, eventTargetPath));
}
}

if (fb.getOperations() != null) {
for (Operation op : fb.getOperations()) {
generateTask(op, context, outputter,
ValidationTaskFactory.getOperationParametersValidationTask(jsonFileExt, operationTargetPath),
ValidationTaskFactory.getOperationReturnTypeValidationTask(jsonFileExt, operationTargetPath));
}
}
}

private void generateForConfiguration(Configuration configuration, InvocationContext context, String targetPath, String jsonFileExtension,
IGeneratedWriter outputter) {
ChainedCodeGeneratorTask<Configuration> generator = new ChainedCodeGeneratorTask<Configuration>();
generator.addTask(new ConfigurationValidationTask(jsonFileExtension, targetPath));
generator.generate(configuration, context, outputter);
}

private void generateForFault(Fault fault, InvocationContext context, String targetPath, String jsonFileExtension,
IGeneratedWriter outputter) {
ChainedCodeGeneratorTask<Fault> generator = new ChainedCodeGeneratorTask<Fault>();
generator.addTask(new FaultValidationTask(jsonFileExtension, targetPath));
generator.generate(fault, context, outputter);
}

private void generateForStatus(Status status, InvocationContext context, String targetPath, String jsonFileExtension,
IGeneratedWriter outputter) {
ChainedCodeGeneratorTask<Status> generator = new ChainedCodeGeneratorTask<Status>();
generator.addTask(new StatusValidationTask(jsonFileExtension, targetPath));
generator.generate(status, context, outputter);
}

public void generateForEvent(
Event event,
InvocationContext context,
String targetPath,
String jsonFileExtension,
IGeneratedWriter outputter)
{
ChainedCodeGeneratorTask<Event> generator = new ChainedCodeGeneratorTask<Event>();
generator.addTask(new EventValidationTask(jsonFileExtension, targetPath));
generator.generate(event, context, outputter);
}

public void generateForOperation(Operation op,
InvocationContext context,
String targetPath, String jsonFileExtension, IGeneratedWriter outputter)
{
ChainedCodeGeneratorTask<Operation> generator = new ChainedCodeGeneratorTask<Operation>();
generator.addTask(new OperationParametersValidationTask(jsonFileExtension, targetPath));
generator.addTask(new OperationReturnTypeValidationTask(jsonFileExtension, targetPath));
generator.generate(op, context, outputter);
@SuppressWarnings("unchecked")
private <K> void generateTask(K element, InvocationContext context, IGeneratedWriter outputter, ICodeGeneratorTask<K>... tasks) {
ChainedCodeGeneratorTask<K> generator = new ChainedCodeGeneratorTask<K>();
for(ICodeGeneratorTask<K> task : tasks) {
generator.addTask(task);
}
generator.generate(element, context, outputter);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c885803

Please sign in to comment.