Search in sources :

Example 66 with NotNull

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;
}
Also used : HarmonizationStudyConfig(org.obiba.mica.micaConfig.domain.HarmonizationStudyConfig) HarmonizationStudyConfig(org.obiba.mica.micaConfig.domain.HarmonizationStudyConfig) NotNull(javax.validation.constraints.NotNull)

Example 67 with NotNull

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();
}
Also used : Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) NetworkState(org.obiba.mica.network.domain.NetworkState) PublishedNetworkService(org.obiba.mica.network.service.PublishedNetworkService) LoggerFactory(org.slf4j.LoggerFactory) Network(org.obiba.mica.network.domain.Network) NetworkService(org.obiba.mica.network.service.NetworkService) NotNull(javax.validation.constraints.NotNull) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NetworkState(org.obiba.mica.network.domain.NetworkState) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NotNull(javax.validation.constraints.NotNull)

Example 68 with NotNull

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

Example 69 with NotNull

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;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Example 70 with NotNull

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)));
            }
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Connection(io.syndesis.common.model.connection.Connection) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) ZipEntry(java.util.zip.ZipEntry) JsonDbDao(io.syndesis.server.jsondb.dao.JsonDbDao) Context(javax.ws.rs.core.Context) Connector(io.syndesis.common.model.connection.Connector) StreamingOutput(javax.ws.rs.core.StreamingOutput) ListResult(io.syndesis.common.model.ListResult) Extension(io.syndesis.common.model.extension.Extension) NotNull(javax.validation.constraints.NotNull) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) ZipOutputStream(java.util.zip.ZipOutputStream) Migrator(io.syndesis.server.jsondb.dao.Migrator) ZipInputStream(java.util.zip.ZipInputStream) GET(javax.ws.rs.GET) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) Names(io.syndesis.common.util.Names) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StreamUtils.nonClosing(org.springframework.util.StreamUtils.nonClosing) DataManager(io.syndesis.server.dao.manager.DataManager) FileDataManager(io.syndesis.server.dao.file.FileDataManager) Api(io.swagger.annotations.Api) MemorySqlJsonDB(io.syndesis.server.jsondb.impl.MemorySqlJsonDB) LinkedHashSet(java.util.LinkedHashSet) SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) WithId(io.syndesis.common.model.WithId) IOException(java.io.IOException) JsonDB(io.syndesis.server.jsondb.JsonDB) ModelExport(io.syndesis.common.model.ModelExport) Dependency(io.syndesis.common.model.Dependency) Component(org.springframework.stereotype.Component) Schema(io.syndesis.common.model.Schema) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) ChangeEvent(io.syndesis.common.model.ChangeEvent) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Integration(io.syndesis.common.model.integration.Integration) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) Dependency(io.syndesis.common.model.Dependency) ZipOutputStream(java.util.zip.ZipOutputStream) ClientErrorException(javax.ws.rs.ClientErrorException) ModelExport(io.syndesis.common.model.ModelExport) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NotNull (javax.validation.constraints.NotNull)77 List (java.util.List)24 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)16 Inject (javax.inject.Inject)16 Logger (org.slf4j.Logger)14 ArrayList (java.util.ArrayList)13 LoggerFactory (org.slf4j.LoggerFactory)13 HashMap (java.util.HashMap)11 Response (javax.ws.rs.core.Response)10 Optional (java.util.Optional)9 Strings (com.google.common.base.Strings)8 Lists (com.google.common.collect.Lists)8 Set (java.util.Set)8 Valid (javax.validation.Valid)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