@Test public void testFindNotificationSchemasByAppIdAndType() { NotificationDto dto = generateNotificationsDto(null, null, 1, null).get(0); generateNotificationSchemaDto(dto.getApplicationId(), NotificationTypeDto.SYSTEM); List<NotificationSchemaDto> schemas = notificationService.findNotificationSchemasByAppIdAndType(dto.getApplicationId(), NotificationTypeDto.SYSTEM); Assert.assertEquals(1, schemas.size()); schemas = notificationService.findNotificationSchemasByAppIdAndType(dto.getApplicationId(), NotificationTypeDto.USER); Assert.assertEquals(2, schemas.size()); }
@Test public void testFindNotificationSchemaVersionsByAppId() { NotificationDto dto = generateNotificationsDto(null, null, 1, null).get(0); generateNotificationSchemaDto(dto.getApplicationId(), NotificationTypeDto.SYSTEM); List<VersionDto> schemas = notificationService.findNotificationSchemaVersionsByAppId(dto.getApplicationId()); Assert.assertEquals(3, schemas.size()); }
@Test public void testFindUserNotificationSchemasByAppId() { NotificationDto dto = generateNotificationsDto(null, null, 1, null).get(0); List<VersionDto> schemas = notificationService.findUserNotificationSchemasByAppId(dto.getApplicationId()); generateNotificationSchemaDto(dto.getApplicationId(), NotificationTypeDto.SYSTEM); Assert.assertEquals(2, schemas.size()); }
@Test public void testFindNotificationSchemaByAppIdAndTypeAndVersion() { NotificationDto dto = generateNotificationsDto(null, null, 1, null).get(0); generateNotificationSchemaDto(dto.getApplicationId(), NotificationTypeDto.SYSTEM); NotificationSchemaDto schema = notificationService.findNotificationSchemaByAppIdAndTypeAndVersion(dto.getApplicationId(), NotificationTypeDto.SYSTEM, 1); Assert.assertNotNull(schema); }
@Test public void testRemoveNotificationSchemasByAppId() { NotificationDto dto = generateNotificationsDto(null, null, 3, null).get(0); String appId = dto.getApplicationId(); notificationService.removeNotificationSchemasByAppId(appId); List<NotificationSchemaDto> schemas = notificationService.findNotificationSchemasByAppId(appId); Assert.assertTrue(schemas.isEmpty()); }
if (notificationDto != null) { updateNotificationDto = new UpdateNotificationDto<NotificationDto>(); updateNotificationDto.setAppId(notificationDto.getApplicationId()); updateNotificationDto.setTopicId(topicId); updateNotificationDto.setPayload(notificationDto);
/** * Create new instance of <code>CassandraNotification</code>. * * @param dto data transfer object contain data that * assign on fields of new instance */ public CassandraNotification(NotificationDto dto) { this.applicationId = dto.getApplicationId(); this.schemaId = dto.getSchemaId(); this.topicId = dto.getTopicId(); this.type = dto.getType(); this.nfVersion = dto.getNfVersion(); this.seqNum = dto.getSecNum(); this.lastModifyTime = dto.getLastTimeModify(); this.body = getByteBuffer(dto.getBody()); this.expiredAt = dto.getExpiredAt(); this.seqNum = dto.getSecNum(); this.id = dto.getId(); if (isBlank(id)) { generateId(); } }
/** * Create new instance of <code>MongoNotification</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public MongoNotification(NotificationDto dto) { this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.schemaId = dto.getSchemaId(); this.topicId = dto.getTopicId(); this.nfVersion = dto.getNfVersion(); this.lastModifyTime = dto.getLastTimeModify(); this.type = dto.getType(); this.body = getArrayCopy(dto.getBody()); this.expiredAt = dto.getExpiredAt(); this.secNum = dto.getSecNum(); }
/** * 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(); }
@Override public NotificationDto sendNotification(NotificationDto notification, 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()); return controlService.editNotification(notification); } catch (Exception ex) { throw Utils.handleException(ex); } }
updateNotificationDto = new UpdateNotificationDto<EndpointNotificationDto>(); NotificationDto savedDto = unicast.getNotificationDto(); updateNotificationDto.setAppId(savedDto.getApplicationId()); updateNotificationDto.setTopicId(savedDto.getTopicId()); updateNotificationDto.setPayload(unicast);
@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); } }
@Override public void sendNotification(NotificationDto notification, RecordField notificationData) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkExpiredDate(notification); GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( notificationData); GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>( record.getSchema()); byte[] body = converter.encodeToJsonBytes(record); notification.setBody(body); checkApplicationId(notification.getApplicationId()); TopicDto topic = controlService.getTopic(notification.getTopicId()); Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); controlService.editNotification(notification); } catch (Exception ex) { throw Utils.handleException(ex); } }