class JobRequestHelper {

    public JobResult deployProject(final String jobId,
                                   final String spaceName,
                                   final String projectName,
                                   final String branchName) {

        JobResult result = new JobResult();
        result.setJobId(jobId);

        final WorkspaceProject workspaceProject = workspaceProjectService.resolveProject(
                spacesAPI.getSpace(spaceName),
                projectName,
                branchName);

        if (workspaceProject == null) {
            return projectDoesNotExistError(jobId, projectName);
        }

        Module module = workspaceProject.getMainModule();

        if (module == null) {
            if (branchName == null) {
                return projectHasNoMainModuleError(jobId, projectName);
            }
            return projectHasNoModuleError(jobId, projectName, branchName);
        }

        try {
            BuildResults buildResults = buildService.buildAndDeploy(module);
            result.setDetailedResult(buildResults == null ? null : deployResultToDetailedStringMessages(buildResults));
            result.setStatus(buildResults != null && buildResults.getErrorMessages().isEmpty() ? JobStatus.SUCCESS : JobStatus.FAIL);
        } catch (RuntimeException ex) {
            GAVAlreadyExistsException gae = findCause(ex, GAVAlreadyExistsException.class).orElseThrow(() -> ex);
            result.setStatus(JobStatus.DUPLICATE_RESOURCE);
            result.setResult("Project's GAV [" + gae.getGAV() + "] already exists at [" + toString(gae.getRepositories()) + "]");
            return result;
        }

        return result;
    }

}