@Override public EndpointProfileDto getEndpointProfileByKeyHash(String endpointProfileKeyHash) throws ControlServiceException { return endpointService.findEndpointProfileByKeyHash( Base64.decodeBase64(endpointProfileKeyHash) ); }
@Override public EndpointGroupDto editEndpointGroup(EndpointGroupDto endpointGroup) throws ControlServiceException { return endpointService.saveEndpointGroup(endpointGroup); }
@Override public EndpointGroupDto addTopicsToEndpointGroup(String endpointGroupId, String topicId) throws ControlServiceException { return notifyAndGetPayload(endpointService.addTopicToEndpointGroup(endpointGroupId, topicId)); }
private EndpointProfileDto updateProfile( EndpointProfileDto update, BiFunction<EndpointProfileDto, EndpointProfileDto, EndpointProfileDto> mergeFunction, int retryCount) { LOG.debug("Updating profile {} ", update); try { return endpointService.saveEndpointProfile(update); } catch (KaaOptimisticLockingFailureException ex) { LOG.warn("Failed to update profile {} ", update, ex); if (retryCount > 0) { EndpointProfileDto stored = endpointService.findEndpointProfileByKeyHash( update.getEndpointKeyHash()); LOG.warn("Going to merge it with stored profile {}", stored); EndpointProfileDto merged = mergeFunction.apply(stored, update); LOG.warn("Merge result: {}", merged); return updateProfile(merged, mergeFunction, retryCount - 1); } else { throw ex; } } }
private void removeAllEndpointUsers() { List<EndpointUserDto> endpointUsers = endpointService.findAllEndpointUsers(); for (EndpointUserDto endpointUser : endpointUsers) { endpointService.removeEndpointUserById(endpointUser.getId()); } }
@Test(expected = IncorrectParameterException.class) public void invalidUpdateEndpointGroupTest() { ApplicationDto app = generateApplicationDto(); List<EndpointGroupDto> groups = endpointService.findEndpointGroupsByAppId(app.getId()); Assert.assertFalse(groups.isEmpty()); EndpointGroupDto group = groups.get(0); group.setName("Updated Group Name"); endpointService.saveEndpointGroup(group); }
@Test(expected = IncorrectParameterException.class) public void saveEndpointGroupWithSameWeightTest() { EndpointGroupDto group = generateEndpointGroupDto(null); EndpointGroupDto found = endpointService.findEndpointGroupById(group.getId()); found.setId(null); endpointService.saveEndpointGroup(found); }
@Test public void attachEndpointToAlreadyAttachedUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String tenantId = tenant.getId(); EndpointUserDto endpointUserDto = generateEndpointUserDto(tenantId); String userExternalId = endpointUserDto.getExternalId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, endpointProfile); savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile.getEndpointUserId()); EndpointUserDto attachedEndpointUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); Assert.assertNotNull(attachedEndpointUser); Assert.assertEquals(userExternalId, attachedEndpointUser.getExternalId()); Assert.assertEquals(tenantId, attachedEndpointUser.getTenantId()); List<String> endpointIds = attachedEndpointUser.getEndpointIds(); Assert.assertNotNull(endpointIds); Assert.assertEquals(1, endpointIds.size()); Assert.assertEquals(endpointProfile.getId(), endpointIds.get(0)); }
@Test public void findEndpointProfilesByExternalUserIdTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto endpointUserDto = generateEndpointUserDto(tenantDto.getId()); String endpointGroupId = "124"; String accessToken1 = "1111"; String accessToken2 = "2222"; EndpointProfileDto endpointProfileDto1 = generateEndpointProfileWithGroupIdDto(endpointGroupId); endpointProfileDto1.setAccessToken(accessToken1); EndpointProfileDto endpointProfileDto2 = generateEndpointProfileWithGroupIdDto(endpointGroupId); endpointProfileDto2.setAccessToken(accessToken2); endpointProfileDto1 = endpointService.saveEndpointProfile(endpointProfileDto1); endpointProfileDto2 = endpointService.saveEndpointProfile(endpointProfileDto2); endpointService.attachEndpointToUser(endpointUserDto.getId(), accessToken1); endpointService.attachEndpointToUser(endpointUserDto.getId(), accessToken2); List<EndpointProfileDto> endpointProfiles = endpointService.findEndpointProfilesByExternalIdAndTenantId(endpointUserDto.getExternalId(), tenantDto.getId()); Assert.assertEquals(2, endpointProfiles.size()); Comparator<EndpointProfileDto> endpointProfilesComparator = new Comparator<EndpointProfileDto>() { @Override public int compare(EndpointProfileDto o1, EndpointProfileDto o2) { return o1.getId().compareTo(o2.getId()); } }; List<EndpointProfileDto> expected = Arrays.asList(endpointProfileDto1, endpointProfileDto2); Collections.sort(expected, endpointProfilesComparator); Collections.sort(endpointProfiles, endpointProfilesComparator); Assert.assertEquals(expected, endpointProfiles); }
@Test public void attachEndpointToUserTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto endpointUserDto = generateEndpointUserDto(tenantDto.getId()); String endpointGroupId = "124"; EndpointProfileDto endpointProfileDto = generateEndpointProfileWithGroupIdDto(endpointGroupId); String accessToken = "1111"; endpointProfileDto.setAccessToken(accessToken); endpointService.saveEndpointProfile(endpointProfileDto); endpointService.attachEndpointToUser(endpointUserDto.getId(), accessToken); endpointUserDto = endpointService.findEndpointUserById(endpointUserDto.getId()); List<String> endpointIds = endpointUserDto.getEndpointIds(); Assert.assertNotNull(endpointIds); Assert.assertEquals(1, endpointIds.size()); Assert.assertEquals(endpointProfileDto.getId(), endpointIds.get(0)); }
@Test public void attachEndpointAlreadyAttachedToAnotherUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String tenantId = tenant.getId(); EndpointUserDto endpointUser1 = generateEndpointUserDto(tenantId); String userExternalId1 = endpointUser1.getExternalId(); EndpointUserDto endpointUser2 = generateEndpointUserDto(tenantId); String userExternalId2 = endpointUser2.getExternalId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId1, tenantId, endpointProfile); savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId2, tenantId, savedEndpointProfile); EndpointUserDto attachedUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); endpointUser1 = endpointService.findEndpointUserByExternalIdAndTenantId(userExternalId1, tenantId); endpointUser2 = endpointService.findEndpointUserByExternalIdAndTenantId(userExternalId2, tenantId); Assert.assertNotNull(attachedUser); Assert.assertEquals(endpointUser2, attachedUser); List<String> user1EndpointIds = endpointUser1.getEndpointIds(); List<String> user2EndpointIds = endpointUser2.getEndpointIds(); Assert.assertTrue(CollectionUtils.isEmpty(user1EndpointIds)); Assert.assertFalse(CollectionUtils.isEmpty(user2EndpointIds)); Assert.assertEquals(1, user2EndpointIds.size()); Assert.assertEquals(endpointProfile.getId(), user2EndpointIds.get(0)); Assert.assertEquals(endpointUser2.getId(), savedEndpointProfile.getEndpointUserId()); }
byte[] endpointKeyHash = Base64Util.decode(endpointDetachRequest.getEndpointKeyHash()); if (Arrays.equals(profile.getEndpointKeyHash(), endpointKeyHash)) { endpointService.detachEndpointFromUser(profile); response.setResult(SyncStatus.SUCCESS); } else { EndpointProfileDto detachEndpoint = endpointService.findEndpointProfileByKeyHash( endpointKeyHash); if (detachEndpoint != null) { if (detachEndpoint.getEndpointUserId() != null && detachEndpoint.getEndpointUserId().equals(profile.getEndpointUserId())) { endpointService.detachEndpointFromUser(detachEndpoint); response.setResult(SyncStatus.SUCCESS); } else {
@Override public EndpointGroupDto getEndpointGroup(String endpointGroupId) throws ControlServiceException { return endpointService.findEndpointGroupById(endpointGroupId); }
@Test public void removeEndpointGroupByAppIdTest() { String appId = generateApplicationDto().getId(); List<EndpointGroupDto> groupDtoList = endpointService.findEndpointGroupsByAppId(appId); Assert.assertNotNull(groupDtoList); Assert.assertFalse(groupDtoList.isEmpty()); endpointService.removeEndpointGroupByAppId(appId); groupDtoList = endpointService.findEndpointGroupsByAppId(appId); Assert.assertNotNull(groupDtoList); Assert.assertTrue(groupDtoList.isEmpty()); }
@Override public List<EndpointGroupDto> getEndpointGroupsByApplicationId(String applicationId) throws ControlServiceException { return endpointService.findEndpointGroupsByAppId(applicationId); }
@Override public EndpointProfileDto attachEndpointToUser(EndpointProfileDto profile, String appToken, String userExternalId) { String tenantId = cacheService.getTenantIdByAppToken(appToken); return endpointService.attachEndpointToUser(userExternalId, tenantId, profile); }
@Override public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(PageLinkDto pageLinkDto) throws ControlServiceException { return endpointService.findEndpointProfileBodyByEndpointGroupId(pageLinkDto); }
@Override @Cacheable("defaultGroups") public EndpointGroupDto getDefaultGroup(String applicationToken) { return defaultGroupMemorizer.compute(applicationToken, applicationToken1 -> { LOG.debug("Fetching result for token id"); ApplicationDto appDto = applicationService.findAppByApplicationToken(applicationToken1); return endpointService.findDefaultGroup(appDto.getId()); }); }
@Override public List<EndpointUserDto> getEndpointUsers() throws ControlServiceException { return endpointService.findAllEndpointUsers(); }
@Override public Void call() { try { endpointService.detachEndpointFromUser(attachedProfile); } catch (Throwable t) { LOG.error("Error: " + t.getMessage(), t); throw t; } return null; } }));