diff --git a/Server/src/main/java/io/hawkcd/core/MessageDispatcher.java b/Server/src/main/java/io/hawkcd/core/MessageDispatcher.java index 93cd8870..2420d917 100644 --- a/Server/src/main/java/io/hawkcd/core/MessageDispatcher.java +++ b/Server/src/main/java/io/hawkcd/core/MessageDispatcher.java @@ -4,7 +4,6 @@ import io.hawkcd.core.publisher.PublisherFactory; import io.hawkcd.core.session.ISessionManager; import io.hawkcd.core.session.SessionFactory; -import io.hawkcd.core.subscriber.MessageTranslator; import io.hawkcd.model.Entity; import io.hawkcd.model.dto.WsContractDto; import io.hawkcd.model.enums.PermissionType; @@ -17,13 +16,14 @@ public class MessageDispatcher { public static void dispatchIncomingMessage(Message message) { if (Config.getConfiguration().isSingleNode()) { - WsContractDto contractDto; + WsContractDto contractDto = null; if (message.isTargetOwner()) { // if this is list contractDto = MessageConverter.convert(message); - } else { // if single message - contractDto = MessageTranslator.translateMessageToContract(message); + SessionFactory.getSessionManager().sendToAllSessions(contractDto); + } else if(message.isUserUpdate()){ + List ids = (List) message.getEnvelope(); + SessionFactory.getSessionManager().updateSessionLoggedUser(ids.toArray(new String[ids.size()])); } - SessionFactory.getSessionManager().sendToAllSessions(contractDto); } else { PublisherFactory.createPublisher().publish("global", message); } @@ -42,7 +42,7 @@ public static void dispatchOutgoingMessage(Message message) { sessionManager.updateSessionLoggedUser(ids.toArray(new String[ids.size()])); } else { // when is single message meant to be broadcast Map permissionTypeByUser = message.getPermissionTypeByUser(); - WsContractDto contract = MessageTranslator.translateMessageToContract(message); + WsContractDto contract = MessageConverter.convert(message); for (Map.Entry entry : permissionTypeByUser.entrySet()) { WSSocket session = sessionManager.getSessionByUserId(entry.getKey()); diff --git a/Server/src/main/java/io/hawkcd/core/security/AuthorizationGrantService.java b/Server/src/main/java/io/hawkcd/core/security/AuthorizationGrantService.java index c6123da4..4b6b76a9 100644 --- a/Server/src/main/java/io/hawkcd/core/security/AuthorizationGrantService.java +++ b/Server/src/main/java/io/hawkcd/core/security/AuthorizationGrantService.java @@ -3,6 +3,7 @@ import com.google.common.collect.Lists; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -75,7 +76,7 @@ private List sortGrants(List grants) { .stream() .sorted(Comparator.comparingInt(g -> g.getPermissionEntity().getPriorityLevel())) .collect(Collectors.toList()); - sortedGrants = Lists.reverse(sortedGrants); + Collections.reverse(sortedGrants); return sortedGrants; } diff --git a/Server/src/main/java/io/hawkcd/core/subscriber/MessageTranslator.java b/Server/src/main/java/io/hawkcd/core/subscriber/MessageTranslator.java deleted file mode 100644 index a1c4edb3..00000000 --- a/Server/src/main/java/io/hawkcd/core/subscriber/MessageTranslator.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.hawkcd.core.subscriber; - -import java.util.Map; - -import io.hawkcd.core.Message; -import io.hawkcd.core.MessageConverter; -import io.hawkcd.model.Entity; -import io.hawkcd.model.dto.WsContractDto; -import io.hawkcd.model.enums.PermissionType; - -/** - * Created by rado on 11.11.16. - */ -public class MessageTranslator{ - - public static WsContractDto translateMessageToContract(Message message) { - WsContractDto contract = MessageConverter.convert(message); - Map permissionTypeByUser = message.getPermissionTypeByUser(); - Entity entity = (Entity) message.getEnvelope(); - - for (String userId : permissionTypeByUser.keySet()) { - entity.setPermissionType(permissionTypeByUser.get(userId)); - contract.setResult(entity); - } - return contract; - } -}