DM-285: get component version without transaction
This commit is contained in:
parent
70b7a258e9
commit
62065e89ca
@ -33,8 +33,7 @@ public class VersionsController implements VersionsResource {
|
|||||||
|
|
||||||
var result = new HashMap<String, VersionsResponse>();
|
var result = new HashMap<String, VersionsResponse>();
|
||||||
dossierTemplateIds.forEach(rsId -> {
|
dossierTemplateIds.forEach(rsId -> {
|
||||||
VersionsResponse response = new VersionsResponse(dictionaryPersistenceService.getVersion(rsId),
|
VersionsResponse response = new VersionsResponse(dictionaryPersistenceService.getVersion(rsId), rulesPersistenceService.getVersion(rsId, RuleFileType.ENTITY));
|
||||||
rulesPersistenceService.getRules(rsId, RuleFileType.ENTITY).getVersion());
|
|
||||||
result.put(rsId, response);
|
result.put(rsId, response);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
|
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException;
|
import com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.LegalBasisMappingPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.LegalBasisMappingPersistenceService;
|
||||||
@ -153,8 +152,8 @@ public class ReanalysisRequiredStatusService {
|
|||||||
|
|
||||||
var versions = new HashMap<VersionType, Long>();
|
var versions = new HashMap<VersionType, Long>();
|
||||||
|
|
||||||
versions.put(RULES, getRulesVersion(dossierTemplateId, RuleFileType.ENTITY));
|
versions.put(RULES, rulesPersistenceService.getVersion(dossierTemplateId, RuleFileType.ENTITY));
|
||||||
versions.put(COMPONENT_RULES, getRulesVersion(dossierTemplateId, RuleFileType.COMPONENT));
|
versions.put(COMPONENT_RULES, rulesPersistenceService.getVersion(dossierTemplateId, RuleFileType.COMPONENT));
|
||||||
versions.put(DICTIONARY, dictionaryPersistenceService.getVersion(dossierTemplateId));
|
versions.put(DICTIONARY, dictionaryPersistenceService.getVersion(dossierTemplateId));
|
||||||
versions.put(LEGAL_BASIS, legalBasisMappingPersistenceService.getVersion(dossierTemplateId));
|
versions.put(LEGAL_BASIS, legalBasisMappingPersistenceService.getVersion(dossierTemplateId));
|
||||||
|
|
||||||
@ -162,17 +161,6 @@ public class ReanalysisRequiredStatusService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Long getRulesVersion(String dossierTemplateId, RuleFileType ruleFileType) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
return rulesPersistenceService.getRules(dossierTemplateId, ruleFileType).getVersion();
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
log.info(e.getMessage());
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Long getDossierVersionData(String dossierId) {
|
private Long getDossierVersionData(String dossierId) {
|
||||||
|
|
||||||
return dictionaryPersistenceService.getVersionForDossier(dossierId);
|
return dictionaryPersistenceService.getVersionForDossier(dossierId);
|
||||||
|
|||||||
@ -105,26 +105,17 @@ public class RulesPersistenceService {
|
|||||||
private final RuleSetRepository ruleSetRepository;
|
private final RuleSetRepository ruleSetRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
||||||
public RuleSetEntity getRules(String dossierTemplateId, RuleFileType ruleFileType) {
|
public RuleSetEntity getRules(String dossierTemplateId, RuleFileType ruleFileType) {
|
||||||
|
|
||||||
if (ruleFileType.equals(RuleFileType.ENTITY)) {
|
|
||||||
return ruleSetRepository.findByDossierTemplateIdAndRuleFileType(dossierTemplateId, ruleFileType.name())
|
|
||||||
.orElseGet(() -> createAndGetDefaultRuleSet(dossierTemplateId, ruleFileType));
|
|
||||||
}
|
|
||||||
return ruleSetRepository.findByDossierTemplateIdAndRuleFileType(dossierTemplateId, ruleFileType.name())
|
return ruleSetRepository.findByDossierTemplateIdAndRuleFileType(dossierTemplateId, ruleFileType.name())
|
||||||
.orElseThrow(() -> new NotFoundException(String.format("No rule file of type %s found for dossierTemplateId %s", ruleFileType, dossierTemplateId)));
|
.orElseThrow(() -> new NotFoundException(String.format("No rule file of type %s found for dossierTemplateId %s", ruleFileType, dossierTemplateId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RuleSetEntity createAndGetDefaultRuleSet(String dossierTemplateId, RuleFileType ruleFileType) {
|
public long getVersion(String dossierTemplateId, RuleFileType ruleFileType) {
|
||||||
|
|
||||||
RuleSetEntity ruleSet = new RuleSetEntity();
|
return ruleSetRepository.findVersionByDossierTemplateIdAndRuleFileType(dossierTemplateId, ruleFileType.name()).orElse(-1L);
|
||||||
ruleSet.setDossierTemplateId(dossierTemplateId);
|
|
||||||
ruleSet.setRuleFileType(ruleFileType.name());
|
|
||||||
ruleSet.setValue(DEFAULT_RULES);
|
|
||||||
ruleSet.setVersion(1);
|
|
||||||
ruleSet.setTimeoutDetected(false);
|
|
||||||
return ruleSetRepository.save(ruleSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,4 +18,8 @@ public interface RuleSetRepository extends JpaRepository<RuleSetEntity, RuleSetE
|
|||||||
|
|
||||||
Optional<RuleSetEntity> findByDossierTemplateIdAndRuleFileType(String dossierTemplateId, String ruleFileType);
|
Optional<RuleSetEntity> findByDossierTemplateIdAndRuleFileType(String dossierTemplateId, String ruleFileType);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("select r.version from RuleSetEntity r where r.dossierTemplateId = :dossierTemplateId and r.ruleFileType = :ruleFileType")
|
||||||
|
Optional<Long> findVersionByDossierTemplateIdAndRuleFileType(String dossierTemplateId, String ruleFileType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user