class TravisRestService {

  @Transactional
  public Map<String, ?> createProf(ProfilingInfo profParams) {
    Build build = buildRepository.findByTravisBuildId(profParams.getBuildId());
    Project project = projectRepository.findByBuild(build);
    Sample sample = sampleRepository.findByNameAndProject_Id(profParams.getSampleName(), project.getId());
    if (sample == null) {
      sample = new Sample();
      sample.setName(profParams.getSampleName());
      sample.setProject(project);
      sample = sampleRepository.save(sample);
    }

    sample.getBuilds().add(build);
    sample = sampleRepository.save(sample);
    build.getSamples().add(sample);
    build = buildRepository.save(build);

    ProfContextDump prof = new ProfContextDump();
    prof.setBuild(build);
    prof.setSample(sample);
    prof.setState(ProfContextState.CREATED);
    prof = profContextDumpRepository.save(prof);

    logger.info("Create Profiling: {}", prof.getId());

    return ImmutableMap.of("profId", prof.getId());
  }

}