class StatusServiceImpl extends AbstractProjectServiceImpl implements StatusService {

    @Override
    @Transactional //Write transaction for first time creation of project finances.
    public ServiceResult<ProjectTeamStatusResource> getProjectTeamStatus(Long projectId, Optional<Long> filterByUserId) {
        Project project = projectRepository.findById(projectId).get();
        PartnerOrganisation lead = project.getLeadOrganisation().get();

        Optional<ProjectUser> partnerUserForFilterUser = filterByUserId.flatMap(
                userId -> simpleFindFirst(project.getProjectUsers(),
                        pu -> pu.getUser().getId().equals(userId) && pu.getRole().isPartner()));

        List<PartnerOrganisation> partnerOrganisationsToInclude =
                simpleFilter(project.getPartnerOrganisations(), partner ->
                        partner.isLeadOrganisation() ||
                                (partnerUserForFilterUser.map(pu -> partner.getOrganisation().getId().equals(pu.getOrganisation().getId()))
                                        .orElse(true)));

        List<PartnerOrganisation> sortedOrganisationsToInclude
                = new PrioritySorting<>(partnerOrganisationsToInclude, lead, p -> p.getOrganisation().getName()).unwrap();

        List<ProjectPartnerStatusResource> projectPartnerStatusResources =
                simpleMap(sortedOrganisationsToInclude, partner -> getProjectPartnerStatus(project, partner));

        ProjectTeamStatusResource projectTeamStatusResource = new ProjectTeamStatusResource();
        projectTeamStatusResource.setPartnerStatuses(projectPartnerStatusResources);
        projectTeamStatusResource.setProjectState(project.getProjectProcess().getProcessState());
        projectTeamStatusResource.setProjectManagerAssigned(getProjectManager(project).isPresent());

        return serviceSuccess(projectTeamStatusResource);
    }

}