Search in sources :

Example 6 with UploadModelResult

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());
}
Also used : UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest)

Example 7 with UploadModelResult

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());
}
Also used : UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest)

Example 8 with UploadModelResult

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());
}
Also used : UploadModelResult(org.eclipse.vorto.repository.api.upload.UploadModelResult) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractIntegrationTest(org.eclipse.vorto.repository.AbstractIntegrationTest)

Example 9 with UploadModelResult

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

Example 10 with UploadModelResult

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

Aggregations

UploadModelResult (org.eclipse.vorto.repository.api.upload.UploadModelResult)17 ClassPathResource (org.springframework.core.io.ClassPathResource)13 AbstractIntegrationTest (org.eclipse.vorto.repository.AbstractIntegrationTest)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)3 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)3 UploadModelResponse (org.eclipse.vorto.repository.api.upload.UploadModelResponse)3 ApiOperation (io.swagger.annotations.ApiOperation)2 IOException (java.io.IOException)2 User (org.eclipse.vorto.repository.account.impl.User)2 UploadTooLargeException (org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 TypeToken (com.google.gson.reflect.TypeToken)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpEntity (org.apache.http.HttpEntity)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1