added default rules for new dossier template
This commit is contained in:
parent
a92870dd5e
commit
c0ea73f200
@ -1,7 +1,6 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.RuleSetEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.RuleSetRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -13,11 +12,26 @@ import javax.transaction.Transactional;
|
||||
@SuppressWarnings("PMD.TooManyStaticImports")
|
||||
public class RulesPersistenceService {
|
||||
|
||||
private static final String RULES_NOT_FOUND = "Could not find rules in database.";
|
||||
private final static String DEFAULT_RULES = "" +
|
||||
"package drools\n" +
|
||||
"\n" +
|
||||
"import com.iqser.red.service.redaction.v1.server.redaction.model.Section\n" +
|
||||
"\n" +
|
||||
"global Section section\n" +
|
||||
"\n" +
|
||||
"// --------------------------------------- Your rules below this line--------------------------------------------------";
|
||||
|
||||
private final RuleSetRepository ruleSetRepository;
|
||||
|
||||
public RuleSetEntity getRules(String dossierTemplateId) {
|
||||
return ruleSetRepository.findById(dossierTemplateId).orElseThrow(() -> new NotFoundException(RULES_NOT_FOUND));
|
||||
return ruleSetRepository.findById(dossierTemplateId).orElseGet(() -> {
|
||||
RuleSetEntity ruleSet = new RuleSetEntity();
|
||||
ruleSet.setDossierTemplateId(dossierTemplateId);
|
||||
ruleSet.setValue(DEFAULT_RULES);
|
||||
ruleSet.setVersion(1);
|
||||
|
||||
return ruleSetRepository.save(ruleSet);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user