use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class TempFileService method addTempFile.
@NotNull
public TempFile addTempFile(@NotNull TempFile tempFile, @NotNull InputStream uploadedInputStream) throws IOException {
TempFile savedTempFile;
if (tempFile.getId() != null) {
savedTempFile = tempFileRepository.findOne(tempFile.getId());
if (savedTempFile == null) {
savedTempFile = tempFileRepository.save(tempFile);
}
} else {
savedTempFile = tempFileRepository.save(tempFile);
}
File file = getFile(savedTempFile.getId());
OutputStream fileOut = new FileOutputStream(file);
ByteStreams.copy(uploadedInputStream, fileOut);
fileOut.close();
savedTempFile.setSize(file.length());
savedTempFile.setMd5(Files.hash(file, Hashing.md5()).toString());
tempFileRepository.save(savedTempFile);
return savedTempFile;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class KeyStoreService method getPEMCertificate.
@NotNull
public String getPEMCertificate(@NotNull String name, String alias) throws KeyStoreException, IOException {
Certificate[] certificates = getKeyStore(name).getKeyStore().getCertificateChain(alias);
if (certificates == null || certificates.length == 0)
throw new IllegalArgumentException("Cannot find certificate for alias: " + alias);
StringWriter writer = new StringWriter();
PEMWriter pemWriter = new PEMWriter(writer);
for (Certificate certificate : certificates) {
pemWriter.writeObject(certificate);
}
pemWriter.flush();
return writer.getBuffer().toString();
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class PopulationDtos method fromDto.
@NotNull
Population fromDto(Mica.PopulationDtoOrBuilder dto) {
Population population = new Population();
population.setId(dto.getId());
if (dto.getNameCount() > 0)
population.setName(localizedStringDtos.fromDto(dto.getNameList()));
if (dto.getDescriptionCount() > 0)
population.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
if (dto.getDataCollectionEventsCount() > 0) {
dto.getDataCollectionEventsList().forEach(dceDto -> population.addDataCollectionEvent(fromDto(dceDto)));
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
population.setModel(JSONUtils.toMap(dto.getContent()));
else
population.setModel(new HashMap<>());
if (dto.hasWeight()) {
population.setWeight(dto.getWeight());
}
return population;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class DataAccessRequestService method save.
private DataAccessRequest save(@NotNull DataAccessRequest request, DateTime lastModifiedDate) {
DataAccessRequest saved = request;
DataAccessEntityStatus from = null;
Iterable<Attachment> attachmentsToDelete = null;
Iterable<Attachment> attachmentsToSave = null;
if (request.isNew()) {
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
saved.setId(generateId());
attachmentsToSave = saved.getAttachments();
} else {
saved = dataAccessRequestRepository.findOne(request.getId());
if (saved != null) {
if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
// preserve current actionLogs as no other user role can add or remove them
request.setActionLogHistory(saved.getActionLogHistory());
}
attachmentsToDelete = Sets.difference(Sets.newHashSet(saved.getAttachments()), Sets.newHashSet(request.getAttachments()));
attachmentsToSave = Sets.difference(Sets.newHashSet(request.getAttachments()), Sets.newHashSet(saved.getAttachments()));
from = saved.getStatus();
// validate the status
dataAccessRequestUtilService.checkStatusTransition(saved, request.getStatus());
saved.setStatus(request.getStatus());
if (request.hasStatusChangeHistory())
saved.setStatusChangeHistory(request.getStatusChangeHistory());
// merge beans
BeanUtils.copyProperties(request, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
} else {
saved = request;
setAndLogStatus(saved, DataAccessEntityStatus.OPENED);
}
}
schemaFormContentFileService.save(saved, dataAccessRequestRepository.findOne(request.getId()), String.format("/data-access-request/%s", saved.getId()));
if (attachmentsToSave != null)
attachmentsToSave.forEach(a -> {
fileStoreService.save(a.getId());
a.setJustUploaded(false);
attachmentRepository.save(a);
});
if (lastModifiedDate != null)
saved.setLastModifiedDate(lastModifiedDate);
dataAccessRequestRepository.saveWithReferences(saved);
if (attachmentsToDelete != null)
attachmentsToDelete.forEach(a -> fileStoreService.delete(a.getId()));
if (saved.hasVariablesSet() && DataAccessEntityStatus.OPENED.equals(saved.getStatus())) {
variableSetService.setLock(saved.getVariablesSet(), false);
}
eventBus.post(new DataAccessRequestUpdatedEvent(saved));
sendNotificationEmails(saved, from);
return saved;
}
use of javax.validation.constraints.NotNull in project cxf by apache.
the class BookStoreFeed method getBooks.
@GET
@Path("/books/feed")
@NotNull
@Valid
@Produces("application/atom+xml")
public AtomFeed getBooks() {
final AtomFeed feed = new AtomFeed();
for (final Book book : service.all()) {
final AtomFeedEntry entry = new AtomFeedEntry();
entry.addLink("/bookstore/books/" + book.getId());
feed.addEntry(entry);
}
return feed;
}
Aggregations