Skip to content

Commit

Permalink
- CHG: Adjusted collaborators endpoints to include projects information.
Browse files Browse the repository at this point in the history
-
  • Loading branch information
sebastian-raubach committed Oct 1, 2024
1 parent b85a8c9 commit 559bd73
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 11 deletions.
Binary file modified lib/germinate-codegen-4.7.4.jar
Binary file not shown.
12 changes: 12 additions & 0 deletions src/main/java/jhi/germinate/resource/GermplasmStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GermplasmStats
private String germplasmName;
private Integer traitId;
private String traitName;
private String traitNameShort;
private BigDecimal min;
private BigDecimal avg;
private BigDecimal max;
Expand Down Expand Up @@ -92,4 +93,15 @@ public void setCount(Integer count)
{
this.count = count;
}

public String getTraitNameShort()
{
return traitNameShort;
}

public GermplasmStats setTraitNameShort(String traitNameShort)
{
this.traitNameShort = traitNameShort;
return this;
}
}
18 changes: 15 additions & 3 deletions src/main/java/jhi/germinate/resource/ProjectStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

public class ProjectStats
{
private int publicationCount = 0;
private int groupCount = 0;
private int datasetCount = 0;
private int publicationCount = 0;
private int groupCount = 0;
private int datasetCount = 0;
private int collaboratorCount = 0;

public int getCollaboratorCount()
{
return collaboratorCount;
}

public ProjectStats setCollaboratorCount(int collaboratorCount)
{
this.collaboratorCount = collaboratorCount;
return this;
}

public int getPublicationCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jhi.germinate.server.util.*;
import org.jooq.*;
import org.jooq.impl.DSL;
import org.yaml.snakeyaml.internal.Logger;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -201,6 +202,7 @@ default Condition filterIndividual(Filter filter, boolean jsonOperationAllowed)
}
else
{
Logger.getLogger("").warn("Trying to use a json operation, but not allowed: " + filter);
return null;
}
case "arrayContains":
Expand All @@ -222,6 +224,7 @@ default Condition filterIndividual(Filter filter, boolean jsonOperationAllowed)
}
else
{
Logger.getLogger("").warn("Trying to use a json operation, but not allowed: " + filter);
return null;
}
case "inSet":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package jhi.germinate.server.resource.collaborator;

import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*;
import jhi.gatekeeper.resource.PaginatedResult;
import jhi.germinate.resource.PaginatedRequest;
import jhi.germinate.server.Database;
import jhi.germinate.server.database.codegen.tables.pojos.ViewTableCollaborators;
import jhi.germinate.server.resource.BaseResource;
import jhi.germinate.server.util.Secured;
import org.jooq.*;

import java.sql.*;
import java.util.List;

import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.VIEW_TABLE_COLLABORATORS;

