Search in sources :

Example 36 with NotNull

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;
}
Also used : TempFile(org.obiba.mica.file.TempFile) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) TempFile(org.obiba.mica.file.TempFile) File(java.io.File) NotNull(javax.validation.constraints.NotNull)

Example 37 with NotNull

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();
}
Also used : StringWriter(java.io.StringWriter) PEMWriter(org.bouncycastle.openssl.PEMWriter) Certificate(java.security.cert.Certificate) NotNull(javax.validation.constraints.NotNull)

Example 38 with NotNull

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;
}
Also used : HashMap(java.util.HashMap) Population(org.obiba.mica.study.domain.Population) NotNull(javax.validation.constraints.NotNull)

Example 39 with NotNull

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;
}
Also used : Comment(org.obiba.mica.core.domain.Comment) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) Async(org.springframework.scheduling.annotation.Async) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AttachmentRepository(org.obiba.mica.core.repository.AttachmentRepository) Roles(org.obiba.mica.security.Roles) LoggerFactory(org.slf4j.LoggerFactory) CommentDeletedEvent(org.obiba.mica.core.event.CommentDeletedEvent) FileStoreService(org.obiba.mica.file.FileStoreService) DataAccessEntityRepository(org.obiba.mica.access.DataAccessEntityRepository) Value(org.springframework.beans.factory.annotation.Value) Inject(javax.inject.Inject) DataAccessFormService(org.obiba.mica.micaConfig.service.DataAccessFormService) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) Map(java.util.Map) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Subscribe(com.google.common.eventbus.Subscribe) Resource(org.springframework.core.io.Resource) org.obiba.mica.access.event(org.obiba.mica.access.event) Validated(org.springframework.validation.annotation.Validated) Attachment(org.obiba.mica.file.Attachment) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) DataAccessRequestRepository(org.obiba.mica.access.DataAccessRequestRepository) DateTime(org.joda.time.DateTime) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) CommentUpdatedEvent(org.obiba.mica.core.event.CommentUpdatedEvent) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SubjectAcl(org.obiba.mica.security.domain.SubjectAcl) DocumentException(com.itextpdf.text.DocumentException) NoSuchDataAccessRequestException(org.obiba.mica.access.NoSuchDataAccessRequestException) List(java.util.List) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus) ByteStreams(com.google.common.io.ByteStreams) SecurityUtils(org.apache.shiro.SecurityUtils) Configuration.defaultConfiguration(com.jayway.jsonpath.Configuration.defaultConfiguration) BeanUtils(org.springframework.beans.BeanUtils) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Attachment(org.obiba.mica.file.Attachment) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus)

Example 40 with NotNull

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;
}
Also used : AtomFeed(org.apache.cxf.systests.cdi.base.AtomFeed) Book(org.apache.cxf.systests.cdi.base.Book) AtomFeedEntry(org.apache.cxf.systests.cdi.base.AtomFeedEntry) Path(javax.ws.rs.Path) Valid(javax.validation.Valid) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NotNull(javax.validation.constraints.NotNull)

Aggregations

NotNull (javax.validation.constraints.NotNull)76 List (java.util.List)24 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)14 ArrayList (java.util.ArrayList)13 LoggerFactory (org.slf4j.LoggerFactory)13 HashMap (java.util.HashMap)11 Set (java.util.Set)10 Optional (java.util.Optional)9 Response (javax.ws.rs.core.Response)9 Strings (com.google.common.base.Strings)8 Lists (com.google.common.collect.Lists)8 Api (io.swagger.annotations.Api)7 ApiParam (io.swagger.annotations.ApiParam)7 IOException (java.io.IOException)7 Collection (java.util.Collection)7 Nullable (javax.annotation.Nullable)7 Valid (javax.validation.Valid)7