private EndpointProfileDataDto convert(EndpointProfileDto profileDto) { return new EndpointProfileDataDto( profileDto.getId(), endpointKey, profileDto.getClientProfileVersion(), profileDto.getClientProfileBody(), profileDto.getServerProfileVersion(), profileDto.getServerProfileBody()); }
private EndpointProfileDto registerEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] register endpoint. request: {}", endpointId, requestHash, request); byte[] endpointKey = toByteArray(request.getEndpointPublicKey()); byte[] profileBody = toByteArray(request.getProfileBody()); RegisterProfileRequest registerProfileRequest = new RegisterProfileRequest( metaData.getApplicationToken(), endpointKey, metaData.getSdkToken(), profileBody, request.getEndpointAccessToken()); EndpointProfileDto endpointProfile = profileService.registerProfile(registerProfileRequest); LOG.debug("profile registered. id: {}, endpointKeyHash: {}", endpointProfile.getId(), endpointProfile.getEndpointKeyHash()); return endpointProfile; }
private EndpointProfileDto updateEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] update endpoint. request: {}", endpointId, requestHash, request); EndpointObjectHash endpointKeyHash = EndpointObjectHash.fromBytes( toByteArray(metaData.getEndpointPublicKeyHash())); UpdateProfileRequest updateRequest = new UpdateProfileRequest( metaData.getApplicationToken(), endpointKeyHash, request.getEndpointAccessToken(), request.getProfileBody().array(), metaData.getSdkToken()); EndpointProfileDto endpointProfile = profileService.updateProfile(updateRequest); LOG.debug("profile updated. id: {}, endpointKeyHash: {}", endpointProfile.getId(), endpointProfile.getEndpointKeyHash()); return endpointProfile; }
@Test public void testFindByEndpointUserId() throws Exception { EndpointProfileDto endpointProfileDto = generateEndpointProfile(null, null, null, null); EndpointUserDto endpointUserDto = generateEndpointUser(Arrays.asList(endpointProfileDto.getId())); List<CassandraEndpointProfile> found = endpointProfileDao.findByEndpointUserId(endpointUserDto.getId()); Assert.assertFalse(found.isEmpty()); Assert.assertEquals(endpointProfileDto, found.get(0).toDto()); }
EndpointUser endpointUser = endpointUserDao.findByExternalIdAndTenantId(userExternalId, tenantId); String currentEndpointUserId = profile.getEndpointUserId(); String endpointId = profile.getId(); if (endpointUser == null) { LOG.info("Creating new endpoint user with external id: [{}] in context of [{}] tenant", userExternalId, tenantId);
endpointService.saveEndpointProfile(endpointProfileDto); accessTokens.add(accessToken); endpointIds.add(endpointProfileDto.getId());
@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 attachEndpointToNewUserByExternalIdTest() { TenantDto tenant = generateTenantDto(); String endpointGroupId = "124"; EndpointProfileDto endpointProfile = generateEndpointProfileWithGroupIdDto(endpointGroupId); String userExternalId = UUID.randomUUID().toString(); String tenantId = tenant.getId(); EndpointProfileDto savedEndpointProfile = endpointService.attachEndpointToUser(userExternalId, tenantId, endpointProfile); Assert.assertNotNull(savedEndpointProfile); Assert.assertNotNull(savedEndpointProfile.getEndpointUserId()); EndpointUserDto attachedEndpointUser = endpointService.findEndpointUserById(savedEndpointProfile.getEndpointUserId()); Assert.assertNotNull(attachedEndpointUser); Assert.assertEquals(userExternalId, attachedEndpointUser.getExternalId()); Assert.assertEquals(userExternalId, attachedEndpointUser.getUsername()); 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 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()); }
@Test public void testFindEndpointIdByKeyHash() throws Exception { EndpointProfileDto endpointProfile = generateEndpointProfile(null, null, null, null); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }
@Test public void attachEndpointToExistingUserByExternalIdTest() { 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); 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 testFindEndpointIdByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }
@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)); }
this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.endpointKey = dto.getEndpointKey();
this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.endpointProfileKey = getByteBuffer(dto.getEndpointKey());