Search in sources :

Example 1 with GeneratorPluginConfiguration

use of org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration in project vorto by eclipse.

the class PluginConfiguration method registerPlugins.

@PostConstruct
public void registerPlugins() throws Exception {
    if (this.pluginsJson == null) {
        return;
    }
    Plugin[] plugins = new ObjectMapper().readValue(Base64.getDecoder().decode(this.pluginsJson.getBytes()), Plugin[].class);
    if (plugins != null && plugins.length > 0) {
        Arrays.stream(plugins).forEach(plugin -> {
            if (plugin.getPluginType().equals(PluginType.generator)) {
                GeneratorPluginConfiguration config = GeneratorPluginConfiguration.of(plugin.getKey(), plugin.getApiVersion(), plugin.getEndpoint(), plugin.getPluginVersion());
                if (plugin.getTag() != null) {
                    config.setTags(new String[] { plugin.getTag() });
                }
                generatorPluginService.registerPlugin(config);
            } else {
                ImporterPluginInfo info = new ImporterPluginInfo(plugin.getKey(), plugin.getName(), plugin.getDescription(), plugin.getVendor(), plugin.getFileType());
                this.importerPluginService.registerImporter(createImporter(info, plugin.getEndpoint()));
            }
        });
    }
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ImporterPluginInfo(org.eclipse.vorto.plugin.importer.ImporterPluginInfo) PostConstruct(javax.annotation.PostConstruct)

Example 2 with GeneratorPluginConfiguration

use of org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration in project vorto by eclipse.

the class GeneratedOutputAttachmentHandlerTest method tagsForRequest.

@Test
public void tagsForRequest() {
    // setup
    GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration.of("eclipseditto", "v2", "http://localhost:8888", "1.0.0");
    Map<String, String> requestParams = new HashMap<>();
    requestParams.put("target", "thingJson");
    requestParams.put("anotherParam", "test");
    // execute
    Tag[] result = GeneratedOutputAttachmentHandler.tagsForRequest(plugin, requestParams);
    // verify
    assertNotNull(result);
    assertTrue(Arrays.asList(result).contains(new Tag("test")));
    assertTrue(Arrays.asList(result).contains(new Tag("thingJson")));
    assertTrue(Arrays.asList(result).contains(new Tag("generated")));
    assertTrue(Arrays.asList(result).contains(new Tag("eclipseditto_1.0.0")));
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) Test(org.junit.Test)

Example 3 with GeneratorPluginConfiguration

use of org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration in project vorto by eclipse.

the class GeneratedOutputAttachmentHandlerTest method attachGeneratedOutput.

@Test
public void attachGeneratedOutput() {
    // setup
    String filename = "thiswasgenerated.json";
    byte[] content = { 0x01 };
    List<Attachment> attList = new ArrayList<>();
    ModelId id = new ModelId();
    id.setName("TestInfoModel");
    attList.add(Attachment.newInstance(id, filename));
    when(repository.getAttachmentsByTags(any(), any())).thenReturn(attList);
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setId(id);
    Map<String, String> requestParams = new HashMap<>();
    GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration.of("eclipseditto", "v2", "http://localhost:8888", "1.0.0");
    when(repository.getAttachmentContent(any(), any())).thenReturn(Optional.of(new FileContent(filename, content)));
    when(modelRepositoryFactory.getRepositoryByModel(any(), any())).thenReturn(repository);
    IUserContext userContext = new IUserContext() {

        @Override
        public Authentication getAuthentication() {
            return null;
        }

        @Override
        public String getUsername() {
            return "testuser";
        }

        @Override
        public String getWorkspaceId() {
            return null;
        }

        @Override
        public String getHashedUsername() {
            return null;
        }

        @Override
        public boolean isAnonymous() {
            return false;
        }

        @Override
        public boolean isSysAdmin() {
            return false;
        }
    };
    GeneratedOutput generatedOutput = sut.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).get();
    // execute
    GeneratedOutput result = sut.attachGeneratedOutput(userContext, modelInfo.getId(), "eclipseditto", requestParams, generatedOutput, plugin);
    // verify
    assertNotNull(result);
    assertEquals(1, result.getSize());
    assertEquals("generated_eclipseditto_1.0.0_TestInfoModel.json", result.getFileName());
    assertEquals(content, result.getContent());
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 4 with GeneratorPluginConfiguration

use of org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration in project vorto by eclipse.

the class GeneratedOutputAttachmentHandlerTest method getGeneratedOutputFromAttachment.

@Test
public void getGeneratedOutputFromAttachment() {
    // setup
    String filename = "thiswasgenerated.json";
    byte[] content = { 0x01 };
    List<Attachment> attList = new ArrayList<>();
    ModelId id = new ModelId();
    id.setName("TestInfoModel");
    attList.add(Attachment.newInstance(id, filename));
    when(repository.getAttachmentsByTags(any(), any())).thenReturn(attList);
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setId(id);
    Map<String, String> requestParams = new HashMap<>();
    GeneratorPluginConfiguration plugin = GeneratorPluginConfiguration.of("eclipseditto", "v2", "http://localhost:8888", "1.0.0");
    when(repository.getAttachmentContent(any(), any())).thenReturn(Optional.of(new FileContent(filename, content)));
    // execute
    Optional<GeneratedOutput> result = sut.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository);
    // verify
    assertTrue(result.isPresent());
    assertEquals(content, result.get().getContent());
    assertEquals(filename, result.get().getFileName());
    assertEquals(1, result.get().getSize());
}
Also used : GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 5 with GeneratorPluginConfiguration

use of org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration in project vorto by eclipse.

the class DefaultGeneratorPluginService method generate.

@Override
public GeneratedOutput generate(IUserContext userContext, ModelId modelId, String serviceKey, Map<String, String> requestParams) {
    incrementMetric(serviceKey);
    IModelRepository repository = modelRepositoryFactory.getRepositoryByModel(modelId);
    ModelInfo modelInfo = repository.getById(modelId);
    GeneratorPluginConfiguration plugin = getPluginInfo(serviceKey, false);
    if (modelInfo.isReleased() && hasGeneratorProductionTag(plugin)) {
        return generatedOutputAttachmentHandler.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).orElseGet(() -> generateAndAttachOutput(userContext, modelInfo, serviceKey, requestParams, plugin));
    }
    return doGenerate(modelInfo, serviceKey, requestParams, plugin);
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration)

Aggregations

GeneratorPluginConfiguration (org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration)6 Test (org.junit.Test)3 ModelId (org.eclipse.vorto.model.ModelId)2 GeneratedOutput (org.eclipse.vorto.repository.plugin.generator.GeneratedOutput)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PostConstruct (javax.annotation.PostConstruct)1 ImporterPluginInfo (org.eclipse.vorto.plugin.importer.ImporterPluginInfo)1 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)1 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)1