Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 8ec5466

Browse files
authored
Merge pull request #39 from Breeding-Insight/release/1.0
Merge for Release/1.0
2 parents b412589 + 86153e9 commit 8ec5466

File tree

7 files changed

+150
-28
lines changed

7 files changed

+150
-28
lines changed

docker-compose.yaml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,34 @@ services:
44
brapi-java-server-v1:
55
image: brapicoordinatorselby/brapi-java-server:v1
66
restart: unless-stopped
7-
depends_on:
7+
depends_on:
88
- postgres
99
volumes:
1010
- /home/jenkins/brapi.org/brapi-test-server/properties/v1/application.properties:/home/brapi/properties/application.properties
1111
brapi-java-server-v2:
1212
image: brapicoordinatorselby/brapi-java-server:v2
1313
restart: unless-stopped
14-
depends_on:
14+
depends_on:
1515
- postgres
1616
volumes:
1717
- /home/jenkins/brapi.org/brapi-test-server/properties/v2/application.properties:/home/brapi/properties/application.properties
1818
keycloak-brapi:
19-
image: jboss/keycloak:12.0.1
19+
image: brapicoordinatorselby/brapi-keycloak:latest
2020
restart: unless-stopped
21-
depends_on:
21+
entrypoint: /opt/keycloak/bin/kc.sh start --optimized --proxy edge
22+
depends_on:
2223
- postgres
23-
volumes:
24-
- /home/jenkins/brapi.org/brapi-test-server/keycloak/standalone.xml:/opt/jboss/keycloak/standalone/configuration/standalone.xml
2524
environment:
2625
- KEYCLOAK_USER
2726
- KEYCLOAK_PASSWORD
28-
- DB_VENDOR
29-
- DB_ADDR
30-
- DB_DATABASE
31-
- DB_USER
32-
- DB_PASSWORD
33-
- PROXY_ADDRESS_FORWARDING=true
27+
- KC_HOSTNAME=auth.brapi.org
28+
- KC_DB
29+
- KC_DB_URL
30+
- KC_DB_USERNAME
31+
- KC_DB_PASSWORD
3432
postgres:
35-
image: postgres
33+
image: postgres:13
3634
restart: unless-stopped
37-
environment:
38-
- POSTGRES_USER
39-
- POSTGRES_PASSWORD
4035
volumes:
4136
- /home/jenkins/brapi.org/brapi-test-server/data:/var/lib/postgresql/data
4237
networks:

