Compare commits
3 Commits
5ff972ebcb
...
94297e75b9
| Author | SHA1 | Date |
|---|---|---|
|
|
94297e75b9 | |
|
|
ff09d1b89a | |
|
|
4fa147282f |
|
|
@ -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.of(samplingRate);
|
return Optional.ofNullable(samplingRate);
|
||||||
}finally {
|
}finally {
|
||||||
if (em.isOpen()) em.close();
|
if (em.isOpen()) em.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,26 +32,36 @@ 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) {
|
||||||
logger.info("Updating sampling rate:{}", value);
|
if (id == null) {
|
||||||
if (value == null || value.trim().isEmpty()) {
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");}
|
}
|
||||||
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
|
logger.info("Updating sampling rate:{}", value);
|
||||||
if(existingSamplingRate.isEmpty()) {
|
if (value == null || value.trim().isEmpty()) {
|
||||||
logger.warn("Sampling rate not found with id:{}", id);
|
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
|
||||||
return Optional.empty();
|
}
|
||||||
}
|
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
|
||||||
SamplingRate samplingRate = existingSamplingRate.get();
|
if(existingSamplingRate.isEmpty()) {
|
||||||
samplingRate.setValue(value);
|
logger.warn("Sampling rate not found with id:{}", id);
|
||||||
SamplingRate updatedSamplingRate = repository.update(samplingRate);
|
return Optional.empty();
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue