class AccessRequestService {

    public List<CompletedAccessRequestWrapper> getRequest(Long id) {
        final ObjectMapper mapper = new ObjectMapper();
        List<CompletedAccessRequestWrapper> results = new ArrayList<>();

        String query = new StringBuilder(REQUESTS_QUERY)
                .append("and access_request.id = :request_id \n")
                .append("order by updated desc;")
                .toString();

        NativeQueryImpl q = (NativeQueryImpl) entityManager.createNativeQuery(query);
        q.setParameter("request_id", id);
        q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

        NativeQueryImpl roleQuery = (NativeQueryImpl) entityManager.createNativeQuery(ROLE_QUERY);
        roleQuery.setParameter("request_id", id);
        roleQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

        NativeQueryImpl instanceQuery = (NativeQueryImpl) entityManager.createNativeQuery(INSTANCE_QUERY);
        instanceQuery.setParameter("request_id", id);
        instanceQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

        NativeQueryImpl userQuery = (NativeQueryImpl) entityManager.createNativeQuery(USER_QUERY);
        userQuery.setParameter("request_id", id);
        userQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

        List < Map < String, AccessRequestWrapper >> result = q.getResultList();
        List < Map < String, User >> userResult = userQuery.getResultList();
        List < Map < String, UserRole >> roleResult = roleQuery.getResultList();
        List < Map < String, AWSRdsDatabase >> instanceResult = instanceQuery.getResultList();

        for (Map<String, AccessRequestWrapper> map: result) {
            CompletedAccessRequestWrapper requestWrapper = mapper.convertValue(map, CompletedAccessRequestWrapper.class);

            for (Map<String, UserRole> roleMap: roleResult) {
                UserRole role = mapper.convertValue(roleMap, UserRole.class);
                requestWrapper.getRoles().add(role);
            }

            for (Map<String, AWSRdsDatabase> instanceeMap: instanceResult) {
                AWSRdsDatabase instance = mapper.convertValue(instanceeMap, AWSRdsDatabase.class);
                requestWrapper.getInstances().add(instance);
            }

            for (Map<String, User> userMap: userResult) {
                User user = mapper.convertValue(userMap, User.class);
                requestWrapper.getUsers().add(user);
            }

            results.add(requestWrapper);
        }

        return (List<CompletedAccessRequestWrapper>)filterResults(results);
    }

    @Autowired public  AccessRequestService(TaskService taskService,
                                AccessRequestRepository accessRequestRepository,
                                GatekeeperRoleService gatekeeperRoleService,
                                RuntimeService runtimeService,
                                HistoryService historyService,
                                GatekeeperApprovalProperties gatekeeperApprovalProperties,
                                AccountInformationService accountInformationService,
                                GatekeeperOverrideProperties overridePolicy,
                                DatabaseConnectionService databaseConnectionService,
                                EntityManager entityManager);

}