int iId = md.getId();
OperationAllowedRepository allowedRepository = context.getBean(OperationAllowedRepository.class);
GroupRepository groupRepository = context.getBean(GroupRepository.class);
OperationRepository operationRepository = context.getBean(OperationRepository.class);
allowedRepository.findAllById_MetadataId(iId);
// Get group Owner ID
Integer grpOwnerId = md.getSourceInfo().getGroupOwner();
String grpOwnerName = "";
HashMap<String, ArrayList<String>> hmPriv = new HashMap<String, ArrayList<String>>();
// --- retrieve accessible groups
GeonetContext gc = (GeonetContext) context
.getHandlerContext(Geonet.CONTEXT_NAME);
AccessManager am = gc.getBean(AccessManager.class);
Set<Integer> userGroups = am.getUserGroups(context.getUserSession(), context.getIpAddress(), false);
// --- scan query result to collect info
OperationAllowedRepository operationAllowedRepository = context.getBean(OperationAllowedRepository.class);
List<OperationAllowed> opsAllowed = operationAllowedRepository.findAllById_MetadataId(iId);
for (OperationAllowed operationAllowed : opsAllowed) {
int grpId = operationAllowed.getId().getGroupId();
Group group = groupRepository.findOne(grpId);
String grpName = group.getName();
if (!userGroups.contains(grpId)) {
continue;
}
Operation operation = operationRepository.findOne(operationAllowed.getId().getOperationId());
String operName = operation.getName();
if (grpOwnerId != null && grpOwnerId == grpId) {
grpOwnerName = grpName;
}