use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class MicaConfigDtos method fromDto.
@NotNull
<T extends EntityConfig> T fromDto(@NotNull Mica.EntityFormDto dto) {
EntityConfig config = null;
switch(dto.getType()) {
case Network:
config = new NetworkConfig();
break;
case Study:
config = new StudyConfig();
break;
case DataCollectionEvent:
config = new DataCollectionEventConfig();
break;
case Population:
config = new PopulationConfig();
break;
case CollectedDataset:
config = new StudyDatasetConfig();
break;
case HarmonizedDataset:
config = new HarmonizationDatasetConfig();
break;
case HarmonizationStudy:
config = new HarmonizationStudyConfig();
break;
case HarmonizationPopulation:
config = new HarmonizationPopulationConfig();
break;
}
config.setSchema(dto.getSchema());
config.setDefinition(dto.getDefinition());
return (T) config;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class NetworkSummaryDtos method asDto.
@NotNull
public Mica.NetworkSummaryDto asDto(@NotNull Network network, boolean asDraft) {
Mica.NetworkSummaryDto.Builder builder = Mica.NetworkSummaryDto.newBuilder();
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setId(network.getId()).addAllAcronym(localizedStringDtos.asDto(network.getAcronym())).addAllName(localizedStringDtos.asDto(network.getName())).setPublished(networkState.isPublished());
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
if (asDraft) {
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.networkSummaryState, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).forEach(sId -> {
try {
builder.addStudyIds(sId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), sId);
// ignore
}
});
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder.build();
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class PopulationDtos method fromDto.
@NotNull
DataCollectionEvent fromDto(@NotNull PopulationDto.DataCollectionEventDto dto) {
DataCollectionEvent dce = new DataCollectionEvent();
dce.setId(dto.getId());
if (dto.getNameCount() > 0)
dce.setName(localizedStringDtos.fromDto(dto.getNameList()));
if (dto.getDescriptionCount() > 0)
dce.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
if (dto.hasStartYear()) {
dce.setStart(dto.getStartYear(), dto.hasStartMonth() ? dto.getStartMonth() : null, Strings.isNullOrEmpty(dto.getStartDay()) ? null : LocalDate.parse(dto.getStartDay(), DateTimeFormatter.ISO_DATE));
}
if (dto.hasEndYear()) {
dce.setEnd(dto.getEndYear(), dto.hasEndMonth() ? dto.getEndMonth() : null, Strings.isNullOrEmpty(dto.getEndDay()) ? null : LocalDate.parse(dto.getEndDay(), DateTimeFormatter.ISO_DATE));
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
dce.setModel(JSONUtils.toMap(dto.getContent()));
else
dce.setModel(new HashMap<>());
if (dto.hasWeight()) {
dce.setWeight(dto.getWeight());
}
return dce;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class StudyDtos method fromDto.
@NotNull
BaseStudy fromDto(@NotNull Mica.StudyDtoOrBuilder dto) {
Assert.isTrue(dto.hasExtension(Mica.CollectionStudyDto.type) || dto.hasExtension(Mica.HarmonizationStudyDto.type), "StudyDto must of a type extension.");
BaseStudy study = dto.hasExtension(Mica.CollectionStudyDto.type) ? new Study() : new HarmonizationStudy();
if (dto.hasId())
study.setId(dto.getId());
if (dto.getNameCount() > 0)
study.setName(localizedStringDtos.fromDto(dto.getNameList()));
if (dto.getAcronymCount() > 0)
study.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
if (dto.hasLogo())
study.setLogo(attachmentDtos.fromDto(dto.getLogo()));
if (dto.hasTimestamps())
TimestampsDtos.fromDto(dto.getTimestamps(), study);
if (dto.getObjectivesCount() > 0)
study.setObjectives(localizedStringDtos.fromDto(dto.getObjectivesList()));
if (dto.hasOpal())
study.setOpal(dto.getOpal());
if (dto.getPopulationsCount() > 0) {
study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
}
if (dto.getMembershipSortOrderCount() > 0) {
Map<String, List<String>> membershipSortOrder = new HashMap<>();
dto.getMembershipSortOrderList().forEach(membership -> {
membershipSortOrder.put(membership.getRole(), membership.getPersonIdsList());
});
study.setMembershipSortOrder(membershipSortOrder);
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
study.setModel(JSONUtils.toMap(dto.getContent()));
else
study.setModel(new HashMap<>());
return study;
}
use of javax.validation.constraints.NotNull in project syndesis by syndesisio.
the class IntegrationSupportHandler method export.
@GET
@Path("/export.zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput export(@NotNull @QueryParam("id") @ApiParam(required = true) List<String> requestedIds) throws IOException {
List<String> ids = requestedIds;
if (ids == null || ids.isEmpty()) {
throw new ClientErrorException("No 'integration' query parameter specified.", Response.Status.BAD_REQUEST);
}
LinkedHashSet<String> extensions = new LinkedHashSet<>();
CloseableJsonDB memJsonDB = MemorySqlJsonDB.create(jsonDB.getIndexes());
if (ids.contains("all")) {
ids = new ArrayList<>();
for (Integration integration : dataManager.fetchAll(Integration.class)) {
ids.add(integration.getId().get());
}
}
for (String id : ids) {
Integration integration = integrationHandler.getIntegration(id);
addToExport(memJsonDB, integration);
resourceManager.collectDependencies(integration.getSteps(), true).stream().filter(Dependency::isExtension).map(Dependency::getId).forEach(extensions::add);
}
LOG.debug("Extensions: {}", extensions);
return out -> {
try (ZipOutputStream tos = new ZipOutputStream(out)) {
ModelExport exportObject = ModelExport.of(Schema.VERSION);
addEntry(tos, EXPORT_MODEL_INFO_FILE_NAME, Json.writer().writeValueAsBytes(exportObject));
addEntry(tos, EXPORT_MODEL_FILE_NAME, memJsonDB.getAsByteArray("/"));
memJsonDB.close();
for (String extensionId : extensions) {
addEntry(tos, "extensions/" + Names.sanitize(extensionId) + ".jar", IOUtils.toByteArray(extensionDataManager.getExtensionBinaryFile(extensionId)));
}
}
};
}
Aggregations