Search in sources :

Example 36 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelImporterTest method testUploadSameModelByAdminReleasedState.

@Test
public void testUploadSameModelByAdminReleasedState() throws Exception {
    ModelInfo info = importModel("Color.type", createUserContext("alex", "playground"));
    this.workflow.start(info.getId(), createUserContext("alex", "playground"));
    setReleaseState(info);
    IUserContext admin = createUserContext("admin", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(admin, Optional.empty()));
    assertFalse(uploadResult.hasWarnings());
    assertFalse(uploadResult.isValid());
    assertFalse(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.ERROR_MODEL_ALREADY_RELEASED, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 37 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelImporterTest method testUploadSameModelTwiceByAuthorAlreadyReleased.

@Test
public void testUploadSameModelTwiceByAuthorAlreadyReleased() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    ModelInfo info = importModel("Color.type", alex);
    this.workflow.start(info.getId(), alex);
    setReleaseState(info);
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream())), Context.create(alex, Optional.empty()));
    assertFalse(uploadResult.hasWarnings());
    assertFalse(uploadResult.isValid());
    assertFalse(uploadResult.getReport().get(0).isValid());
    assertEquals(ValidationReport.ERROR_MODEL_ALREADY_RELEASED, uploadResult.getReport().get(0).getMessage());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 38 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class VersionSearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    // Color type with version 1.0.0 - will update to 1.0.1
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL, testInfrastructure.getDefaultUser());
    // Switcher fb with version 1.0.0 - will update to 2.1.0
    testInfrastructure.importModel(testInfrastructure.FUNCTIONBLOCK_MODEL, testInfrastructure.getDefaultUser());
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.getDefaultUser()).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    IModelRepository repo = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.getDefaultUser());
    ModelInfo type = model.stream().filter(m -> m.getFileName().equals(testInfrastructure.DATATYPE_MODEL)).findFirst().orElseGet(() -> {
        fail("Model not found");
        return null;
    });
    ModelInfo functionBlock = model.stream().filter(m -> m.getFileName().equals(testInfrastructure.FUNCTIONBLOCK_MODEL)).findFirst().orElseGet(() -> {
        fail("Model not found");
        return null;
    });
    // updating infomodel to 1.0.1 and removing previous
    repo.createVersion(type.getId(), "1.0.1", testInfrastructure.getDefaultUser());
    repo.removeModel(type.getId());
    // updating functionblock to 2.1.0 and removing previous
    repo.createVersion(functionBlock.getId(), "2.1.0", testInfrastructure.getDefaultUser());
    repo.removeModel(functionBlock.getId());
    // finally, importing mapping as-is (1.0.0)
    testInfrastructure.importModel(testInfrastructure.MAPPING_MODEL);
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) BeforeClass(org.junit.BeforeClass)

Example 39 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class UserReferenceSearchSimpleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    erleContext = testInfrastructure.createUserContext("erle");
    testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
    List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.getDefaultUser()).search("*");
    // this is arguably over-cautious, as the next statement would fail all tests anyway
    if (model.isEmpty()) {
        fail("Model is empty after importing.");
    }
    // "reviewer" user updates the only imported model's visibility to public, i.e.
    // "lastModifiedBy" -> reviewer
    model.get(0).setLastModifiedBy("reviewer");
    ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("reviewer")).updateVisibility(model.get(0).getId(), "Public");
    // "control group": importing another model as another user
    testInfrastructure.importModel("HueLightStrips.infomodel", erleContext);
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId) BeforeClass(org.junit.BeforeClass)

Example 40 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelController method getModelInfo.

@PreAuthorize("isAuthenticated() or hasAuthority('model_viewer')")
@GetMapping("/{modelId:.+}")
public ModelInfo getModelInfo(@ApiParam(value = "The modelId of vorto model, e.g. com.mycompany:Car:1.0.0", required = true) @PathVariable final String modelId) {
    Objects.requireNonNull(modelId, "modelId must not be null");
    ModelId modelID = ModelId.fromPrettyFormat(modelId);
    LOGGER.info(String.format("Generated model info: [%s]", modelID.getPrettyFormat()));
    ModelInfo resource = getModelRepository(modelID).getByIdWithPlatformMappings(modelID);
    if (resource == null) {
        LOGGER.warn(String.format("Could not find model with ID [%s] in repository", modelID));
        throw new ModelNotFoundException("Model does not exist", null);
    }
    return ModelDtoFactory.createDto(resource);
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) ModelId(org.eclipse.vorto.model.ModelId) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5