Skip to content

Commit 559bd73

Browse files
- CHG: Adjusted collaborators endpoints to include projects information.
-
1 parent b85a8c9 commit 559bd73

File tree

10 files changed

+118
-11
lines changed

10 files changed

+118
-11
lines changed

lib/germinate-codegen-4.7.4.jar

554 Bytes
Binary file not shown.

src/main/java/jhi/germinate/resource/GermplasmStats.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class GermplasmStats
88
private String germplasmName;
99
private Integer traitId;
1010
private String traitName;
11+
private String traitNameShort;
1112
private BigDecimal min;
1213
private BigDecimal avg;
1314
private BigDecimal max;
@@ -92,4 +93,15 @@ public void setCount(Integer count)
9293
{
9394
this.count = count;
9495
}
96+
97+
public String getTraitNameShort()
98+
{
99+
return traitNameShort;
100+
}
101+
102+
public GermplasmStats setTraitNameShort(String traitNameShort)
103+
{
104+
this.traitNameShort = traitNameShort;
105+
return this;
106+
}
95107
}

src/main/java/jhi/germinate/resource/ProjectStats.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
public class ProjectStats
44
{
5-
private int publicationCount = 0;
6-
private int groupCount = 0;
7-
private int datasetCount = 0;
5+
private int publicationCount = 0;
6+
private int groupCount = 0;
7+
private int datasetCount = 0;
8+
private int collaboratorCount = 0;
9+
10+
public int getCollaboratorCount()
11+
{
12+
return collaboratorCount;
13+
}
14+
15+
public ProjectStats setCollaboratorCount(int collaboratorCount)
16+
{
17+
this.collaboratorCount = collaboratorCount;
18+
return this;
19+
}
820

921
public int getPublicationCount()
1022
{

src/main/java/jhi/germinate/server/resource/IFilteredResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import jhi.germinate.server.util.*;
55
import org.jooq.*;
66
import org.jooq.impl.DSL;
7+
import org.yaml.snakeyaml.internal.Logger;
78

89
import java.util.*;
910
import java.util.stream.Collectors;
@@ -201,6 +202,7 @@ default Condition filterIndividual(Filter filter, boolean jsonOperationAllowed)
201202
}
202203
else
203204
{
205+
Logger.getLogger("").warn("Trying to use a json operation, but not allowed: " + filter);
204206
return null;
205207
}
206208
case "arrayContains":
@@ -222,6 +224,7 @@ default Condition filterIndividual(Filter filter, boolean jsonOperationAllowed)
222224
}
223225
else
224226
{
227+
Logger.getLogger("").warn("Trying to use a json operation, but not allowed: " + filter);
225228
return null;
226229
}
227230
case "inSet":
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package jhi.germinate.server.resource.collaborator;
2+
3+
import jakarta.annotation.security.PermitAll;
4+
import jakarta.ws.rs.*;
5+
import jakarta.ws.rs.core.*;
6+
import jhi.gatekeeper.resource.PaginatedResult;
7+
import jhi.germinate.resource.PaginatedRequest;
8+
import jhi.germinate.server.Database;
9+
import jhi.germinate.server.database.codegen.tables.pojos.ViewTableCollaborators;
10+
import jhi.germinate.server.resource.BaseResource;
11+
import jhi.germinate.server.util.Secured;
12+
import org.jooq.*;
13+
14+
import java.sql.*;
15+
import java.util.List;
16+
17+
import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.VIEW_TABLE_COLLABORATORS;
18+
19+
@Path("collaborator/table")
20+
@Secured
21+
@PermitAll
22+
public class CollaboratorTableResource extends BaseResource
23+
{
24+
@POST
25+
@Consumes(MediaType.APPLICATION_JSON)
26+
@Produces(MediaType.APPLICATION_JSON)
27+
public Response postCollaboratorTable(PaginatedRequest request)
28+
throws SQLException
29+
{
30+
processRequest(request);
31+
try (Connection conn = Database.getConnection())
32+
{
33+
DSLContext context = Database.getContext(conn);
34+
SelectSelectStep<Record> select = context.select();
35+
36+
if (previousCount == -1)
37+
select.hint("SQL_CALC_FOUND_ROWS");
38+
39+
SelectJoinStep<Record> from = select.from(VIEW_TABLE_COLLABORATORS);
40+
41+
// Filter here!
42+
where(from, filters, true);
43+
44+
List<ViewTableCollaborators> result = setPaginationAndOrderBy(from)
45+
.fetch()
46+
.into(ViewTableCollaborators.class);
47+
48+
long count = previousCount == -1 ? context.fetchOne("SELECT FOUND_ROWS()").into(Long.class) : previousCount;
49+
50+
return Response.ok(new PaginatedResult<>(result, count)).build();
51+
}
52+
}
53+
}

src/main/java/jhi/germinate/server/resource/datasets/CollaboratorTableResource.java renamed to src/main/java/jhi/germinate/server/resource/datasets/DatasetCollaboratorTableResource.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package jhi.germinate.server.resource.datasets;
22

3+
import jakarta.annotation.security.PermitAll;
4+
import jakarta.servlet.http.*;
5+
import jakarta.ws.rs.*;
6+
import jakarta.ws.rs.core.MediaType;
37
import jhi.gatekeeper.resource.PaginatedResult;
48
import jhi.germinate.resource.PaginatedRequest;
59
import jhi.germinate.server.*;
@@ -8,19 +12,15 @@
812
import jhi.germinate.server.util.Secured;
913
import org.jooq.*;
1014

11-
import jakarta.annotation.security.PermitAll;
12-
import jakarta.servlet.http.*;
13-
import jakarta.ws.rs.*;
14-
import jakarta.ws.rs.core.MediaType;
1515
import java.sql.*;
1616
import java.util.*;
1717

