for (CandidacyDocumentUploadBean candidacyDocumentUploadBean : candidacyDocuments) {
if (candidacyDocumentUploadBean.getTemporaryFile() != null) {
String filename = candidacyDocumentUploadBean.getFilename();
CandidacyDocument candidacyDocument = candidacyDocumentUploadBean.getCandidacyDocument();
Candidacy candidacy = candidacyDocument.getCandidacy();
Person person = candidacy.getPerson();
final byte[] content = read(candidacyDocumentUploadBean.getTemporaryFile());
if (candidacyDocument.getFile() != null) {
candidacyDocument.getFile().delete();
}
final CandidacyDocumentFile candidacyDocumentFile =
new CandidacyDocumentFile(filename, filename, content, permittedGroup.or(UserGroup.of(person.getUser())));
candidacyDocument.setFile(candidacyDocumentFile);
}
}
}