@Test public void shouldThrowErrorWhenSampleIsNotAvailable() { final Long INVALID_SAMPLE_ID = -10L; given(sampleRepository.findOne(INVALID_SAMPLE_ID)).willReturn(null); try { tested.updateAvailableForGridMaking(INVALID_SAMPLE_ID, false); fail("It failed to throw exception when sample is not available."); } catch (ResourceNotFoundException e) { } }
public void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking) { final Sample sample = repository.findOne(sampleId); if (sample == null) { LOGGER.info("[updateAvailableForGridMaking] Sample not found for ID: " + sampleId); throw new ResourceNotFoundException("Sample not found for ID: " + sampleId); } if (sample.getAvailableForGridMaking() == availabilityForGridMaking) { return; } sample.setAvailableForGridMaking(availabilityForGridMaking); repository.save(sample); }
SampleService extends BaseProjectRestService<Sample> { public void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking) { final Sample sample = repository.findOne(sampleId); if (sample == null) { LOGGER.info("[updateAvailableForGridMaking] Sample not found for ID: " + sampleId); throw new ResourceNotFoundException("Sample not found for ID: " + sampleId); } if (sample.getAvailableForGridMaking() == availabilityForGridMaking) { return; } sample.setAvailableForGridMaking(availabilityForGridMaking); repository.save(sample); } }
SampleService extends BaseProjectRestService<Sample> { public void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking) { final Sample sample = repository.findOne(sampleId); if (sample == null) { LOGGER.info("[updateAvailableForGridMaking] Sample not found for ID: " + sampleId); throw new ResourceNotFoundException("Sample not found for ID: " + sampleId); } if (sample.getAvailableForGridMaking() == availabilityForGridMaking) { return; } sample.setAvailableForGridMaking(availabilityForGridMaking); repository.save(sample); } @Autowired  SampleService(final SampleRepository sampleRepository,
                  final ProjectRepository projectRepository,
                  @NotNull final ProteinRepository proteinRepository,
                  @NotNull final LigandRepository ligandRepository
    ); }
SampleService extends BaseProjectRestService<Sample> { public void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking) { final Sample sample = repository.findOne(sampleId); if (sample == null) { LOGGER.info("[updateAvailableForGridMaking] Sample not found for ID: " + sampleId); throw new ResourceNotFoundException("Sample not found for ID: " + sampleId); } if (sample.getAvailableForGridMaking() == availabilityForGridMaking) { return; } sample.setAvailableForGridMaking(availabilityForGridMaking); repository.save(sample); } @Autowired  SampleService(final SampleRepository sampleRepository,
                  final ProjectRepository projectRepository,
                  @NotNull final ProteinRepository proteinRepository,
                  @NotNull final LigandRepository ligandRepository
    ); @NonNull Collection<Project> getItemProjects(@NonNull final String slug); @Override Collection<Project> getItemProjects(@NonNull final Long id); @Transactional @NonNull Sample createItem(@NonNull final Sample input, @NonNull final Long projectId); @Transactional @NonNull Sample createItem(@NonNull final Sample input,
                             @NonNull @ApiIgnore final String projectSlug); Collection<Sample> findSamplesAvailableForGridMaking(@NonNull final Long projectId); Collection<Sample> findSamplesAvailableForGridMaking(@NonNull final String projectSlug); @Transactional @NonNull @Override Sample updateItem(@NonNull final Sample input); void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking); }
SampleService extends BaseProjectRestService<Sample> { public void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking) { final Sample sample = repository.findOne(sampleId); if (sample == null) { LOGGER.info("[updateAvailableForGridMaking] Sample not found for ID: " + sampleId); throw new ResourceNotFoundException("Sample not found for ID: " + sampleId); } if (sample.getAvailableForGridMaking() == availabilityForGridMaking) { return; } sample.setAvailableForGridMaking(availabilityForGridMaking); repository.save(sample); } @Autowired  SampleService(final SampleRepository sampleRepository,
                  final ProjectRepository projectRepository,
                  @NotNull final ProteinRepository proteinRepository,
                  @NotNull final LigandRepository ligandRepository
    ); @NonNull Collection<Project> getItemProjects(@NonNull final String slug); @Override Collection<Project> getItemProjects(@NonNull final Long id); @Transactional @NonNull Sample createItem(@NonNull final Sample input, @NonNull final Long projectId); @Transactional @NonNull Sample createItem(@NonNull final Sample input,
                             @NonNull @ApiIgnore final String projectSlug); Collection<Sample> findSamplesAvailableForGridMaking(@NonNull final Long projectId); Collection<Sample> findSamplesAvailableForGridMaking(@NonNull final String projectSlug); @Transactional @NonNull @Override Sample updateItem(@NonNull final Sample input); void updateAvailableForGridMaking(@NonNull final Long sampleId, @NonNull final Boolean availabilityForGridMaking);  }