Search in sources :

Example 26 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class Lwm2mObjectIdResolverTest method testResolveForExistingObjectId.

@Test
public void testResolveForExistingObjectId() {
    importModel("lwm2m/ColorLight.fbmodel");
    importModel("lwm2m/ColorLight_lwm2m.mapping");
    DefaultResolver lwm2mResolver = new DefaultResolver();
    lwm2mResolver.setRepositoryFactory(repositoryFactory);
    lwm2mResolver.setSearchService(searchService);
    assertEquals(new ModelId("ColorLight", "com.mycompany.fb", "1.0.0"), lwm2mResolver.resolve(new LWM2MQuery("2")));
    assertNotNull(repositoryFactory.getRepository(createUserContext("admin")).getById(lwm2mResolver.resolve(new LWM2MQuery("2"))));
}
Also used : DefaultResolver(org.eclipse.vorto.repository.core.impl.resolver.DefaultResolver) LWM2MQuery(org.eclipse.vorto.repository.web.core.dto.LWM2MQuery) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 27 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class BulkApproveFunction method execute.

@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
    for (ModelId referenceId : model.getReferences()) {
        IModelRepository repository = repositoryFactory.getRepositoryByModel(referenceId);
        ModelInfo referenceModel = repository.getById(referenceId);
        if (ModelState.InReview.getName().equals(referenceModel.getState())) {
            try {
                workflowService.doAction(referenceId, user, SimpleWorkflowModel.ACTION_APPROVE.getName());
            } catch (WorkflowException e) {
                logger.error("Problem executing release for model " + referenceId + "during bulk approve function", e);
            }
        }
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Example 28 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testDeleteAttachments.

@Test
public void testDeleteAttachments() throws Exception {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    ModelId modelId = new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0");
    repositoryFactory.getRepository(erle).attachFile(modelId, new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle);
    boolean deleteResult = repositoryFactory.getRepository(erle).deleteAttachment(modelId, "backup1.xml");
    assertTrue(deleteResult);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 29 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testOverwriteAttachmentWithoutTags.

@Test
public void testOverwriteAttachmentWithoutTags() {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    try {
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup1.xml").getInputStream())), erle);
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("backup1.xml", IOUtils.toByteArray(new ClassPathResource("sample_models/backup-withImages.xml").getInputStream())), erle);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
        assertEquals(1, attachments.size());
        assertEquals("backup1.xml", attachments.get(0).getFilename());
        assertEquals(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), attachments.get(0).getModelId());
        assertEquals(0, attachments.get(0).getTags().size());
        attachments.forEach(attachment -> System.out.println(attachment));
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 30 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryAttachmentTest method testOverwriteImageWithDiffernentTag.

@Test
public void testOverwriteImageWithDiffernentTag() {
    IUserContext erle = createUserContext("erle", "playground");
    importModel("Color.type", erle);
    try {
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("sample.png", IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream())), erle, Attachment.TAG_IMAGE);
        repositoryFactory.getRepository(erle).attachFile(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), new FileContent("sample.png", IOUtils.toByteArray(new ClassPathResource("sample_models/sample.png").getInputStream())), erle, Attachment.TAG_DOCUMENTATION);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
        assertEquals(1, attachments.size());
        assertEquals("sample.png", attachments.get(0).getFilename());
        assertEquals(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"), attachments.get(0).getModelId());
        assertEquals(1, attachments.get(0).getTags().size());
        assertEquals("Documentation", attachments.get(0).getTags().get(0).getLabel());
    } catch (IOException | FatalModelRepositoryException e) {
        e.printStackTrace();
        fail("Cannot load sample file");
    }
}
Also used : IOException(java.io.IOException) ModelId(org.eclipse.vorto.model.ModelId) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8