class ActivityLogViewModelPopulator {

    public ActivityLogViewModel populate(long projectId, UserResource user) {
        ProjectResource project = projectRestService.getProjectById(projectId).getSuccess();
        List<PartnerOrganisationResource> partnerOrganisationResources = partnerOrganisationRestService.getProjectPartnerOrganisations(projectId).getSuccess();
        List<ProjectUserResource> projectUserResources = projectRestService.getProjectUsersForProject(projectId).getSuccess();
        List<ActivityLogResource> activities = activityLogRestService.findByApplicationId(project.getApplication()).getSuccess();

        List<ActivityLogEntryViewModel> views = activities.stream()
                .map(activity -> {
                    String url = url(activity, project);
                    return new ActivityLogEntryViewModel(
                            title(activity),
                            activity.getOrganisationName(),
                            userText(activity, projectUserResources, partnerOrganisationResources),
                            activity.getCreatedOn(),
                            linkText(activity),
                            url,
                            url != null && userCanSeeLink(activity, user),
                            activity.getActivityType());
                })
                .collect(toList());

        return new ActivityLogViewModel(
                project,
                partnerOrganisationResources.stream()
                        .filter(PartnerOrganisationResource::isLeadOrganisation)
                        .findFirst()
                        .map(PartnerOrganisationResource::getOrganisationName)
                        .orElse(""),
                partnerOrganisationResources.stream()
                        .filter(negate(PartnerOrganisationResource::isLeadOrganisation))
                        .map(PartnerOrganisationResource::getOrganisationName)
                        .collect(joining(", ")),
                views
        );

    }

}