Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed May 20, 2021
1 parent d3e63ab commit 9041605
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ChangeSuggestionMapper {
List<ChangeSuggestionDto> list(
@Param("status") Status status,
@Param("type") Type type,
@Param("collectionEntityType") CollectionEntityType collectionEntityType,
@Param("entityType") CollectionEntityType entityType,
@Param("country") Country country,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey,
Expand All @@ -34,7 +34,7 @@ List<ChangeSuggestionDto> list(
long count(
@Param("status") Status status,
@Param("type") Type type,
@Param("collectionEntityType") CollectionEntityType collectionEntityType,
@Param("entityType") CollectionEntityType entityType,
@Param("country") Country country,
@Param("proposerEmail") String proposerEmail,
@Param("entityKey") UUID entityKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ChangeSuggestionDto {

private Integer key;
private CollectionEntityType collectionEntityType;
private CollectionEntityType entityType;
private UUID entityKey;
private Type type;
private Status status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
type enum_change_suggestion_type NOT NULL,
status enum_change_suggestion_status NOT NULL,
proposed timestamptz NOT NULL DEFAULT now(),
proposed_by varchar NOT NULL CHECK (assert_min_length(proposed_by, 3)),
proposed_by varchar CHECK (assert_min_length(proposed_by, 3)),
proposer_email varchar NOT NULL CHECK (assert_min_length(proposer_email, 3)),
applied timestamptz,
applied_by varchar CHECK (assert_min_length(applied_by, 3)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</sql>

<sql id="SUGGESTION_PARAMS_CREATE">
#{collectionEntityType,jdbcType=OTHER},
#{entityType,jdbcType=OTHER},
#{entityKey,jdbcType=OTHER},
#{type,jdbcType=OTHER},
#{status,jdbcType=OTHER},
Expand Down Expand Up @@ -78,8 +78,8 @@
<if test="type != null">
AND cs.type = #{type,jdbcType=OTHER}
</if>
<if test="collectionEntityType != null">
AND cs.entity_type = #{collectionEntityType,jdbcType=OTHER}
<if test="entityType != null">
AND cs.entity_type = #{entityType,jdbcType=OTHER}
</if>
<if test="country != null">
AND cs.country = #{country,jdbcType=VARCHAR}
Expand Down Expand Up @@ -107,8 +107,8 @@
<if test="type != null">
AND cs.type = #{type,jdbcType=OTHER}
</if>
<if test="collectionEntityType != null">
AND cs.entity_type = #{collectionEntityType,jdbcType=OTHER}
<if test="entityType != null">
AND cs.entity_type = #{entityType,jdbcType=OTHER}
</if>
<if test="country != null">
AND cs.country = #{country,jdbcType=VARCHAR}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.gbif.registry.service.collections.suggestions;

import org.gbif.api.model.collections.Address;
import org.gbif.api.model.collections.Collection;
import org.gbif.api.model.collections.*;
import org.gbif.api.model.collections.suggestions.*;
import org.gbif.api.model.collections.CollectionEntity;
import org.gbif.api.model.collections.CollectionEntityType;
import org.gbif.api.model.collections.Contactable;
import org.gbif.api.model.collections.Institution;
import org.gbif.api.model.collections.OccurrenceMappeable;
import org.gbif.api.model.collections.suggestions.Change;
import org.gbif.api.model.collections.suggestions.ChangeSuggestion;
import org.gbif.api.model.collections.suggestions.ChangeSuggestionService;
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.model.common.paging.PagingRequest;
import org.gbif.api.model.common.paging.PagingResponse;
Expand All @@ -25,22 +34,29 @@

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import static com.google.common.base.Preconditions.checkArgument;
import static org.gbif.registry.security.UserRoles.GRSCICOLL_ADMIN_ROLE;
import static org.gbif.registry.security.UserRoles.GRSCICOLL_EDITOR_ROLE;
import static com.google.common.base.Preconditions.checkArgument;

public abstract class BaseChangeSuggestionService<
T extends
Expand Down Expand Up @@ -131,8 +147,7 @@ public int createChangeSuggestion(R changeSuggestion) {
// send email
try {
BaseEmailModel emailModel =
emailManager.generateNewChangeSuggestionEmailModel(
dto.getKey(), dto.getCollectionEntityType());
emailManager.generateNewChangeSuggestionEmailModel(dto.getKey(), dto.getEntityType());
emailSender.send(emailModel);
} catch (Exception e) {
LOG.error("Couldn't send email for new change suggestion", e);
Expand Down Expand Up @@ -243,7 +258,7 @@ public void discardChangeSuggestion(int key) {
try {
BaseEmailModel emailModel =
emailManager.generateDiscardedChangeSuggestionEmailModel(
dto.getKey(), dto.getCollectionEntityType());
dto.getKey(), dto.getEntityType());
emailSender.send(emailModel);
} catch (Exception e) {
LOG.error("Couldn't send email for discarded change suggestion", e);
Expand Down Expand Up @@ -285,8 +300,7 @@ public UUID applyChangeSuggestion(int suggestionKey) {
// send email
try {
BaseEmailModel emailModel =
emailManager.generateAppliedChangeSuggestionEmailModel(
dto.getKey(), dto.getCollectionEntityType());
emailManager.generateAppliedChangeSuggestionEmailModel(dto.getKey(), dto.getEntityType());
emailSender.send(emailModel);
} catch (Exception e) {
LOG.error("Couldn't send email for applied change suggestion", e);
Expand All @@ -307,22 +321,11 @@ public PagingResponse<R> list(

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

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

List<R> changeSuggestions =
dtos.stream().map(this::dtoToChangeSuggestion).collect(Collectors.toList());
Expand Down Expand Up @@ -384,7 +387,7 @@ protected ChangeSuggestionDto createBaseChangeSuggestionDto(R changeSuggestion)
dto.setStatus(Status.PENDING);
dto.setType(changeSuggestion.getType());
dto.setComments(changeSuggestion.getComments());
dto.setCollectionEntityType(collectionEntityType);
dto.setEntityType(collectionEntityType);
dto.setProposerEmail(changeSuggestion.getProposerEmail());
dto.setProposedBy(getUsername());
dto.setModifiedBy(getUsername());
Expand Down

0 comments on commit 9041605

Please sign in to comment.