18-
import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.*;
18+
import static jhi.germinate.server.database.codegen.tables.ViewTableCollaborators.VIEW_TABLE_COLLABORATORS;
1919

2020
@Path("dataset/{datasetId}/collaborator")
2121
@Secured
2222
@PermitAll
23-
public class CollaboratorTableResource extends BaseResource
23+
public class DatasetCollaboratorTableResource extends BaseResource
2424
{
2525
@PathParam("datasetId")
2626
private Integer datasetId;

src/main/java/jhi/germinate/server/resource/datasets/export/DatasetExportResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ private File exportIsaTab(SubsettedDatasetRequest request, DSLContext context, L
461461
resultFiles.add(datasetFile);
462462
inv.addStudy(study);
463463

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

466466
if (!CollectionUtils.isEmpty(collaborators))
467467
collaborators.forEach(c -> study.addContact(new Person(c.getCollaboratorLastName(), c.getCollaboratorFirstName(), c.getCollaboratorEmail(), c.getInstitutionName(), c.getInstitutionAddress())));

src/main/java/jhi/germinate/server/resource/germplasm/GermplasmTraitStatsResource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public List<GermplasmStats> getGermplasmTraitStats(@PathParam("germplasmId") Int
7373
GERMINATEBASE.NAME.as("germplasm_name"),
7474
PHENOTYPES.ID.as("trait_id"),
7575
PHENOTYPES.NAME.as("trait_name"),
76+
PHENOTYPES.SHORT_NAME.as("trait_name_short"),
7677
min.asField("min"),
7778
DSL.avg(PHENOTYPEDATA.PHENOTYPE_VALUE.cast(SQLDataType.DECIMAL.precision(64, 10))).as("avg"),
7879
max.asField("max"),

src/main/java/jhi/germinate/server/resource/projects/ProjectResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static jhi.germinate.server.database.codegen.tables.Experiments.EXPERIMENTS;
2222
import static jhi.germinate.server.database.codegen.tables.Images.IMAGES;
2323
import static jhi.germinate.server.database.codegen.tables.Imagetypes.IMAGETYPES;
24+
import static jhi.germinate.server.database.codegen.tables.Projectcollaborators.PROJECTCOLLABORATORS;
2425
import static jhi.germinate.server.database.codegen.tables.Projectgroups.PROJECTGROUPS;
2526
import static jhi.germinate.server.database.codegen.tables.Projectpublications.PROJECTPUBLICATIONS;
2627
import static jhi.germinate.server.database.codegen.tables.Projects.PROJECTS;
@@ -52,6 +53,7 @@ public Response getProjectStats(@PathParam("projectId") Integer projectId)
5253
result.setGroupCount(context.selectCount().from(PROJECTGROUPS).where(PROJECTGROUPS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
5354
result.setDatasetCount(context.selectCount().from(DATASETS).leftJoin(EXPERIMENTS).on(EXPERIMENTS.ID.eq(DATASETS.EXPERIMENT_ID)).where(EXPERIMENTS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
5455
result.setPublicationCount(context.selectCount().from(PROJECTPUBLICATIONS).where(PROJECTPUBLICATIONS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
56+
result.setCollaboratorCount(context.selectCount().from(PROJECTCOLLABORATORS).where(PROJECTCOLLABORATORS.PROJECT_ID.eq(projectId)).fetchOneInto(Integer.class));
5557

5658
return Response.ok(result).build();
5759
}

src/main/resources/jhi/germinate/server/util/database/init/views_procedures.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,31 @@ DROP VIEW IF EXISTS `view_table_traits`;
8080
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`;
8181

8282
DROP VIEW IF EXISTS `view_table_collaborators`;
83-
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`;
83+
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `view_table_collaborators` AS
84+
SELECT `collaborators`.`id` AS `collaborator_id`,
85+
`collaborators`.`first_name` AS `collaborator_first_name`,
86+
`collaborators`.`last_name` AS `collaborator_last_name`,
87+
`collaborators`.`external_id` AS `collaborator_external_id`,
88+
`collaborators`.`email` AS `collaborator_email`,
89+
`collaborators`.`phone` AS `collaborator_phone`,
90+
`datasetcollaborators`.`collaborator_roles` AS `collaborator_roles`,
91+
`institutions`.`id` AS `institution_id`,
92+
`institutions`.`name` AS `institution_name`,
93+
`institutions`.`address` AS `institution_address`,
94+
`datasets`.`id` AS `dataset_id`,
95+
`countries`.`id` AS `country_id`,
96+
`countries`.`country_name` AS `country_name`,
97+
`countries`.`country_code2` AS `country_code2`,
98+
`countries`.`country_code3` AS `country_code3`,
99+
(SELECT json_arrayagg(`projectcollaborators`.`project_id`)
100+
FROM `projectcollaborators`
101+
WHERE `projectcollaborators`.`collaborator_id` = `collaborators`.`id`
102+
GROUP BY `projectcollaborators`.`collaborator_id`) AS `project_ids`
103+
FROM `collaborators`
104+
LEFT JOIN `institutions` ON `institutions`.`id` = `collaborators`.`institution_id`
105+
LEFT JOIN `countries` ON `countries`.`id` = `institutions`.`country_id`
106+
LEFT JOIN `datasetcollaborators` ON `datasetcollaborators`.`collaborator_id` = `collaborators`.`id`
107+
LEFT JOIN `datasets` ON `datasets`.`id` = `datasetcollaborators`.`dataset_id`;
84108

85109
DROP VIEW IF EXISTS `view_table_trials_data`;
86110
# 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`;

0 commit comments

Comments
 (0)