class ProjectTeamViewModelPopulator {

    public ProjectTeamViewModel populate(long projectId, UserResource loggedInUser) {

        ProjectResource project = projectService.getById(projectId);
        boolean isMonitoringOfficer = monitoringOfficerRestService.isMonitoringOfficerOnProject(projectId, loggedInUser.getId()).getSuccess();

        List<ProjectUserResource> projectUsers = projectService.getDisplayProjectUsersForProject(project.getId());
        List<OrganisationResource> projectOrganisations = projectService.getPartnerOrganisationsForProject(projectId);
        OrganisationResource leadOrganisation = projectService.getLeadOrganisation(projectId);

        OrganisationResource loggedInUserOrg;
        if(isMonitoringOfficer) {
            loggedInUserOrg = null;
        } else {
            loggedInUserOrg = projectRestService.getOrganisationByProjectAndUser(projectId, loggedInUser.getId()).getSuccess();
        }

        List<ProjectUserInviteResource> invitedUsers = projectInviteRestService.getInvitesByProject(projectId).getSuccess();

        boolean isLead = leadOrganisation.equals(loggedInUserOrg);

        List<ProjectTeamOrganisationViewModel> partnerOrgModels = projectOrganisations.stream()
                .map(org -> mapToProjectOrganisationViewModel(projectId,
                        projectUsers,
                        invitedUsers,
                        org,
                        loggedInUser,
                        org.equals(leadOrganisation),
                        org.equals(loggedInUserOrg)))
                .sorted()
                .collect(toList());
        ProjectTeamOrganisationViewModel loggedInUserOrgModel = getLoggedInUserOrgModel(partnerOrgModels, loggedInUserOrg, isMonitoringOfficer);

        ProjectTeamStatusResource teamStatus = statusService.getProjectTeamStatus(projectId, Optional.empty());
        SetupSectionAccessibilityHelper statusAccessor = new SetupSectionAccessibilityHelper(teamStatus);

        boolean isReadOnly = statusAccessor.isGrantOfferLetterGenerated() || project.getProjectState().isComplete() || isMonitoringOfficer;

        return new ProjectTeamViewModel(
                project,
                partnerOrgModels,
                loggedInUserOrgModel,
                getProjectManager(project.getId()).orElse(null),
                isLead,
                loggedInUser.getId(),
                statusAccessor.isGrantOfferLetterGenerated(),
                false,
                isReadOnly,
                false,
                false);
    }

}