@Override public TopicListEntryDto toDto() { List<TopicDto> topicDtos = ModelUtils.getTopicDtos(topicIds); return new TopicListEntryDto(simpleHash, hash, topicDtos); } }
/** * 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()); } } }
@Override @Transactional public TopicListEntryDto findTopicListEntryByHash(byte[] hash) { LOG.debug("Looking for a topic list entry by hash: [{}]", hash); TopicListEntry topicListEntry = topicListEntryDao.findByHash(hash); List<TopicDto> foundTopics = ModelUtils.convertDtoList(topicDao.findTopicsByIds( topicListEntry.getTopicIds())); TopicListEntryDto topicListEntryDto = getDto(topicListEntry); topicListEntryDto.setTopics(foundTopics); return topicListEntryDto; }
/** * 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 TopicListEntryDto toDto() { List<TopicDto> topicDtos = ModelUtils.getTopicDtos(topicIds); return new TopicListEntryDto(simpleHash, getBytes(hash), topicDtos); } }
@Override public TopicListCacheEntry compute(EndpointObjectHash key) { LOG.debug("Fetching result for getTopicListByHash {}", key); TopicListEntryDto entryDto = endpointService.findTopicListEntryByHash(key.getData()); if (entryDto != null) { return new TopicListCacheEntry( entryDto.getSimpleHash(), EndpointObjectHash.fromBytes(entryDto.getHash()), entryDto.getTopics()); } else { return null; } } });
@Override @CachePut(value = "topicListEntries", key = "#key") public TopicListCacheEntry putTopicList(EndpointObjectHash key, TopicListCacheEntry entry) { if (entry != null) { TopicListEntryDto entryDto = new TopicListEntryDto( entry.getSimpleHash(), entry.getHash().getData(), entry.getTopics()); endpointService.saveTopicListEntry(entryDto); } return entry; }
@Test public void findEndpointUserConfigurationDtoTest() throws IOException { List<TopicDto> topics = new ArrayList<>(); topics.add(generateTopicDto(null, TopicTypeDto.OPTIONAL)); byte[] hash = "hash".getBytes(); int simpleHash = 123; TopicListEntryDto topicListEntryDto = new TopicListEntryDto(123, hash, topics); topicListEntryDao.save(topicListEntryDto); MongoTopicListEntry topicListEntry = topicListEntryDao.findByHash(hash); Assert.assertEquals(simpleHash, topicListEntry.getSimpleHash()); } }
@Test public void testFindByHash() throws Exception { List<TopicDto> topics = new ArrayList<>(); TopicDto topicDto = new TopicDto(); topicDto.setId("6123"); topics.add(topicDto); byte[] hash = "hash".getBytes(); int simpleHash = 123; TopicListEntryDto topicListEntryDto = new TopicListEntryDto(123, hash, topics); topicListEntryDao.save(topicListEntryDto); CassandraTopicListEntry topicListEntry = topicListEntryDao.findByHash(hash); Assert.assertEquals(simpleHash, topicListEntry.getSimpleHash()); } }
@Test public void findTopicListEntryByHashTest() { ApplicationDto applicationDto = generateApplicationDto(); TopicDto topicDto = generateTopicDto(applicationDto.getId(), TopicTypeDto.MANDATORY); List<TopicDto> topics = Arrays.asList(topicDto); byte[] hash = "123".getBytes(); TopicListEntryDto topicListEntryDto = new TopicListEntryDto(1, hash, topics); endpointService.saveTopicListEntry(topicListEntryDto); TopicListEntryDto foundTopicListEntry = endpointService.findTopicListEntryByHash(hash); Assert.assertEquals(topicListEntryDto, foundTopicListEntry); }