class JobRequestHelper {

    public JobResult addBranch(final String jobId,
                               final String spaceName,
                               final String projectName,
                               final String newBranchName,
                               final String baseBranchName,
                               final String userIdentifier) {

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

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

        if (project == null) {
            result.setStatus(JobStatus.RESOURCE_NOT_EXIST);
            result.setResult("Project [" + projectName + "] does not exist");
            return result;
        }

        try {
            workspaceProjectService.addBranch(newBranchName,
                                              baseBranchName,
                                              project,
                                              userIdentifier);
            result.setStatus(JobStatus.SUCCESS);
        } catch (FileAlreadyExistsException e) {
            result.setStatus(JobStatus.DUPLICATE_RESOURCE);
            result.setResult("Branch [" + newBranchName + "] already exists.");
        } catch (Exception e) {
            result.setStatus(JobStatus.FAIL);
            result.setResult(e.getMessage());
        }

        return result;
    }

}