Search in sources :

Example 1 with BulkUploadHelper

use of org.eclipse.vorto.repository.core.impl.utils.BulkUploadHelper 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());
    }
}
Also used : UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) BulkUploadHelper(org.eclipse.vorto.repository.core.impl.utils.BulkUploadHelper) UploadModelResponse(org.eclipse.vorto.repository.api.upload.UploadModelResponse) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with BulkUploadHelper

use of org.eclipse.vorto.repository.core.impl.utils.BulkUploadHelper in project vorto by eclipse.

the class BulkUploadTest method beforeEach.

@Override
public void beforeEach() throws Exception {
    super.beforeEach();
    bulkUploadHelper = new BulkUploadHelper(this.modelRepository, new InMemoryTemporaryStorage());
}
Also used : BulkUploadHelper(org.eclipse.vorto.repository.core.impl.utils.BulkUploadHelper) InMemoryTemporaryStorage(org.eclipse.vorto.repository.core.impl.InMemoryTemporaryStorage)

Aggregations

BulkUploadHelper (org.eclipse.vorto.repository.core.impl.utils.BulkUploadHelper)2 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 UploadModelResponse (org.eclipse.vorto.repository.api.upload.UploadModelResponse)1 UploadModelResult (org.eclipse.vorto.repository.api.upload.UploadModelResult)1 InMemoryTemporaryStorage (org.eclipse.vorto.repository.core.impl.InMemoryTemporaryStorage)1 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1