private void checkClientInfoAgainstPreparedMessages(ClientInfoListResult cliInfo, List<KapuaDataMessage> msgLst) { Set<String> msgClients = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No client info data!", cliInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); } for (ClientInfo tmpClient : cliInfo.getItems()) { infoClients.add(tmpClient.getClientId()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
private void checkChannelInfoAgainstPreparedMessages(ChannelInfoListResult chnInfo, List<KapuaDataMessage> msgLst) { Set<String> msgTopics = new HashSet<>(); Set<String> msgClients = new HashSet<>(); Set<String> infoTopics = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No channel info data!", chnInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); msgTopics.add(tmpMsg.getChannel().toString()); } for (ChannelInfo tmpInfo : chnInfo.getItems()) { infoClients.add(tmpInfo.getClientId()); infoTopics.add(tmpInfo.getName()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); assertEquals("The number of topics does not match!", msgTopics.size(), infoTopics.size()); for (String tmpTopic : msgTopics) { assertTrue(String.format("The topic [%s] is not found in the info list!", tmpTopic), infoTopics.contains(tmpTopic)); } for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
private void checkMetricInfoAgainstPreparedMessages(MetricInfoListResult metInfo, List<KapuaDataMessage> msgLst) { Set<String> msgMetrics = new HashSet<>(); Set<String> msgClients = new HashSet<>(); Set<String> infoMetrics = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No channel info data!", metInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); for (String tmpMet : tmpMsg.getPayload().getMetrics().keySet()) { msgMetrics.add(tmpMet); } } for (MetricInfo tmpMet : metInfo.getItems()) { infoClients.add(tmpMet.getClientId()); infoMetrics.add(tmpMet.getName()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); assertEquals("The number of topics does not match!", msgMetrics.size(), infoMetrics.size()); for (String tmpMetric : msgMetrics) { assertTrue(String.format("The topic [%s] is not found in the info list!", tmpMetric), infoMetrics.contains(tmpMetric)); } for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
public JsonKapuaDataMessage(KapuaDataMessage kapuaDataMessage) { setId(kapuaDataMessage.getId()); setScopeId(kapuaDataMessage.getScopeId()); setDeviceId(kapuaDataMessage.getDeviceId()); setClientId(kapuaDataMessage.getClientId()); setReceivedOn(kapuaDataMessage.getReceivedOn()); setSentOn(kapuaDataMessage.getSentOn()); setCapturedOn(kapuaDataMessage.getCapturedOn()); setPosition(kapuaDataMessage.getPosition()); setChannel(kapuaDataMessage.getChannel()); setPayload(kapuaDataMessage.getPayload()); }
ArgumentValidator.notNull(requestMessage.getClientId(), "clientId");
@Override public KuraDataMessage translate(KapuaDataMessage kapuaDataMessage) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); AccountService accountService = locator.getService(AccountService.class); Account account = accountService.find(kapuaDataMessage.getScopeId()); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kapuaDataMessage.getScopeId()); } // // Kapua Channel KuraDataChannel kuraDataChannel = translate(kapuaDataMessage.getChannel()); kuraDataChannel.setClientId(kapuaDataMessage.getClientId()); kuraDataChannel.setScope(account.getName()); // // Kapua payload KuraDataPayload kuraDataPayload = translate(kapuaDataMessage.getPayload()); kuraDataPayload.setBody(kapuaDataMessage.getPayload().getBody()); kuraDataPayload.setMetrics(kapuaDataMessage.getPayload().getMetrics()); kuraDataPayload.setPosition(TranslatorKapuaKuraUtils.translate(kapuaDataMessage.getPosition())); kuraDataPayload.setTimestamp(kapuaDataMessage.getSentOn()); // // Kapua message KuraDataMessage kuraDataMessage = new KuraDataMessage(); kuraDataMessage.setChannel(kuraDataChannel); kuraDataMessage.setPayload(kuraDataPayload); // Return Kapua Message return kuraDataMessage; }
@Override public KuraDataMessage translate(KapuaDataMessage kapuaDataMessage) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); AccountService accountService = locator.getService(AccountService.class); Account account = accountService.find(kapuaDataMessage.getScopeId()); if (account == null) { throw new KapuaEntityNotFoundException(Account.TYPE, kapuaDataMessage.getScopeId()); } // // Kapua Channel KuraDataChannel kuraDataChannel = translate(kapuaDataMessage.getChannel()); kuraDataChannel.setClientId(kapuaDataMessage.getClientId()); kuraDataChannel.setScope(account.getName()); // // Kapua payload KuraDataPayload kuraDataPayload = translate(kapuaDataMessage.getPayload()); kuraDataPayload.setBody(kapuaDataMessage.getPayload().getBody()); kuraDataPayload.setMetrics(kapuaDataMessage.getPayload().getMetrics()); kuraDataPayload.setPosition(TranslatorKapuaKuraUtils.translate(kapuaDataMessage.getPosition())); kuraDataPayload.setTimestamp(kapuaDataMessage.getSentOn()); // // Kapua message KuraDataMessage kuraDataMessage = new KuraDataMessage(); kuraDataMessage.setChannel(kuraDataChannel); kuraDataMessage.setPayload(kuraDataPayload); // Return Kapua Message return kuraDataMessage; }