@Test @RunWithCustomExecutor public void testForSomeOriginatingAgency() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); AccessContractModel mockedContract = new AccessContractModel(); mockedContract.setId(CONTRACT_ID); mockedContract.setEveryOriginatingAgency(false); Set<String> originatingAgencies = new HashSet<>(); originatingAgencies.add("FRAN_AGENCY_1"); originatingAgencies.add("FRAN_AGENCY_2"); mockedContract.setOriginatingAgencies(originatingAgencies); RequestResponseOK<AccessContractModel> mockedResponse = new RequestResponseOK<>(); mockedResponse.setHttpCode(200); mockedResponse.addResult(mockedContract); when(adminManagementClient.findAccessContracts(any())) .thenReturn(mockedResponse); MultivaluedMap<String, String> requestHeaders = new MultivaluedHashMap<>(); requestHeaders.putSingle(GlobalDataRest.X_ACCESS_CONTRAT_ID, CONTRACT_ID); AccessContractIdHeaderHelper.manageAccessContractFromHeader(requestHeaders, adminManagementClientFactory); assertFalse(VitamThreadUtils.getVitamSession().getContract().getEveryOriginatingAgency()); assertEquals(originatingAgencies, VitamThreadUtils.getVitamSession().getContract().getOriginatingAgencies()); }
public static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders, AdminManagementClientFactory adminManagementClientFactory) throws MissingAccessContractIdException { try (final AdminManagementClient client = adminManagementClientFactory.getClient()) { String headerAccessContractId = requestHeaders.getFirst(GlobalDataRest.X_ACCESS_CONTRAT_ID); if (headerAccessContractId == null) { throw new MissingAccessContractIdException( "Missing access contract header " + GlobalDataRest.X_ACCESS_CONTRAT_ID); } JsonNode queryDsl = getQueryDsl(headerAccessContractId); RequestResponse<AccessContractModel> response = client.findAccessContracts(queryDsl); if (!response.isOk()) { VitamError vitamError = (VitamError) response; throw new MissingAccessContractIdException( vitamError.getMessage() + " : " + vitamError.getDescription()); } if (((RequestResponseOK<AccessContractModel>) response).getResults().size() == 0) { throw new MissingAccessContractIdException(headerAccessContractId + " not found in the system"); } List<AccessContractModel> contracts = ((RequestResponseOK<AccessContractModel>) response).getResults(); VitamThreadUtils.getVitamSession().setContract(contracts.get(0)); } catch (final VitamThreadAccessException | AdminManagementClientServerException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new MissingAccessContractIdException( "Got an exception while trying to check the access contract in the current session ; exception was : {}", e); } }
AccessContractIdHeaderHelper { public static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders, AdminManagementClientFactory adminManagementClientFactory) throws MissingAccessContractIdException { try (final AdminManagementClient client = adminManagementClientFactory.getClient()) { String headerAccessContractId = requestHeaders.getFirst(GlobalDataRest.X_ACCESS_CONTRAT_ID); if (headerAccessContractId == null) { throw new MissingAccessContractIdException( "Missing access contract header " + GlobalDataRest.X_ACCESS_CONTRAT_ID); } JsonNode queryDsl = getQueryDsl(headerAccessContractId); RequestResponse<AccessContractModel> response = client.findAccessContracts(queryDsl); if (!response.isOk()) { VitamError vitamError = (VitamError) response; throw new MissingAccessContractIdException( vitamError.getMessage() + " : " + vitamError.getDescription()); } if (((RequestResponseOK<AccessContractModel>) response).getResults().size() == 0) { throw new MissingAccessContractIdException(headerAccessContractId + " not found in the system"); } List<AccessContractModel> contracts = ((RequestResponseOK<AccessContractModel>) response).getResults(); VitamThreadUtils.getVitamSession().setContract(contracts.get(0)); } catch (final VitamThreadAccessException | AdminManagementClientServerException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new MissingAccessContractIdException( "Got an exception while trying to check the access contract in the current session ; exception was : {}", e); } } }
AccessContractIdHeaderHelper { public static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders, AdminManagementClientFactory adminManagementClientFactory) throws MissingAccessContractIdException { try (final AdminManagementClient client = adminManagementClientFactory.getClient()) { String headerAccessContractId = requestHeaders.getFirst(GlobalDataRest.X_ACCESS_CONTRAT_ID); if (headerAccessContractId == null) { throw new MissingAccessContractIdException( "Missing access contract header " + GlobalDataRest.X_ACCESS_CONTRAT_ID); } JsonNode queryDsl = getQueryDsl(headerAccessContractId); RequestResponse<AccessContractModel> response = client.findAccessContracts(queryDsl); if (!response.isOk()) { VitamError vitamError = (VitamError) response; throw new MissingAccessContractIdException( vitamError.getMessage() + " : " + vitamError.getDescription()); } if (((RequestResponseOK<AccessContractModel>) response).getResults().size() == 0) { throw new MissingAccessContractIdException(headerAccessContractId + " not found in the system"); } List<AccessContractModel> contracts = ((RequestResponseOK<AccessContractModel>) response).getResults(); VitamThreadUtils.getVitamSession().setContract(contracts.get(0)); } catch (final VitamThreadAccessException | AdminManagementClientServerException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new MissingAccessContractIdException( "Got an exception while trying to check the access contract in the current session ; exception was : {}", e); } } private  AccessContractIdHeaderHelper(); }
AccessContractIdHeaderHelper { public static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders, AdminManagementClientFactory adminManagementClientFactory) throws MissingAccessContractIdException { try (final AdminManagementClient client = adminManagementClientFactory.getClient()) { String headerAccessContractId = requestHeaders.getFirst(GlobalDataRest.X_ACCESS_CONTRAT_ID); if (headerAccessContractId == null) { throw new MissingAccessContractIdException( "Missing access contract header " + GlobalDataRest.X_ACCESS_CONTRAT_ID); } JsonNode queryDsl = getQueryDsl(headerAccessContractId); RequestResponse<AccessContractModel> response = client.findAccessContracts(queryDsl); if (!response.isOk()) { VitamError vitamError = (VitamError) response; throw new MissingAccessContractIdException( vitamError.getMessage() + " : " + vitamError.getDescription()); } if (((RequestResponseOK<AccessContractModel>) response).getResults().size() == 0) { throw new MissingAccessContractIdException(headerAccessContractId + " not found in the system"); } List<AccessContractModel> contracts = ((RequestResponseOK<AccessContractModel>) response).getResults(); VitamThreadUtils.getVitamSession().setContract(contracts.get(0)); } catch (final VitamThreadAccessException | AdminManagementClientServerException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new MissingAccessContractIdException( "Got an exception while trying to check the access contract in the current session ; exception was : {}", e); } } private  AccessContractIdHeaderHelper(); static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders,
        AdminManagementClientFactory adminManagementClientFactory); }
