40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
package de.etecture.ga.service;
|
|
|
|
import java.security.InvalidParameterException;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.Assert;
|
|
|
|
import de.etecture.ga.model.MDService;
|
|
import de.etecture.ga.repository.MDServiceRepository;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
@Service
|
|
@AllArgsConstructor
|
|
public class MDServiceService {
|
|
|
|
private final MDServiceRepository serviceRepository;
|
|
|
|
public MDService storeMDService(String serviceCode) {
|
|
|
|
if (StringUtils.isBlank(serviceCode))
|
|
throw new InvalidParameterException("serviceCode should not been empty");
|
|
|
|
MDService service = serviceRepository.findByCode(serviceCode).orElse(new MDService().code(serviceCode));
|
|
|
|
return serviceRepository.save(service);
|
|
}
|
|
|
|
public MDService storeMDService(MDService serviceToSafe) {
|
|
|
|
Assert.notNull(serviceToSafe, "Service must not be null");
|
|
Assert.notNull(serviceToSafe.code(), "Service code must not be null");
|
|
Assert.isTrue(serviceToSafe.duration().isPositive(), "Service duration must must be bigger then 0");
|
|
|
|
MDService service = serviceRepository.findByCode(serviceToSafe.code()).orElse(serviceToSafe);
|
|
|
|
return serviceRepository.save(service);
|
|
}
|
|
}
|