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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations