public GetInstitutionsResponse getInstitutions()

in services/src/main/java/org/apache/custos/service/federated/cilogon/FederatedAuthenticationService.java [288:338]


    public GetInstitutionsResponse getInstitutions(CacheManipulationRequest request) {
        try {
            LOGGER.debug("Calling getInstitutions API for tenantId " + request.getTenantId());

            long tenant = request.getTenantId();
            List<CILogonInstitution> institutions = institutionRepository.findAllByTenantIdAndType(tenant, InstitutionCacheType.ALLOWLIST.name());
            List<CILogonInstitution> blockedInstitutions = institutionRepository.findAllByTenantIdAndType(tenant, InstitutionCacheType.BLOCKLIST.name());

            org.apache.custos.service.federated.client.cilogon.CILogonInstitution[] ciLogonInstitutions = ciLogonClient.getInstitutions();
            List<org.apache.custos.service.federated.client.cilogon.CILogonInstitution> selectedLists = new ArrayList<>();

            if (institutions.isEmpty() && blockedInstitutions.isEmpty()) {
                selectedLists.addAll(Arrays.asList(ciLogonInstitutions));

            } else if (!institutions.isEmpty()) {
                for (org.apache.custos.service.federated.client.cilogon.CILogonInstitution ciLogonInstitution : ciLogonInstitutions) {
                    institutions.forEach(it -> {
                        if (it.getInstitutionId().equals(ciLogonInstitution.getEntityId()) && it.getType().equals(InstitutionCacheType.ALLOWLIST.name())) {
                            selectedLists.add(ciLogonInstitution);
                        }
                    });
                }

            } else {
                for (org.apache.custos.service.federated.client.cilogon.CILogonInstitution ciLogonInstitution : ciLogonInstitutions) {
                    AtomicBoolean doNotAdd = new AtomicBoolean(false);
                    for (CILogonInstitution it : blockedInstitutions) {
                        if (it.getInstitutionId().equals(ciLogonInstitution.getEntityId())) {
                            doNotAdd.set(true);
                            break;
                        }
                    }

                    if (!doNotAdd.get()) {
                        selectedLists.add(ciLogonInstitution);
                    }

                }
            }

            List<Institution> institutionList = new ArrayList<>();
            selectedLists.forEach(sl -> institutionList.add(convertCILogonToInstitution(sl)));

            return GetInstitutionsResponse.newBuilder().addAllInstitutions(institutionList).build();

        } catch (Exception ex) {
            String msg = " Error at federated authentication core service " + ex;
            LOGGER.error(msg);
            throw new InternalServerException(msg, ex);
        }
    }