use of org.eclipse.vorto.repository.api.upload.UploadModelResult in project vorto by eclipse.
the class ModelRepositoryTest method tesUploadValidModel.
@Test
public void tesUploadValidModel() throws IOException {
UploadModelResult uploadResult = modelRepository.upload(IOUtils.toByteArray(new ClassPathResource("sample_models/Color.type").getInputStream()), "Color.type", "admin");
assertEquals(true, uploadResult.isValid());
assertNull(uploadResult.getErrorMessage());
assertNotNull(uploadResult.getHandleId());
ModelInfo resource = uploadResult.getModelResource();
assertEquals("org.eclipse.vorto.examples.type", resource.getId().getNamespace());
assertEquals("Color", resource.getId().getName());
assertEquals("1.0.0", resource.getId().getVersion());
assertEquals(ModelType.Datatype, resource.getType());
assertEquals(0, resource.getReferences().size());
assertEquals("Color", resource.getDisplayName());
assertNull(resource.getDescription());
assertEquals(0, modelRepository.search("*").size());
}
use of org.eclipse.vorto.repository.api.upload.UploadModelResult in project vorto by eclipse.
the class ModelRepositoryTest method testUploadSameModelTwiceByAuthor.
@Test
public void testUploadSameModelTwiceByAuthor() throws Exception {
checkinModel("Color.type", "alex");
UploadModelResult uploadResult = modelRepository.upload(IOUtils.toByteArray(new ClassPathResource("sample_models/Color2.type").getInputStream()), "Color.type", "alex");
assertTrue(uploadResult.isValid());
}
use of org.eclipse.vorto.repository.api.upload.UploadModelResult in project vorto by eclipse.
the class ModelRepositoryTest method testOverwriteInvalidModelByAdmin.
@Test
public void testOverwriteInvalidModelByAdmin() throws Exception {
checkinModel("Color.type", "alex");
UploadModelResult uploadResult = modelRepository.upload(IOUtils.toByteArray(new ClassPathResource("sample_models/Color3.type").getInputStream()), "Color.type", "admin");
assertFalse(uploadResult.isValid());
}
use of org.eclipse.vorto.repository.api.upload.UploadModelResult in project vorto by eclipse.
the class ShareModelController method uploadModel.
@ApiOperation(value = "Upload and validate a single vorto model")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<UploadModelResponse> uploadModel(@ApiParam(value = "The vorto model file to upload", required = true) @RequestParam("file") MultipartFile file) {
if (file.getSize() > maxModelSize) {
throw new UploadTooLargeException("model", maxModelSize);
}
LOGGER.info("uploadModel: [" + file.getOriginalFilename() + "]");
try {
uploadModelResult = modelRepository.upload(file.getBytes(), file.getOriginalFilename(), SecurityContextHolder.getContext().getAuthentication().getName());
List<UploadModelResult> uploadModelResults = Lists.newArrayList();
uploadModelResults.add(uploadModelResult);
String message = "Uploaded model " + file.getOriginalFilename() + (uploadModelResult.isValid() ? " is valid to check in." : " has errors. Cannot check in.");
return validResponse(new UploadModelResponse(message, uploadModelResult.isValid(), uploadModelResults));
} catch (IOException e) {
LOGGER.error("Error upload model." + e.getStackTrace());
UploadModelResponse errorResponse = new UploadModelResponse("Error during upload. Try again. " + e.getMessage(), false, null);
return new ResponseEntity<UploadModelResponse>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.eclipse.vorto.repository.api.upload.UploadModelResult in project vorto by eclipse.
the class ShareModelController method uploadMultipleModels.
@ApiOperation(value = "Upload and validate multiple vorto models")
@RequestMapping(value = "multiple", method = RequestMethod.POST)
public ResponseEntity<UploadModelResponse> uploadMultipleModels(@ApiParam(value = "The vorto model files to upload", required = true) @RequestParam("file") MultipartFile file) {
if (file.getSize() > maxModelSize) {
throw new UploadTooLargeException("model", maxModelSize);
}
LOGGER.info("Bulk upload Models: [" + file.getOriginalFilename() + "]");
try {
BulkUploadHelper bulkUploadService = new BulkUploadHelper(this.modelRepository, uploadStorage);
List<UploadModelResult> uploadModelResults = bulkUploadService.uploadMultiple(file.getBytes(), file.getOriginalFilename(), SecurityContextHolder.getContext().getAuthentication().getName());
LOGGER.info("Models Uploaded: [" + uploadModelResults.size() + "]");
UploadModelResponse serverResponse = (uploadModelResults.size() == 0) ? new UploadModelResponse("Uploaded file doesn't have any valid models.", false, uploadModelResults) : createModelResponse(uploadModelResults);
return validResponse(serverResponse);
} catch (Exception e) {
LOGGER.error("Error bulk upload models.", e);
return erroredResponse("Error during upload. Try again. " + e.getMessage());
}
}
Aggregations