AccessContractIdHeaderHelper { public static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders, AdminManagementClientFactory adminManagementClientFactory) throws MissingAccessContractIdException { try (final AdminManagementClient client = adminManagementClientFactory.getClient()) { String headerAccessContractId = requestHeaders.getFirst(GlobalDataRest.X_ACCESS_CONTRAT_ID); if (headerAccessContractId == null) { throw new MissingAccessContractIdException( "Missing access contract header " + GlobalDataRest.X_ACCESS_CONTRAT_ID); } JsonNode queryDsl = getQueryDsl(headerAccessContractId); RequestResponse<AccessContractModel> response = client.findAccessContracts(queryDsl); if (!response.isOk()) { VitamError vitamError = (VitamError) response; throw new MissingAccessContractIdException( vitamError.getMessage() + " : " + vitamError.getDescription()); } if (((RequestResponseOK<AccessContractModel>) response).getResults().size() == 0) { throw new MissingAccessContractIdException(headerAccessContractId + " not found in the system"); } List<AccessContractModel> contracts = ((RequestResponseOK<AccessContractModel>) response).getResults(); VitamThreadUtils.getVitamSession().setContract(contracts.get(0)); } catch (final VitamThreadAccessException | AdminManagementClientServerException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new MissingAccessContractIdException( "Got an exception while trying to check the access contract in the current session ; exception was : {}", e); } } private  AccessContractIdHeaderHelper(); static void manageAccessContractFromHeader(MultivaluedMap<String, String> requestHeaders,
        AdminManagementClientFactory adminManagementClientFactory);  }