@Path("collaborator/table")
@Secured
@PermitAll
public class CollaboratorTableResource extends BaseResource
{
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postCollaboratorTable(PaginatedRequest request)
throws SQLException
{
processRequest(request);
try (Connection conn = Database.getConnection())
{
DSLContext context = Database.getContext(conn);
SelectSelectStep<Record> select = context.select();

if (previousCount == -1)
select.hint("SQL_CALC_FOUND_ROWS");

SelectJoinStep<Record> from = select.from(VIEW_TABLE_COLLABORATORS);

// Filter here!
where(from, filters, true);

List<ViewTableCollaborators> result = setPaginationAndOrderBy(from)
.fetch()
.into(ViewTableCollaborators.class);

long count = previousCount == -1 ? context.fetchOne("SELECT FOUND_ROWS()").into(Long.class) : previousCount;

return Response.ok(new PaginatedResult<>(result, count)).build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package jhi.germinate.server.resource.datasets;

import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jhi.gatekeeper.resource.PaginatedResult;
import jhi.germinate.resource.PaginatedRequest;
import jhi.germinate.server.*;
Expand All @@ -8,19 +12,15 @@
import jhi.germinate.server.util.Secured;
import org.jooq.*;

import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import java.sql.*;
import java.util.*;

import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.*;
import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.VIEW_TABLE_COLLABORATORS;

@Path("dataset/{datasetId}/collaborator")
@Secured
@PermitAll
public class CollaboratorTableResource extends BaseResource
public class DatasetCollaboratorTableResource extends BaseResource
{
@PathParam("datasetId")
private Integer datasetId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private File exportIsaTab(SubsettedDatasetRequest request, DSLContext context, L
resultFiles.add(datasetFile);
inv.addStudy(study);

List<ViewTableCollaborators> collaborators = CollaboratorTableResource.getCollaboratorsForDataset(dataset.getDatasetId(), req, resp, userDetails);
List<ViewTableCollaborators> collaborators = DatasetCollaboratorTableResource.getCollaboratorsForDataset(dataset.getDatasetId(), req, resp, userDetails);

if (!CollectionUtils.isEmpty(collaborators))
collaborators.forEach(c -> study.addContact(new Person(c.getCollaboratorLastName(), c.getCollaboratorFirstName(), c.getCollaboratorEmail(), c.getInstitutionName(), c.getInstitutionAddress())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public List<GermplasmStats> getGermplasmTraitStats(@PathParam("germplasmId") Int
GERMINATEBASE.NAME.as("germplasm_name"),
PHENOTYPES.ID.as("trait_id"),
PHENOTYPES.NAME.as("trait_name"),
PHENOTYPES.SHORT_NAME.as("trait_name_short"),
min.asField("min"),
DSL.avg(PHENOTYPEDATA.PHENOTYPE_VALUE.cast(SQLDataType.DECIMAL.precision(64, 10))).as("avg"),
max.asField("max"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static jhi.germinate.server.database.codegen.tables.Experiments.EXPERIMENTS;
import static jhi.germinate.server.database.codegen.tables.Images.IMAGES;
import static jhi.germinate.server.database.codegen.tables.Imagetypes.IMAGETYPES;
import static jhi.germinate.server.database.codegen.tables.Projectcollaborators.PROJECTCOLLABORATORS;
import static jhi.germinate.server.database.codegen.tables.Projectgroups.PROJECTGROUPS;
import static jhi.germinate.server.database.codegen.tables.Projectpublications.PROJECTPUBLICATIONS;
import static jhi.germinate.server.database.codegen.tables.Projects.PROJECTS;
Expand Down Expand Up @@ -52,6 +53,7 @@ public Response getProjectStats(@PathParam("projectId") Integer projectId)
result.setGroupCount(context.selectCount().from(PROJECTGROUPS).where(PROJECTGROUPS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
result.setDatasetCount(context.selectCount().from(DATASETS).leftJoin(EXPERIMENTS).on(EXPERIMENTS.ID.eq(DATASETS.EXPERIMENT_ID)).where(EXPERIMENTS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
result.setPublicationCount(context.selectCount().from(PROJECTPUBLICATIONS).where(PROJECTPUBLICATIONS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
result.setCollaboratorCount(context.selectCount().from(PROJECTCOLLABORATORS).where(PROJECTCOLLABORATORS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));

return Response.ok(result).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,31 @@ DROP VIEW IF EXISTS `view_table_traits`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_table_traits` AS select distinct `phenotypes`.`id` AS `trait_id`,`phenotypes`.`name` AS `trait_name`,`phenotypes`.`short_name` AS `trait_name_short`,`phenotypes`.`description` AS `trait_description`,`phenotypes`.`datatype` AS `data_type`,`phenotypes`.`restrictions` AS `trait_restrictions`,`units`.`id` AS `unit_id`,`units`.`unit_name` AS `unit_name`,`units`.`unit_description` AS `unit_description`,`units`.`unit_abbreviation` AS `unit_abbreviation`,`synonyms`.`synonyms` AS `synonyms`, (SELECT CAST(CONCAT('[', (SELECT GROUP_CONCAT(DISTINCT `dataset_id`) FROM `phenotypedata` LEFT JOIN `trialsetup` ON `trialsetup`.`id` = `phenotypedata`.`trialsetup_id` WHERE `phenotypedata`.`phenotype_id` = `phenotypes`.`id`) ,']') as json)) AS `dataset_ids`, (select count(1) from `phenotypedata` where (`phenotypedata`.`phenotype_id` = `phenotypes`.`id`)) AS `count` from ((`phenotypes` left join `units` on((`units`.`id` = `phenotypes`.`unit_id`))) left join `synonyms` on(((`synonyms`.`foreign_id` = `phenotypes`.`id`) and (`synonyms`.`synonymtype_id` = 4)))) group by `phenotypes`.`id`,`synonyms`.`id`;

DROP VIEW IF EXISTS `view_table_collaborators`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_table_collaborators` AS SELECT `collaborators`.`id` AS `collaborator_id`, `collaborators`.`first_name` AS `collaborator_first_name`, `collaborators`.`last_name` AS `collaborator_last_name`, `collaborators`.`external_id` AS `collaborator_external_id`, `collaborators`.`email` AS `collaborator_email`, `collaborators`.`phone` AS `collaborator_phone`, `datasetcollaborators`.`collaborator_roles` AS `collaborator_roles`, `institutions`.`id` AS `institution_id`, `institutions`.`name` AS `institution_name`, `institutions`.`address` AS `institution_address`, `datasets`.`id` AS `dataset_id`, `countries`.`id` AS `country_id`, `countries`.`country_name` AS `country_name`, `countries`.`country_code2` AS `country_code2`, `countries`.`country_code3` AS `country_code3` FROM `collaborators` LEFT JOIN `institutions` ON `institutions`.`id` = `collaborators`.`institution_id` LEFT JOIN `countries` ON `countries`.`id` = `institutions`.`country_id` LEFT JOIN `datasetcollaborators` ON `datasetcollaborators`.`collaborator_id` = `collaborators`.`id` LEFT JOIN `datasets` ON `datasets`.`id` = `datasetcollaborators`.`dataset_id`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_table_collaborators` AS
SELECT `collaborators`.`id` AS `collaborator_id`,
`collaborators`.`first_name` AS `collaborator_first_name`,
`collaborators`.`last_name` AS `collaborator_last_name`,
`collaborators`.`external_id` AS `collaborator_external_id`,
`collaborators`.`email` AS `collaborator_email`,
`collaborators`.`phone` AS `collaborator_phone`,
`datasetcollaborators`.`collaborator_roles` AS `collaborator_roles`,
`institutions`.`id` AS `institution_id`,
`institutions`.`name` AS `institution_name`,
`institutions`.`address` AS `institution_address`,
`datasets`.`id` AS `dataset_id`,
`countries`.`id` AS `country_id`,
`countries`.`country_name` AS `country_name`,
`countries`.`country_code2` AS `country_code2`,
`countries`.`country_code3` AS `country_code3`,
(SELECT json_arrayagg(`projectcollaborators`.`project_id`)
FROM `projectcollaborators`
WHERE `projectcollaborators`.`collaborator_id` = `collaborators`.`id`
GROUP BY `projectcollaborators`.`collaborator_id`) AS `project_ids`
FROM `collaborators`
LEFT JOIN `institutions` ON `institutions`.`id` = `collaborators`.`institution_id`
LEFT JOIN `countries` ON `countries`.`id` = `institutions`.`country_id`
LEFT JOIN `datasetcollaborators` ON `datasetcollaborators`.`collaborator_id` = `collaborators`.`id`
LEFT JOIN `datasets` ON `datasets`.`id` = `datasetcollaborators`.`dataset_id`;

DROP VIEW IF EXISTS `view_table_trials_data`;
# CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_table_trials_data` AS select `germinatebase`.`id` AS `germplasm_id`,`germinatebase`.`general_identifier` AS `germplasm_gid`,`germinatebase`.`name` AS `germplasm_name`,`synonyms`.`synonyms` AS `germplasm_synonyms`,`g`.`name` AS `entity_parent_name`,`g`.`general_identifier` AS `entity_parent_general_identifier`,`entitytypes`.`name` AS `entity_type`,`datasets`.`id` AS `dataset_id`,`datasets`.`name` AS `dataset_name`,`datasets`.`description` AS `dataset_description`,`locations`.`site_name` AS `location_name`,`countries`.`country_name` AS `country_name`,`countries`.`country_code2` AS `country_code2`,`phenotypes`.`id` AS `trait_id`,`phenotypes`.`name` AS `trait_name`,`phenotypes`.`short_name` AS `trait_name_short`,`phenotypes`.`restrictions` AS `trait_restrictions`,`units`.`unit_name` AS `unit_name`,`treatments`.`name` AS `treatment`,`phenotypedata`.`rep` AS `rep`, `phenotypedata`.`recording_date` AS `recording_date`,`phenotypedata`.`phenotype_value` AS `trait_value` from `phenotypedata` left join `germinatebase` on `germinatebase`.`id` = `phenotypedata`.`germinatebase_id` left join `germinatebase` `g` on `germinatebase`.`entityparent_id` = `g`.`id` left join `synonyms` on (`synonyms`.`synonymtype_id` = 1 AND `synonyms`.`foreign_id` = `germinatebase`.`id`) left join `entitytypes` on `entitytypes`.`id` = `germinatebase`.`entitytype_id` left join `phenotypes` on `phenotypes`.`id` = `phenotypedata`.`phenotype_id` left join `units` on `units`.`id` = `phenotypes`.`unit_id` left join `datasets` on `datasets`.`id` = `phenotypedata`.`dataset_id` left join `locations` on `phenotypedata`.`location_id` = `locations`.`id` left join `countries` on `countries`.`id` = `locations`.`country_id` left join `treatments` on `phenotypedata`.`treatment_id` = `treatments`.`id`;
Expand Down

0 comments on commit 559bd73

Please sign in to comment.