Compare commits

..

No commits in common. "94297e75b9b87eb18d7f13c3f291ebe48d1d5f8b" and "5ff972ebcb2175c1ee6f8aa6b8358b3b0b78d81d" have entirely different histories.

2 changed files with 13 additions and 23 deletions

View File

@ -53,7 +53,7 @@ public class SamplingRateRepository {
EntityManager em = entityManagerFactory.createEntityManager(); EntityManager em = entityManagerFactory.createEntityManager();
try{ try{
SamplingRate samplingRate = em.find(SamplingRate.class, id); SamplingRate samplingRate = em.find(SamplingRate.class, id);
return Optional.ofNullable(samplingRate); return Optional.of(samplingRate);
}finally { }finally {
if (em.isOpen()) em.close(); if (em.isOpen()) em.close();
} }

View File

@ -32,36 +32,26 @@ public class SamplingRateService {
} }
public Optional<SamplingRate> getSamplingRateById(Integer id) { public Optional<SamplingRate> getSamplingRateById(Integer id) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Getting sampling rate by id:{}", id); logger.info("Getting sampling rate by id:{}", id);
return repository.findById(id); return repository.findById(id);
} }
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) { public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
if (id == null) { logger.info("Updating sampling rate:{}", value);
throw new IllegalArgumentException("ID cannot be null"); if (value == null || value.trim().isEmpty()) {
} throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");}
logger.info("Updating sampling rate:{}", value); Optional<SamplingRate> existingSamplingRate = repository.findById(id);
if (value == null || value.trim().isEmpty()) { if(existingSamplingRate.isEmpty()) {
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty"); logger.warn("Sampling rate not found with id:{}", id);
} return Optional.empty();
Optional<SamplingRate> existingSamplingRate = repository.findById(id); }
if(existingSamplingRate.isEmpty()) { SamplingRate samplingRate = existingSamplingRate.get();
logger.warn("Sampling rate not found with id:{}", id); samplingRate.setValue(value);
return Optional.empty(); SamplingRate updatedSamplingRate = repository.update(samplingRate);
} return Optional.of(updatedSamplingRate);
SamplingRate samplingRate = existingSamplingRate.get();
samplingRate.setValue(value);
SamplingRate updatedSamplingRate = repository.update(samplingRate);
return Optional.of(updatedSamplingRate);
} }
public boolean deleteSamplingRate(Integer id) { public boolean deleteSamplingRate(Integer id) {
if (id == null) {
throw new IllegalArgumentException("Sampling rate id cannot be null");
}
logger.info("Deleting sampling rate:{}", id); logger.info("Deleting sampling rate:{}", id);
return repository.deleteById(id); return repository.deleteById(id);
} }