public void deleteTopic(TopicDto topic) throws Exception { deleteTopic(topic.getId()); }
private void performAdd() { LinkedList<String> topicIds = new LinkedList<>(); for (TopicDto topicDto : topic.getValue()) { topicIds.add(topicDto.getId()); } addTopics(topicIds); }
private void sendNotification(TopicDto value) { RowActionEvent<String> rowSendNotificationEvent = new RowActionEvent<>( value.getId(), KaaRowAction.SEND_NOTIFICATION); fireEvent(rowSendNotificationEvent); }
public void addTopicToEndpointGroup(EndpointGroupDto endpointGroup, TopicDto topic) throws Exception { addTopicToEndpointGroup(endpointGroup.getId(), topic.getId()); }
@Override public TopicListCacheEntry getTopicListHash(String appToken, String endpointId, EndpointProfileDto profile) { LOG.debug("[{}][{}] Calculating new topic list", appToken, endpointId); List<TopicDto> topics = recalculateTopicList(profile.getGroupState()); Collections.sort(topics); long[] ids = new long[topics.size()]; StringJoiner joiner = new StringJoiner("|"); for (int i = 0; i < topics.size(); i++) { Long id = Long.valueOf(topics.get(i).getId()); ids[i] = id.longValue(); joiner.add(id.toString()); } int simpleHash = Arrays.hashCode(ids); EndpointObjectHash complexHash = EndpointObjectHash.fromBytes( Sha1HashUtils.hashToBytes(joiner.toString())); TopicListCacheEntry entry = new TopicListCacheEntry(simpleHash, complexHash, topics); cacheService.putTopicList(complexHash, entry); LOG.debug("[{}][{}] Calculated new topic list {}", appToken, endpointId, entry); return entry; }
/** * Create new instance of <code>MongoTopicListEntry</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public MongoTopicListEntry(TopicListEntryDto dto) { this.hash = dto.getHash(); this.simpleHash = dto.getSimpleHash(); this.topicIds = new ArrayList<>(); if (dto.getTopics() != null) { for (TopicDto topic : dto.getTopics()) { topicIds.add(topic.getId()); } } }
/** * Create new instance of <code>CassandraTopicListEntry</code>. * * @param dto data transfer object contain data that * assign on fields of new instance */ public CassandraTopicListEntry(TopicListEntryDto dto) { this.hash = getByteBuffer(dto.getHash()); this.simpleHash = dto.getSimpleHash(); this.topicIds = new ArrayList<>(); if (dto.getTopics() != null) { for (TopicDto topic : dto.getTopics()) { topicIds.add(topic.getId()); } } }
@Override public TopicDto saveTopic(TopicDto topicDto) { validateSqlObject(topicDto, "Can't save topic. Invalid topic object"); if (StringUtils.isBlank(topicDto.getId())) { LOG.debug("Save new topic."); topicDto.setCreatedTime(System.currentTimeMillis()); Topic topic = topicDao.findTopicByAppIdAndName(topicDto.getApplicationId(), topicDto.getName()); if (topic != null) { throw new IllegalArgumentException("Topic with the same name already present!"); } } return getDto(topicDao.save(new Topic(topicDto))); }
@Test public void removeTopicByIdAddedToGroupTest() { TopicDto topic = generateTopicDto(null, null); EndpointGroupDto groupDto = generateEndpointGroupDto(topic.getApplicationId()); endpointService.addTopicToEndpointGroup(groupDto.getId(), topic.getId()); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); }
@Test public void removeTopicByIdTest() { TopicDto topic = generateTopicDto(null, null); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); List<EndpointGroupDto> groups = endpointService.findEndpointGroupsByAppId(topic.getApplicationId()); Assert.assertFalse(groups.isEmpty()); }
@Test public void testRemoveUnicastNotificationsByKeyHash() { TopicDto topicDto = generateTopicDto(null, null); EndpointProfileDto profile = generateEndpointProfileDto(topicDto.getApplicationId(), Arrays.asList(topicDto.getId())); byte[] keyHash = profile.getEndpointKeyHash(); EndpointNotificationDto notification = generateUnicastNotificationDto(null, topicDto.getId(), keyHash); Assert.assertTrue(isNotBlank(notification.getId())); notificationService.removeUnicastNotificationsByKeyHash(keyHash); List<EndpointNotificationDto> notifications = notificationService.findUnicastNotificationsByKeyHash(keyHash); Assert.assertTrue(notifications.isEmpty()); }
@Test public void findTopicByIdTest() { TopicDto topic = generateTopicDto(null, null); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertEquals(topic, found); }
@Test public void testFindUnicastNotificationById() { TopicDto topicDto = generateTopicDto(null, null); EndpointProfileDto profile = generateEndpointProfileDto(topicDto.getApplicationId(), Arrays.asList(topicDto.getId())); byte[] keyHash = profile.getEndpointKeyHash(); EndpointNotificationDto notification = generateUnicastNotificationDto(null, topicDto.getId(), keyHash); Assert.assertTrue(isNotBlank(notification.getId())); EndpointNotificationDto found = notificationService.findUnicastNotificationById(notification.getId()); Assert.assertEquals(notification, found); }
@Test public void testRemoveUnicastNotificationById() { TopicDto topicDto = generateTopicDto(null, null); EndpointProfileDto profile = generateEndpointProfileDto(topicDto.getApplicationId(), Arrays.asList(topicDto.getId())); byte[] keyHash = profile.getEndpointKeyHash(); EndpointNotificationDto notification = generateUnicastNotificationDto(null, topicDto.getId(), keyHash); Assert.assertTrue(isNotBlank(notification.getId())); notificationService.removeUnicastNotificationById(notification.getId()); EndpointNotificationDto notif = notificationService.findUnicastNotificationById(notification.getId()); Assert.assertNull(notif); }
@Override public TopicDto editTopic(TopicDto topic) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(topic.getId())) { topic.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(topic.getApplicationId()); } else { throw new KaaAdminServiceException( "Unable to edit existing topic!", ServiceErrorCode.INVALID_ARGUMENTS); } return controlService.editTopic(topic); } catch (Exception ex) { throw Utils.handleException(ex); } }
notification.setSchemaId(schema.getId()); if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId();
@Test public void testFindTopicsByEndpointGroupId() { ApplicationDto app = generateApplicationDto(); EndpointGroupDto group = generateEndpointGroupDto(app.getId()); TopicDto topic = generateTopicDto(app.getId(), null); endpointService.addTopicToEndpointGroup(group.getId(), topic.getId()); List<TopicDto> found = topicService.findTopicsByEndpointGroupId(group.getId()); Assert.assertEquals(topic, found.get(0)); } }
protected EndpointNotificationDto generateUnicastNotificationDto(String schemaId, String topicId, byte[] keyHash) { EndpointNotificationDto endpointNotification = new EndpointNotificationDto(); endpointNotification.setEndpointKeyHash(keyHash); NotificationDto notification = new NotificationDto(); NotificationSchemaDto schema; if (isBlank(schemaId)) { schema = generateNotificationSchemaDto(null, NotificationTypeDto.USER); } else { schema = notificationService.findNotificationSchemaById(schemaId); } if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId(); } notification.setTopicId(topicId); notification.setApplicationId(schema.getApplicationId()); notification.setSchemaId(schema.getId()); notification.setType(NotificationTypeDto.USER); byte[] body = null; try { body = readSchemaFileAsString("dao/schema/testBaseData.json").getBytes(Charset.forName("UTF-8")); } catch (IOException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } notification.setBody(body); endpointNotification.setNotificationDto(notification); UpdateNotificationDto<EndpointNotificationDto> update = notificationService.saveUnicastNotification(endpointNotification); return update.getPayload(); }
dto.setTopicId(topicDto.getId()); dto.setBody("{\"notificationBody\":\"dummy\", \"systemNotificationParam1\":42, \"systemNotificationParam2\":43}".getBytes()); dto.setExpiredAt(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10L)));