Search in sources :

Example 6 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class BulkUploadHelper method uploadMultiple.

public List<ValidationReport> uploadMultiple(byte[] content, String zipFileName, IUserContext user) {
    if (!isValid(zipFileName)) {
        throw new FatalModelRepositoryException("Filename/type is invalid", null);
    }
    ZipParseResult parseResult = parseZipFile(content);
    try {
        /*
       * Create mapping function that will convert from a ModelInfo to an UploadModelResult using
       * validators
       */
        Function<ModelInfo, ValidationReport> convertToValidationReport = createConvertToUploadModelResultFn(constructBulkUploadValidators(parseResult.validModels), InvocationContext.create(user));
        /*
       * Convert parsed models to ValidationReport
       */
        Set<ValidationReport> validatedModelResults = parseResult.validModels.stream().map(convertToValidationReport).collect(Collectors.toSet());
        /*
       * Add everything to a Set to eliminate redundancy
       */
        Set<ValidationReport> validationReports = new HashSet<>();
        validationReports.addAll(parseResult.invalidModels);
        validationReports.addAll(validatedModelResults);
        return new ArrayList<>(validationReports);
    } catch (Exception e) {
        throw new BulkUploadException("Invalid zip file", e);
    }
}
Also used : ValidationReport(org.eclipse.vorto.repository.importer.ValidationReport) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) IOException(java.io.IOException) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)

Example 7 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class BulkUploadHelper method copyStream.

protected static byte[] copyStream(ZipInputStream in) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(out);
        while ((size = in.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    } catch (IOException e) {
        throw new BulkUploadException("IOException while copying stream to ZipEntry", e);
    }
    return out.toByteArray();
}
Also used : BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

IOException (java.io.IOException)7 BulkUploadException (org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)7 BufferedOutputStream (java.io.BufferedOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipInputStream (java.util.zip.ZipInputStream)3 ArrayList (java.util.ArrayList)2 FileContent (org.eclipse.vorto.repository.core.FileContent)1 ValidationReport (org.eclipse.vorto.repository.importer.ValidationReport)1