diff --git a/src/main/java/com/nonononoki/alovoa/config/EventListenerConfig.java b/src/main/java/com/nonononoki/alovoa/config/EventListenerConfig.java index 1fb57dc9..14dad375 100644 --- a/src/main/java/com/nonononoki/alovoa/config/EventListenerConfig.java +++ b/src/main/java/com/nonononoki/alovoa/config/EventListenerConfig.java @@ -84,17 +84,41 @@ public void handleContextRefresh(ApplicationStartedEvent event) { private void setDefaultUserMiscInfo() { if(userMiscInfoRepo.count() == 0) { - UserMiscInfo drugsTobaccoInfo = new UserMiscInfo(); - drugsTobaccoInfo.setValue(UserMiscInfo.DRUGS_TOBACCO); - - UserMiscInfo drugsAlcoholInfo = new UserMiscInfo(); - drugsAlcoholInfo.setValue(UserMiscInfo.DRUGS_ALCOHOL); - - UserMiscInfo drugsCannabisInfo = new UserMiscInfo(); - drugsCannabisInfo.setValue(UserMiscInfo.DRUGS_CANNABIS); - - UserMiscInfo drugsOtherInfo = new UserMiscInfo(); - drugsOtherInfo.setValue(UserMiscInfo.DRUGS_OTHER); + UserMiscInfo drugsTobaccoInfoYes = new UserMiscInfo(); + drugsTobaccoInfoYes.setValue(UserMiscInfo.DRUGS_TOBACCO_YES); + + UserMiscInfo drugsTobaccoInfoNo = new UserMiscInfo(); + drugsTobaccoInfoNo.setValue(UserMiscInfo.DRUGS_TOBACCO_NO); + + UserMiscInfo drugsTobaccoInfoSometimes = new UserMiscInfo(); + drugsTobaccoInfoSometimes.setValue(UserMiscInfo.DRUGS_TOBACCO_SOMETIMES); + + UserMiscInfo drugsAlcoholInfoYes = new UserMiscInfo(); + drugsAlcoholInfoYes.setValue(UserMiscInfo.DRUGS_ALCOHOL_YES); + + UserMiscInfo drugsAlcoholInfoNo = new UserMiscInfo(); + drugsAlcoholInfoNo.setValue(UserMiscInfo.DRUGS_ALCOHOL_NO); + + UserMiscInfo drugsAlcoholInfoSometimes = new UserMiscInfo(); + drugsAlcoholInfoSometimes.setValue(UserMiscInfo.DRUGS_ALCOHOL_SOMETIMES); + + UserMiscInfo drugsCannabisInfoYes = new UserMiscInfo(); + drugsCannabisInfoYes.setValue(UserMiscInfo.DRUGS_CANNABIS_YES); + + UserMiscInfo drugsCannabisInfoNo = new UserMiscInfo(); + drugsCannabisInfoNo.setValue(UserMiscInfo.DRUGS_CANNABIS_NO); + + UserMiscInfo drugsCannabisInfoSometimes = new UserMiscInfo(); + drugsCannabisInfoSometimes.setValue(UserMiscInfo.DRUGS_CANNABIS_SOMETIMES); + + UserMiscInfo drugsOtherInfoYes = new UserMiscInfo(); + drugsOtherInfoYes.setValue(UserMiscInfo.DRUGS_OTHER_YES); + + UserMiscInfo drugsOtherInfoNo = new UserMiscInfo(); + drugsOtherInfoNo.setValue(UserMiscInfo.DRUGS_OTHER_NO); + + UserMiscInfo drugsOtherInfoSometimes = new UserMiscInfo(); + drugsOtherInfoSometimes.setValue(UserMiscInfo.DRUGS_OTHER_SOMETIMES); UserMiscInfo relationshipSingleInfo = new UserMiscInfo(); @@ -117,10 +141,18 @@ private void setDefaultUserMiscInfo() { kidsYesInfo.setValue(UserMiscInfo.KIDS_YES); userMiscInfoRepo.saveAllAndFlush(Arrays.asList( - drugsTobaccoInfo, - drugsAlcoholInfo, - drugsCannabisInfo, - drugsOtherInfo, + drugsTobaccoInfoYes, + drugsTobaccoInfoNo, + drugsTobaccoInfoSometimes, + drugsAlcoholInfoYes, + drugsAlcoholInfoNo, + drugsAlcoholInfoSometimes, + drugsCannabisInfoYes, + drugsCannabisInfoNo, + drugsCannabisInfoSometimes, + drugsOtherInfoYes, + drugsOtherInfoNo, + drugsOtherInfoSometimes, relationshipSingleInfo, relationshipTakenInfo, relationshipOpenInfo, diff --git a/src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java b/src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java index eeaf3737..5f586c31 100644 --- a/src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java +++ b/src/main/java/com/nonononoki/alovoa/entity/user/UserMiscInfo.java @@ -22,14 +22,14 @@ public class UserMiscInfo { @Transient - public static final long DRUGS_TOBACCO = 1; + public static final long DRUGS_TOBACCO_YES = 1; @Transient - public static final long DRUGS_ALCOHOL = 2; + public static final long DRUGS_ALCOHOL_YES = 2; @Transient - public static final long DRUGS_CANNABIS = 3; + public static final long DRUGS_CANNABIS_YES = 3; @Transient - public static final long DRUGS_OTHER = 4; - + public static final long DRUGS_OTHER_YES = 4; + @Transient public static final long RELATIONSHIP_SINGLE = 11; @Transient @@ -44,6 +44,24 @@ public class UserMiscInfo { @Transient public static final long KIDS_YES = 22; + @Transient + public static final long DRUGS_TOBACCO_NO = 31; + @Transient + public static final long DRUGS_ALCOHOL_NO = 32; + @Transient + public static final long DRUGS_CANNABIS_NO = 33; + @Transient + public static final long DRUGS_OTHER_NO = 34; + + @Transient + public static final long DRUGS_TOBACCO_SOMETIMES = 41; + @Transient + public static final long DRUGS_ALCOHOL_SOMETIMES = 42; + @Transient + public static final long DRUGS_CANNABIS_SOMETIMES = 43; + @Transient + public static final long DRUGS_OTHER_SOMETIMES = 44; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/nonononoki/alovoa/service/UserService.java b/src/main/java/com/nonononoki/alovoa/service/UserService.java index ebbcc4d4..0b1129b3 100644 --- a/src/main/java/com/nonononoki/alovoa/service/UserService.java +++ b/src/main/java/com/nonononoki/alovoa/service/UserService.java @@ -42,6 +42,7 @@ import java.security.*; import java.util.List; import java.util.*; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -55,6 +56,12 @@ public class UserService { private static final String MIME_WAV = "wav"; private static final String MIME_MPEG = "mpeg"; private static final String MIME_MP3 = "mp3"; + + private final Set drugsAlcohol = new HashSet<>(Set.of(UserMiscInfo.DRUGS_ALCOHOL_YES, UserMiscInfo.DRUGS_ALCOHOL_SOMETIMES, UserMiscInfo.DRUGS_ALCOHOL_NO)); + private final Set drugsTobacco = new HashSet<>(Set.of(UserMiscInfo.DRUGS_TOBACCO_YES, UserMiscInfo.DRUGS_TOBACCO_SOMETIMES, UserMiscInfo.DRUGS_TOBACCO_NO)); + private final Set drugsCannabis = new HashSet<>(Set.of(UserMiscInfo.DRUGS_CANNABIS_YES, UserMiscInfo.DRUGS_CANNABIS_SOMETIMES, UserMiscInfo.DRUGS_CANNABIS_NO)); + private final Set drugsOther = new HashSet<>(Set.of(UserMiscInfo.DRUGS_OTHER_YES, UserMiscInfo.DRUGS_OTHER_SOMETIMES, UserMiscInfo.DRUGS_OTHER_NO)); + @Autowired private AuthService authService; @Autowired @@ -513,6 +520,14 @@ public Set updateUserMiscInfo(long infoValue, boolean activated) t } else if (infoValue >= UserMiscInfo.RELATIONSHIP_SINGLE && infoValue <= UserMiscInfo.RELATIONSHIP_OTHER) { list.removeIf(o -> o.getValue() != infoValue && o.getValue() >= UserMiscInfo.RELATIONSHIP_SINGLE && o.getValue() <= UserMiscInfo.RELATIONSHIP_OTHER); + } else if (drugsAlcohol.contains(infoValue)) { + list.removeIf(conditionToRemoveIfExistent(drugsAlcohol, infoValue)); + } else if (drugsTobacco.contains(infoValue)) { + list.removeIf(conditionToRemoveIfExistent(drugsAlcohol, infoValue)); + } else if (drugsCannabis.contains(infoValue)) { + list.removeIf(conditionToRemoveIfExistent(drugsCannabis, infoValue)); + } else if (drugsOther.contains(infoValue)) { + list.removeIf(conditionToRemoveIfExistent(drugsOther, infoValue)); } } else { @@ -523,6 +538,10 @@ public Set updateUserMiscInfo(long infoValue, boolean activated) t return list; } + private Predicate conditionToRemoveIfExistent(final Set options, final long infoValue) { + return c -> options.contains(c.getValue()) && c.getValue() != infoValue; + } + public void addInterest(String value) throws AlovoaException { User user = authService.getCurrentUser(true);