private void updateGrantedConsentEntity(UserConsentEntity consentEntity, UserConsentModel consentModel) { Collection<UserConsentClientScopeEntity> grantedClientScopeEntities = consentEntity.getGrantedClientScopes(); Collection<UserConsentClientScopeEntity> scopesToRemove = new HashSet<>(grantedClientScopeEntities); for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) { UserConsentClientScopeEntity grantedClientScopeEntity = new UserConsentClientScopeEntity(); grantedClientScopeEntity.setUserConsent(consentEntity); grantedClientScopeEntity.setScopeId(clientScope.getId()); // Check if it's already there if (!grantedClientScopeEntities.contains(grantedClientScopeEntity)) { em.persist(grantedClientScopeEntity); em.flush(); grantedClientScopeEntities.add(grantedClientScopeEntity); } else { scopesToRemove.remove(grantedClientScopeEntity); } } // Those client scopes were no longer on consentModel and will be removed for (UserConsentClientScopeEntity toRemove : scopesToRemove) { grantedClientScopeEntities.remove(toRemove); em.remove(toRemove); } consentEntity.setLastUpdatedDate(Time.currentTimeMillis()); em.flush(); }
private void updateGrantedConsentEntity(FederatedUserConsentEntity consentEntity, UserConsentModel consentModel) { Collection<FederatedUserConsentClientScopeEntity> grantedClientScopeEntities = consentEntity.getGrantedClientScopes(); Collection<FederatedUserConsentClientScopeEntity> scopesToRemove = new HashSet<>(grantedClientScopeEntities); for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) { FederatedUserConsentClientScopeEntity grantedClientScopeEntity = new FederatedUserConsentClientScopeEntity(); grantedClientScopeEntity.setUserConsent(consentEntity); grantedClientScopeEntity.setScopeId(clientScope.getId()); // Check if it's already there if (!grantedClientScopeEntities.contains(grantedClientScopeEntity)) { em.persist(grantedClientScopeEntity); em.flush(); grantedClientScopeEntities.add(grantedClientScopeEntity); } else { scopesToRemove.remove(grantedClientScopeEntity); } } // Those mappers were no longer on consentModel and will be removed for (FederatedUserConsentClientScopeEntity toRemove : scopesToRemove) { grantedClientScopeEntities.remove(toRemove); em.remove(toRemove); } consentEntity.setLastUpdatedDate(Time.currentTimeMillis()); em.flush(); }
public CachedUserConsent(UserConsentModel consentModel) { this.clientDbId = consentModel.getClient().getId(); for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) { this.clientScopeIds.add(clientScope.getId()); } this.createdDate = consentModel.getCreatedDate(); this.lastUpdatedDate = consentModel.getLastUpdatedDate(); }