Search in sources :

Example 46 with ModelId

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

the class ModelRepositoryAttachmentTest method testAttachFileWithTag.

@Test
public void testAttachFileWithTag() {
    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, Attachment.TAG_DOCUMENTATION);
        List<Attachment> attachments = repositoryFactory.getRepository(erle).getAttachments(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
        assertEquals(1, attachments.get(0).getTags().size());
        assertEquals(Attachment.TAG_DOCUMENTATION, attachments.get(0).getTags().get(0));
        attachments.forEach(System.out::println);
    } 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 47 with ModelId

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

the class ModelRepositoryTest method testGetModelWithNoImage.

@Test
public void testGetModelWithNoImage() {
    importModel("Color.type");
    importModel("Colorlight.fbmodel");
    importModel("Switcher.fbmodel");
    importModel("HueLightStrips.infomodel");
    assertEquals(false, this.repositoryFactory.getRepository(createUserContext("admin")).getById(new ModelId("HueLightStrips", "com.mycompany", "1.0.0")).isHasImage());
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 48 with ModelId

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

the class ModelRepositoryTest method testCreateModelWithVersionNotFound.

@Test(expected = ModelNotFoundException.class)
public void testCreateModelWithVersionNotFound() {
    IUserContext alex = createUserContext("alex", "playground");
    importModel("Color.type");
    importModel("Colorlight.fbmodel", alex);
    final String newVersion = "1.0.0";
    this.repositoryFactory.getRepository(createUserContext("admin")).createVersion(new ModelId("Some", "demo", "1.0.0"), newVersion, alex);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 49 with ModelId

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

the class ModelRepositoryTest method testGetLatestModelVersionIdNoReleasedVersion.

@Test
public void testGetLatestModelVersionIdNoReleasedVersion() throws Exception {
    importModel("Color.type");
    importModel("Color6.type");
    importModel("sample.mapping");
    ModelId id = this.repositoryFactory.getRepository(createUserContext("admin")).getLatestModelVersionIfLatestTagIsSet(ModelId.fromReference("org.eclipse.vorto.examples.type.Color", "latest"));
    assertNull(id);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 50 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)

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