@Override public CassandraEndpointNotification findById(String id) { LOG.debug("Try to find endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Select.Where where = select().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); LOG.debug("[{}] Execute query {}:", id, where); CassandraEndpointNotification endpointNotification = findOneByStatement(where); LOG.trace("Found endpoint notification {} by id {}:", endpointNotification, id); return endpointNotification; }
public CassandraEndpointNotification(String id) { parseStringId(id); }
@Override public CassandraEndpointNotification save(EndpointNotificationDto dto) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(dto); LOG.debug("Save endpoint notification for endpoint profile {}", Utils.encodeHexString(endpointNotification.getEndpointKeyHash())); save(new CassandraEndpointNotification(dto)); LOG.trace("Saved endpoint notification {}", endpointNotification); return endpointNotification; }
protected List<CassandraEndpointNotification> generateEndpointNotification(ByteBuffer endpointKeyHash, int count) { List<CassandraEndpointNotification> savedNotifications = new ArrayList<>(); String appId = generateStringId(); if (endpointKeyHash == null) { endpointKeyHash = ByteBuffer.wrap(generateEndpointProfile(appId, null, null, null).getEndpointKeyHash()); } String schemaId = generateStringId(); for (int i = 0; i < count; i++) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(); endpointNotification.setEndpointKeyHash(endpointKeyHash); endpointNotification.setApplicationId(appId); endpointNotification.setSchemaId(schemaId); endpointNotification.setType(NotificationTypeDto.USER); endpointNotification.setSeqNum(100 + i); endpointNotification.setLastModifyTime(new Date(System.currentTimeMillis())); savedNotifications.add(unicastNotificationDao.save(endpointNotification)); } return savedNotifications; }
@Test public void testDtoConversation() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); Assert.assertNull(notification.getId()); EndpointNotificationDto notificationDto = notification.toDto(); CassandraEndpointNotification cassandraEndpointNotification = new CassandraEndpointNotification(notificationDto); Assert.assertEquals(notificationDto, cassandraEndpointNotification.toDto()); }
@Test public void testRemoveNotificationsByAppId() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 3).get(0); String appId = notification.getApplicationId(); unicastNotificationDao.removeNotificationsByAppId(appId); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertTrue(found.isEmpty()); }
@Test public void testSave() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(1, found.size()); }
@Test public void testFindById() { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); CassandraEndpointNotification saved = unicastNotificationDao.save(notification.toDto()); Assert.assertNotNull(saved.getId()); CassandraEndpointNotification found = unicastNotificationDao.findById(saved.getId()); Assert.assertEquals(saved, found); } }
/** * 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 testFindNotificationsByKeyHash() throws Exception { List<CassandraEndpointNotification> notifications = generateEndpointNotification(null, 1); generateEndpointNotification(null, 2); CassandraEndpointNotification notification = notifications.get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(notifications.size(), found.size()); }
@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; } }
@Override public void removeById(String id) { LOG.debug("Remove endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Statement delete = delete().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); execute(delete); LOG.debug("[{}] Execute query {}:", id, delete); }