use of org.eclipse.vorto.core.api.model.datatype.Entity 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.datatype.Entity in project vorto by eclipse.
the class ProSystGenerator method generate.
@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext ctx, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
Set<EObject> visited = new HashSet<>();
Set<String> exports = new HashSet<>();
for (FunctionblockProperty fbp : infomodel.getProperties()) {
Set<String> imports = new HashSet<>();
FunctionBlock fb = fbp.getType().getFunctionblock();
for (Entity entity : Utils.getReferencedEntities(fb)) {
if (!visited.contains(entity)) {
generateForEntity(infomodel, ctx, entity, zipOutputter);
visited.add(entity);
}
imports.add(entity.getNamespace());
exports.add(entity.getNamespace());
}
for (Enum en : Utils.getReferencedEnums(fb)) {
if (!visited.contains(en)) {
generateForEnum(infomodel, ctx, en, zipOutputter);
visited.add(en);
}
imports.add(en.getNamespace());
exports.add(en.getNamespace());
}
exports.add(infomodel.getNamespace());
generateForFunctionBlock(infomodel, ctx, fbp.getType(), zipOutputter, imports.toArray(new String[imports.size()]));
}
generateEclipseProject(infomodel, ctx, zipOutputter, exports);
return zipOutputter;
}
use of org.eclipse.vorto.core.api.model.datatype.Entity in project vorto by eclipse.
the class CoAPGenerator method generate.
public IGenerationResult generate(InformationModel infomodel, InvocationContext mappingContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
/*
/ Generate the client part...
*/
String CLIENT_PROJ = infomodel.getName() + COAP_CLIENT_PROJECT_SUFFIX;
initPaths(CLIENT_PROJ);
generator.addTask(new CoAPClientInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPMethodTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ClientDemoApp", CLIENT_PROJ)));
generator.generate(infomodel, mappingContext, zipOutputter);
for (FunctionblockProperty fbp : infomodel.getProperties()) {
FunctionBlock fb = fbp.getType().getFunctionblock();
for (Entity entity : Utils.getReferencedEntities(fb)) {
generateForEntity(entity, zipOutputter);
}
for (Enum en : Utils.getReferencedEnums(fb)) {
generateForEnum(en, zipOutputter);
}
for (Operation op : fb.getOperations()) {
generateForOperation(op, zipOutputter);
}
if (fb.getStatus() != null) {
for (Property property : fb.getStatus().getProperties()) {
generateForProperty(property, zipOutputter);
}
}
this.generateForClientFunctionBlock(fbp.getType(), zipOutputter);
}
/*
/ Generate the server part...
*/
String SERVER_PROJ = infomodel.getName() + COAP_SERVER_PROJECT_SUFFIX;
initPaths(SERVER_PROJ);
generator.addTask(new CoAPServerGeneratorTask(COAP_SERVER_NAME, COAP_SERVER_PACKAGE, JAVA_FILE_EXTENSION, coapServerPath, JAVA_INTERFACE_PREFIX + COAP_REQUEST_HANDLER_NAME, COAP_REQUEST_HANDLER_PACKAGE));
generator.addTask(new CoAPServerIMRequestHandlerGeneratorTask(COAP_REQUEST_HANDLER_NAME, JAVA_FILE_EXTENSION, coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE, JAVA_INTERFACE_PREFIX, COAP_PRIM_TYPE_WRAPPER_SUFFIX, IM_PACKAGE, DT_PACKAGE, getOpParamSetPackage(), getPrimitiveParamWrapperPackage()));
generator.addTask(new JavaInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ICoAPRequestHandlerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new JsonTransformerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new URIAnalyzerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ResourceTemplate(coapServerPath, COAP_SERVER_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LinkTemplate(coapServerPath, COAP_SERVER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPServerDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE, COAP_SERVER_PACKAGE)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ServerDemoApp", SERVER_PROJ)));
generator.generate(infomodel, mappingContext, zipOutputter);
for (FunctionblockProperty fbp : infomodel.getProperties()) {
this.generateForFunctionBlock(fbp.getType(), zipOutputter);
FunctionBlock fb = fbp.getType().getFunctionblock();
for (Entity entity : Utils.getReferencedEntities(fb)) {
generateForEntity(entity, zipOutputter);
}
for (Enum en : Utils.getReferencedEnums(fb)) {
generateForEnum(en, zipOutputter);
}
for (Operation op : fb.getOperations()) {
generateForOperation(op, zipOutputter);
}
}
return zipOutputter;
}
use of org.eclipse.vorto.core.api.model.datatype.Entity in project vorto by eclipse.
the class JavabeanGenerator method generate.
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;
}
use of org.eclipse.vorto.core.api.model.datatype.Entity in project vorto by eclipse.
the class TestEntityFactory method createEntity.
public static Entity createEntity() {
Entity entity = DatatypeFactory.eINSTANCE.createEntity();
Property stringProperty = createPrimitiveProperty("testString", PrimitiveType.STRING);
entity.getProperties().add(stringProperty);
return entity;
}
Aggregations