Skip to content

Commit 8bd2ab3

Browse files
authored
Merge pull request #25 from TAMULib/sprint3-B03243-schedulability-merge
schedulibility merge
2 parents 61cb719 + 139dd5a commit 8bd2ab3

32 files changed

Lines changed: 647 additions & 294 deletions

src/main/java/edu/tamu/app/controller/NotificationController.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,63 +32,63 @@ public class NotificationController {
3232

3333
@Autowired
3434
private NotificationRepo notificationRepo;
35-
35+
3636
@ApiMapping("/all")
37-
@Auth(role="ROLE_STAFF")
37+
@Auth(role = "ROLE_STAFF")
3838
public ApiResponse getAllNotifications() {
3939
return new ApiResponse(SUCCESS, notificationRepo.findAll());
4040
}
41-
41+
4242
@ApiMapping("/{id}")
43-
@Auth(role="ROLE_STAFF")
43+
@Auth(role = "ROLE_STAFF")
4444
public ApiResponse getNotification(@ApiVariable Long id) {
4545
return new ApiResponse(SUCCESS, notificationRepo.findOne(id));
4646
}
47-
47+
4848
@ApiMapping("/create")
49-
@Auth(role="ROLE_WEB_MANAGER")
49+
@Auth(role = "ROLE_WEB_MANAGER")
5050
@ApiValidation(business = { @ApiValidation.Business(value = CREATE), @ApiValidation.Business(value = EXISTS) })
5151
public ApiResponse create(@ApiValidatedModel Notification notification) {
52-
notification = notificationRepo.create(notification.getName(), notification.getBody(), notification.getIsActive(), notification.getLocations());
52+
notification = notificationRepo.create(notification);
5353
return new ApiResponse(SUCCESS, notification);
5454
}
55-
55+
5656
@ApiMapping("/update")
57-
@Auth(role="ROLE_WEB_MANAGER")
57+
@Auth(role = "ROLE_WEB_MANAGER")
5858
@ApiValidation(business = { @ApiValidation.Business(value = UPDATE), @ApiValidation.Business(value = NONEXISTS) })
5959
public ApiResponse update(@ApiValidatedModel Notification notification) {
6060
notification = notificationRepo.update(notification);
6161
return new ApiResponse(SUCCESS, notification);
6262
}
63-
63+
6464
@ApiMapping("/remove")
65-
@Auth(role="ROLE_WEB_MANAGER")
65+
@Auth(role = "ROLE_WEB_MANAGER")
6666
@ApiValidation(business = { @ApiValidation.Business(value = DELETE), @ApiValidation.Business(value = NONEXISTS) })
6767
public ApiResponse remove(@ApiValidatedModel Notification notification) {
6868
notificationRepo.delete(notification);
6969
return new ApiResponse(SUCCESS);
7070
}
71-
71+
7272
@SkipAop
7373
@RequestMapping("/notification/active")
7474
public String getActiveNotifications(@RequestParam(value = "location", defaultValue = "ALL") String locationString) {
7575
String notificationString = "";
7676
List<Notification> notificationList;
7777
if (locationString.equals("ALL")) {
78-
notificationList = notificationRepo.findByIsActive(true);
78+
notificationList = notificationRepo.findByActive(true);
7979
} else {
8080
try {
8181
NotificationLocation location = NotificationLocation.valueOf(locationString);
82-
notificationList = notificationRepo.findByIsActiveAndLocations(true, location);
82+
notificationList = notificationRepo.findByActiveAndLocations(true, location);
8383
} catch (IllegalArgumentException e) {
8484
notificationList = new ArrayList<Notification>();
8585
}
8686
}
8787
for (Notification notification : notificationList) {
8888
notificationString += "<p>" + notification.getBody() + "</p>";
8989
}
90-
90+
9191
return notificationString;
9292
}
93-
93+
9494
}

