public static List<FunctionblockModel> getFunctionBlocksUsingStatus(InformationModel model) { List<FunctionblockModel> result = new ArrayList<>(); for (FunctionblockProperty fbProp : model.getProperties()) { if (fbProp.getType().getFunctionblock().getStatus() != null) { result.add(fbProp.getType()); } } return result; } }
public static List<FunctionblockModel> getFunctionBlocksUsingStatus(InformationModel model) { List<FunctionblockModel> result = new ArrayList<>(); for (FunctionblockProperty fbProp : model.getProperties()) { if (fbProp.getType().getFunctionblock().getStatus() != null) { result.add(fbProp.getType()); } } return result; } }
@Override public void generate(InformationModel infomodel, InvocationContext invocationContext, IGeneratedWriter writer) { for (FunctionblockProperty fbp : infomodel.getProperties()) { FunctionBlock fb = fbp.getType().getFunctionblock(); generateForFunctionblock( fb, invocationContext, TARGET_PATH + "/" + fbp.getType().getNamespace() + "_" + fbp.getType().getName() + "_" + fbp.getType().getVersion(), JSON_SCHEMA_FILE_EXTENSION, writer); } }
/** * Sorts all functionblock properties according to their functionblock model */ public static EMap<FunctionblockModel, EList<FunctionblockProperty>> sortByPropertyType(final EList<FunctionblockProperty> properties) { EMap<FunctionblockModel, EList<FunctionblockProperty>> map = new BasicEMap<FunctionblockModel, EList<FunctionblockProperty>>(); for (final FunctionblockProperty property : properties) { FunctionblockModel _type = property.getType(); boolean _containsKey = map.containsKey(_type); if (_containsKey) { FunctionblockModel _type_1 = property.getType(); EList<FunctionblockProperty> eList = map.get(_type_1); eList.add(property); FunctionblockModel _type_2 = property.getType(); map.put(_type_2, eList); } else { EList<FunctionblockProperty> eList_1 = new BasicEList<FunctionblockProperty>(); eList_1.add(property); FunctionblockModel _type_3 = property.getType(); map.put(_type_3, eList_1); } } return map; } }
private boolean hasLWM2MMapping(final FunctionblockProperty property, final InvocationContext context) { return context.getMappedElement(property.getType(), LWM2MConstants.STEREOTYPE_OBJECT).isMapped(); }
/** * Sorts all functionblock properties according to their functionblock model */ public static EMap<FunctionblockModel, EList<FunctionblockProperty>> sortByPropertyType(final EList<FunctionblockProperty> properties) { EMap<FunctionblockModel, EList<FunctionblockProperty>> map = new BasicEMap<FunctionblockModel, EList<FunctionblockProperty>>(); for (final FunctionblockProperty property : properties) { FunctionblockModel _type = property.getType(); boolean _containsKey = map.containsKey(_type); if (_containsKey) { FunctionblockModel _type_1 = property.getType(); EList<FunctionblockProperty> eList = map.get(_type_1); eList.add(property); FunctionblockModel _type_2 = property.getType(); map.put(_type_2, eList); } else { EList<FunctionblockProperty> eList_1 = new BasicEList<FunctionblockProperty>(); eList_1.add(property); FunctionblockModel _type_3 = property.getType(); map.put(_type_3, eList_1); } } return map; } }
@Override public IGenerationResult generate(InformationModel infomodel, InvocationContext context, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException { GenerationResultZip output = new GenerationResultZip(infomodel,getServiceKey()); for (FunctionblockProperty fbProperty : infomodel.getProperties()) { if (hasLWM2MMapping(fbProperty, context)) { LWM2M_XML_GENERATOR.generate(fbProperty.getType(), context, output); } if (context.getConfigurationProperties().getOrDefault(CONFIG_PARAM_SKIP_CLIENT, "false").equalsIgnoreCase("false")) { LWM2M_CLIENT_GENERATOR.generate(fbProperty.getType(), context, output); } } return output; }
@Override public void generate(InformationModel ctx, InvocationContext context, IGeneratedWriter writer) { Set<Type> allTypesUsedInModel = new HashSet<>(); for (FunctionblockProperty prop : ctx.getProperties()) { allTypesUsedInModel.addAll(getTypes(prop.getType())); } for (Type type : allTypesUsedInModel) { if (type instanceof Entity) { writer.write(new Generated(entityTemplate.getFileName((Entity)type),entityTemplate.getPath((Entity)type),entityTemplate.getContent((Entity)type,context))); } else if (type instanceof Enum) { writer.write(new Generated(enumTemplate.getFileName((Enum)type),enumTemplate.getPath((Enum)type),enumTemplate.getContent((Enum)type,context))); } } }
public static InformationModel convertToFlatHierarchy(InformationModel infomodel) { for (FunctionblockProperty fbProperty : infomodel.getProperties()) { FunctionblockModel fbm = fbProperty.getType(); fbProperty.setType(convertToFlatHierarchy(fbm)); // merge any extended properties from information model to the FB properties if (fbProperty.getExtendedFunctionBlock() != null && fbProperty.getExtendedFunctionBlock().getStatus() != null) { for (Property extendedProperty : fbProperty.getExtendedFunctionBlock().getStatus() .getProperties()) { Optional<Property> baseProperty = fbm.getFunctionblock().getStatus().getProperties() .stream().filter(p -> p.getName().equals(extendedProperty.getName())).findFirst(); if (baseProperty.isPresent()) { baseProperty.get().setConstraintRule(extendedProperty.getConstraintRule()); } } } } return infomodel; }
public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException { GenerationResultZip zipOutputter = new GenerationResultZip(infomodel,getServiceKey()); for (FunctionblockProperty fbp : infomodel.getProperties()) { this.generateForFunctionBlock(infomodel, fbp.getType(), zipOutputter); FunctionBlock fb = fbp.getType().getFunctionblock(); for (Entity entity : Utils.getReferencedEntities(fb)) { generateForEntity(infomodel, entity, zipOutputter); } for (Enum en : Utils.getReferencedEnums(fb)) { generateForEnum(infomodel, en, zipOutputter); } } new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate()).generate(infomodel, invocationContext,zipOutputter); return zipOutputter; }
/** * Generates Alexa Custom Slot Types for every Infomodel Enumeration */ public void generateCustomSlotTypes(final InformationModel infomodel, final InvocationContext context, final IGeneratedWriter output) { EList<FunctionblockProperty> _properties = infomodel.getProperties(); for (final FunctionblockProperty fbModel : _properties) { { FunctionblockModel _type = fbModel.getType(); FunctionBlock _functionblock = _type.getFunctionblock(); EList<org.eclipse.vorto.core.api.model.datatype.Enum> enums = Utils.getReferencedEnums(_functionblock); for (final org.eclipse.vorto.core.api.model.datatype.Enum enumeration : enums) { { AlexaSlotTypeTemplate _alexaSlotTypeTemplate = new AlexaSlotTypeTemplate(); GeneratorTaskFromFileTemplate<org.eclipse.vorto.core.api.model.datatype.Enum> _template = new GeneratorTaskFromFileTemplate<org.eclipse.vorto.core.api.model.datatype.Enum>(_alexaSlotTypeTemplate); _template.generate(enumeration, context, output); } } } } }
/** * Generates Alexa Custom Slot Types for every Infomodel Enumeration */ public void generateCustomSlotTypes(final InformationModel infomodel, final InvocationContext context, final IGeneratedWriter output) { EList<FunctionblockProperty> _properties = infomodel.getProperties(); for (final FunctionblockProperty fbModel : _properties) { { FunctionblockModel _type = fbModel.getType(); FunctionBlock _functionblock = _type.getFunctionblock(); EList<org.eclipse.vorto.core.api.model.datatype.Enum> enums = Utils.getReferencedEnums(_functionblock); for (final org.eclipse.vorto.core.api.model.datatype.Enum enumeration : enums) { { AlexaSlotTypeTemplate _alexaSlotTypeTemplate = new AlexaSlotTypeTemplate(); GeneratorTaskFromFileTemplate<org.eclipse.vorto.core.api.model.datatype.Enum> _template = new GeneratorTaskFromFileTemplate<org.eclipse.vorto.core.api.model.datatype.Enum>(_alexaSlotTypeTemplate); _template.generate(enumeration, context, output); } } } } }
@Override public void generate(InformationModel model, InvocationContext context, IGeneratedWriter writer) { for (FunctionblockProperty fbProperty : model.getProperties()) { for (Operation operation : fbProperty.getType().getFunctionblock().getOperations()) { IMapped<Operation> mappedElement = context.getMappedElement(operation,STEREOTYPE_AWS_THINGSHADOW); if (isUpdateableOperation(mappedElement)) { ICodeGeneratorTask<Operation> generator = new GeneratorTaskFromFileTemplate<>(new UpdateThingShadowLambdaTemplate(mappedElement)); generator.generate(operation,context,writer); } else if (!operation.getParams().isEmpty() && !operation.getName().startsWith("get")) { ICodeGeneratorTask<Operation> generator = new GeneratorTaskFromFileTemplate<>(new UpdateThingShadowLambdaTemplate(mappedElement)); generator.generate(operation,context,writer); } } if (fbProperty.getType().getFunctionblock().getStatus() != null) { for (Property statusProperty : fbProperty.getType().getFunctionblock().getStatus().getProperties()) { ICodeGeneratorTask<Property> generator = new GeneratorTaskFromFileTemplate<>(new GetThingShadowLambdaTemplate()); generator.generate(statusProperty,context,writer); } } } }
@Override public String getContent(final FunctionblockProperty fbProperty, final InvocationContext invocationContext) { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append("* "); String _description = fbProperty.getDescription(); _builder.append(_description, ""); _builder.newLineIfNotEmpty(); _builder.append("*/"); _builder.newLine(); _builder.append("private "); _builder.append(this.interfacePrefix, ""); FunctionblockModel _type = fbProperty.getType(); String _name = _type.getName(); _builder.append(_name, ""); _builder.append(" "); String _name_1 = fbProperty.getName(); _builder.append(_name_1, ""); _builder.append(";"); _builder.newLineIfNotEmpty(); return _builder.toString(); } }
@Override public String getContent(final FunctionblockProperty fbProperty, final InvocationContext invocationContext) { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append("* "); String _description = fbProperty.getDescription(); _builder.append(_description, ""); _builder.newLineIfNotEmpty(); _builder.append("*/"); _builder.newLine(); _builder.append("private "); _builder.append(this.interfacePrefix, ""); FunctionblockModel _type = fbProperty.getType(); String _name = _type.getName(); _builder.append(_name, ""); _builder.append(" "); String _name_1 = fbProperty.getName(); _builder.append(_name_1, ""); _builder.append(";"); _builder.newLineIfNotEmpty(); return _builder.toString(); } }
@Override public String getContent(final FunctionblockProperty fbProperty, final InvocationContext invocationContext) { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append("* Getter for "); String _name = fbProperty.getName(); _builder.append(_name, ""); _builder.append("."); _builder.newLineIfNotEmpty(); _builder.append("*/"); _builder.newLine(); _builder.append("public "); _builder.append(this.interfacePrefix, ""); FunctionblockModel _type = fbProperty.getType(); String _name_1 = _type.getName(); _builder.append(_name_1, ""); _builder.append(" "); _builder.append(this.getterPrefix, ""); String _name_2 = fbProperty.getName(); String _firstUpper = StringExtensions.toFirstUpper(_name_2); _builder.append(_firstUpper, ""); _builder.append("();"); _builder.newLineIfNotEmpty(); return _builder.toString(); } }
@Override public String getContent(final FunctionblockProperty fbProperty, final InvocationContext invocationContext) { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append("* Getter for "); String _name = fbProperty.getName(); _builder.append(_name, ""); _builder.append("."); _builder.newLineIfNotEmpty(); _builder.append("*/"); _builder.newLine(); _builder.append("public "); _builder.append(this.interfacePrefix, ""); FunctionblockModel _type = fbProperty.getType(); String _name_1 = _type.getName(); _builder.append(_name_1, ""); _builder.append(" "); _builder.append(this.getterPrefix, ""); String _name_2 = fbProperty.getName(); String _firstUpper = StringExtensions.toFirstUpper(_name_2); _builder.append(_firstUpper, ""); _builder.append("();"); _builder.newLineIfNotEmpty(); return _builder.toString(); } }
@Override public String getContent(final FunctionblockProperty fbProperty, final InvocationContext invocationContext) { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append("* Setter for "); String _name = fbProperty.getName(); _builder.append(_name, ""); _builder.append("."); _builder.newLineIfNotEmpty(); _builder.append("*/"); _builder.newLine(); _builder.append("public void "); _builder.append(this.setterPrefix, ""); String _name_1 = fbProperty.getName(); String _firstUpper = StringExtensions.toFirstUpper(_name_1); _builder.append(_firstUpper, ""); _builder.append("("); _builder.append(this.interfacePrefix, ""); FunctionblockModel _type = fbProperty.getType(); String _name_2 = _type.getName(); _builder.append(_name_2, ""); _builder.append(" "); String _name_3 = fbProperty.getName(); _builder.append(_name_3, ""); _builder.append(");"); _builder.newLineIfNotEmpty(); return _builder.toString(); } }
@Override public IGenerationResult generate(InformationModel context, InvocationContext invocationContext) throws Exception { 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); return GenerationResultBuilder.from(outputter).append(javaResult).build(); }
generator.addTask(new GeneratorTaskFromFileTemplate<>(new ServiceClassTemplate())); generator.addTask(new GeneratorTaskFromFileTemplate<>(new PageTemplate())); generator.generate(property.getType(),invocationContext, outputter);