public String getAppToken() { return metaData.getApplicationToken(); }
@Override public SyncContext syncConfiguration(SyncContext context, ConfigurationClientSync request) throws GetDeltaException { if (request != null) { GetDeltaResponse confResponse = calculateConfigurationDelta( context.getMetaData().getApplicationToken(), request, context); ConfigurationServerSync confSyncResponse = buildConfSyncResponse(confResponse); context.setConfigurationSyncResponse(confSyncResponse); } return context; }
@Override public EndpointProfileDto updateProfile(ClientSyncMetaData metaData, EndpointObjectHash keyHash, boolean useConfigurationRawSchema) { LOG.debug("Updating Profile for {}", keyHash); EndpointProfileDto dto = endpointService.findEndpointProfileByKeyHash(keyHash.getData()); AppSeqNumber appSeqNumber = cacheService.getAppSeqNumber(metaData.getApplicationToken()); SdkProfileDto sdkProfile = cacheService.getSdkProfileBySdkToken(metaData.getSdkToken()); Function<EndpointProfileDto, EndpointProfileDto> updateFunction = profile -> { populateVersionStates(appSeqNumber.getTenantId(), profile, sdkProfile); profile.setGroupState(new ArrayList<>()); profile.setUseConfigurationRawSchema(useConfigurationRawSchema); profile.setSequenceNumber(0); return profile; }; return updateProfile(updateFunction.apply(dto), (storedProfile, newProfile) -> { return updateFunction.apply(storedProfile); }); }
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; }
@Override public SyncContext processEventListenerRequests(SyncContext context, EventClientSync request) { if (request != null) { ClientSyncMetaData metaData = context.getMetaData(); LOG.trace("[{}][{}] procesing event sync request {}.", context.getEndpointKey(), context.getRequestHash(), request); EventServerSync eventSyncResponse = processEventSyncResponse( context.getEndpointKey(), context.getRequestHash(), metaData.getApplicationToken(), request, context.getEndpointProfile()); context.setEventSyncResponse(eventSyncResponse); } return context; }
@Override public SyncContext syncNotification(SyncContext context, NotificationClientSync request) { if (request != null) { GetNotificationResponse notificationResponse = calculateNotificationDelta( context.getMetaData().getApplicationToken(), request, context); context.setSubscriptionStates(notificationResponse.getSubscriptionStates()); NotificationServerSync nfSyncResponse = buildNotificationSyncResponse(notificationResponse); context.setNotificationSyncResponse(nfSyncResponse); if (notificationResponse.isSubscriptionListChanged()) { EndpointProfileDto profileDto = context.getEndpointProfile(); Function<EndpointProfileDto, EndpointProfileDto> updateFunction = profile -> { profile.setSubscriptions(new ArrayList<>(notificationResponse.getSubscriptionSet())); return profile; }; context.setNotificationVersion(profileService.updateProfile( updateFunction.apply(profileDto), (storedProfile, newProfile) -> { return updateFunction.apply(storedProfile); })); } } return context; }
@Override public SyncContext syncUseConfigurationRawSchema(SyncContext context, boolean useConfigurationRawSchema) { EndpointProfileDto profile = context.getEndpointProfile(); if (profile.isUseConfigurationRawSchema() != useConfigurationRawSchema) { ClientSyncMetaData metaData = context.getMetaData(); EndpointObjectHash endpointKeyHash = EndpointObjectHash.fromBytes( toByteArray(metaData.getEndpointPublicKeyHash())); profile = profileService.updateProfile(metaData, endpointKeyHash, useConfigurationRawSchema); profile = syncProfileState( metaData.getApplicationToken(), context.getEndpointKey(), profile, false); context.setNotificationVersion(profile); } return context; }
metaData.getApplicationToken(), context.getEndpointKey(), profile, false);
diff.setClientSyncMetaData(other.getClientSyncMetaData()); diff.setUseConfigurationRawSchema(other.isUseConfigurationRawSchema()); if (request.getClientSyncMetaData().getApplicationToken() != null) { LOG.debug("Setting application token, as it was null: {}", request.getClientSyncMetaData().getApplicationToken()); diff.getClientSyncMetaData() .setApplicationToken(request.getClientSyncMetaData().getApplicationToken()); } else { LOG.trace("[{}] Application token is null for request", request);