Fixed tests

This commit is contained in:
jamesagnew 2018-07-14 13:51:11 -04:00
parent 738abc415c
commit 84b57f04d3
2 changed files with 35 additions and 43 deletions

View File

@ -92,9 +92,9 @@ import static org.apache.commons.lang3.StringUtils.*;
* 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.
@ -1167,7 +1167,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
public SearchBuilder newSearchBuilder() {
SearchBuilder builder = new SearchBuilder(
getContext(), myEntityManager, myFulltextSearchSvc, this, myResourceIndexedSearchParamUriDao,
myForcedIdDao, myTerminologySvc, mySerarchParamRegistry, myResourceTagDao, myResourceViewDao);
myForcedIdDao, myTerminologySvc, mySerarchParamRegistry, myResourceTagDao, myResourceViewDao);
return builder;
}
@ -1301,21 +1301,24 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
}
}
// Don't keep duplicate tags
Set<ResourceTag> allTagsNew = getAllTagDefinitions(theEntity);
Set<TagDefinition> allDefsPresent = new HashSet<>();
Collection<ResourceTag> tags;
allTagsOld.removeIf(theResourceTag -> !allDefsPresent.add(theResourceTag.getTag()));
allTagsNew.forEach(tag -> {
// Remove any tags that have been removed
for (ResourceTag next : allTagsOld) {
if (!allDefs.contains(next)) {
if (shouldDroppedTagBeRemovedOnUpdate(theRequest, next)) {
allTagsOld.remove(next);
// Don't keep duplicate tags
if (!allDefsPresent.add(tag.getTag())) {
theEntity.getTags().remove(tag);
}
// Drop any tags that have been removed
if (!allDefs.contains(tag)) {
if (shouldDroppedTagBeRemovedOnUpdate(theRequest, tag)) {
theEntity.getTags().remove(tag);
}
}
}
Set<ResourceTag> allTagsNew = getAllTagDefinitions(theEntity);
});
if (!allTagsOld.equals(allTagsNew)) {
changed = true;
}
@ -1474,6 +1477,15 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
return retVal;
}
/**
* Subclasses may override to provide behaviour. Called when a pre-existing resource has been updated in the database
*
* @param theEntity The resource
*/
protected void postDelete(ResourceTable theEntity) {
// nothing
}
/**
* Subclasses may override to provide behaviour. Called when a resource has been inserted into the database for the first time.
*
@ -1484,15 +1496,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
// nothing
}
/**
* Subclasses may override to provide behaviour. Called when a pre-existing resource has been updated in the database
*
* @param theEntity The resource
*/
protected void postDelete(ResourceTable theEntity) {
// nothing
}
/**
* Subclasses may override to provide behaviour. Called when a pre-existing resource has been updated in the database
*
@ -1627,20 +1630,20 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
@SuppressWarnings("unchecked")
@Override
public <R extends IBaseResource> R toResource(Class<R> theResourceType, IBaseResourceEntity theEntity, Collection<ResourceTag> theTagList, boolean theForHistoryOperation) {
// 1. get resource, it's encoding and the tags if any
byte[] resourceBytes = null;
ResourceEncodingEnum resourceEncoding = null;
Collection<? extends BaseTag> myTagList = null;
if (theEntity instanceof ResourceHistoryTable) {
ResourceHistoryTable history = (ResourceHistoryTable) theEntity;
resourceBytes = history.getResource();
resourceEncoding = history.getEncoding();
myTagList = history.getTags();
} else if (theEntity instanceof ResourceTable) {
ResourceTable resource = (ResourceTable)theEntity;
ResourceHistoryTable history = myResourceHistoryTableDao.findForIdAndVersion(theEntity.getId(), theEntity.getVersion());
ResourceTable resource = (ResourceTable) theEntity;
ResourceHistoryTable history = myResourceHistoryTableDao.findForIdAndVersion(theEntity.getId(), theEntity.getVersion());
if (history == null) {
return null;
}
@ -1649,7 +1652,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
myTagList = resource.getTags();
} else if (theEntity instanceof ResourceSearchView) {
// This is the search View
ResourceSearchView myView = (ResourceSearchView)theEntity;
ResourceSearchView myView = (ResourceSearchView) theEntity;
resourceBytes = myView.getResource();
resourceEncoding = myView.getEncoding();
if (theTagList == null)
@ -1664,7 +1667,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
// 2. get The text
String resourceText = null;
switch (resourceEncoding) {
case JSON:
case JSON:
try {
resourceText = new String(resourceBytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
@ -1677,7 +1680,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
case DEL:
break;
}
// 3. Use the appropriate custom type if one is specified in the context
Class<R> resourceType = theResourceType;
if (myContext.hasDefaultTypeForProfile()) {
@ -2197,16 +2200,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
} // if thePerformIndexing
// FIXME: needed?
//theEntity = myEntityManager.merge(theEntity);
myEntityManager.flush();
if (theResource != null) {
populateResourceIdFromEntity(theEntity, theResource);
}
return theEntity;
}

View File

@ -39,9 +39,7 @@ public class FhirResourceDaoR4UpdateTagSnapshotTest extends BaseJpaR4Test {
myPatientDao.update(p, mySrd);
p = myPatientDao.read(new IdType("A"), mySrd);
// It would be nice if this didn't trigger a version update but
// i guess it's not so bad that it does
assertEquals("2", p.getIdElement().getVersionIdPart());
assertEquals("1", p.getIdElement().getVersionIdPart());
assertEquals(true, p.getActive());
assertEquals(1, p.getMeta().getTag().size());
}
@ -86,9 +84,7 @@ public class FhirResourceDaoR4UpdateTagSnapshotTest extends BaseJpaR4Test {
myPatientDao.update(p, mySrd);
p = myPatientDao.read(new IdType("A"), mySrd);
// It would be nice if this didn't trigger a version update but
// i guess it's not so bad that it does
assertEquals("2", p.getIdElement().getVersionIdPart());
assertEquals("1", p.getIdElement().getVersionIdPart());
assertEquals(true, p.getActive());
assertEquals(1, p.getMeta().getTag().size());
assertEquals("urn:foo", p.getMeta().getTag().get(0).getSystem());
@ -136,9 +132,7 @@ public class FhirResourceDaoR4UpdateTagSnapshotTest extends BaseJpaR4Test {
p = myPatientDao.read(new IdType("A"), mySrd);
assertEquals(true, p.getActive());
assertEquals(0, p.getMeta().getTag().size());
// It would be nice if this didn't trigger a version update but
// i guess it's not so bad that it does
assertEquals("2", p.getIdElement().getVersionIdPart());
assertEquals("1", p.getIdElement().getVersionIdPart());
}
@AfterClass