Skip to content

Commit

Permalink
WebSocket function: New Event for updated task participation - see vi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalinow committed Apr 19, 2020
1 parent a05340e commit 935dc20
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ public enum EventType {
QUEST,
ADVENTURE,
MESSAGE,
ARTEFACT
ARTEFACT,
TASK,
RAID,
QUALITYGATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ public Task addParticipation(final Principal principal,
}
task.setParticipation(participation);
task = taskService.save(task);
// TODO Refactoring with issue 266 (= Websocket for tasks)
webSocketController.onUpdateTaskParticipation(task, principal);
}

webSocketController.onUpdateTask(task, principal);
return task;
}

Expand All @@ -209,6 +209,8 @@ public void deleteParticipation(@PathVariable(value = "taskId") final Long taskI
task.setParticipation(null);
task.setStatus(SonarQuestStatus.OPEN);
taskService.save(task);

webSocketController.onUpdateTaskParticipation(task, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class WebSocketController {

private static final String CHAT = "/chat";

// TODO: Refactoring this! Issue: https://github.com/viadee/sonarQuest/issues/266
private static final String RAID = "/raid";

@Autowired
private SimpMessagingTemplate template;

Expand All @@ -39,15 +36,15 @@ public void onReceivedMessage(final MessageDto messageDto) {
}

/**
* TODO: Refactoring this! Issue: https://github.com/viadee/sonarQuest/issues/266
*
* TODO: Refactoring with Issue: https://github.com/viadee/sonarQuest/issues/266
* onUpdateTaskParticipation
* @param task
* @param principal
*/
public void onUpdateTask(final Task task, Principal principal) {
Event event = eventService.createEventForUpdatedQuest(task.getQuest(), principal);
public void onUpdateTaskParticipation(final Task task, Principal principal) {
Event event = eventService.createEventForUpdatedTaskParticipation(task, principal);
EventUserDto eventUserDto = eventService.eventToEventUserDto(event);
template.convertAndSend(RAID, eventUserDto);
template.convertAndSend(CHAT, eventUserDto);
}

public void onCreateQuest(final Quest quest, Principal principal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.viadee.sonarquest.entities.EventUserDto;
import com.viadee.sonarquest.entities.MessageDto;
import com.viadee.sonarquest.entities.Quest;
import com.viadee.sonarquest.entities.Task;
import com.viadee.sonarquest.entities.User;
import com.viadee.sonarquest.entities.UserDto;
import com.viadee.sonarquest.entities.World;
Expand Down Expand Up @@ -74,7 +75,31 @@ private Event adventureToEvent(Adventure adventure, Principal principal, EventSt
String head = StringUtils.EMPTY;
return new Event(type, title, story, state, image, world, head, userService.getUser(principal));
}


/**
* TODO: Refactoring! Issue: https://github.com/viadee/sonarQuest/issues/266
* @param task
* @param principal
* @return
*/
public Event createEventForUpdatedTaskParticipation(Task task, Principal principal) {
Event event = taskParticipationToEvent(task, principal, EventState.UPDATED);
return event;
}
private Event taskParticipationToEvent(Task task, Principal principal, EventState state) {
EventType type = EventType.TASK;
String title = task.getTitle();
String image = StringUtils.EMPTY;
World world = task.getWorld();
String head = StringUtils.EMPTY;

if (principal != null) {
return new Event(type, title, "", state, image, world, head, userService.getUser(principal));
}

return new Event(type, title, "", state, image, world, head, null);
}

public Event createEventForSolvedQuest(Quest quest, Principal principal) {
Event event = questToEvent(quest, principal, EventState.SOLVED);
LOGGER.info(String.format("New event because of a solved quest '%s'", quest.getTitle()));
Expand Down

0 comments on commit 935dc20

Please sign in to comment.