use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static org.eclipse.vorto.repository.api.content.FunctionblockModel createResource(FunctionblockModel model, Optional<MappingModel> mappingModel) {
org.eclipse.vorto.repository.api.content.FunctionblockModel resource = new org.eclipse.vorto.repository.api.content.FunctionblockModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Functionblock);
resource.setDescription(model.getDescription());
resource.setDisplayName(model.getDisplayname());
resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
if (model.getFunctionblock().getConfiguration() != null) {
resource.setConfigurationProperties(model.getFunctionblock().getConfiguration().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getStatus() != null) {
resource.setStatusProperties(model.getFunctionblock().getStatus().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getFault() != null) {
resource.setFaultProperties(model.getFunctionblock().getFault().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getEvents() != null) {
resource.setEvents(model.getFunctionblock().getEvents().stream().map(e -> createEvent(e, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getOperations() != null) {
resource.setOperations(model.getFunctionblock().getOperations().stream().map(o -> createOperation(o)).collect(Collectors.toList()));
}
if (mappingModel.isPresent()) {
MappingModel _mappingModel = mappingModel.get();
resource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
for (MappingRule rule : getFbRule(_mappingModel.getRules())) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
}
}
return resource;
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class CGenerator method generate.
@Override
public IGenerationResult generate(InformationModel model, InvocationContext context) {
GenerationResultZip outputter = new GenerationResultZip(model, getServiceKey());
for (FunctionblockProperty property : model.getProperties()) {
ChainedCodeGeneratorTask<FunctionblockModel> generator = new ChainedCodeGeneratorTask<FunctionblockModel>();
if (property.getType().getFunctionblock().getStatus() != null) {
generator.addTask(new GeneratorTaskFromFileTemplate<>(new CHeaderTemplate()));
}
generator.generate(property.getType(), context, outputter);
}
return outputter;
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class TestFunctionBlockFactory method createFunctionBlockModel.
public static FunctionblockModel createFunctionBlockModel() {
FunctionblockModel fbmodel = FunctionblockFactory.eINSTANCE.createFunctionblockModel();
FunctionBlock fb = FunctionblockFactory.eINSTANCE.createFunctionBlock();
fbmodel.setName("Fridge");
fbmodel.setCategory("demo");
fbmodel.setDescription("A Simple Fridge Functionblock for tester");
fbmodel.setNamespace("www.bosch.com");
fbmodel.setVersion("1.2.3");
fbmodel.setDisplayname("Fridge Function Block");
fb.getOperations().add(createOnOperation());
fb.getOperations().add(createOffOperation());
fb.getOperations().add(createToggleOperation());
fb.setConfiguration(createConfiguration());
fb.setStatus(createStatus());
fb.setFault(createFault());
fbmodel.setFunctionblock(fb);
return fbmodel;
}
use of org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel in project vorto by eclipse.
the class WebDeviceGenerator 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>();
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ServiceClassTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PageTemplate()));
generator.generate(property.getType(), invocationContext, outputter);
}
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
generator.addTask(new GeneratorTaskFromFileTemplate<>(new WebSocketConfigTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new IndexHtmlFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceInfoTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceInfoServiceTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ControllersScriptFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new AppScriptFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ApplicationMainTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new CssTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ApplicationYmlTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ReadmeTemplate()));
generator.generate(context, 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 UIComponentFactory method getByModelId.
public static IFunctionBlockUITemplate getByModelId(FunctionblockModel fbm, InvocationContext ctx) {
IMapped<FunctionblockModel> mappedElement = ctx.getMappedElement(fbm, STEREOTYPE_COMPONENT);
String uiType = mappedElement.getAttributeValue(ATTRIBUTE_TYPE, "default");
if (uiType.equalsIgnoreCase("barchart")) {
List<String> properties = new ArrayList<String>();
for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
if (uiProperty.equalsIgnoreCase("value")) {
properties.add(property.getName());
}
}
return new BarChartUITemplate(properties);
} else if (uiType.equalsIgnoreCase("map")) {
String latitude = null;
String longitude = null;
for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
if (uiProperty.equalsIgnoreCase("longitude")) {
longitude = property.getName();
} else if (uiProperty.equalsIgnoreCase("latitude")) {
latitude = property.getName();
}
}
return new LocationMapUITemplate(longitude, latitude);
} else if (uiType.equalsIgnoreCase("gauge")) {
String value = null;
String min = null;
String max = null;
String symbol = null;
for (Property property : fbm.getFunctionblock().getStatus().getProperties()) {
IMapped<Property> uiAttribute = ctx.getMappedElement(property, STEREOTYPE_COMPONENT);
String uiProperty = uiAttribute.getAttributeValue(ATTRIBUTE_TYPE, "");
if (uiProperty.equalsIgnoreCase("value")) {
value = property.getName();
} else if (uiProperty.equalsIgnoreCase("min")) {
min = property.getName();
} else if (uiProperty.equalsIgnoreCase("max")) {
max = property.getName();
} else if (uiProperty.equalsIgnoreCase("symbol")) {
symbol = property.getName();
}
}
return new GaugeUITemplate(symbol, min, max, value);
} else {
return new DefaultUITemplate();
}
}
Aggregations