this.id = dto.getId(); this.applicationId = dto.getApplicationId(); this.endpointKey = dto.getEndpointKey(); this.endpointKeyHash = dto.getEndpointKeyHash(); this.endpointUserId = dto.getEndpointUserId(); this.accessToken = dto.getAccessToken(); this.groupState = MongoDaoUtil.convertDtoToModelList(dto.getGroupState()); this.sequenceNumber = dto.getSequenceNumber(); this.epsConfigurationHash = dto.getEpsConfigurationHash(); this.profile = MongoDaoUtil.encodeReservedCharacteres( (DBObject) JSON.parse(dto.getClientProfileBody())); this.profileHash = dto.getProfileHash(); this.profileVersion = dto.getClientProfileVersion(); this.serverProfileVersion = dto.getServerProfileVersion(); this.configurationHash = dto.getConfigurationHash(); this.userConfigurationHash = dto.getUserConfigurationHash(); this.configurationVersion = dto.getConfigurationVersion(); this.subscriptions = dto.getSubscriptions(); this.notificationVersion = dto.getNotificationVersion(); this.topicHash = dto.getTopicHash(); this.simpleTopicHash = dto.getSimpleTopicHash(); this.systemNfVersion = dto.getSystemNfVersion(); this.userNfVersion = dto.getUserNfVersion(); this.logSchemaVersion = dto.getLogSchemaVersion(); this.ecfVersionStates = MongoDaoUtil.convertEcfVersionDtoToModelList( dto.getEcfVersionStates()); this.serverHash = dto.getServerHash(); this.sdkToken = dto.getSdkToken(); this.serverProfile = MongoDaoUtil.encodeReservedCharacteres(
@Override public EndpointProfileDto toDto() { EndpointProfileDto dto = new EndpointProfileDto(); dto.setId(id); dto.setGroupState(DaoUtil.convertDtoList(groupState)); dto.setSequenceNumber(sequenceNumber); dto.setConfigurationHash(configurationHash); dto.setUserConfigurationHash(userConfigurationHash); dto.setEpsConfigurationHash(epsConfigurationHash); dto.setConfigurationVersion(configurationVersion); dto.setApplicationId(applicationId); dto.setEndpointKey(endpointKey); dto.setEndpointKeyHash(endpointKeyHash); dto.setEndpointUserId(endpointUserId); dto.setAccessToken(accessToken); dto.setClientProfileBody( profile != null ? MongoDaoUtil.decodeReservedCharacteres(profile).toString() : ""); dto.setProfileHash(profileHash); dto.setClientProfileVersion(profileVersion); dto.setServerProfileVersion(serverProfileVersion); dto.setNotificationVersion(notificationVersion); dto.setSubscriptions(subscriptions); dto.setTopicHash(topicHash); dto.setSimpleTopicHash(simpleTopicHash); dto.setSystemNfVersion(systemNfVersion); dto.setUserNfVersion(userNfVersion); dto.setLogSchemaVersion(logSchemaVersion); dto.setEcfVersionStates(DaoUtil.convertDtoList(ecfVersionStates));
private EndpointProfileDataDto convert(EndpointProfileDto profileDto) { return new EndpointProfileDataDto( profileDto.getId(), endpointKey, profileDto.getClientProfileVersion(), profileDto.getClientProfileBody(), profileDto.getServerProfileVersion(), profileDto.getServerProfileBody()); }
@Override public Optional<EndpointSpecificConfigurationDto> findActiveConfigurationByEndpointProfile(EndpointProfileDto endpointProfileDto) { byte[] endpointKeyHash = endpointProfileDto.getEndpointKeyHash(); int configurationVersion = endpointProfileDto.getConfigurationVersion(); EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, configurationVersion); return Optional.ofNullable(configuration).map(ToDto::toDto); }
dto = new EndpointProfileDto(); dto.setSdkToken(sdkProfile.getToken()); dto.setApplicationId(appSeqNumber.getAppId()); dto.setEndpointKey(request.getEndpointKey()); dto.setEndpointKeyHash(keyHash.getData()); dto.setClientProfileBody(profileJson); dto.setProfileHash(EndpointObjectHash.fromSha1(request.getProfile()).getData()); if (endpointRegistrationLookup.isPresent()) { LOG.debug("Endpoint registration information found {}: {}", dto.getEndpointKey(), endpointRegistrationLookup.get()); EndpointRegistrationDto endpointRegistration = endpointRegistrationLookup.get(); if (endpointRegistration.getServerProfileBody() != null && endpointRegistration.getServerProfileVersion() != null) { dto.setServerProfileVersion(endpointRegistration.getServerProfileVersion()); dto.setServerProfileBody(endpointRegistration.getServerProfileBody()); LOG.debug("Endpoint registration information not found {}", dto.getEndpointKey()); dto.getEndpointKey(), ex); throw new RuntimeException(ex); dto.setAccessToken(request.getAccessToken()); dto.setSequenceNumber(0); cacheService.putEndpointKey(keyHash, KeyUtil.getPublic(dto.getEndpointKey())); } catch (InvalidKeyException ex) { LOG.error("Can't generate public key for endpoint key: {}. Reason: {}",
protected EndpointProfileDto generateEndpointProfileForTestUpdate(String id, byte[] keyHash, List<EndpointGroupStateDto> cfGroupState) { EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setId(id); profileDto.setEndpointKeyHash(keyHash); profileDto.setApplicationId(generateStringId()); profileDto.setAccessToken(generateStringId()); profileDto.setGroupState(cfGroupState); profileDto.setSdkToken(UUID.randomUUID().toString()); profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); return profileDto; }
+ "profile object " + endpointProfileDto); byte[] keyHash = endpointProfileDto.getEndpointKeyHash(); validateHash(keyHash, "Incorrect key hash for endpoint profile."); if (endpointProfileDto.getServerProfileBody() == null) { ServerProfileSchemaDto serverProfileSchemaDto = serverProfileService .findLatestServerProfileSchema(endpointProfileDto.getApplicationId()); CTLSchemaDto schemaDto = ctlService.findCtlSchemaById( serverProfileSchemaDto.getCtlSchemaId()); + "key [{}]", serverProfileSchemaDto.getVersion(), schemaDto.getBody(), keyHash); endpointProfileDto.setServerProfileVersion(serverProfileSchemaDto.getVersion()); endpointProfileDto.setServerProfileBody(schemaDto.getDefaultRecord()); if (isBlank(endpointProfileDto.getId())) { EndpointProfile storedProfile = endpointProfileDao.findByKeyHash(keyHash); if (storedProfile dto = getDto(endpointProfileDao.save(endpointProfileDto)); } else { if (Arrays.equals(storedProfile.getEndpointKey(), endpointProfileDto.getEndpointKey())) { LOG.debug("Got register profile for already existing profile {}. Will overwrite " + "existing profile!", keyHash); endpointProfileDto.setId(storedProfile.getId()); endpointProfileDto.setVersion(storedProfile.getVersion()); dto = getDto(endpointProfileDao.save(endpointProfileDto)); } else {
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(); }
endpointProfileKeyHash); Utils.checkNotNull(endpointProfile); checkApplicationId(endpointProfile.getApplicationId()); EndpointProfileViewDto endpointProfileView = new EndpointProfileViewDto(); endpointProfileView.setEndpointKeyHash(endpointProfile.getEndpointKeyHash()); endpointProfileView.setSdkProfileDto(controlService.findSdkProfileByToken( endpointProfile.getSdkToken())); if (endpointProfile.getEndpointUserId() != null) { EndpointUserDto endpointUser = controlService.getEndpointUser( endpointProfile.getEndpointUserId()); if (endpointUser != null) { endpointProfileView.setUserId(endpointUser.getId()); endpointProfile.getApplicationId(), endpointProfile.getClientProfileVersion()); ServerProfileSchemaDto serverProfileSchema = controlService.getServerProfileSchemaByApplicationIdAndVersion( endpointProfile.getApplicationId(), endpointProfile.getServerProfileVersion()); endpointProfileView.setProfileSchemaName(clientProfileSchema.getName()); endpointProfileView.setProfileSchemaVersion(clientProfileSchema.toVersionDto()); endpointProfileView.setProfileRecord(createRecordFieldFromCtlSchemaAndBody( clientProfileSchema.getCtlSchemaId(), endpointProfile.getClientProfileBody())); endpointProfileView.setServerProfileRecord(createRecordFieldFromCtlSchemaAndBody( serverProfileSchema.getCtlSchemaId(), endpointProfile.getServerProfileBody()));
protected EndpointProfileDto generateEndpointProfile(String appId, String sdkToken, String accessToken, List<String> topicIds, CtlDataDto ctlDataDto) { byte[] keyHash = generateBytes(); if (appId == null) { appId = generateStringId(); } if (sdkToken == null) { sdkToken = generateStringId(); } if (accessToken == null) { accessToken = generateStringId(); } EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setApplicationId(appId); profileDto.setSdkToken(sdkToken); profileDto.setSubscriptions(topicIds); profileDto.setEndpointKeyHash(keyHash); profileDto.setAccessToken(accessToken); profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); if (ctlDataDto != null) { profileDto.setServerProfileBody(ctlDataDto.getBody()); profileDto.setServerProfileVersion(ctlDataDto.getServerProfileVersion()); } return endpointProfileDao.save(new CassandraEndpointProfile(profileDto)).toDto(); }
protected EndpointProfileDto generateEndpointProfileDtoWithSchemaVersion(String appId, int schemaVersion, String srvProfileBody) { EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setApplicationId(appId); profileDto.setServerProfileVersion(schemaVersion); profileDto.setEndpointKeyHash("TEST_KEY_HASH".getBytes()); profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); try { profileDto.setClientProfileBody(readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); } catch (IOException e) { LOG.error("Can't set client-side EP body {}", e); } profileDto.setSdkToken(UUID.randomUUID().toString()); profileDto.setServerProfileBody(srvProfileBody); return endpointService.saveEndpointProfile(profileDto); }
protected EndpointProfileDto generateEndpointProfileDto(String appId, List<String> topicIds) { if (isBlank(appId)) { appId = generateApplicationDto().getId(); } EndpointProfileDto profileDto = new EndpointProfileDto(); profileDto.setApplicationId(appId); profileDto.setSubscriptions(topicIds); profileDto.setEndpointKeyHash("TEST_KEY_HASH".getBytes()); profileDto.setServerProfileBody("{\"serverTitle\": \"SERVER_TEST\"}"); profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); try { profileDto.setClientProfileBody(readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); } catch (IOException e) { LOG.error("Can't set client-side EP body {}", e); } profileDto.setSdkToken(UUID.randomUUID().toString()); return endpointService.saveEndpointProfile(profileDto); }
@Override public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile body by endpoint key hash [{}] ", endpointKeyHash); EndpointProfileBodyDto endpointProfileBodyDto = null; Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash)); query.fields() .include(DaoConstants.PROFILE) .include(EP_SERVER_PROFILE_PROPERTY) .include(EP_APPLICATION_ID) .include(EP_PROFILE_VERSION) .include(EP_SERVER_PROFILE_VERSION_PROPERTY) .include(EP_USE_RAW_SCHEMA); EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto(); if (pf != null) { endpointProfileBodyDto = new EndpointProfileBodyDto( endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); } LOG.debug("[{}] Found client-side endpoint profile body {} with client-side endpoint " + "profile version {} and server-side endpoint profile body {} " + "with server-side endpoint profile version {} and application id {}", endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); return endpointProfileBodyDto; }
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); }
@Override public void detachEndpointFromUser(EndpointProfileDto endpoint) { String endpointUserId = endpoint.getEndpointUserId(); validateString(endpointUserId, "Incorrect endpointUserId " + endpointUserId); if (endpointIds != null && endpointIds.contains(endpoint.getId())) { endpointIds.remove(endpoint.getId()); } else { LOG.warn("Endpoint is not assigned to current user {}!", endpointUserId); try { LOG.trace("Save endpoint user {} and endpoint profile {}", endpointUser, endpoint); endpoint.setEndpointUserId(null); saveEndpointProfile(endpoint); break; } catch (KaaOptimisticLockingFailureException ex) { LOG.warn("Optimistic lock detected in endpoint profile ", Arrays.toString(endpoint .getEndpointKey()), ex); endpoint = getDto(endpointProfileDao.findByKeyHash(Sha1HashUtils.hashToBytes(endpoint .getEndpointKey())));
@Override public void init(EndpointProfileDto profile, String profileSchemaBody, String serverProfileSchemaBody) { GenericAvroConverter<GenericRecord> endpointProfileConverter = new GenericAvroConverter<>( new Schema.Parser().parse(profileSchemaBody)); GenericAvroConverter<GenericRecord> serverProfileConverter = new GenericAvroConverter<>( new Schema.Parser().parse(serverProfileSchemaBody)); this.epKey = Base64Util.encode(profile.getEndpointKeyHash()); try { if (profile.getServerProfileBody() != null) { serverProfileGenericRecord = serverProfileConverter.decodeJson( profile.getServerProfileBody()); } if (profile.getClientProfileBody() != null) { clientProfileGenericRecord = endpointProfileConverter.decodeJson( profile.getClientProfileBody()); } } catch (IOException ioe) { LOG.error("Error decoding avro object from Json string", ioe); } }
@Override public String getValue(EndpointProfileDto item) { return BaseEncoding.base64().encode(item.getEndpointKeyHash()); } }, 160);
String appToken, EventListenersRequest request) { if (profile.getEndpointUserId() == null || profile.getEndpointUserId().isEmpty()) { LOG.info("Can't find listeners for unassigned endpoint!"); return new EventListenersResponse(request.getRequestId(), null, SyncStatus.FAILURE); profile.getEndpointUserId()); if (endpointProfiles.size() <= 1) { LOG.info("There is only one endpoint(current) assigned to this user!"); new EventClassFqnKey(tenantId, eventClassFqn)); int version = 0; for (EventClassFamilyVersionStateDto ecfVersionDto : profile.getEcfVersionStates()) { if (ecfVersionDto.getEcfId().equals(ecfId)) { version = ecfVersionDto.getVersion(); if (endpointProfile.getId().equals(profile.getId())) { continue; AppSeqNumber endpointProfileSeqNumber = cacheService.getAppSeqNumber( routeTableKey.getAppToken()); if (!endpointProfile.getApplicationId().equals(endpointProfileSeqNumber.getAppId())) { continue; for (EventClassFamilyVersionStateDto ecfVersionDto : profile.getEcfVersionStates()) { if (ecfVersionDto.getEcfId().equals(routeTableKey.getEcfVersion().getEcfId()) && ecfVersionDto.getVersion() == routeTableKey.getEcfVersion().getVersion()) { eventClassSet.add( EndpointObjectHash.fromBytes(endpointProfile.getEndpointKeyHash()));
@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()); }
private EndpointProfileDto generateProfile() { EndpointProfileDto profile = new EndpointProfileDto(); profile.setEndpointKeyHash(KEY); profile.setConfigurationVersion(CONF_VERSION); profile.setApplicationId(APP_ID); return profile; }