src/main/java/edu/tamu/app/controller/ServiceController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ApiResponse getService(@ApiVariable Long id) {
5050
@Auth(role = "ROLE_SERVICE_MANAGER")
5151
@ApiValidation(business = { @ApiValidation.Business(value = CREATE), @ApiValidation.Business(value = EXISTS) })
5252
public ApiResponse createService(@ApiValidatedModel Service service, @ApiCredentials Credentials credentials) {
53-
service = serviceRepo.create(service.getName(), service.getStatus(), service.getIsAuto(), service.getIsPublic(), service.getOnShortList(), service.getServiceUrl(), service.getDescription());
53+
service = serviceRepo.create(service);
5454
return new ApiResponse(SUCCESS, service);
5555
}
5656

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package edu.tamu.app.model;
2+
3+
import static javax.persistence.FetchType.EAGER;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import javax.persistence.CascadeType;
9+
import javax.persistence.Column;
10+
import javax.persistence.Entity;
11+
import javax.persistence.Inheritance;
12+
import javax.persistence.OneToMany;
13+
14+
import org.hibernate.annotations.Fetch;
15+
16+
import edu.tamu.framework.model.BaseEntity;
17+
18+
import static javax.persistence.InheritanceType.JOINED;
19+
import static org.hibernate.annotations.FetchMode.SELECT;
20+
21+
@Entity
22+
@Inheritance(strategy = JOINED)
23+
public abstract class AbstractScheduler extends BaseEntity implements Scheduler {
24+
25+
@OneToMany(fetch = EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true)
26+
@Fetch(value = SELECT)
27+
private List<Schedule> schedules;
28+
29+
@Column(nullable = false)
30+
private Boolean withinSchedule;
31+
32+
public AbstractScheduler() {
33+
super();
34+
setSchedules(new ArrayList<Schedule>());
35+
setWithinSchedule(false);
36+
}
37+
38+
public List<Schedule> getSchedules() {
39+
return schedules;
40+
}
41+
42+
public void setSchedules(List<Schedule> schedules) {
43+
this.schedules = schedules;
44+
}
45+
46+
public void addSchedule(Schedule schedule) {
47+
this.schedules.add(schedule);
48+
}
49+
50+
public void removeSchedule(Schedule schedule) {
51+
this.schedules.remove(schedule);
52+
}
53+
54+
public Boolean getWithinSchedule() {
55+
return withinSchedule;
56+
}
57+
58+
public void setWithinSchedule(Boolean withinSchedule) {
59+
this.withinSchedule = withinSchedule;
60+
}
61+
62+
public abstract String getType();
63+
64+
}

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* AppUser.java
3-
*
4-
* Version:
5-
* $Id$
6-
*
7-
* Revisions:
8-
* $Log$
9-
*/
101
package edu.tamu.app.model;
112

123
import java.util.ArrayList;
@@ -18,6 +9,8 @@
189
import javax.persistence.FetchType;
1910
import javax.persistence.OneToMany;
2011

12+
import org.hibernate.annotations.Fetch;
13+
import org.hibernate.annotations.FetchMode;
2114
import org.springframework.security.core.GrantedAuthority;
2215
import org.springframework.security.core.authority.SimpleGrantedAuthority;
2316

@@ -35,9 +28,9 @@
3528
*/
3629
@Entity
3730
public class AppUser extends AbstractCoreUser {
38-
31+
3932
private static final long serialVersionUID = -4974106399870286015L;
40-
33+
4134
@Column(name = "role")
4235
private AppRole role;
4336

@@ -57,8 +50,9 @@ public class AppUser extends AbstractCoreUser {
5750

5851
@Column(nullable = true)
5952
private String lastName;
60-
53+
6154
@OneToMany(fetch = FetchType.EAGER)
55+
@Fetch(FetchMode.SELECT)
6256
private List<Note> notes;
6357

6458
/**
@@ -97,7 +91,7 @@ public AppUser(String email, String firstName, String lastName, String role) {
9791
setLastName(lastName);
9892
setRole(AppRole.valueOf(role));
9993
}
100-
94+
10195
/**
10296
* @return the role
10397
*/
@@ -107,7 +101,8 @@ public IRole getRole() {
107101
}
108102

109103
/**
110-
* @param role the role to set
104+
* @param role
105+
* the role to set
111106
*/
112107
@JsonSerialize(as = AppRole.class)
113108
public void setRole(IRole role) {
@@ -193,9 +188,7 @@ public String getLastName() {
193188
public void setLastName(String lastName) {
194189
this.lastName = lastName;
195190
}
196-
197-
198-
191+
199192
public List<Note> getNotes() {
200193
return notes;
201194
}
@@ -209,31 +202,31 @@ public void setNotes(List<Note> notes) {
209202
public boolean isAccountNonExpired() {
210203
return false;
211204
}
212-
205+
213206
@Override
214207
@JsonIgnore
215208
public boolean isAccountNonLocked() {
216209
return false;
217210
}
218-
211+
219212
@Override
220213
@JsonIgnore
221214
public boolean isCredentialsNonExpired() {
222215
return false;
223216
}
224-
217+
225218
@Override
226219
@JsonIgnore
227220
public String getUsername() {
228221
return getUin();
229222
}
230-
223+
231224
@Override
232225
@JsonIgnore
233226
public boolean isEnabled() {
234227
return true;
235228
}
236-
229+
237230
@Override
238231
@JsonIgnore
239232
public Collection<? extends GrantedAuthority> getAuthorities() {

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

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static javax.persistence.FetchType.EAGER;
66

77
import java.util.Calendar;
8+
import java.util.Map;
89

910
import javax.persistence.Column;
1011
import javax.persistence.Entity;
@@ -18,10 +19,9 @@
1819

1920
import edu.tamu.app.enums.NoteType;
2021
import edu.tamu.app.model.validation.NoteValidator;
21-
import edu.tamu.framework.model.BaseEntity;
2222

2323
@Entity
24-
public class Note extends BaseEntity {
24+
public class Note extends AbstractScheduler {
2525

2626
@Column(nullable = false)
2727
private String title;
@@ -33,27 +33,26 @@ public class Note extends BaseEntity {
3333
private String body;
3434

3535
@Column(nullable = false)
36-
private boolean pinned;
36+
private Boolean pinned;
3737

38-
@Temporal(TemporalType.DATE)
39-
private Calendar scheduledPostingStart;
40-
41-
@Temporal(TemporalType.DATE)
42-
private Calendar scheduledPostingEnd;
38+
@Column(nullable = false)
39+
private Boolean active;
4340

4441
@Temporal(TemporalType.TIMESTAMP)
4542
@UpdateTimestamp
4643
private Calendar lastModified;
4744

48-
@ManyToOne(fetch = EAGER, cascade = MERGE)
45+
@ManyToOne(fetch = EAGER, cascade = MERGE, optional = false)
4946
private Service service;
5047

5148
@ManyToOne(cascade = REFRESH, optional = false)
5249
private AppUser author;
5350

5451
public Note() {
55-
setPinned(false);
52+
super();
5653
setModelValidator(new NoteValidator());
54+
setPinned(false);
55+
setActive(false);
5756
setService(new Service());
5857
}
5958

@@ -106,28 +105,20 @@ public void setBody(String body) {
106105
this.body = body;
107106
}
108107

109-
public boolean isPinned() {
108+
public Boolean getPinned() {
110109
return pinned;
111110
}
112111

113-
public void setPinned(boolean pinned) {
112+
public void setPinned(Boolean pinned) {
114113
this.pinned = pinned;
115114
}
116115

117-
public Calendar getScheduledPostingStart() {
118-
return scheduledPostingStart;
119-
}
120-
121-
public void setScheduledPostingStart(Calendar scheduledPostingStart) {
122-
this.scheduledPostingStart = scheduledPostingStart;
123-
}
124-
125-
public Calendar getScheduledPostingEnd() {
126-
return scheduledPostingEnd;
116+
public Boolean getActive() {
117+
return active;
127118
}
128119

129-
public void setScheduledPostingEnd(Calendar scheduledPostingEnd) {
130-
this.scheduledPostingEnd = scheduledPostingEnd;
120+
public void setActive(Boolean active) {
121+
this.active = active;
131122
}
132123

133124
public Calendar getLastModified() {
@@ -145,4 +136,20 @@ public AppUser getAuthor() {
145136
public void setAuthor(AppUser author) {
146137
this.author = author;
147138
}
139+
140+
@Override
141+
public String getType() {
142+
return "note";
143+
}
144+
145+
@Override
146+
public void scheduleStart(Map<String, String> scheduleData) {
147+
setActive(true);
148+
}
149+
150+
@Override
151+
public void scheduleEnd(Map<String, String> scheduleData) {
152+
setActive(false);
153+
}
154+
148155
}

0 commit comments

Comments
 (0)