Search in sources :

Example 1 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel 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);
    }
}
Also used : Entity(org.eclipse.vorto.core.api.model.datatype.Entity) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ModelEMFResource(org.eclipse.vorto.repository.core.impl.ModelEMFResource) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel)

Example 2 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class VortoService method getModel.

public Optional<InformationModel> getModel(String namespace, String name, String version) {
    Optional<byte[]> modelResources = downloadUrl(urlForModel(namespace, name, version));
    if (!modelResources.isPresent()) {
        return Optional.empty();
    }
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelResources.get()))).read();
    return toInformationModel(workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Generated(org.eclipse.vorto.codegen.api.Generated) ZipInputStream(java.util.zip.ZipInputStream) GatewayUtils(org.eclipse.vorto.codegen.gateway.utils.GatewayUtils) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DatatypePackageImpl(org.eclipse.vorto.core.api.model.datatype.impl.DatatypePackageImpl) Model(org.eclipse.vorto.core.api.model.model.Model) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Utils(org.eclipse.vorto.codegen.utils.Utils) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) InvocationContext(org.eclipse.vorto.codegen.api.InvocationContext) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) Throwables(com.google.common.base.Throwables) NotFoundException(org.eclipse.vorto.codegen.gateway.exception.NotFoundException) Collectors(java.util.stream.Collectors) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) EnvironmentConfig(org.eclipse.vorto.codegen.gateway.config.EnvironmentConfig) FunctionblockPackageImpl(org.eclipse.vorto.core.api.model.functionblock.impl.FunctionblockPackageImpl) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) InformationModelPackageImpl(org.eclipse.vorto.core.api.model.informationmodel.impl.InformationModelPackageImpl) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) Component(org.springframework.stereotype.Component) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) GeneratorRepository(org.eclipse.vorto.codegen.gateway.repository.GeneratorRepository) IVortoCodeGenerator(org.eclipse.vorto.codegen.api.IVortoCodeGenerator) Collections(java.util.Collections) Generator(org.eclipse.vorto.codegen.gateway.model.Generator) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace)

Example 3 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class VortoService method generate.

public IGenerationResult generate(String key, String namespace, String name, String version, Map<String, String> parameters) {
    LOGGER.info(String.format("Generating for Platform [%s] and Model [%s.%s:%s]", key, namespace, name, version));
    Generator generator = repo.get(key).orElseThrow(GatewayUtils.notFound(String.format("[Generator %s]", key)));
    InformationModel model = getModel(namespace, name, version).orElseThrow(GatewayUtils.notFound(String.format("[Model %s.%s:%s]", namespace, name, version)));
    List<MappingModel> mappings = getMappings(key, namespace, name, version);
    InvocationContext invocationContext = new InvocationContext(mappings, repo.newGeneratorLookup(), parameters);
    return generate(generator.getInstance(), model, invocationContext);
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) InvocationContext(org.eclipse.vorto.codegen.api.InvocationContext) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) IVortoCodeGenerator(org.eclipse.vorto.codegen.api.IVortoCodeGenerator) Generator(org.eclipse.vorto.codegen.gateway.model.Generator)

Example 4 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class KuraGenerator method generate.

@Override
public IGenerationResult generate(InformationModel context, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip outputter = new GenerationResultZip(context, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseClasspathTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new EclipseProjectFileTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ManifestTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new BuildPropertiesTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new ComponentXmlTemplate()));
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new IDataServiceTemplate()));
    if (invocationContext.getConfigurationProperties().getOrDefault("boschcloud", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschDataServiceTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new ThingClientFactoryTemplate()));
    } else if (invocationContext.getConfigurationProperties().getOrDefault("boschhub", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new PomTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubDataService()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new BoschHubClientTemplate()));
    } else {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new KuraCloudDataServiceTemplate()));
    }
    if (invocationContext.getConfigurationProperties().getOrDefault("bluetooth", "false").equalsIgnoreCase("true")) {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new MetatypeTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceBluetoothFinderTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new ConfigurationTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceFilterTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DeviceToInformationModelTransformerTemplate()));
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelConsumerTemplate()));
    } else {
        generator.addTask(new GeneratorTaskFromFileTemplate<>(new DefaultAppTemplate()));
    }
    generator.addTask(new GeneratorTaskFromFileTemplate<>(new InformationModelTemplate()));
    for (FunctionblockProperty fbProperty : context.getProperties()) {
        new GeneratorTaskFromFileTemplate<>(new FunctionblockTemplate(context)).generate(fbProperty.getType(), invocationContext, outputter);
    }
    generator.generate(context, invocationContext, outputter);
    return outputter;
}
Also used : EclipseClasspathTemplate(org.eclipse.vorto.codegen.kura.templates.EclipseClasspathTemplate) PomTemplate(org.eclipse.vorto.codegen.kura.templates.PomTemplate) InformationModelConsumerTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.InformationModelConsumerTemplate) ComponentXmlTemplate(org.eclipse.vorto.codegen.kura.templates.osgiinf.ComponentXmlTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) BoschHubClientTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschHubClientTemplate) ConfigurationTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.ConfigurationTemplate) ManifestTemplate(org.eclipse.vorto.codegen.kura.templates.ManifestTemplate) BoschHubDataService(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschHubDataService) EclipseProjectFileTemplate(org.eclipse.vorto.codegen.kura.templates.EclipseProjectFileTemplate) KuraCloudDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.KuraCloudDataServiceTemplate) GeneratorTaskFromFileTemplate(org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate) DeviceBluetoothFinderTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceBluetoothFinderTemplate) MetatypeTemplate(org.eclipse.vorto.codegen.kura.templates.osgiinf.MetatypeTemplate) DeviceToInformationModelTransformerTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceToInformationModelTransformerTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) BuildPropertiesTemplate(org.eclipse.vorto.codegen.kura.templates.BuildPropertiesTemplate) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) IDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.IDataServiceTemplate) ThingClientFactoryTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.ThingClientFactoryTemplate) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) FunctionblockTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.FunctionblockTemplate) BoschDataServiceTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.bosch.BoschDataServiceTemplate) InformationModelTemplate(org.eclipse.vorto.codegen.kura.templates.cloud.InformationModelTemplate) DefaultAppTemplate(org.eclipse.vorto.codegen.kura.templates.DefaultAppTemplate) DeviceFilterTemplate(org.eclipse.vorto.codegen.kura.templates.bluetooth.DeviceFilterTemplate)

Example 5 with InformationModel

use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.

the class LatexGenerator method generate.

public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    generator.addTask(new LatexInformationModelGeneratorTask(LATEX_FILE_EXTENSION, LATEX_TARGET_PATH));
    generator.generate(infomodel, invocationContext, zipOutputter);
    return zipOutputter;
}
Also used : GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) LatexInformationModelGeneratorTask(org.eclipse.vorto.codegen.latex.tasks.LatexInformationModelGeneratorTask)

Aggregations

InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)24 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)13 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)10 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)8 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)7 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)6 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)6 Model (org.eclipse.vorto.core.api.model.model.Model)6 ZipInputStream (java.util.zip.ZipInputStream)5 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)5 IVortoCodeGenerator (org.eclipse.vorto.codegen.api.IVortoCodeGenerator)4 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Generated (org.eclipse.vorto.codegen.api.Generated)3 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)3 IOException (java.io.IOException)2 List (java.util.List)2 GeneratorTaskFromFileTemplate (org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate)2