Skip to content

Commit

Permalink
Merge branch 'master' into valueset_expansion_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jun 21, 2018
2 parents 024394e + e63604a commit cc98f65
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 104 deletions.
Expand Up @@ -1174,7 +1174,7 @@ protected void markRequestAsProcessingSubRequest(ServletRequestDetails theReques
public SearchBuilder newSearchBuilder() {
SearchBuilder builder = new SearchBuilder(getContext(), myEntityManager, myFulltextSearchSvc, this, myResourceIndexedSearchParamUriDao,
myForcedIdDao,
myTerminologySvc, mySerarchParamRegistry);
myTerminologySvc, mySerarchParamRegistry, myResourceHistoryTableDao, myResourceTagDao);
return builder;
}

Expand Down Expand Up @@ -1355,7 +1355,7 @@ protected EncodedResource populateResourceIntoEntity(RequestDetails theRequest,
}

@SuppressWarnings("unchecked")
private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IResource res) {
private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theResourceType, BaseHasResource theEntity, Collection<? extends BaseTag> theTagList, boolean theForHistoryOperation, IResource res) {
R retVal = (R) res;
if (theEntity.getDeleted() != null) {
res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance();
Expand Down Expand Up @@ -1384,7 +1384,7 @@ private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theRes
ResourceMetadataKeyEnum.UPDATED.put(res, theEntity.getUpdated());
IDao.RESOURCE_PID.put(res, theEntity.getId());

Collection<? extends BaseTag> tags = theEntity.getTags();
Collection<? extends BaseTag> tags = theTagList;
if (theEntity.isHasTags()) {
TagList tagList = new TagList();
List<IBaseCoding> securityLabels = new ArrayList<>();
Expand Down Expand Up @@ -1421,7 +1421,7 @@ private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theRes
}

@SuppressWarnings("unchecked")
private <R extends IBaseResource> R populateResourceMetadataRi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IAnyResource res) {
private <R extends IBaseResource> R populateResourceMetadataRi(Class<R> theResourceType, BaseHasResource theEntity, Collection<? extends BaseTag> theTagList, boolean theForHistoryOperation, IAnyResource res) {
R retVal = (R) res;
if (theEntity.getDeleted() != null) {
res = (IAnyResource) myContext.getResourceDefinition(theResourceType).newInstance();
Expand Down Expand Up @@ -1454,7 +1454,7 @@ private <R extends IBaseResource> R populateResourceMetadataRi(Class<R> theResou
res.getMeta().setLastUpdated(theEntity.getUpdatedDate());
IDao.RESOURCE_PID.put(res, theEntity.getId());

Collection<? extends BaseTag> tags = theEntity.getTags();
Collection<? extends BaseTag> tags = theTagList;

if (theEntity.isHasTags()) {
for (BaseTag next : tags) {
Expand Down Expand Up @@ -1601,19 +1601,25 @@ private ExpungeOutcome toExpungeOutcome(ExpungeOptions theExpungeOptions, Atomic
public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) {
RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType());
Class<? extends IBaseResource> resourceType = type.getImplementingClass();
return toResource(resourceType, theEntity, theForHistoryOperation);
return toResource(resourceType, theEntity, null, null, theForHistoryOperation);
}

@SuppressWarnings("unchecked")
@Override
public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity,
public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, ResourceHistoryTable theHistory, Collection<ResourceTag> theTagList,
boolean theForHistoryOperation) {

// May 28, 2018 - #936
// Could set historyList to null, if it's not called in the loop for the backward compatibility
ResourceHistoryTable history;
if (theEntity instanceof ResourceHistoryTable) {
history = (ResourceHistoryTable) theEntity;
} else {
history = myResourceHistoryTableDao.findForIdAndVersion(theEntity.getId(), theEntity.getVersion());
if (theHistory == null) {
history = myResourceHistoryTableDao.findForIdAndVersion(theEntity.getId(), theEntity.getVersion());
} else {
history = theHistory;
}
}

if (history == null) {
Expand All @@ -1639,12 +1645,21 @@ public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasR
break;
}

// get preload the tagList
Collection<? extends BaseTag> myTagList;

if (theTagList == null)
myTagList = theEntity.getTags();
else
myTagList = theTagList;


/*
* Use the appropriate custom type if one is specified in the context
*/
Class<R> resourceType = theResourceType;
if (myContext.hasDefaultTypeForProfile()) {
for (BaseTag nextTag : theEntity.getTags()) {
for (BaseTag nextTag : myTagList) {
if (nextTag.getTag().getTagType() == TagTypeEnum.PROFILE) {
String profile = nextTag.getTag().getCode();
if (isNotBlank(profile)) {
Expand Down Expand Up @@ -1691,10 +1706,10 @@ public <R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasR

if (retVal instanceof IResource) {
IResource res = (IResource) retVal;
retVal = populateResourceMetadataHapi(resourceType, theEntity, theForHistoryOperation, res);
retVal = populateResourceMetadataHapi(resourceType, theEntity, myTagList, theForHistoryOperation, res);
} else {
IAnyResource res = (IAnyResource) retVal;
retVal = populateResourceMetadataRi(resourceType, theEntity, theForHistoryOperation, res);
retVal = populateResourceMetadataRi(resourceType, theEntity, myTagList, theForHistoryOperation, res);
}


Expand Down Expand Up @@ -1730,7 +1745,7 @@ private String translatePidIdToForcedId(String theResourceType, Long theId) {
return theResourceType + '/' + theId.toString();
}
}

@SuppressWarnings("unchecked")
protected ResourceTable updateEntity(RequestDetails theRequest, final IBaseResource theResource, ResourceTable
theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
Expand Down
Expand Up @@ -207,7 +207,7 @@ public DaoMethodOutcome delete(IIdType theId, List<DeleteConflict> theDeleteConf

StopWatch w = new StopWatch();

T resourceToDelete = toResource(myResourceType, entity, false);
T resourceToDelete = toResource(myResourceType, entity, null, null, false);

// Notify IServerOperationInterceptors about pre-action call
if (theReques != null) {
Expand Down Expand Up @@ -289,7 +289,7 @@ public DeleteMethodOutcome deleteByUrl(String theUrl, List<DeleteConflict> delet
ResourceTable entity = myEntityManager.find(ResourceTable.class, pid);
deletedResources.add(entity);

T resourceToDelete = toResource(myResourceType, entity, false);
T resourceToDelete = toResource(myResourceType, entity, null, null, false);

// Notify IServerOperationInterceptors about pre-action call
if (theRequest != null) {
Expand Down Expand Up @@ -854,7 +854,7 @@ public T read(IIdType theId, RequestDetails theRequestDetails) {
BaseHasResource entity = readEntity(theId);
validateResourceType(entity);

T retVal = toResource(myResourceType, entity, false);
T retVal = toResource(myResourceType, entity, null, null, false);

IPrimitiveType<Date> deleted;
if (retVal instanceof IResource) {
Expand Down
@@ -1,15 +1,18 @@
package ca.uhn.fhir.jpa.dao;

import java.util.Collection;
import java.util.Set;

import org.hl7.fhir.instance.model.api.IBaseResource;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.entity.ResourceTag;
import ca.uhn.fhir.jpa.search.PersistedJpaBundleProvider;
import org.hl7.fhir.instance.model.api.IBaseResource;

import java.util.Collection;
import java.util.Set;

/*
* #%L
Expand Down Expand Up @@ -56,6 +59,6 @@ public interface IDao {

IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation);

<R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation);
<R extends IBaseResource> R toResource(Class<R> theResourceType, BaseHasResource theEntity, ResourceHistoryTable theHistory, Collection<ResourceTag> theTagList, boolean theForHistoryOperation);

}

0 comments on commit cc98f65

Please sign in to comment.