Commit 06f03651 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'jdbc-get-member-groups-fix' into 'master'

GET MEMBERS request doesnt return a member group in case member is a group (GONRG-3535)

See merge request !131
parents 6c83d492 b6e808c7
Pipeline #71341 failed with stages
in 44 minutes and 19 seconds
......@@ -19,6 +19,7 @@ package org.opengroup.osdu.entitlements.v2.jdbc.service;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.entitlements.v2.jdbc.JdbcAppProperties;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.ParentReference;
import org.opengroup.osdu.entitlements.v2.service.GroupCacheService;
......@@ -28,33 +29,41 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class GroupCacheServiceJdbc implements GroupCacheService {
private final RetrieveGroupRepo retrieveGroupRepo;
private final VmGroupCache vmGroupCache;
private static final String CACHE_KEY_FORMAT = "%s-%s";
private static final String CACHE_KEY_FORMAT = "%s-%s";
@Override
public Set<ParentReference> getFromPartitionCache(String requesterId, String partitionId) {
String key = String.format(CACHE_KEY_FORMAT, requesterId, partitionId);
Set<ParentReference> result = vmGroupCache.getGroupCache(key);
if (result == null) {
EntityNode entityNode = EntityNode.createMemberNodeForNewUser(requesterId, partitionId);
result = retrieveGroupRepo.loadAllParents(entityNode).getParentReferences();
vmGroupCache.addGroupCache(key, result);
}
return result;
}
@Override
public void refreshListGroupCache(Set<String> userIds, String partitionId) {
for (String userId: userIds) {
String key = String.format(CACHE_KEY_FORMAT, userId, partitionId);
EntityNode entityNode = EntityNode.createMemberNodeForNewUser(userId, partitionId);
vmGroupCache.addGroupCache(key, retrieveGroupRepo.loadAllParents(entityNode).getParentReferences());
}
}
private final RetrieveGroupRepo retrieveGroupRepo;
private final VmGroupCache vmGroupCache;
private final JdbcAppProperties config;
@Override
public void flushListGroupCacheForUser(String userId, String partitionId) {
String key = String.format(CACHE_KEY_FORMAT, userId, partitionId);
vmGroupCache.deleteGroupCache(key);
}
@Override
public Set<ParentReference> getFromPartitionCache(String requesterId, String partitionId) {
String key = String.format(CACHE_KEY_FORMAT, requesterId, partitionId);
Set<ParentReference> result = vmGroupCache.getGroupCache(key);
if (result == null) {
EntityNode entityNode = getNodeByNodeType(requesterId, partitionId);
result = retrieveGroupRepo.loadAllParents(entityNode).getParentReferences();
vmGroupCache.addGroupCache(key, result);
}
return result;
}
@Override
public void refreshListGroupCache(Set<String> userIds, String partitionId) {
for (String userId: userIds) {
String key = String.format(CACHE_KEY_FORMAT, userId, partitionId);
EntityNode entityNode = EntityNode.createMemberNodeForNewUser(userId, partitionId);
vmGroupCache.addGroupCache(key, retrieveGroupRepo.loadAllParents(entityNode).getParentReferences());
}
}
@Override
public void flushListGroupCacheForUser(String userId, String partitionId) {
String key = String.format(CACHE_KEY_FORMAT, userId, partitionId);
vmGroupCache.deleteGroupCache(key);
}
private EntityNode getNodeByNodeType(String memberId, String partitionId) {
return memberId.endsWith(String.format("@%s.%s", partitionId, config.getDomain()))
? EntityNode.createNodeFromGroupEmail(memberId)
: EntityNode.createMemberNodeForNewUser(memberId, partitionId);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment