Skip to content

Commit

Permalink
#530 added country to grscicoll suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Nov 15, 2023
1 parent 484b8ff commit c83e29e
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<spring-cloud-sleuth.version>2.2.8.RELEASE</spring-cloud-sleuth.version>

<!-- GBIF -->
<gbif-api.version>1.12.8</gbif-api.version>
<gbif-api.version>1.12.9</gbif-api.version>
<gbif-common.version>0.59</gbif-common.version>
<gbif-common-mybatis.version>1.3</gbif-common-mybatis.version>
<gbif-common-ws.version>1.25</gbif-common-ws.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public void listChangeSuggestionTest() {
UUID entityKey = UUID.randomUUID();
Pageable page = new PagingRequest();

when(getMockChangeSuggestionService().list(status, type, proposerEmail, entityKey, page))
when(getMockChangeSuggestionService().list(status, type, proposerEmail, entityKey, null, page))
.thenReturn(
new PagingResponse<>(
new PagingRequest(), 1L, Collections.singletonList(changeSuggestion)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ public void discardSuggestionTest() {
public void listTest() {
// State
T entity = createEntity();

Address address = new Address();
address.setCountry(Country.DENMARK);
entity.setAddress(address);

R suggestion = createEmptyChangeSuggestion();
suggestion.setSuggestedEntity(entity);
suggestion.setType(Type.CREATE);
Expand All @@ -442,8 +447,17 @@ public void listTest() {
int suggKey1 = changeSuggestionService.createChangeSuggestion(suggestion);

T entity2 = createEntity();
Address address2 = new Address();
address2.setCountry(Country.DENMARK);
entity2.setAddress(address2);

UUID entity2Key = collectionEntityService.create(entity2);
R suggestion2 = createEmptyChangeSuggestion();

Address addressSugg = new Address();
addressSugg.setCountry(Country.SPAIN);
entity2.setAddress(addressSugg);

suggestion2.setSuggestedEntity(entity2);
suggestion2.setEntityKey(entity2Key);
suggestion2.setType(Type.UPDATE);
Expand All @@ -454,26 +468,38 @@ public void listTest() {

// When
PagingResponse<R> results =
changeSuggestionService.list(Status.APPLIED, null, null, null, DEFAULT_PAGE);
changeSuggestionService.list(Status.APPLIED, null, null, null, null, DEFAULT_PAGE);
// Then
assertEquals(0, results.getResults().size());
assertEquals(0, results.getCount());

// When
results = changeSuggestionService.list(null, Type.CREATE, null, null, DEFAULT_PAGE);
results = changeSuggestionService.list(null, Type.CREATE, null, null, null, DEFAULT_PAGE);
// Then
assertEquals(1, results.getResults().size());
assertEquals(1, results.getCount());

// When
results = changeSuggestionService.list(null, null, null, entity2Key, DEFAULT_PAGE);
results = changeSuggestionService.list(null, null, null, entity2Key, null, DEFAULT_PAGE);
// Then
assertEquals(1, results.getResults().size());
assertEquals(1, results.getCount());

// When
results = changeSuggestionService.list(null, null, null, null, Country.DENMARK, DEFAULT_PAGE);
// Then
assertEquals(2, results.getResults().size());
assertEquals(2, results.getCount());

// When
results = changeSuggestionService.list(null, null, null, null, Country.SPAIN, DEFAULT_PAGE);
// Then
assertEquals(0, results.getResults().size());
assertEquals(0, results.getCount());

// When - user with no rights can't see the proposer email
resetSecurityContext("user", UserRole.USER);
results = changeSuggestionService.list(null, null, null, entity2Key, DEFAULT_PAGE);
results = changeSuggestionService.list(null, null, null, entity2Key, null, DEFAULT_PAGE);
// Then
assertTrue(results.getResults().stream().allMatch(v -> v.getProposerEmail() == null));
}
Expand Down Expand Up @@ -587,15 +613,14 @@ public void updateContactsTest() {
assertTrue(applied.getContactPersons().stream().anyMatch(c -> c.getFirstName().equals("11")));
assertTrue(applied.getContactPersons().stream().anyMatch(c -> c.getFirstName().equals("22")));


entity = collectionEntityService.get(entityKey);

// suggestion to change contact1
entity.getContactPersons().stream()
.filter(c -> c.getKey().equals(contact1.getKey()))
.findFirst()
.get()
.setModifiedBy("11");
.filter(c -> c.getKey().equals(contact1.getKey()))
.findFirst()
.get()
.setModifiedBy("11");

R suggestion3 = createEmptyChangeSuggestion();
suggestion3.setSuggestedEntity(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.gbif.api.model.collections.suggestions.Status;
import org.gbif.api.model.collections.suggestions.Type;
import org.gbif.api.model.common.paging.Pageable;
import org.gbif.api.vocabulary.Country;
import org.gbif.registry.persistence.mapper.collections.dto.ChangeSuggestionDto;

import java.util.List;
Expand All @@ -43,14 +44,16 @@ List<ChangeSuggestionDto> list(
@Param("entityType") CollectionEntityType entityType,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey,
@Param("country") Country country,
@Nullable @Param("page") Pageable page);

long count(
@Param("status") Status status,
@Param("type") Type type,
@Param("entityType") CollectionEntityType entityType,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey);
@Param("entityKey") UUID entityKey,
@Param("country") Country country);

void update(ChangeSuggestionDto suggestion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,5 @@ public class ChangeSuggestionDto {
private String nameNewInstitutionConvertedCollection;
private Date modified;
private String modifiedBy;

// this field is not persisted in the DB. It stores the country that has to be taken into account
// to check the user permissions
private Country countryScope;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet id="128" author="mlopez" runInTransaction="false">
<sql splitStatements="false" stripComments="false">
<![CDATA[
ALTER TABLE change_suggestion ADD COLUMN entity_country CHAR(2) CHECK (assert_min_length(entity_country, 2));
]]>
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@
<include file="liquibase/125-occurrence-counts-grscicoll.xml" />
<include file="liquibase/126-wikidata-ncbi-identifier-types.xml" />
<include file="liquibase/127-organization-country-not-null.xml" />
<include file="liquibase/128-suggestions-country.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
<id property="key" column="key"/>
<result property="comments" column="comments" typeHandler="StringArrayTypeHandler"/>
<result property="changes" column="changes" typeHandler="SuggestedChangesTypeHandler"/>
<result property="countryScope" column="entity_country"/>
</resultMap>

<sql id="SUGGESTION_WRITE_FIELDS">
entity_type, entity_key, type, status, proposed, proposed_by, proposer_email, changes, comments,
suggested_entity, merge_target_key, institution_converted_collection, name_new_institution_converted_collection,
modified, modified_by
modified, modified_by, entity_country
</sql>

<sql id="SUGGESTION_READ_FIELDS">
cs.key, cs.entity_type, cs.entity_key, cs.type, cs.status, cs.proposed, cs.proposed_by, cs.proposer_email, cs. applied,
cs.applied_by, cs.discarded_by, cs.discarded, cs.suggested_entity, cs.comments,
cs.merge_target_key, cs.changes, cs.institution_converted_collection, cs.name_new_institution_converted_collection,
cs.modified, cs.modified_by
cs.modified, cs.modified_by, cs.entity_country
</sql>

<sql id="SUGGESTION_PARAMS_CREATE">
Expand All @@ -37,7 +38,8 @@
#{institutionConvertedCollection,jdbcType=OTHER},
#{nameNewInstitutionConvertedCollection,jdbcType=VARCHAR},
now(), <!-- modified -->
#{modifiedBy,jdbcType=VARCHAR}
#{modifiedBy,jdbcType=VARCHAR},
#{countryScope,jdbcType=VARCHAR}
</sql>

<sql id="SUGGESTION_PARAMS_UPDATE">
Expand All @@ -51,7 +53,8 @@
discarded_by = #{discardedBy,jdbcType=INTEGER},
applied = #{applied,jdbcType=OTHER},
applied_by = #{appliedBy,jdbcType=INTEGER},
entity_key = #{entityKey,jdbcType=INTEGER}
entity_key = #{entityKey,jdbcType=INTEGER},
entity_country = #{countryScope,jdbcType=VARCHAR}
</sql>

<insert id="create" parameterType="ChangeSuggestionDto" useGeneratedKeys="true" keyProperty="key">
Expand Down Expand Up @@ -94,6 +97,9 @@
<if test="entityKey != null">
AND cs.entity_key = #{entityKey,jdbcType=OTHER}
</if>
<if test="country != null">
AND cs.entity_country = #{country,jdbcType=VARCHAR}
</if>
</where>
ORDER BY cs.proposed DESC
<if test="page != null">
Expand All @@ -120,6 +126,9 @@
<if test="entityKey != null">
AND cs.entity_key = #{entityKey,jdbcType=OTHER}
</if>
<if test="country != null">
AND cs.entity_country = #{country,jdbcType=VARCHAR}
</if>
</where>
</select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,17 @@ public PagingResponse<R> list(
@Nullable Type type,
@Nullable String proposerEmail,
@Nullable UUID entityKey,
@Nullable Country country,
@Nullable Pageable pageable) {
Pageable page = pageable == null ? new PagingRequest() : pageable;

List<ChangeSuggestionDto> dtos =
changeSuggestionMapper.list(
status, type, collectionEntityType, proposerEmail, entityKey, page);
status, type, collectionEntityType, proposerEmail, entityKey, country, page);

long count =
changeSuggestionMapper.count(status, type, collectionEntityType, proposerEmail, entityKey);
changeSuggestionMapper.count(
status, type, collectionEntityType, proposerEmail, entityKey, country);

List<R> changeSuggestions =
dtos.stream().map(this::dtoToChangeSuggestion).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ public PagingResponse<R> listChangeSuggestion(
@RequestParam(value = "type", required = false) Type type,
@RequestParam(value = "proposerEmail", required = false) String proposerEmail,
@RequestParam(value = "entityKey", required = false) UUID entityKey,
Country country,
Pageable page) {
return changeSuggestionService.list(status, type, proposerEmail, entityKey, page);
return changeSuggestionService.list(status, type, proposerEmail, entityKey, country, page);
}

@Operation(
Expand Down

0 comments on commit c83e29e

Please sign in to comment.