@Override public EndpointNotificationDto toDto() { EndpointNotificationDto dto = new EndpointNotificationDto(); dto.setId(id); dto.setEndpointKeyHash(getArrayCopy(endpointKeyHash)); dto.setNotificationDto(notification != null ? notification.toDto() : null); return dto; } }
/** * Create new instance of <code>MongoEndpointNotification</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public MongoEndpointNotification(EndpointNotificationDto dto) { this.id = dto.getId(); this.endpointKeyHash = getArrayCopy(dto.getEndpointKeyHash()); this.notification = dto.getNotificationDto() != null ? new MongoNotification(dto.getNotificationDto()) : null; }
/** * Convert unicast notification. * * @param unicastNotification the unicast notification * @return the notification dto */ private NotificationDto convertUnicastNotification(EndpointNotificationDto unicastNotification) { NotificationDto dto = unicastNotification.getNotificationDto(); dto.setId(unicastNotification.getId()); return dto; }
@Override public EndpointNotificationDto sendUnicastNotification(NotificationDto notification, String clientKeyHash, byte[] body) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkExpiredDate(notification); notification.setBody(body); checkApplicationId(notification.getApplicationId()); TopicDto topic = controlService.getTopic(notification.getTopicId()); Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); EndpointNotificationDto unicastNotification = new EndpointNotificationDto(); unicastNotification.setEndpointKeyHash( Base64.decode(clientKeyHash.getBytes(Charsets.UTF_8))); unicastNotification.setNotificationDto(notification); return controlService.editUnicastNotification(unicastNotification); } catch (Exception ex) { throw Utils.handleException(ex); } }
String endpointId = Base64Util.encode(notificationDto.getEndpointKeyHash()); OperationsNodeInfo server = resolve(endpointId); appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, ByteBuffer.wrap(notificationDto.getEndpointKeyHash()) nf.setNotificationId(notificationDto.getId()); if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]",
validateObject(dto, "Can't save unicast notification. Invalid endpoint notification object."); UpdateNotificationDto<EndpointNotificationDto> updateNotificationDto = null; NotificationDto notificationDto = dto.getNotificationDto(); String schemaId = notificationDto.getSchemaId(); String topicId = notificationDto.getTopicId(); throw new IncorrectParameterException("Invalid notification topic id: " + schemaId); } else { byte[] endpointKeyHash = dto.getEndpointKeyHash(); if (endpointKeyHash != null) { EndpointProfile ep = endpointProfileDao.findByKeyHash(endpointKeyHash); if (unicast != null && unicast.getNotificationDto() != null) { LOG.trace("Saved unicast notifications {}", unicast); updateNotificationDto = new UpdateNotificationDto<EndpointNotificationDto>(); NotificationDto savedDto = unicast.getNotificationDto(); updateNotificationDto.setAppId(savedDto.getApplicationId()); updateNotificationDto.setTopicId(savedDto.getTopicId());
@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); }
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(); }
for (EndpointNotificationDto unicastNotification : unicastNotifications) { LOG.debug("[{}] detected new unicast notification: {} ", endpointId, unicastNotification.getId()); LOG.trace("[{}] detected new unicast notification: {} ", endpointId, unicastNotification); NotificationDto notificationDto = unicastNotification.getNotificationDto(); if (notificationDto != null) { Date date = notificationDto.getExpiredAt(); LOG.trace("[{}] notification expiration time is {}({}) which is later then {}", endpointId, date.getTime(), date, now); notificationDto.setId(unicastNotification.getId()); notifications.add(notificationDto);
@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); }
@Override public EndpointNotificationDto toDto() { EndpointNotificationDto dto = new EndpointNotificationDto(); dto.setId(id != null ? id : generateId()); dto.setEndpointKeyHash(endpointKeyHash != null ? endpointKeyHash.array() : null); NotificationDto notificationDto = new NotificationDto(); notificationDto.setSecNum(seqNum); notificationDto.setType(type); notificationDto.setApplicationId(applicationId); notificationDto.setSchemaId(schemaId); notificationDto.setNfVersion(nfVersion); notificationDto.setLastTimeModify(lastModifyTime); notificationDto.setBody(getBytes(body)); notificationDto.setExpiredAt(expiredAt); notificationDto.setTopicId(topicId); dto.setNotificationDto(notificationDto); return dto; } }
/** * Create new instance of <code>CassandraTopicListEntry</code>. * * @param dto data transfer object contain data that assign on fields of new instance */ public CassandraEndpointNotification(EndpointNotificationDto dto) { this.endpointKeyHash = ByteBuffer.wrap(dto.getEndpointKeyHash()); NotificationDto notificationDto = dto.getNotificationDto(); if (notificationDto != null) { this.seqNum = notificationDto.getSecNum(); this.type = notificationDto.getType(); this.applicationId = notificationDto.getApplicationId(); this.schemaId = notificationDto.getSchemaId(); this.nfVersion = notificationDto.getNfVersion(); this.lastModifyTime = notificationDto.getLastTimeModify(); this.body = getByteBuffer(notificationDto.getBody()); this.expiredAt = notificationDto.getExpiredAt(); this.topicId = notificationDto.getTopicId(); } this.id = dto.getId() != null ? dto.getId() : generateId(); }
@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()); }