Skip to content

Commit 5aade28

Browse files
committed
WIP attempting to fix broadcasting bugs
1 parent 463fde1 commit 5aade28

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
import org.springframework.data.domain.Sort;
1414
import org.springframework.data.domain.Sort.Direction;
1515
import org.springframework.messaging.simp.SimpMessagingTemplate;
16+
import org.springframework.transaction.annotation.Transactional;
1617
import org.springframework.web.bind.annotation.RestController;
1718

1819
import com.fasterxml.jackson.databind.JsonNode;
1920
import com.fasterxml.jackson.databind.node.ArrayNode;
2021

2122
import edu.tamu.app.model.Note;
2223
import edu.tamu.app.model.repo.NoteRepo;
24+
import edu.tamu.app.model.repo.ServiceRepo;
2325
import edu.tamu.app.model.request.FilteredPageRequest;
2426
import edu.tamu.framework.aspect.annotation.ApiCredentials;
2527
import edu.tamu.framework.aspect.annotation.ApiData;
@@ -37,6 +39,9 @@ public class NoteController {
3739

3840
@Autowired
3941
private NoteRepo noteRepo;
42+
43+
@Autowired
44+
private ServiceRepo serviceRepo;
4045

4146
@Autowired
4247
private SimpMessagingTemplate simpMessagingTemplate;
@@ -58,7 +63,8 @@ public ApiResponse getNote(@ApiVariable Long id) {
5863
@ApiValidation(business = { @ApiValidation.Business(value = CREATE), @ApiValidation.Business(value = EXISTS) })
5964
public ApiResponse create(@ApiValidatedModel Note note, @ApiCredentials Credentials credentials) {
6065
note = noteRepo.create(note, credentials);
61-
simpMessagingTemplate.convertAndSend("/channel/note", new ApiResponse(SUCCESS, noteRepo.findAll()));
66+
System.out.println("Note value: " + note);
67+
// simpMessagingTemplate.convertAndSend("/channel/service/" + note.getService().getId(), new ApiResponse(SUCCESS, serviceRepo.getOne(note.getService().getId())));
6268
return new ApiResponse(SUCCESS, note);
6369
}
6470

@@ -70,12 +76,13 @@ public ApiResponse update(@ApiValidatedModel Note note) {
7076
return new ApiResponse(SUCCESS, note);
7177
}
7278

79+
@Transactional
7380
@ApiMapping("/remove")
7481
@Auth(role = "ROLE_SERVICE_MANAGER")
7582
public ApiResponse remove(@ApiValidatedModel Note note) {
7683
noteRepo.delete(note);
7784
simpMessagingTemplate.convertAndSend("/channel/note", new ApiResponse(SUCCESS, noteRepo.findAll()));
78-
return new ApiResponse(SUCCESS);
85+
return new ApiResponse(SUCCESS, serviceRepo.getOne(note.getService().getId()));
7986
}
8087

8188
@ApiMapping("/page")

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package edu.tamu.app.model;
22

3+
import static javax.persistence.CascadeType.DETACH;
4+
import static javax.persistence.CascadeType.PERSIST;
35
import static javax.persistence.CascadeType.REFRESH;
46
import static javax.persistence.CascadeType.REMOVE;
57
import static javax.persistence.FetchType.EAGER;
68

79
import java.util.ArrayList;
8-
import java.util.HashSet;
910
import java.util.List;
10-
import java.util.Set;
1111

1212
import javax.persistence.Column;
1313
import javax.persistence.ElementCollection;
@@ -56,19 +56,20 @@ public class Service extends BaseEntity {
5656

5757
@Column(nullable = false)
5858
private Boolean onShortList;
59-
59+
6060
@Lob
6161
@Column(nullable = true)
6262
private String description;
6363

64-
@OneToMany(fetch = EAGER, cascade = { REFRESH, REMOVE }, mappedBy = "service")
64+
@OneToMany(fetch = EAGER, cascade = { DETACH, REMOVE, PERSIST, REFRESH }, mappedBy = "service")
65+
@Fetch(FetchMode.SELECT)
6566
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, scope = Note.class, property = "id")
6667
@JsonIdentityReference(alwaysAsId = true)
67-
private Set<Note> notes;
68+
private List<Note> notes;
6869

6970
public Service() {
7071
setModelValidator(new ServiceValidator());
71-
setNotes(new HashSet<Note>());
72+
setNotes(new ArrayList<Note>());
7273
setAliases(new ArrayList<String>());
7374
}
7475

@@ -115,16 +116,20 @@ public void setServiceUrl(String serviceUrl) {
115116
this.serviceUrl = serviceUrl;
116117
}
117118

118-
public Set<Note> getNotes() {
119+
public List<Note> getNotes() {
119120
return notes;
120121
}
121122

122-
public void setNotes(Set<Note> notes) {
123+
public void setNotes(List<Note> notes) {
123124
this.notes = notes;
124125
}
125126

126127
public void addNote(Note note) {
127-
this.notes.add(note);
128+
System.out.println("addNote size before: " + this.notes.size());
129+
if (!this.notes.contains(note)) {
130+
this.notes.add(note);
131+
}
132+
System.out.println("addNote size after: " + this.notes.size());
128133
}
129134

130135
public void removeNote(Note note) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ public class NoteRepoImpl implements NoteRepoCustom {
3232
public Note create(Note note, Credentials credentials) {
3333
note.setAuthor(userRepo.findByUin(credentials.getUin()));
3434
note = noteRepo.save(note);
35-
Service service = note.getService();
35+
Service service = serviceRepo.findOne(note.getService().getId());
36+
System.out.println(service.getNotes().size());
37+
3638
service.addNote(note);
37-
serviceRepo.saveAndFlush(service);
38-
simpMessagingTemplate.convertAndSend("/channel/service/" + note.getService().getId(), new ApiResponse(SUCCESS, note.getService()));
39+
40+
service = serviceRepo.save(service);
41+
42+
System.out.println(service.getNotes().size());
43+
44+
simpMessagingTemplate.convertAndSend("/channel/service/" + note.getService().getId(), new ApiResponse(SUCCESS, service));
45+
3946
return note;
4047
}
4148
}

src/main/resources/config/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ auth.security.jwt-expiration: 120000
3535
app.security.secret: verysecretsecret
3636

3737
# Required in framework - CoreCorsFilter
38-
app.security.allow-access: http://localhost
38+
app.security.allow-access: http://localhost, http://laddusaw.tamu.edu
3939

4040
# required in framework - CoreControllerAspect
4141
app.aspect.retry: 3

0 commit comments

Comments
 (0)