Use boolean parameter as DAO misinterprets RequestDetails

This commit is contained in:
juan.marchionatto 2021-08-27 10:57:06 -04:00
parent 3fbae63968
commit f63f12e976
11 changed files with 45 additions and 50 deletions

View File

@ -28,7 +28,6 @@ import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

View File

@ -68,7 +68,6 @@ import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
import ca.uhn.fhir.jpa.term.ex.ExpansionTooCostlyException;
import ca.uhn.fhir.jpa.util.LogicUtil;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -1884,7 +1883,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
@Override
@Transactional
public void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet , RequestDetails theRequestDetails) {
public void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet , boolean theMakeItCurrent) {
ValidateUtil.isTrueOrThrowInvalidRequest(theResourceTable != null, "No resource supplied");
if (isPlaceholder(theValueSet)) {
@ -1903,12 +1902,12 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
termValueSet.setUrl(theValueSet.getUrl());
termValueSet.setVersion(theValueSet.getVersion());
termValueSet.setName(theValueSet.hasName() ? theValueSet.getName() : null);
termValueSet.setCurrentVersion(false);
// value sets must be marked as current only when version is present and flag indicates that
if (theValueSet.getVersion() != null) {
if (ITermCodeSystemStorageSvc.isMakeVersionCurrent(theRequestDetails)) {
makeVersionCurrent(theValueSet);
}
if (theValueSet.getVersion() != null && theMakeItCurrent) {
resetCurrentValueSetVersion(theValueSet);
termValueSet.setCurrentVersion(true);
}
// Delete version being replaced
@ -1948,20 +1947,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
}
private void makeVersionCurrent(ValueSet theValueSet) {
resetCurrentValueSetVersion(theValueSet);
TermValueSet termValueSet = myTermValueSetDao.findTermValueSetByUrlAndVersion(
theValueSet.getUrl(), theValueSet.getVersion())
.orElseThrow(() ->
new InternalErrorException("Couldn't retrieve TermValueSet with url: " +
theValueSet.getUrl() + " and version: " + theValueSet.getVersion() ) );
termValueSet.setCurrentVersion(true);
myTermValueSetDao.save(termValueSet);
}
private void resetCurrentValueSetVersion(ValueSet theValueSet) {
Optional<TermValueSet> termValueSetOpt = myTermValueSetDao.findTermValueSetByUrlAndCurrentVersion(theValueSet.getUrl());
if (! termValueSetOpt.isPresent()) return;

View File

@ -399,7 +399,9 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
theCodeSystemResource.getVersion(), theCodeSystemVersion, resource, theRequest);
myDeferredStorageSvc.addConceptMapsToStorageQueue(theConceptMaps);
myDeferredStorageSvc.addValueSetsToStorageQueue(theValueSets, theRequest);
boolean isMakeVersionCurrent = ITermCodeSystemStorageSvc.isMakeVersionCurrent(theRequest);
myDeferredStorageSvc.addValueSetsToStorageQueue(theValueSets, isMakeVersionCurrent);
return csId;
}
@ -470,10 +472,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
codeSystemToStore = myCodeSystemVersionDao.saveAndFlush(codeSystemToStore);
}
// defaults to true
boolean isMakeVersionCurrent = theRequestDetails == null ||
(boolean) theRequestDetails.getUserData().getOrDefault(MAKE_LOADING_VERSION_CURRENT, Boolean.TRUE);
boolean isMakeVersionCurrent = ITermCodeSystemStorageSvc.isMakeVersionCurrent(theRequestDetails);
if (isMakeVersionCurrent) {
codeSystem.setCurrentVersion(codeSystemToStore);
if (codeSystem.getPid() == null) {

View File

@ -37,7 +37,6 @@ import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.util.StopWatch;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.Validate;
@ -75,7 +74,7 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
final private List<TermCodeSystem> myDeferredCodeSystemsDeletions = Collections.synchronizedList(new ArrayList<>());
final private Queue<TermCodeSystemVersion> myDeferredCodeSystemVersionsDeletions = new ConcurrentLinkedQueue<>();
final private List<TermConcept> myDeferredConcepts = Collections.synchronizedList(new ArrayList<>());
final private List<Pair<ValueSet, RequestDetails>> myDeferredValueSets = Collections.synchronizedList(new ArrayList<>());
final private List<Pair<ValueSet, Boolean>> myDeferredValueSets = Collections.synchronizedList(new ArrayList<>());
final private List<ConceptMap> myDeferredConceptMaps = Collections.synchronizedList(new ArrayList<>());
final private List<TermConceptParentChildLink> myConceptLinksToSaveLater = Collections.synchronizedList(new ArrayList<>());
@Autowired
@ -119,9 +118,9 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
}
@Override
public void addValueSetsToStorageQueue(List<ValueSet> theValueSets, RequestDetails theRequestDetails) {
public void addValueSetsToStorageQueue(List<ValueSet> theValueSets, boolean theMakeThemCurrent) {
Validate.notNull(theValueSets);
myDeferredValueSets.addAll(theValueSets.stream().map(vs -> Pair.of(vs, theRequestDetails)).collect(Collectors.toList()));
myDeferredValueSets.addAll(theValueSets.stream().map(vs -> Pair.of(vs, theMakeThemCurrent)).collect(Collectors.toList()));
}
@Override
@ -220,11 +219,11 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
private void processDeferredValueSets() {
int count = Math.min(myDeferredValueSets.size(), 200);
for (Pair<ValueSet, RequestDetails> nextPair : new ArrayList<>(myDeferredValueSets.subList(0, count))) {
for (Pair<ValueSet, Boolean> nextPair : new ArrayList<>(myDeferredValueSets.subList(0, count))) {
ValueSet valueSet = nextPair.getFirst();
RequestDetails requestDetails = nextPair.getSecond();
ourLog.info("Creating ValueSet: {}", valueSet.getId());
myTerminologyVersionAdapterSvc.createOrUpdateValueSet(valueSet, requestDetails);
boolean makeItCurrent = nextPair.getSecond();
ourLog.info("Creating ValueSet: {} , {}making it current version", valueSet.getId(), (makeItCurrent ? "" : "not "));
myTerminologyVersionAdapterSvc.createOrUpdateValueSet(valueSet, makeItCurrent);
myDeferredValueSets.remove(nextPair);
}
ourLog.info("Saved {} deferred ValueSet resources, have {} remaining", count, myDeferredValueSets.size());

View File

@ -40,7 +40,7 @@ public class TermVersionAdapterSvcDstu2 implements ITermVersionAdapterSvc {
}
@Override
public void createOrUpdateValueSet(ValueSet theValueSet, RequestDetails theRequestDetails) {
public void createOrUpdateValueSet(ValueSet theValueSet, boolean theMakeItCurrent) {
throw new UnsupportedOperationException();
}

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.term;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.util.UrlUtil;
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
@ -37,6 +38,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import static ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc.MAKE_LOADING_VERSION_CURRENT;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class TermVersionAdapterSvcDstu3 extends BaseTermVersionAdapterSvcImpl implements ITermVersionAdapterSvc {
@ -103,7 +105,7 @@ public class TermVersionAdapterSvcDstu3 extends BaseTermVersionAdapterSvcImpl im
}
@Override
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, RequestDetails theRequestDetails) {
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, boolean theMakeItCurrent) {
ValueSet valueSetDstu3;
try {
valueSetDstu3 = (ValueSet) VersionConvertorFactory_30_40.convertResource(theValueSet, new BaseAdvisor_30_40(false));
@ -111,11 +113,14 @@ public class TermVersionAdapterSvcDstu3 extends BaseTermVersionAdapterSvcImpl im
throw new InternalErrorException(e);
}
TransactionDetails txDetails = new TransactionDetails();
txDetails.putUserData(MAKE_LOADING_VERSION_CURRENT, theMakeItCurrent);
if (isBlank(valueSetDstu3.getIdElement().getIdPart())) {
String matchUrl = "ValueSet?url=" + UrlUtil.escapeUrlParam(theValueSet.getUrl());
myValueSetResourceDao.update(valueSetDstu3, matchUrl, theRequestDetails);
myValueSetResourceDao.update(valueSetDstu3, matchUrl, true, false, null, txDetails);
} else {
myValueSetResourceDao.update(valueSetDstu3, theRequestDetails);
myValueSetResourceDao.update(valueSetDstu3, null, true, false, null, txDetails);
}
}

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.term;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.util.UrlUtil;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.CodeSystem;
@ -33,6 +34,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import static ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc.MAKE_LOADING_VERSION_CURRENT;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class TermVersionAdapterSvcR4 extends BaseTermVersionAdapterSvcImpl implements ITermVersionAdapterSvc {
@ -81,12 +83,15 @@ public class TermVersionAdapterSvcR4 extends BaseTermVersionAdapterSvcImpl imple
}
@Override
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, RequestDetails theRequestDetails) {
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, boolean theMakeItCurrent) {
TransactionDetails txDetails = new TransactionDetails();
txDetails.putUserData(MAKE_LOADING_VERSION_CURRENT, theMakeItCurrent);
if (isBlank(theValueSet.getIdElement().getIdPart())) {
String matchUrl = "ValueSet?url=" + UrlUtil.escapeUrlParam(theValueSet.getUrl());
myValueSetResourceDao.update(theValueSet, matchUrl, theRequestDetails);
myValueSetResourceDao.update(theValueSet, matchUrl, true, false, null, txDetails);
} else {
myValueSetResourceDao.update(theValueSet, theRequestDetails);
myValueSetResourceDao.update(theValueSet, null, true, false, null, txDetails);
}
}

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.term;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
import ca.uhn.fhir.util.UrlUtil;
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
@ -35,6 +36,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import static ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc.MAKE_LOADING_VERSION_CURRENT;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class TermVersionAdapterSvcR5 extends BaseTermVersionAdapterSvcImpl implements ITermVersionAdapterSvc {
@ -88,15 +90,18 @@ public class TermVersionAdapterSvcR5 extends BaseTermVersionAdapterSvcImpl imple
}
@Override
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, RequestDetails theRequestDetails) {
public void createOrUpdateValueSet(org.hl7.fhir.r4.model.ValueSet theValueSet, boolean theMakeItCurrent) {
ValueSet valueSetR4 = (ValueSet) VersionConvertorFactory_40_50.convertResource(theValueSet, new BaseAdvisor_40_50(false));
TransactionDetails txDetails = new TransactionDetails();
txDetails.putUserData(MAKE_LOADING_VERSION_CURRENT, theMakeItCurrent);
if (isBlank(theValueSet.getIdElement().getIdPart())) {
String matchUrl = "ValueSet?url=" + UrlUtil.escapeUrlParam(theValueSet.getUrl());
myValueSetResourceDao.update(valueSetR4, matchUrl, theRequestDetails);
myValueSetResourceDao.update(valueSetR4, matchUrl, true, false, null, txDetails);
} else {
myValueSetResourceDao.update(valueSetR4, theRequestDetails);
myValueSetResourceDao.update(valueSetR4, null, true, false, null, txDetails);
}
}

View File

@ -25,7 +25,6 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.hl7.fhir.r4.model.ConceptMap;
import org.hl7.fhir.r4.model.ValueSet;
@ -53,7 +52,7 @@ public interface ITermDeferredStorageSvc {
void addConceptMapsToStorageQueue(List<ConceptMap> theConceptMaps);
void addValueSetsToStorageQueue(List<ValueSet> theValueSets, RequestDetails theRequestDetails);
void addValueSetsToStorageQueue(List<ValueSet> theValueSets, boolean theMakeThemCurrent);
void deleteCodeSystem(TermCodeSystem theCodeSystem);

View File

@ -7,7 +7,6 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.IValueSetConceptAccumulator;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.util.FhirVersionIndependentConcept;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
@ -90,10 +89,10 @@ public interface ITermReadSvc extends IValidationSupport {
void deleteValueSetAndChildren(ResourceTable theResourceTable);
void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet, RequestDetails theRequestDetails);
void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet, boolean theMakeItCurrent);
default void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet) {
storeTermValueSet(theResourceTable, theValueSet, null);
storeTermValueSet(theResourceTable, theValueSet, true);
}

View File

@ -41,6 +41,6 @@ public interface ITermVersionAdapterSvc {
void createOrUpdateConceptMap(ConceptMap theNextConceptMap);
void createOrUpdateValueSet(ValueSet theValueSet, RequestDetails theRequestDetails);
void createOrUpdateValueSet(ValueSet theValueSet, boolean makeItCurrent);
}