use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class AttachmentDtos method fromDto.
@NotNull
Attachment fromDto(@NotNull Mica.AttachmentDtoOrBuilder dto) {
Attachment attachment = new Attachment();
attachment.setId(dto.getId());
attachment.setName(dto.getFileName());
if (dto.hasType())
attachment.setType(dto.getType());
if (dto.getDescriptionCount() > 0)
attachment.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
if (dto.hasLang())
attachment.setLang(new Locale(dto.getLang()));
attachment.setSize(dto.getSize());
if (dto.hasMd5())
attachment.setMd5(dto.getMd5());
attachment.setJustUploaded(dto.getJustUploaded());
if (dto.hasTimestamps())
TimestampsDtos.fromDto(dto.getTimestamps(), attachment);
if (dto.getAttributesCount() > 0) {
dto.getAttributesList().forEach(attributeDto -> attachment.addAttribute(attributeDtos.fromDto(attributeDto)));
}
if (dto.hasPath())
attachment.setPath(dto.getPath());
return attachment;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class DatasetDtos method fromDto.
@NotNull
public Dataset fromDto(Mica.DatasetDtoOrBuilder dto) {
Dataset dataset = dto.hasExtension(Mica.HarmonizedDatasetDto.type) ? fromDto(dto.getExtension(Mica.HarmonizedDatasetDto.type)) : dto.hasExtension(Mica.CollectedDatasetDto.type) ? fromDto(dto.getExtension(Mica.CollectedDatasetDto.type)) : new StudyDataset();
if (dto.hasId())
dataset.setId(dto.getId());
dataset.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
dataset.setName(localizedStringDtos.fromDto(dto.getNameList()));
dataset.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
dataset.setEntityType(dto.getEntityType());
dataset.setPublished(dto.getPublished());
if (dto.getAttributesCount() > 0) {
dto.getAttributesList().forEach(attributeDto -> dataset.addAttribute(attributeDtos.fromDto(attributeDto)));
}
if (dto.hasContent()) {
dataset.setModel(JSONUtils.toMap(dto.getContent()));
}
return dataset;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class NetworkDtos method asDtoBuilderInternal.
private Mica.NetworkDto.Builder asDtoBuilderInternal(@NotNull Network network, boolean asDraft, boolean forListing) {
Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
if (network.hasModel())
builder.setContent(JSONUtils.toJSON(network.getModel()));
//
builder.setId(network.getId()).addAllName(//
localizedStringDtos.asDto(network.getName())).addAllDescription(//
localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setPublished(networkState.isPublished());
if (asDraft) {
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
builder.setPermissions(permissionsDto);
}
if (network.getLogo() != null) {
builder.setLogo(attachmentDtos.asDto(network.getLogo()));
}
List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
if (!publishedStudies.isEmpty()) {
Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
publishedStudies.forEach(study -> {
builder.addStudyIds(study.getId());
if (!forListing) {
builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
}
});
}
unpublishedStudyIds.forEach(studyId -> {
try {
if (!forListing)
builder.addStudySummaries(studySummaryDtos.asDto(studyId));
builder.addStudyIds(studyId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), studyId);
// ignore
}
});
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
if (!forListing)
builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class ProjectDtos method fromDto.
@NotNull
public Project fromDto(@NotNull Mica.ProjectDto dto) {
Project.Builder builder = Project.newBuilder();
builder.content(dto.hasContent() ? dto.getContent() : null);
builder.title(localizedStringDtos.fromDto(dto.getTitleList()));
builder.summary(localizedStringDtos.fromDto(dto.getSummaryList()));
Project project = builder.build();
if (dto.hasId())
project.setId(dto.getId());
TimestampsDtos.fromDto(dto.getTimestamps(), project);
return project;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class StudySummaryDtos method asDto.
@NotNull
Mica.DataCollectionEventSummaryDto asDto(@NotNull DataCollectionEvent dce) {
Mica.DataCollectionEventSummaryDto.Builder builder = Mica.DataCollectionEventSummaryDto.newBuilder().setId(dce.getId()).addAllName(localizedStringDtos.asDto(dce.getName()));
if (dce.getDescription() != null)
builder.addAllDescription(localizedStringDtos.asDto(dce.getDescription()));
if (dce.hasModel())
builder.setContent(JSONUtils.toJSON(dce.getModel()));
if (dce.hasStart()) {
PersistableYearMonth start = dce.getStart();
builder.setStart(start.getDay() != null ? start.getDay().format(DateTimeFormatter.ISO_DATE) : dce.getStart().getYearMonth());
}
if (dce.hasEnd()) {
PersistableYearMonth end = dce.getEnd();
builder.setEnd(end.getDay() != null ? end.getDay().format(DateTimeFormatter.ISO_DATE) : end.getYearMonth());
}
return builder.build();
}
Aggregations