@Override public EndpointGroupStateDto toDto() { EndpointGroupStateDto groupStateDto = new EndpointGroupStateDto(); groupStateDto.setEndpointGroupId(endpointGroupId); groupStateDto.setProfileFilterId(profileFilterId); groupStateDto.setConfigurationId(configurationId); return groupStateDto; } }
/** * Create new instance of <code>EndpointGroupState</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public EndpointGroupState(EndpointGroupStateDto dto) { this.endpointGroupId = dto.getEndpointGroupId(); this.profileFilterId = dto.getProfileFilterId(); this.configurationId = dto.getConfigurationId(); }
endpointId, changeType, change.getConfigurationId(), change.getEndpointGroupId()); if (changeType == ChangeType.ADD_CONF) { egs.setConfigurationId(change.getConfigurationId()); } else { egs.setConfigurationId(null); endpointId, changeType, change.getProfileFilterId(), change.getEndpointGroupId()); groupsMap.remove(egs.getEndpointGroupId()); historyDelta.setAllChanged(); } else if (changeType == ChangeType.ADD_PROF) { + "which means configuration/topic list change", endpointId, change.getProfileFilterId()); groupsMap.remove(egs.getEndpointGroupId()); historyDelta.setAllChanged(); } else { egs.setProfileFilterId(change.getProfileFilterId()); + "possible configuration/topic list change", endpointId, change.getProfileFilterId()); egs = new EndpointGroupStateDto(groupId, change.getProfileFilterId(), null); groupsMap.put(groupId, egs); historyDelta.setAllChanged(); if (entry.getValue().getConfigurationId() == null) { LOG.debug("[{}] Attempt to fetch configuration id for {}", endpointId, entry.getKey()); String confId = cacheService.getConfIdByKey(confIdKey.copyWithNewEgId(entry.getKey())); if (confId != null) {
cfGroupStateSave.add(new EndpointGroupStateDto("111", null, null)); cfGroupStateSave.add(new EndpointGroupStateDto("222", null, null)); cfGroupStateSave.add(new EndpointGroupStateDto("333", null, null)); EndpointProfileDto endpointProfileSave = generateEndpointProfileForTestUpdate(null, "TEST_KEY_HASH".getBytes(), cfGroupStateSave); EndpointProfile saved = endpointProfileDao.save(endpointProfileSave); cfGroupStateUpdate.add(new EndpointGroupStateDto("111", null, null)); cfGroupStateUpdate.add(new EndpointGroupStateDto("444", null, null)); EndpointProfileDto endpointProfileUpdate = generateEndpointProfileForTestUpdate(saved.getId(), "TEST_KEY_HASH".getBytes(), cfGroupStateUpdate); endpointProfileUpdate.setVersion(saved.getVersion());
for (EndpointGroupStateDto egs : egsList) { EndpointGroupDto endpointGroup = null; if (!StringUtils.isBlank(egs.getEndpointGroupId())) { endpointGroup = endpointService.findEndpointGroupById(egs.getEndpointGroupId()); if (endpointGroup != null) { endpointGroups.add(endpointGroup); if (!StringUtils.isBlank(egs.getConfigurationId())) { configuration = configurationService.findConfigurationById( egs.getConfigurationId()); if (configuration != null) { configurations.add(configuration);
/** * Recalculate topic list. * * @param groups endpoint group state list * @return the list */ private List<TopicDto> recalculateTopicList(List<EndpointGroupStateDto> groups) { Set<TopicDto> topicSet = new HashSet<TopicDto>(); for (EndpointGroupStateDto egs : groups) { EndpointGroupDto endpointGroup = cacheService.getEndpointGroupById(egs.getEndpointGroupId()); if (endpointGroup.getTopics() != null) { for (String topicId : endpointGroup.getTopics()) { TopicDto topic = cacheService.getTopicById(topicId); topicSet.add(topic); } } } List<TopicDto> topicList = new ArrayList<>(topicSet); Collections.sort(topicList, new Comparator<TopicDto>() { @Override public int compare(TopicDto o1, TopicDto o2) { return o1.getId().compareTo(o2.getId()); } }); return topicList; }
EndpointGroupDto endpointGroupDto = new EndpointGroupDto(); endpointGroupDto.setWeight(1); cfGroupStateSave.add(new EndpointGroupStateDto("111", null, null)); cfGroupStateSave.add(new EndpointGroupStateDto("222", null, null)); cfGroupStateSave.add(new EndpointGroupStateDto("333", null, null)); byte[] keyHash = generateBytes(); EndpointProfileDto endpointProfileSave = generateEndpointProfileForTestUpdate(null, keyHash, cfGroupStateSave); EndpointProfile saved = endpointProfileDao.save(endpointProfileSave); cfGroupStateUpdate.add(new EndpointGroupStateDto("111", null, null)); cfGroupStateUpdate.add(new EndpointGroupStateDto("444", null, null)); EndpointProfileDto endpointProfileUpdate = generateEndpointProfileForTestUpdate(endpointProfileId, keyHash, cfGroupStateUpdate); endpointProfileUpdate.setVersion(saved.getVersion());
private PageLinkDto getPageLinkDto() { List<EndpointProfileDto> endpointProfileList = new ArrayList<>(); for (int i = 0; i < GENERATED_PROFILES_COUNT; i++) { endpointProfileList.add(generateEndpointProfileWithEndpointGroupId(TEST_APPID)); } String id = endpointProfileList.get(0).getGroupState().get(0).getEndpointGroupId(); return new PageLinkDto(id, TEST_LIMIT, TEST_OFFSET); }
@Override public EndpointGroupStateDto toDto() { EndpointGroupStateDto groupStateDto = new EndpointGroupStateDto(); groupStateDto.setEndpointGroupId(endpointGroupId); groupStateDto.setProfileFilterId(profileFilterId); groupStateDto.setConfigurationId(configurationId); return groupStateDto; } }
/** * Create new instance of <code>CassandraEndpointGroupState</code>. * * @param dto data transfer object contain data that * assign on fields of new instance */ public CassandraEndpointGroupState(EndpointGroupStateDto dto) { this.endpointGroupId = dto.getEndpointGroupId(); this.profileFilterId = dto.getProfileFilterId(); this.configurationId = dto.getConfigurationId(); }
protected EndpointProfileDto generateEndpointProfileWithGroupIdDto(String endpointGroupId) { EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setEndpointKeyHash(generateString("TEST_KEY_HASH").getBytes()); String appId = generateApplicationDto().getId(); profileDto.setApplicationId(appId); List<EndpointGroupStateDto> groupState = new ArrayList<>(); groupState.add(new EndpointGroupStateDto(endpointGroupId, null, null)); profileDto.setGroupState(groupState); try { profileDto.setClientProfileBody(readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); } catch (IOException e) { LOG.error("Can't set client-side EP body {}", e); } profileDto.setServerProfileBody("{\"serverTitle\": \"SERVER_TEST\"}"); profileDto.setSdkToken(UUID.randomUUID().toString()); return endpointService.saveEndpointProfile(profileDto); }
for (EndpointGroupStateDto endpointGroupState : endpointProfile.getGroupState()) { endpointGroupsSet.add(controlService.getEndpointGroup( endpointGroupState.getEndpointGroupId()));
@Override public HistoryDelta getDelta(EndpointProfileDto profile, String applicationToken, int curAppSeqNumber) { String endpointId = Base64Util.encode(profile); ConfigurationIdKey confIdKey = new ConfigurationIdKey( applicationToken, curAppSeqNumber, profile.getConfigurationVersion()); AppProfileVersionsKey appVersionsKey = new AppProfileVersionsKey( applicationToken, profile.getClientProfileVersion(), profile.getServerProfileVersion()); List<ProfileFilterDto> filters = filterService.getAllMatchingFilters(appVersionsKey, profile); LOG.debug("[{}] Found {} matching filters", endpointId, filters.size()); List<EndpointGroupStateDto> result = new ArrayList<>(1 + filters.size()); EndpointGroupDto groupDto = cacheService.getDefaultGroup(applicationToken); EndpointGroupStateDto groupAllState = new EndpointGroupStateDto(); groupAllState.setEndpointGroupId(groupDto.getId()); groupAllState.setConfigurationId(cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(groupDto.getId()))); result.add(groupAllState); for (ProfileFilterDto filter : filters) { String confId = cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(filter.getEndpointGroupId())); EndpointGroupStateDto endpointGroupState = new EndpointGroupStateDto(); endpointGroupState.setEndpointGroupId(filter.getEndpointGroupId()); endpointGroupState.setProfileFilterId(filter.getId()); endpointGroupState.setConfigurationId(confId); result.add(endpointGroupState); } return new HistoryDelta(result, true, true, true); }
/** * Specific method for converting list of <code>EndpointGroupStateDto</code> objects * to list of model objects <code>EndpointGroupState</code>. * * @param stateDtoList the state dto list * @return converted list of <code>EndpointGroupState</code> objects */ public static List<EndpointGroupState> convertDtoToModelList( List<EndpointGroupStateDto> stateDtoList) { List<EndpointGroupState> states = null; if (stateDtoList != null && !stateDtoList.isEmpty()) { states = new ArrayList<>(); for (EndpointGroupStateDto dto : stateDtoList) { EndpointGroupState state = new EndpointGroupState(); state.setConfigurationId(dto.getConfigurationId()); state.setEndpointGroupId(dto.getEndpointGroupId()); state.setProfileFilterId(dto.getProfileFilterId()); states.add(state); } } return states; }
protected EndpointProfileDto generateEndpointProfileWithEndpointGroupId(String appId) { byte[] keyHash = generateBytes(); if (appId == null) { appId = generateStringId(); } EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setApplicationId(appId); profileDto.setEndpointKeyHash(keyHash); profileDto.setAccessToken(generateStringId()); profileDto.setClientProfileBody("test profile"); profileDto.setServerProfileBody("test server-side profile"); profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); List<EndpointGroupStateDto> groupState = new ArrayList<>(); groupState.add(new EndpointGroupStateDto(TEST_ENDPOINT_GROUP_ID, null, null)); profileDto.setGroupState(groupState); profileDto.setSdkToken(UUID.randomUUID().toString()); return endpointProfileDao.save(new CassandraEndpointProfile(profileDto)).toDto(); }
@Test public void EndpointStateTest() { EndpointGroupStateDto state = new EndpointGroupStateDto(); String groupId = String.valueOf(RANDOM.nextInt(LIMIT)); String filterId = String.valueOf(RANDOM.nextInt(LIMIT)); String configId = String.valueOf(RANDOM.nextInt(LIMIT)); state.setConfigurationId(configId); state.setProfileFilterId(filterId); state.setEndpointGroupId(groupId); CassandraEndpointGroupState stateOne = new CassandraEndpointGroupState(state); CassandraEndpointGroupState stateTwo = new CassandraEndpointGroupState(); stateTwo.setConfigurationId(configId); stateTwo.setProfileFilterId(filterId); stateTwo.setEndpointGroupId(groupId); Assert.assertEquals(stateOne, stateTwo); Assert.assertEquals(stateOne.hashCode(), stateTwo.hashCode()); Assert.assertEquals(stateOne.toDto(), stateTwo.toDto()); Assert.assertEquals(stateOne.toString(), stateTwo.toString()); }
/** * Specific method for converting list of <code>EndpointGroupStateDto</code> objects * to list of model objects <code>CassandraEndpointGroupState</code>. * * @param stateDtoList the state dto list * @return converted list of <code>CassandraEndpointGroupState</code> objects */ public static List<CassandraEndpointGroupState> convertDtoToModelList( List<EndpointGroupStateDto> stateDtoList) { List<CassandraEndpointGroupState> states = null; if (stateDtoList != null && !stateDtoList.isEmpty()) { states = new ArrayList<>(); for (EndpointGroupStateDto dto : stateDtoList) { CassandraEndpointGroupState state = new CassandraEndpointGroupState(); state.setConfigurationId(dto.getConfigurationId()); state.setEndpointGroupId(dto.getEndpointGroupId()); state.setProfileFilterId(dto.getProfileFilterId()); states.add(state); } } return states; }
@Test public void EndpointStateTest() { EndpointGroupStateDto state = new EndpointGroupStateDto(); String groupId = String.valueOf(RANDOM.nextInt(LIMIT)); String filterId = String.valueOf(RANDOM.nextInt(LIMIT)); String configId = String.valueOf(RANDOM.nextInt(LIMIT)); state.setConfigurationId(configId); state.setProfileFilterId(filterId); state.setEndpointGroupId(groupId); EndpointGroupState stateOne = new EndpointGroupState(state); EndpointGroupState stateTwo = new EndpointGroupState(); stateTwo.setConfigurationId(configId); stateTwo.setProfileFilterId(filterId); stateTwo.setEndpointGroupId(groupId); Assert.assertEquals(stateOne, stateTwo); Assert.assertEquals(stateOne.hashCode(), stateTwo.hashCode()); Assert.assertEquals(stateOne.toDto(), stateTwo.toDto()); Assert.assertEquals(stateOne.toString(), stateTwo.toString()); }