Skip to content

Commit

Permalink
removed country and name from the suggestions DB table
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed May 28, 2021
1 parent f6eac0b commit c008bdb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,18 @@ public void listChangeSuggestionTest() {
changeSuggestion.setKey(1);
Status status = Status.PENDING;
Type type = Type.CREATE;
Country country = Country.DENMARK;
String proposerEmail = "aa@aa.com";
UUID entityKey = UUID.randomUUID();
Pageable page = new PagingRequest();

when(getMockChangeSuggestionService()
.list(status, type, country, proposerEmail, entityKey, page))
when(getMockChangeSuggestionService().list(status, type, proposerEmail, entityKey, page))
.thenReturn(
new PagingResponse<>(
new PagingRequest(), 1L, Collections.singletonList(changeSuggestion)));

PagingResponse<R> result =
getPrimaryCollectionEntityClient()
.listChangeSuggestion(status, type, country, proposerEmail, entityKey, page);
.listChangeSuggestion(status, type, proposerEmail, entityKey, page);
assertEquals(1, result.getResults().size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,34 +325,26 @@ public void listTest() {

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

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

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

// When
results =
changeSuggestionService.list(
null, null, Country.AFGHANISTAN, null, entity2Key, 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, null, entity2Key, DEFAULT_PAGE);
results = changeSuggestionService.list(null, null, null, entity2Key, DEFAULT_PAGE);
// Then
assertTrue(results.getResults().stream().allMatch(v -> v.getProposerEmail() == null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -26,7 +25,6 @@ List<ChangeSuggestionDto> list(
@Param("status") Status status,
@Param("type") Type type,
@Param("entityType") CollectionEntityType entityType,
@Param("entityCountry") Country entityCountry,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey,
@Nullable @Param("page") Pageable page);
Expand All @@ -35,7 +33,6 @@ long count(
@Param("status") Status status,
@Param("type") Type type,
@Param("entityType") CollectionEntityType entityType,
@Param("entityCountry") Country entityCountry,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class ChangeSuggestionDto {
private Integer key;
private CollectionEntityType entityType;
private UUID entityKey;
private String entityName;
private Country entityCountry;
private Type type;
private Status status;
private String proposedBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
applied_by varchar CHECK (assert_min_length(applied_by, 3)),
discarded timestamptz,
discarded_by varchar CHECK (assert_min_length(discarded_by, 3)),
entity_country varchar(2) CHECK (length(entity_country) = 2),
entity_name varchar,
suggested_entity jsonb,
comments text[],
merge_target_key uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
</resultMap>

<sql id="SUGGESTION_WRITE_FIELDS">
entity_type, entity_key, type, status, proposed, proposed_by, proposer_email, entity_country, changes, comments,
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, entity_name
modified, modified_by
</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.entity_country, cs.suggested_entity, cs.comments,
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.entity_name
cs.modified, cs.modified_by
</sql>

<sql id="SUGGESTION_PARAMS_CREATE">
Expand All @@ -30,16 +30,14 @@
now(), <!-- proposed -->
#{proposedBy,jdbcType=VARCHAR},
#{proposerEmail,jdbcType=VARCHAR},
#{entityCountry,jdbcType=VARCHAR},
#{changes,jdbcType=OTHER,typeHandler=SuggestedChangesTypeHandler}::jsonb,
#{comments,jdbcType=OTHER,typeHandler=StringArrayTypeHandler},
#{suggestedEntity,jdbcType=OTHER}::jsonb,
#{mergeTargetKey,jdbcType=OTHER},
#{institutionConvertedCollection,jdbcType=OTHER},
#{nameNewInstitutionConvertedCollection,jdbcType=VARCHAR},
now(), <!-- modified -->
#{modifiedBy,jdbcType=VARCHAR},
#{entityName,jdbcType=VARCHAR}
#{modifiedBy,jdbcType=VARCHAR}
</sql>

<sql id="SUGGESTION_PARAMS_UPDATE">
Expand Down Expand Up @@ -83,9 +81,6 @@
<if test="entityType != null">
AND cs.entity_type = #{entityType,jdbcType=OTHER}
</if>
<if test="entityCountry != null">
AND cs.entity_country = #{entityCountry,jdbcType=VARCHAR}
</if>
<if test="proposerEmail != null">
AND cs.proposer_email = #{proposerEmail,jdbcType=OTHER}
</if>
Expand All @@ -112,9 +107,6 @@
<if test="entityType != null">
AND cs.entity_type = #{entityType,jdbcType=OTHER}
</if>
<if test="entityCountry != null">
AND cs.entity_country = #{entityCountry,jdbcType=VARCHAR}
</if>
<if test="proposerEmail != null">
AND cs.proposer_email = #{proposerEmail,jdbcType=OTHER}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,17 @@ public UUID applyChangeSuggestion(int suggestionKey) {
public PagingResponse<R> list(
@Nullable Status status,
@Nullable Type type,
@Nullable Country entityCountry,
@Nullable String proposerEmail,
@Nullable UUID entityKey,
@Nullable Pageable pageable) {
Pageable page = pageable == null ? new PagingRequest() : pageable;

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

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

List<R> changeSuggestions =
dtos.stream().map(this::dtoToChangeSuggestion).collect(Collectors.toList());
Expand Down Expand Up @@ -387,12 +385,6 @@ protected ChangeSuggestionDto createBaseChangeSuggestionDto(R changeSuggestion)
dto.setProposedBy(getUsername());
dto.setModifiedBy(getUsername());

if (changeSuggestion.getEntityKey() != null) {
T currentEntity = crudService.get(changeSuggestion.getEntityKey());
dto.setEntityCountry(getCountry(currentEntity));
dto.setEntityName(currentEntity.getName());
}

return dto;
}

Expand Down Expand Up @@ -423,8 +415,6 @@ protected R dtoToChangeSuggestion(ChangeSuggestionDto dto) {
suggestion.setKey(dto.getKey());
suggestion.setStatus(dto.getStatus());
suggestion.setType(dto.getType());
suggestion.setEntityCountry(dto.getEntityCountry());
suggestion.setEntityName(dto.getEntityName());
suggestion.setAppliedBy(dto.getAppliedBy());
suggestion.setApplied(dto.getApplied());
suggestion.setDiscarded(dto.getDiscarded());
Expand All @@ -437,6 +427,13 @@ protected R dtoToChangeSuggestion(ChangeSuggestionDto dto) {
suggestion.setProposedBy(dto.getProposedBy());
suggestion.setMergeTargetKey(dto.getMergeTargetKey());

if (dto.getEntityKey() != null) {
// we take the country and the name from the current entity
T currentEntity = crudService.get(dto.getEntityKey());
suggestion.setEntityCountry(getCountry(currentEntity));
suggestion.setEntityName(currentEntity.getName());
}

// we only show the proposer email for users with the right permissions (data protection)
if (hasRightsToSeeProposerEmail(dto)) {
suggestion.setProposerEmail(dto.getProposerEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class InstitutionChangeSuggestionService
LoggerFactory.getLogger(InstitutionChangeSuggestionService.class);

private final ChangeSuggestionMapper changeSuggestionMapper;
private final InstitutionService institutionService;
private final InstitutionMergeService institutionMergeService;

@Autowired
Expand All @@ -57,7 +56,6 @@ public InstitutionChangeSuggestionService(
eventManager,
grSciCollEditorAuthorizationService);
this.changeSuggestionMapper = changeSuggestionMapper;
this.institutionService = institutionService;
this.institutionMergeService = institutionMergeService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.gbif.api.model.registry.Identifiable;
import org.gbif.api.model.registry.MachineTaggable;
import org.gbif.api.model.registry.Taggable;
import org.gbif.api.vocabulary.Country;

import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -127,7 +126,6 @@ void deleteOccurrenceMapping(
PagingResponse<R> listChangeSuggestion(
@RequestParam(value = "status", required = false) Status status,
@RequestParam(value = "type", required = false) Type type,
@RequestParam(value = "entityCountry") Country entityCountry,
@RequestParam(value = "proposerEmail", required = false) String proposerEmail,
@RequestParam(value = "entityKey", required = false) UUID entityKey,
@SpringQueryMap Pageable page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.gbif.api.model.registry.MachineTaggable;
import org.gbif.api.model.registry.Taggable;
import org.gbif.api.service.collections.PrimaryCollectionEntityService;
import org.gbif.api.vocabulary.Country;
import org.gbif.registry.persistence.mapper.collections.params.DuplicatesSearchParams;
import org.gbif.registry.service.collections.duplicates.DuplicatesService;
import org.gbif.registry.service.collections.merge.MergeService;
Expand Down Expand Up @@ -188,12 +187,10 @@ public R getChangeSuggestion(@PathVariable("key") int key) {
public PagingResponse<R> listChangeSuggestion(
@RequestParam(value = "status", required = false) Status status,
@RequestParam(value = "type", required = false) Type type,
Country entityCountry,
@RequestParam(value = "proposerEmail", required = false) String proposerEmail,
@RequestParam(value = "entityKey", required = false) UUID entityKey,
Pageable page) {
return changeSuggestionService.list(
status, type, entityCountry, proposerEmail, entityKey, page);
return changeSuggestionService.list(status, type, proposerEmail, entityKey, page);
}

@PutMapping(value = "changeSuggestion/{key}/discard")
Expand Down

0 comments on commit c008bdb

Please sign in to comment.