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