JPA server cleanup and add some tests

This commit is contained in:
James Agnew 2018-01-05 16:41:18 -05:00
parent b18e71d4f5
commit 0369b7fd70
10 changed files with 821 additions and 713 deletions

View File

@ -942,6 +942,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
break;
}
ourLog.info("Encoded {} chars of resource body as {} bytes", encoded.length(), bytes.length);
boolean changed = false;
if (theUpdateHash) {
@ -963,7 +965,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
theEntity.setResource(bytes);
Set<TagDefinition> allDefs = new HashSet<TagDefinition>();
Set<TagDefinition> allDefs = new HashSet<>();
theEntity.setHasTags(false);
@ -988,7 +990,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
}
ArrayList<ResourceTag> existingTags = new ArrayList<ResourceTag>();
ArrayList<ResourceTag> existingTags = new ArrayList<>();
if (theEntity.isHasTags()) {
existingTags.addAll(theEntity.getTags());
}
@ -1042,8 +1044,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
Collection<? extends BaseTag> tags = theEntity.getTags();
if (theEntity.isHasTags()) {
TagList tagList = new TagList();
List<IBaseCoding> securityLabels = new ArrayList<IBaseCoding>();
List<IdDt> profiles = new ArrayList<IdDt>();
List<IBaseCoding> securityLabels = new ArrayList<>();
List<IdDt> profiles = new ArrayList<>();
for (BaseTag next : tags) {
switch (next.getTag().getTagType()) {
case PROFILE:
@ -1171,9 +1173,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
throw new InternalErrorException("No DAO for resource type: " + theResourceType.getName());
}
Set<Long> ids = dao.searchForIds(paramMap);
return ids;
return dao.searchForIds(paramMap);
}
@CoverageIgnore
@ -1181,14 +1181,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
throw new NotImplementedException("");
}
public void setEntityManager(EntityManager theEntityManager) {
myEntityManager = theEntityManager;
}
public void setPlatformTransactionManager(PlatformTransactionManager thePlatformTransactionManager) {
myPlatformTransactionManager = thePlatformTransactionManager;
}
private void setUpdatedTime(Collection<? extends BaseResourceIndexedSearchParam> theParams, Date theUpdateTime) {
for (BaseResourceIndexedSearchParam nextSearchParam : theParams) {
nextSearchParam.setUpdated(theUpdateTime);
@ -1206,7 +1198,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
*
* @param theEntity The entity being updated (Do not modify the entity! Undefined behaviour will occur!)
* @param theTag The tag
* @return Retturns <code>true</code> if the tag should be removed
* @return Returns <code>true</code> if the tag should be removed
*/
protected boolean shouldDroppedTagBeRemovedOnUpdate(ResourceTable theEntity, ResourceTag theTag) {
if (theTag.getTag().getTagType() == TagTypeEnum.PROFILE) {
@ -1222,14 +1214,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return toResource(resourceType, theEntity, theForHistoryOperation);
}
// protected ResourceTable toEntity(IResource theResource) {
// ResourceTable retVal = new ResourceTable();
//
// populateResourceIntoEntity(theResource, retVal, true);
//
// return retVal;
// }
@SuppressWarnings("unchecked")
@Override
public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) {

View File

@ -1,5 +1,38 @@
package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.jpa.dao.data.IForcedIdDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.dao.data.ITermConceptDao;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.ReindexFailureException;
import ca.uhn.fhir.jpa.util.StopWatch;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Nonnull;
import javax.persistence.Query;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import static org.apache.commons.lang3.StringUtils.isBlank;
/*
@ -11,9 +44,9 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,34 +54,6 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
* limitations under the License.
* #L%
*/
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import javax.persistence.*;
import javax.persistence.criteria.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import ca.uhn.fhir.jpa.dao.data.*;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.ReindexFailureException;
import ca.uhn.fhir.jpa.util.StopWatch;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBaseResource> implements IFhirSystemDao<T, MT> {
@ -64,32 +69,21 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
@Autowired
private PlatformTransactionManager myTxManager;
@Transactional(propagation = Propagation.REQUIRED)
@Override
public void deleteAllTagsOnServer(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails);
myEntityManager.createQuery("DELETE from ResourceTag t").executeUpdate();
}
@Autowired
private IResourceTableDao myResourceTableDao;
private int doPerformReindexingPass(final Integer theCount) {
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
int retVal = doPerformReindexingPassForResources(theCount, txTemplate);
return retVal;
return doPerformReindexingPassForResources(theCount, txTemplate);
}
@Autowired
private IResourceTableDao myResourceTableDao;
@SuppressWarnings("ConstantConditions")
private int doPerformReindexingPassForResources(final Integer theCount, TransactionTemplate txTemplate) {
return txTemplate.execute(new TransactionCallback<Integer>() {
@SuppressWarnings("unchecked")
@Override
public Integer doInTransaction(TransactionStatus theStatus) {
public Integer doInTransaction(@Nonnull TransactionStatus theStatus) {
int maxResult = 500;
if (theCount != null) {
@ -108,7 +102,7 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
for (Long nextId : resources) {
ResourceTable resourceTable = myResourceTableDao.findOne(nextId);
try {
/*
* This part is because from HAPI 1.5 - 1.6 we changed the format of forced ID to be "type/id" instead of just "id"
@ -124,16 +118,15 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
final IBaseResource resource = toResource(resourceTable, false);
@SuppressWarnings("rawtypes")
final IFhirResourceDao dao = getDao(resource.getClass());
@SuppressWarnings("rawtypes") final IFhirResourceDao dao = getDao(resource.getClass());
dao.reindex(resource, resourceTable);
} catch (Exception e) {
ourLog.error("Failed to index resource {}: {}", new Object[] { resourceTable.getIdDt(), e.toString(), e });
ourLog.error("Failed to index resource {}: {}", new Object[]{resourceTable.getIdDt(), e.toString(), e});
throw new ReindexFailureException(resourceTable.getId());
}
count++;
if (count >= maxResult) {
break;
}
@ -143,29 +136,17 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
long avg;
if (count > 0) {
avg = (delay / count);
ourLog.info("Indexed {} resources in {}ms - Avg {}ms / resource", new Object[] { count, delay, avg });
ourLog.info("Indexed {} resources in {}ms - Avg {}ms / resource", new Object[]{count, delay, avg});
} else {
ourLog.debug("Indexed 0 resources in {}ms", delay);
}
return count;
}
});
}
@Override
public TagList getAllTags(RequestDetails theRequestDetails) {
// Notify interceptors
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.GET_TAGS, requestDetails);
StopWatch w = new StopWatch();
TagList retVal = super.getTags(null, null);
ourLog.info("Processed getAllTags in {}ms", w.getMillisAndRestart());
return retVal;
}
@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
@Override
public Map<String, Long> getResourceCounts() {
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
@ -176,7 +157,7 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
TypedQuery<Tuple> q = myEntityManager.createQuery(cq);
Map<String, Long> retVal = new HashMap<String, Long>();
Map<String, Long> retVal = new HashMap<>();
for (Tuple next : q.getResultList()) {
String resourceName = next.get(0, String.class);
Long count = next.get(1, Long.class);
@ -185,10 +166,6 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
return retVal;
}
protected boolean hasValue(InstantDt theInstantDt) {
return theInstantDt != null && theInstantDt.isEmpty() == false;
}
@Override
public IBundleProvider history(Date theSince, Date theUntil, RequestDetails theRequestDetails) {
if (theRequestDetails != null) {
@ -196,27 +173,23 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails);
notifyInterceptors(RestOperationTypeEnum.HISTORY_SYSTEM, requestDetails);
}
StopWatch w = new StopWatch();
IBundleProvider retVal = super.history(null, null, theSince, theUntil);
ourLog.info("Processed global history in {}ms", w.getMillisAndRestart());
return retVal;
}
protected ResourceTable loadFirstEntityFromCandidateMatches(Set<Long> candidateMatches) {
return myEntityManager.find(ResourceTable.class, candidateMatches.iterator().next());
}
@Transactional()
@Override
public int markAllResourcesForReindexing() {
ourLog.info("Marking all resources as needing reindexing");
int retVal = myEntityManager.createQuery("UPDATE " + ResourceTable.class.getSimpleName() + " t SET t.myIndexStatus = null").executeUpdate();
ourLog.info("Marking all concepts as needing reindexing");
retVal += myTermConceptDao.markAllForReindexing();
ourLog.info("Done marking reindexing");
return retVal;
}
@ -226,13 +199,13 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus theStatus) {
ourLog.info("Marking resource with PID {} as indexing_failed", new Object[] { theId });
public Void doInTransaction(@Nonnull TransactionStatus theStatus) {
ourLog.info("Marking resource with PID {} as indexing_failed", new Object[]{theId});
Query q = myEntityManager.createQuery("UPDATE ResourceTable t SET t.myIndexStatus = :status WHERE t.myId = :id");
q.setParameter("status", INDEX_STATUS_INDEXING_FAILED);
q.setParameter("id", theId);
q.executeUpdate();
q = myEntityManager.createQuery("DELETE FROM ResourceTag t WHERE t.myResourceId = :id");
q.setParameter("id", theId);
q.executeUpdate();
@ -277,7 +250,7 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
}
});
}
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public Integer performReindexingPass(final Integer theCount) {
@ -295,20 +268,4 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
}
}
public void setTxManager(PlatformTransactionManager theTxManager) {
myTxManager = theTxManager;
}
protected ResourceTable tryToLoadEntity(IdDt nextId) {
ResourceTable entity;
try {
Long pid = translateForcedIdToPid(nextId.getResourceType(), nextId.getIdPart());
entity = myEntityManager.find(ResourceTable.class, pid);
} catch (ResourceNotFoundException e) {
entity = null;
}
return entity;
}
}

View File

@ -85,7 +85,6 @@ public class DaoConfig {
*/
private Integer myFetchSizeDefaultMaximum = null;
private int myHardTagListLimit = 1000;
private int myIncludeLimit = 2000;
/**
* update setter javadoc if default changes
*/
@ -104,8 +103,8 @@ public class DaoConfig {
private Long myReuseCachedSearchResultsForMillis = DEFAULT_REUSE_CACHED_SEARCH_RESULTS_FOR_MILLIS;
private boolean mySchedulingDisabled;
private boolean mySuppressUpdatesWithNoChange = true;
private Set<String> myTreatBaseUrlsAsLocal = new HashSet<String>();
private Set<String> myTreatReferencesAsLogical = new HashSet<String>(DEFAULT_LOGICAL_BASE_URLS);
private Set<String> myTreatBaseUrlsAsLocal = new HashSet<>();
private Set<String> myTreatReferencesAsLogical = new HashSet<>(DEFAULT_LOGICAL_BASE_URLS);
private boolean myAutoCreatePlaceholderReferenceTargets;
private Integer myCacheControlNoStoreMaxResultsUpperLimit = 1000;
private Integer myCountSearchResultsUpTo = null;
@ -129,7 +128,7 @@ public class DaoConfig {
validateTreatBaseUrlsAsLocal(theTreatReferencesAsLogical);
if (myTreatReferencesAsLogical == null) {
myTreatReferencesAsLogical = new HashSet<String>();
myTreatReferencesAsLogical = new HashSet<>();
}
myTreatReferencesAsLogical.add(theTreatReferencesAsLogical);
}
@ -271,7 +270,6 @@ public class DaoConfig {
* (next/prev links in search response bundles) will become invalid. Defaults to 1 hour.
* </p>
* <p>
* <p>
* To disable this feature entirely, see {@link #setExpireSearchResults(boolean)}
* </p>
*
@ -291,8 +289,6 @@ public class DaoConfig {
* (next/prev links in search response bundles) will become invalid. Defaults to 1 hour.
* </p>
* <p>
* <p>
* <p>
* To disable this feature entirely, see {@link #setExpireSearchResults(boolean)}
* </p>
*
@ -344,17 +340,16 @@ public class DaoConfig {
myHardTagListLimit = theHardTagListLimit;
}
public int getIncludeLimit() {
return myIncludeLimit;
}
/**
* This is the maximum number of resources that will be added to a single page of returned resources. Because of
* includes with wildcards and other possibilities it is possible for a client to make requests that include very
* large amounts of data, so this hard limit can be imposed to prevent runaway requests.
*
* @deprecated Deprecated in HAPI FHIR 3.2.0 as this method doesn't actually do anything
*/
public void setIncludeLimit(int theIncludeLimit) {
myIncludeLimit = theIncludeLimit;
@Deprecated
public void setIncludeLimit(@SuppressWarnings("unused") int theIncludeLimit) {
// nothing
}
/**

View File

@ -35,7 +35,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum.ResourceMetadataKeySupporti
public interface IDao {
public static final ResourceMetadataKeySupportingAnyResource<Long, Long> RESOURCE_PID = new MetadataKeyResourcePid("RESOURCE_PID");
ResourceMetadataKeySupportingAnyResource<Long, Long> RESOURCE_PID = new MetadataKeyResourcePid("RESOURCE_PID");
FhirContext getContext();

View File

@ -20,14 +20,12 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import java.util.Date;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.util.Date;
import java.util.Map;
/**
* @param <T>
@ -37,17 +35,7 @@ import ca.uhn.fhir.rest.api.server.RequestDetails;
*/
public interface IFhirSystemDao<T, MT> extends IDao {
/**
* Use with caution! This deletes everything!!
*
* @param theRequestDetails
* TODO
*/
void deleteAllTagsOnServer(RequestDetails theRequestDetails);
TagList getAllTags(RequestDetails theRequestDetails);
public <R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType);
<R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType);
Map<String, Long> getResourceCounts();

View File

@ -4,6 +4,8 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.config.TestDstu2Config;
import ca.uhn.fhir.jpa.dao.*;
import ca.uhn.fhir.jpa.dao.data.IResourceIndexedSearchParamStringDao;
import ca.uhn.fhir.jpa.dao.data.IResourceIndexedSearchParamTokenDao;
import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceTable;
@ -112,6 +114,9 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest {
@Qualifier("myPatientDaoDstu2")
protected IFhirResourceDaoPatient<Patient> myPatientDao;
@Autowired
@Qualifier("myGroupDaoDstu2")
protected IFhirResourceDao<Group> myGroupDao;
@Autowired
@Qualifier("myPractitionerDaoDstu2")
protected IFhirResourceDao<Practitioner> myPractitionerDao;
@Autowired
@ -141,6 +146,10 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest {
@Autowired
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
@Autowired
protected IResourceIndexedSearchParamTokenDao myResourceIndexedSearchParamTokenDao;
@Autowired
protected IResourceLinkDao myResourceLinkDao;
@Autowired
protected IResourceTableDao myResourceTableDao;
@Autowired
@Qualifier("mySystemDaoDstu2")

View File

@ -1,15 +1,14 @@
package ca.uhn.fhir.jpa.dao.dstu2;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Appointment;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
import ca.uhn.fhir.model.dstu2.resource.SearchParameter;
import ca.uhn.fhir.model.dstu2.resource.*;
import ca.uhn.fhir.model.dstu2.valueset.*;
import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
@ -21,6 +20,8 @@ import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.mockito.internal.util.collections.ListUtil;
import org.thymeleaf.util.ListUtils;
import java.util.List;
@ -33,6 +34,7 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
@Before
public void beforeDisableResultReuse() {
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
myDaoConfig.setDefaultSearchParamsCanBeOverridden(new DaoConfig().isDefaultSearchParamsCanBeOverridden());
}
@Test
@ -51,6 +53,90 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
}
}
@Test
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingEnabled() {
myDaoConfig.setDefaultSearchParamsCanBeOverridden(true);
SearchParameter memberSp = new SearchParameter();
memberSp.setCode("member");
memberSp.setBase(ResourceTypeEnum.GROUP);
memberSp.setType(SearchParamTypeEnum.REFERENCE);
memberSp.setXpath("Group.member.entity");
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
mySearchParameterDao.create(memberSp, mySrd);
SearchParameter identifierSp = new SearchParameter();
identifierSp.setCode("identifier");
identifierSp.setBase(ResourceTypeEnum.GROUP);
identifierSp.setType(SearchParamTypeEnum.TOKEN);
identifierSp.setXpath("Group.identifier");
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
mySearchParameterDao.create(identifierSp, mySrd);
mySearchParamRegsitry.forceRefresh();
Patient p = new Patient();
p.addName().addGiven("G");
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
Group g = new Group();
g.addIdentifier().setSystem("urn:foo").setValue("bar");
g.addMember().getEntity().setReference(pid);
myGroupDao.create(g);
assertThat(myResourceLinkDao.findAll(), empty());
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
@Override
public boolean isOut(ResourceIndexedSearchParamToken object) {
return !object.getResourceType().equals("Group") || object.isMissing();
}
}), empty());
}
@Test
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingDisabled() {
myDaoConfig.setDefaultSearchParamsCanBeOverridden(false);
SearchParameter memberSp = new SearchParameter();
memberSp.setCode("member");
memberSp.setBase(ResourceTypeEnum.GROUP);
memberSp.setType(SearchParamTypeEnum.REFERENCE);
memberSp.setXpath("Group.member.entity");
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
mySearchParameterDao.create(memberSp, mySrd);
SearchParameter identifierSp = new SearchParameter();
identifierSp.setCode("identifier");
identifierSp.setBase(ResourceTypeEnum.GROUP);
identifierSp.setType(SearchParamTypeEnum.TOKEN);
identifierSp.setXpath("Group.identifier");
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
mySearchParameterDao.create(identifierSp, mySrd);
mySearchParamRegsitry.forceRefresh();
Patient p = new Patient();
p.addName().addGiven("G");
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
Group g = new Group();
g.addIdentifier().setSystem("urn:foo").setValue("bar");
g.addMember().getEntity().setReference(pid);
myGroupDao.create(g);
assertThat(myResourceLinkDao.findAll(), not(empty()));
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
@Override
public boolean isOut(ResourceIndexedSearchParamToken object) {
return !object.getResourceType().equals("Group") || object.isMissing();
}
}), not(empty()));
}
@Test
public void testCreateInvalidParamInvalidResourceName() {
SearchParameter fooSp = new SearchParameter();

View File

@ -162,7 +162,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
* Per the spec, update should preserve tags and security labels but not profiles
*/
@Test
public void testUpdateMaintainsTagsAndSecurityLabels() throws InterruptedException {
public void testUpdateMaintainsTagsAndSecurityLabels() {
String methodName = "testUpdateMaintainsTagsAndSecurityLabels";
IIdType p1id;
@ -173,10 +173,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
TagList tagList = new TagList();
tagList.addTag("tag_scheme1", "tag_term1");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, tagList);
List<BaseCodingDt> secList = new ArrayList<BaseCodingDt>();
List<BaseCodingDt> secList = new ArrayList<>();
secList.add(new CodingDt("sec_scheme1", "sec_term1"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(p1, secList);
List<IdDt> profileList = new ArrayList<IdDt>();
List<IdDt> profileList = new ArrayList<>();
profileList.add(new IdDt("http://foo1"));
ResourceMetadataKeyEnum.PROFILES.put(p1, profileList);
@ -190,10 +190,10 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
TagList tagList = new TagList();
tagList.addTag("tag_scheme2", "tag_term2");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, tagList);
List<BaseCodingDt> secList = new ArrayList<BaseCodingDt>();
List<BaseCodingDt> secList = new ArrayList<>();
secList.add(new CodingDt("sec_scheme2", "sec_term2"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(p1, secList);
List<IdDt> profileList = new ArrayList<IdDt>();
List<IdDt> profileList = new ArrayList<>();
profileList.add(new IdDt("http://foo2"));
ResourceMetadataKeyEnum.PROFILES.put(p1, profileList);
@ -204,7 +204,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(p1);
assertThat(tagList, containsInAnyOrder(new Tag("tag_scheme1", "tag_term1"), new Tag("tag_scheme2", "tag_term2")));
List<BaseCodingDt> secList = ResourceMetadataKeyEnum.SECURITY_LABELS.get(p1);
Set<String> secListValues = new HashSet<String>();
Set<String> secListValues = new HashSet<>();
for (BaseCodingDt next : secList) {
secListValues.add(next.getSystemElement().getValue() + "|" + next.getCodeElement().getValue());
}
@ -215,7 +215,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
}
@Test
public void testUpdateMaintainsSearchParams() throws InterruptedException {
public void testUpdateMaintainsSearchParams() {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2AAA");
p1.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2AAA");
@ -224,7 +224,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testUpdateMaintainsSearchParamsDstu2BBB");
p2.addName().addFamily("Tester").addGiven("testUpdateMaintainsSearchParamsDstu2BBB");
myPatientDao.create(p2, mySrd).getId();
myPatientDao.create(p2, mySrd);
Set<Long> ids = myPatientDao.searchForIds(new SearchParameterMap(Patient.SP_GIVEN, new StringDt("testUpdateMaintainsSearchParamsDstu2AAA")));
assertEquals(1, ids.size());
@ -251,7 +251,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
}
@Test
public void testUpdateRejectsInvalidTypes() throws InterruptedException {
public void testUpdateRejectsInvalidTypes() {
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes");
p1.addName().addFamily("Tester").addGiven("testUpdateRejectsInvalidTypes");
@ -285,7 +285,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addName().addFamily(name);
List<IdDt> tl = new ArrayList<IdDt>();
List<IdDt> tl = new ArrayList<>();
tl.add(new IdDt("http://foo/bar"));
tl.add(new IdDt("http://foo/bar"));
tl.add(new IdDt("http://foo/bar"));
@ -312,7 +312,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
Patient patient = new Patient();
patient.addName().addFamily(name);
List<IdDt> tl = new ArrayList<IdDt>();
List<IdDt> tl = new ArrayList<>();
tl.add(new IdDt("http://foo/bar"));
ResourceMetadataKeyEnum.PROFILES.put(patient, tl);
@ -333,7 +333,7 @@ public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test {
patient.setId(id);
patient.addName().addFamily(name);
List<IdDt> tl = new ArrayList<IdDt>();
List<IdDt> tl = new ArrayList<>();
tl.add(new IdDt("http://foo/baz"));
ResourceMetadataKeyEnum.PROFILES.put(patient, tl);

View File

@ -56,6 +56,8 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
private static JpaValidationSupportChainR4 ourJpaValidationSupportChainR4;
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
@Autowired
protected IResourceLinkDao myResourceLinkDao;
@Autowired
protected ISearchParamDao mySearchParamDao;
@Autowired