src/main/java/org/brapi/test/BrAPITestServer/model/entity/core/ListEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ListEntity extends BrAPIPrimaryEntity {
3030
@ManyToOne(fetch = FetchType.LAZY)
3131
private PersonEntity listOwnerPerson;
3232
@OneToMany(mappedBy="list", cascade = CascadeType.ALL)
33+
@OrderColumn(name = "position")
3334
private List<ListItemEntity> data;
3435

3536
public PersonEntity getListOwnerPerson() {

src/main/java/org/brapi/test/BrAPITestServer/model/entity/core/ListItemEntity.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class ListItemEntity extends BrAPIBaseEntity {
1111
private ListEntity list;
1212
@Column
1313
private String item;
14+
@Column
15+
private Integer position;
1416

1517
public ListEntity getList() {
1618
return list;
@@ -24,6 +26,10 @@ public String getItem() {
2426
public void setItem(String item) {
2527
this.item = item;
2628
}
27-
28-
29+
public Integer getPosition() {
30+
return position;
31+
}
32+
public void setPosition(Integer position) {
33+
this.position = position;
34+
}
2935
}

src/main/java/org/brapi/test/BrAPITestServer/service/core/ListService.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.brapi.test.BrAPITestServer.service.core;
22

3-
import java.util.ArrayList;
4-
import java.util.Date;
5-
import java.util.List;
6-
import java.util.Optional;
3+
import java.util.*;
74
import java.util.stream.Collectors;
85

96
import jakarta.validation.Valid;
@@ -237,12 +234,19 @@ private void updateEntity(ListEntity entity, @Valid ListNewRequest list) throws
237234
}
238235

239236
if (list.getData() != null) {
240-
entity.setData(list.getData().stream().map((item) -> {
241-
ListItemEntity itemEntity = new ListItemEntity();
242-
itemEntity.setItem(item);
243-
itemEntity.setList(entity);
244-
return itemEntity;
245-
}).collect(Collectors.toList()));
237+
List<ListItemEntity> items = new ArrayList<>();
238+
ListIterator<String> iter = list.getData().listIterator();
239+
while (iter.hasNext()) {
240+
String item = iter.next();
241+
if (item != null) {
242+
ListItemEntity itemEntity = new ListItemEntity();
243+
itemEntity.setPosition(iter.nextIndex());
244+
itemEntity.setItem(item);
245+
itemEntity.setList(entity);
246+
items.add(itemEntity);
247+
}
248+
}
249+
entity.setData(items);
246250
} else {
247251
entity.setData(new ArrayList<>());
248252
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- See the NOTICE file distributed with this work for additional information
2+
-- regarding copyright ownership.
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
16+
-- Updates trial.additional_info to have a datasets array instead of just observationDatasetId.
17+
-- Leaves observationDatasetId in place out of an abundance of caution.
18+
-- Only updates rows that don't already have datasets key (just in case the code was updated prematurely).
19+
DO
20+
$$
21+
BEGIN
22+
UPDATE
23+
trial
24+
SET
25+
additional_info = additional_info
26+
|| JSONB_BUILD_OBJECT(
27+
'datasets',
28+
JSONB_BUILD_ARRAY(
29+
JSONB_BUILD_OBJECT(
30+
'id', additional_info->'observationDatasetId',
31+
'name', additional_info->'defaultObservationLevel',
32+
'level', '0'
33+
)
34+
)
35+
)
36+
WHERE
37+
additional_info->'datasets' IS NULL;
38+
END
39+
$$;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
-- This migration updates existing list_item records based on DeltaBreed (Breeding Insight) specific fields.
3+
--
4+
-- These are the list types, the BJTS uses Java enums and stores ints in the database.
5+
-- 0: germplasm
6+
-- 1: markers
7+
-- 2: programs
8+
-- 3: trials
9+
-- 4: studies
10+
-- 5: observationUnits
11+
-- 6: observations
12+
-- 7: observationVariables
13+
-- 8: samples
14+
15+
DO
16+
$$
17+
BEGIN
18+
-- Update germplasm list items, the goal is to use the order defined by the listEntryNumbers.
19+
UPDATE
20+
list_item
21+
SET
22+
position = subquery.position
23+
FROM
24+
(
25+
SELECT
26+
-- Subtract 1 from row_number to get zero indexing.
27+
row_number() OVER (PARTITION BY li.list_id ORDER BY (g.additional_info->'listEntryNumbers'->>xr.external_reference_id)::int) - 1 AS position,
28+
li.id AS list_item_id
29+
FROM
30+
list_item li
31+
JOIN list l ON li.list_id = l.id
32+
JOIN list_external_references ler ON l.id = ler.list_entity_id
33+
JOIN external_reference xr ON xr.id = ler.external_references_id AND xr.external_reference_source = 'breedinginsight.org/lists'
34+
JOIN germplasm g ON li.item = g.germplasm_name
35+
WHERE
36+
l.list_type = 0 -- 0 is germplasm
37+
ORDER BY
38+
l.id
39+
) AS subquery
40+
WHERE
41+
list_item.id = subquery.list_item_id
42+
;
43+
44+
-- Update all non-germplasm list items. There is no existing order to preserve, assign sequential position values arbitrarily.
45+
UPDATE
46+
list_item
47+
SET
48+
position = subquery.position
49+
FROM
50+
(
51+
SELECT
52+
-- Subtract 1 from row_number to get zero indexing.
53+
row_number() OVER (PARTITION BY li.list_id) - 1 AS position,
54+
li.id AS list_item_id
55+
FROM
56+
list_item li
57+
JOIN list l ON li.list_id = l.id
58+
WHERE
59+
l.list_type != 0 -- 0 is germplasm, here we are addressing non-germplasm lists.
60+
ORDER BY
61+
l.id
62+
) AS subquery
63+
WHERE
64+
list_item.id = subquery.list_item_id
65+
;
66+
67+
END;
68+
$$;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- This migration adds a position field to list_item so that lists can be explicitly ordered.
2+
3+
-- Add position to list_item.
4+
ALTER TABLE list_item
5+
ADD COLUMN position INT NOT NULL DEFAULT 0;
6+
-- Add an index on the position column
7+
CREATE INDEX idx_list_item_position ON list_item(position);
8+
-- Add a composite index on list_id and position for better performance when querying items within a specific list
9+
CREATE INDEX idx_list_item_list_position ON list_item(list_id, position);

0 commit comments

Comments
 (0)