@JsonIgnore public Integer getEndpointProfileSchemaVersion() { return activeStructureDto != null ? activeStructureDto.getEndpointProfileSchemaVersion() : inactiveStructureDto.getEndpointProfileSchemaVersion(); }
private boolean supports(ProfileFilterDto profileFilter, Integer endpointProfileSchemaVersion, Integer serverProfileSchemaVersion) { return (profileFilter.getEndpointProfileSchemaVersion() == null || profileFilter.getEndpointProfileSchemaVersion() == endpointProfileSchemaVersion) && (profileFilter.getServerProfileSchemaVersion() == null || profileFilter.getServerProfileSchemaVersion() == serverProfileSchemaVersion); } });
/** * All-args constructor. */ public static List<ProfileFilterRecordDto> convertToProfileFilterRecords( Collection<ProfileFilterDto> profileFilters) { Map<ProfileVersionPairDto, ProfileFilterRecordDto> profileFiltterRecordsMap = new HashMap<>(); for (ProfileFilterDto profileFilter : profileFilters) { ProfileVersionPairDto versionPair = new ProfileVersionPairDto( profileFilter.getEndpointProfileSchemaId(), profileFilter.getEndpointProfileSchemaVersion(), profileFilter.getServerProfileSchemaId(), profileFilter.getServerProfileSchemaVersion()); ProfileFilterRecordDto profileFilterRecord = profileFiltterRecordsMap.get(versionPair); if (profileFilterRecord == null) { profileFilterRecord = new ProfileFilterRecordDto(); profileFiltterRecordsMap.put(versionPair, profileFilterRecord); } if (profileFilter.getStatus() == UpdateStatus.ACTIVE) { profileFilterRecord.setActiveStructureDto(profileFilter); } else if (profileFilter.getStatus() == UpdateStatus.INACTIVE) { profileFilterRecord.setInactiveStructureDto(profileFilter); } } return new ArrayList<>(profileFiltterRecordsMap.values()); }
@Test public void findProfileFilterByAppIdAndVersionTest() { List<ProfileFilterDto> generated = generateFilterDto(null, null, null, 1, true); ProfileFilterDto first = generated.get(0); List<ProfileFilterDto> filters = profileService.findProfileFiltersByAppIdAndVersionsCombination(first.getApplicationId(), first.getEndpointProfileSchemaVersion(), first.getServerProfileSchemaVersion()); Assert.assertNotNull(filters); Assert.assertFalse(filters.isEmpty()); }
@Override public boolean matches(ProfileFilterDto filter) { final Expression expression = new SpelExpressionParser().parseExpression(filter.getBody()); StandardEvaluationContext evaluationContext; if (filter.getEndpointProfileSchemaVersion() != null) { evaluationContext = new StandardEvaluationContext(clientProfileGenericRecord); evaluationContext.setVariable(CLIENT_PROFILE_VARIABLE_NAME, clientProfileGenericRecord); } else { evaluationContext = new StandardEvaluationContext(); } evaluationContext.addPropertyAccessor(new GenericRecordPropertyAccessor()); evaluationContext.setVariable(EP_KEYHASH_VARIABLE_NAME, epKey); if (filter.getServerProfileSchemaVersion() != null) { evaluationContext.setVariable(SERVER_PROFILE_VARIABLE_NAME, serverProfileGenericRecord); } return expression.getValue(evaluationContext, Boolean.class); }
cacheService.resetFilters(new AppProfileVersionsKey( appDto.getApplicationToken(), filterDto .getEndpointProfileSchemaVersion(), filterDto.getServerProfileSchemaVersion())); } else if (filterDto.getServerProfileSchemaVersion() == null) { for (VersionDto version
@Test public void deactivateProfileFilterTest() { List<ProfileFilterDto> filterList = generateFilterDto(null, null, null, 1, true); ProfileFilterDto pf = filterList.get(0); String appId = pf.getApplicationId(); List<ProfileFilterDto> filters = profileService.findProfileFiltersByAppIdAndVersionsCombination(pf.getApplicationId(), pf.getEndpointProfileSchemaVersion(), pf.getServerProfileSchemaVersion()); Assert.assertNotNull(filters); ProfileFilterDto filter = filters.get(0); filter.setId(null); EndpointGroupDto group = generateEndpointGroupDto(appId); filter.setEndpointGroupId(group.getId()); ProfileFilterDto dto = profileService.saveProfileFilter(filter); ChangeProfileFilterNotification change = profileService.activateProfileFilter(dto.getId(), null); Assert.assertNotNull(change); Assert.assertEquals(UpdateStatus.ACTIVE, change.getProfileFilterDto().getStatus()); change = profileService.deactivateProfileFilter(dto.getId(), null); Assert.assertNotNull(change); Assert.assertEquals(UpdateStatus.DEPRECATED, change.getProfileFilterDto().getStatus()); }