Skip to content

Commit 6782116

Browse files
authored
Merge branch 'master' into sprint6-staging-test-improvements
2 parents 3155a31 + 49cad2a commit 6782116

5 files changed

Lines changed: 59 additions & 16 deletions

File tree

src/main/java/edu/tamu/app/model/FeatureProposal.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121

2222
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
2323
import com.fasterxml.jackson.annotation.JsonIdentityReference;
24-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2524
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
2625

2726
import edu.tamu.app.enums.FeatureProposalState;
2827
import edu.tamu.app.model.validation.FeatureProposalValidator;
2928

3029
@Entity
31-
@JsonIgnoreProperties(value = { "voters" }, allowGetters = true)
3230
public class FeatureProposal extends AbstractIdea {
3331

3432
@OneToMany(fetch = EAGER, cascade = { CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE }, mappedBy = "featureProposal")
@@ -51,7 +49,6 @@ public class FeatureProposal extends AbstractIdea {
5149

5250
public FeatureProposal() {
5351
super();
54-
this.modelValidator = new FeatureProposalValidator();
5552
setup();
5653
}
5754

@@ -77,6 +74,7 @@ public FeatureProposal(Idea idea) {
7774
}
7875

7976
private void setup() {
77+
this.modelValidator = new FeatureProposalValidator();
8078
this.ideas = new ArrayList<Idea>();
8179
this.voters = new ArrayList<User>();
8280
this.state = FeatureProposalState.IN_PROGRESS;

src/main/java/edu/tamu/app/model/repo/impl/FeatureProposalRepoImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.Optional;
66

7+
import org.springframework.beans.BeanUtils;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.messaging.simp.SimpMessagingTemplate;
910

@@ -65,16 +66,19 @@ public FeatureProposal create(Idea idea) {
6566
}
6667

6768
@Override
68-
public FeatureProposal update(FeatureProposal featureProposal) {
69-
for (Idea idea : featureProposal.getIdeas()) {
69+
public FeatureProposal update(FeatureProposal featureProposalToUpdate) {
70+
FeatureProposal persistedFeatureProposal = featureProposalRepo.findOne(featureProposalToUpdate.getId());
71+
// NOTE: ignore voters on update to avoid concurrency issue of save after votes occur
72+
BeanUtils.copyProperties(featureProposalToUpdate, persistedFeatureProposal, "voters");
73+
for (Idea idea : persistedFeatureProposal.getIdeas()) {
7074
idea.setState(IdeaState.ELEVATED);
71-
idea.setFeatureProposal(featureProposal);
75+
idea.setFeatureProposal(persistedFeatureProposal);
7276
idea = ideaRepo.save(idea);
7377
simpMessagingTemplate.convertAndSend("/channel/ideas/update", new ApiResponse(SUCCESS, idea));
7478
}
75-
featureProposal = featureProposalRepo.save(featureProposal);
76-
simpMessagingTemplate.convertAndSend("/channel/feature-proposals/update", new ApiResponse(SUCCESS, featureProposal));
77-
return featureProposal;
79+
persistedFeatureProposal = featureProposalRepo.save(persistedFeatureProposal);
80+
simpMessagingTemplate.convertAndSend("/channel/feature-proposals/update", new ApiResponse(SUCCESS, persistedFeatureProposal));
81+
return persistedFeatureProposal;
7882
}
7983

8084
@Override

src/main/resources/application.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spring:
2020
platform: h2
2121
driverClassName: org.h2.Driver
2222
url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
23+
# platform: postgres
24+
# driverClassName: org.postgresql.Driver
25+
# url: jdbc:postgresql://localhost:5432/lsss
2326

2427
username: spring
2528
password: spring
@@ -36,6 +39,7 @@ spring:
3639

3740
jpa:
3841
database-platform: org.hibernate.dialect.H2Dialect
42+
# database-platform: org.hibernate.dialect.PostgreSQLDialect
3943

4044
show-sql: false
4145
hibernate.ddl-auto: create-drop
@@ -50,12 +54,12 @@ app:
5054
# Framework app properties #
5155
############################
5256
# edu.tamu.weaver.auth.service.UserCredentialsService
53-
authority.admins: 402001311,613001223,102001721,222004429,709005486,523008230,724001395,123456789
57+
authority.admins: 402001311,613001223,102001721,222004429,709005486,523008230,724001395,123456789,512004707,427008012
5458
security:
5559
# edu.tamu.weaver.auth.service.CryptoService
5660
secret: verysecretsecret
5761
# edu.tamu.weaver.filter.CorsFilter
58-
allow-access: http://localhost,http://localhost:8080,http://machuff.tamu.edu,http://janus.evans.tamu.edu,http://savell.evans.tamu.edu,http://jmicah.tamu.edu
62+
allow-access: http://localhost,http://localhost:8080,http://machuff.tamu.edu,http://janus.evans.tamu.edu,http://savell.evans.tamu.edu,http://jmicah.tamu.edu,http://laddusaw.tamu.edu,http://muninn.evans.tamu.edu:8080
5963
# edu.tamu.weaver.email.config.WeaverEmailConfig
6064
email:
6165
host: relay.tamu.edu
@@ -94,4 +98,4 @@ shib:
9498
uin: tamuuin
9599
lastName: tdl-sn
96100
firstName: tdl-givenname
97-
email: tdl-mail
101+
email: tdl-mail
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package edu.tamu.app.model;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.Calendar;
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
13+
@RunWith(SpringRunner.class)
14+
public class ScheduleTest {
15+
16+
@Test
17+
public void testNewSchedule() {
18+
Calendar calendar = Calendar.getInstance();
19+
Long now = calendar.getTimeInMillis();
20+
21+
Map<String, String> scheduleData = new HashMap<String, String>();
22+
scheduleData.put("test", "This is only a test!");
23+
24+
User author = new User("123456789");
25+
Note note = new Note("Test", author);
26+
27+
Schedule schedule = new Schedule();
28+
29+
schedule.setScheduledPostingStart(now);
30+
schedule.setScheduledPostingEnd(now + 36000);
31+
schedule.setScheduleData(scheduleData);
32+
schedule.setScheduler(note);
33+
34+
assertEquals("Schedule posting start was not as expected!", now, schedule.getScheduledPostingStart());
35+
assertEquals("Schedule posting end was not as expected!", now + 36000, schedule.getScheduledPostingEnd(), 0);
36+
assertEquals("Schedule date was not as expected!", scheduleData, schedule.getScheduleData());
37+
assertEquals("Schedule scheduler was not as expected!", note, schedule.getScheduler());
38+
39+
}
40+
41+
}

src/test/resources/application.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ spring:
2020
platform: h2
2121
driverClassName: org.h2.Driver
2222
url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
23-
# platform: postgres
24-
# driverClassName: org.postgresql.Driver
25-
# url: jdbc:postgresql://localhost:5432/lsss
2623

2724
username: spring
2825
password: spring
@@ -39,7 +36,6 @@ spring:
3936

4037
jpa:
4138
database-platform: org.hibernate.dialect.H2Dialect
42-
# database-platform: org.hibernate.dialect.PostgreSQLDialect
4339

4440
show-sql: false
4541
hibernate.ddl-auto: create-drop

0 commit comments

Comments
 (0)