Search in sources :

Example 26 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class VortoService method getMappings.

public List<MappingModel> getMappings(String generatorKey, String namespace, String name, String version) {
    Optional<byte[]> mappingResources = downloadUrl(urlForMapping(generatorKey, namespace, name, version));
    if (mappingResources.isPresent()) {
        IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingResources.get()))).read();
        List<Model> models = workspace.get().stream().filter(p -> p instanceof MappingModel).collect(Collectors.toList());
        return models.stream().map(MappingModel.class::cast).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
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) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 27 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class CodeGenerationController method createInvocationContext.

private InvocationContext createInvocationContext(InformationModel model, String targetPlatform, Map<String, String> requestParams) {
    byte[] mappingResources = downloadMappingModel(model, targetPlatform);
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingResources))).read();
    List<MappingModel> mappingModels = workspace.get().stream().filter(p -> p instanceof MappingModel).map(MappingModel.class::cast).collect(Collectors.toList());
    return new InvocationContext(mappingModels, lookupService, requestParams);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationContext(org.eclipse.vorto.codegen.api.InvocationContext) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)27 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)18 Test (org.junit.Test)15 ZipInputStream (java.util.zip.ZipInputStream)6 ModelId (org.eclipse.vorto.repository.api.ModelId)6 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)4 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)4 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)4 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)4 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 ZipEntry (java.util.zip.ZipEntry)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 IOUtils (org.apache.commons.io.IOUtils)3