Return last updated time and version ID for instance $meta operation
This commit is contained in:
parent
febae3f07d
commit
fa76071bd3
|
@ -870,7 +870,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
}
|
||||
}
|
||||
|
||||
protected MetaDt toMetaDt(List<TagDefinition> tagDefinitions) {
|
||||
protected MetaDt toMetaDt(Collection<TagDefinition> tagDefinitions) {
|
||||
MetaDt retVal = new MetaDt();
|
||||
for (TagDefinition next : tagDefinitions) {
|
||||
switch (next.getTagType()) {
|
||||
|
|
|
@ -1733,9 +1733,10 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
|||
}
|
||||
|
||||
myEntityManager.merge(entity);
|
||||
|
||||
myEntityManager.flush();
|
||||
|
||||
ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() });
|
||||
|
||||
|
||||
return metaGetOperation(theResourceId);
|
||||
}
|
||||
|
||||
|
@ -1761,16 +1762,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
|||
ActionRequestDetails requestDetails = new ActionRequestDetails(theId, getResourceName());
|
||||
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
|
||||
|
||||
Long pid = super.translateForcedIdToPid(theId);
|
||||
|
||||
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t WHERE t.myResourceType = :res_type AND t.myResourceId = :res_id)";
|
||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
|
||||
q.setParameter("res_type", myResourceName);
|
||||
q.setParameter("res_id", pid);
|
||||
List<TagDefinition> tagDefinitions = q.getResultList();
|
||||
|
||||
MetaDt retVal = super.toMetaDt(tagDefinitions);
|
||||
Set<TagDefinition> tagDefs = new HashSet<TagDefinition>();
|
||||
BaseHasResource entity = readEntity(theId);
|
||||
for (BaseTag next : entity.getTags()) {
|
||||
tagDefs.add(next.getTag());
|
||||
}
|
||||
MetaDt retVal = super.toMetaDt(tagDefs);
|
||||
|
||||
retVal.setLastUpdated(entity.getUpdated());
|
||||
retVal.setVersionId(Long.toString(entity.getVersion()));
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,9 +77,10 @@ public class ResourceHistoryTag extends BaseTag implements Serializable {
|
|||
|
||||
|
||||
public ResourceHistoryTag(ResourceHistoryTable theResourceHistoryTable, TagDefinition theTag) {
|
||||
myResourceHistory=theResourceHistoryTable;
|
||||
setTag(theTag);
|
||||
setResource(theResourceHistoryTable);
|
||||
setResourceId(theResourceHistoryTable.getResourceId());
|
||||
setResourceType(theResourceHistoryTable.getResourceType());
|
||||
}
|
||||
|
||||
public ResourceHistoryTable getResourceHistory() {
|
||||
|
|
|
@ -143,7 +143,6 @@ public class ResourceTable extends BaseHasResource implements Serializable {
|
|||
|
||||
public ResourceTag addTag(TagDefinition theTag) {
|
||||
ResourceTag tag = new ResourceTag(this, theTag);
|
||||
tag.setResourceType(getResourceType());
|
||||
getTags().add(tag);
|
||||
return tag;
|
||||
}
|
||||
|
|
|
@ -65,9 +65,10 @@ public class ResourceTag extends BaseTag {
|
|||
}
|
||||
|
||||
public ResourceTag(ResourceTable theResourceTable, TagDefinition theTag) {
|
||||
myResource = theResourceTable;
|
||||
myResourceId = theResourceTable.getId();
|
||||
setTag(theTag);
|
||||
setResource(theResourceTable);
|
||||
setResourceId(theResourceTable.getId());
|
||||
setResourceType(theResourceTable.getResourceType());
|
||||
}
|
||||
|
||||
public ResourceTable getResource() {
|
||||
|
|
|
@ -230,8 +230,8 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
@Test
|
||||
public void testCreateOperationOutcome() {
|
||||
/*
|
||||
* If any of this ever fails, it means that one of the OperationOutcome issue severity codes has changed code
|
||||
* value across versions. We store the string as a constant, so something will need to be fixed.
|
||||
* If any of this ever fails, it means that one of the OperationOutcome issue severity codes has changed code value across versions. We store the string as a constant, so something will need to
|
||||
* be fixed.
|
||||
*/
|
||||
assertEquals(org.hl7.fhir.instance.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseHapiFhirResourceDao.OO_SEVERITY_ERROR);
|
||||
assertEquals(ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum.ERROR.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_ERROR);
|
||||
|
@ -311,7 +311,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("Organization/");
|
||||
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
|
@ -325,12 +325,12 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("Blah/123");
|
||||
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Does not contain resource ID"));
|
||||
assertThat(e.getMessage(), containsString("Resource type is unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("123");
|
||||
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
|
@ -348,8 +348,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateWithIfNoneExistBasic() {
|
||||
String methodName = "testCreateWithIfNoneExistBasic";
|
||||
|
@ -1108,6 +1106,141 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstanceMetaOperations() {
|
||||
String methodName = "testMetaRead";
|
||||
IIdType id;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
TagList tagList = new TagList();
|
||||
tagList.addTag("tag_scheme1", "tag_code1", "tag_display1");
|
||||
tagList.addTag("tag_scheme2", "tag_code2", "tag_display2");
|
||||
ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList);
|
||||
|
||||
List<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
|
||||
securityLabels.add(new CodingDt().setSystem("seclabel_sys1").setCode("seclabel_code1").setDisplay("seclabel_dis1"));
|
||||
securityLabels.add(new CodingDt().setSystem("seclabel_sys2").setCode("seclabel_code2").setDisplay("seclabel_dis2"));
|
||||
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
|
||||
|
||||
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
|
||||
profiles.add(new IdDt("http://profile/1"));
|
||||
profiles.add(new IdDt("http://profile/2"));
|
||||
ResourceMetadataKeyEnum.PROFILES.put(patient, profiles);
|
||||
|
||||
id = myPatientDao.create(patient).getId();
|
||||
}
|
||||
|
||||
assertTrue(id.hasVersionIdPart());
|
||||
|
||||
/*
|
||||
* Create a second version
|
||||
*/
|
||||
|
||||
Patient pt = myPatientDao.read(id);
|
||||
pt.addName().addFamily("anotherName");
|
||||
myPatientDao.update(pt);
|
||||
|
||||
/*
|
||||
* Meta-Delete on previous version
|
||||
*/
|
||||
|
||||
MetaDt meta = new MetaDt();
|
||||
meta.addTag().setSystem("tag_scheme1").setCode("tag_code1");
|
||||
meta.addProfile("http://profile/1");
|
||||
meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1");
|
||||
MetaDt newMeta = myPatientDao.metaDeleteOperation(id.withVersion("1"), meta);
|
||||
assertEquals(1, newMeta.getProfile().size());
|
||||
assertEquals(1, newMeta.getSecurity().size());
|
||||
assertEquals(1, newMeta.getTag().size());
|
||||
assertEquals("tag_code2", newMeta.getTag().get(0).getCode());
|
||||
assertEquals("http://profile/2", newMeta.getProfile().get(0).getValue());
|
||||
assertEquals("seclabel_code2", newMeta.getSecurity().get(0).getCode());
|
||||
|
||||
/*
|
||||
* Meta Read on Version
|
||||
*/
|
||||
|
||||
meta = myPatientDao.metaGetOperation(id.withVersion("1"));
|
||||
assertEquals(1, meta.getProfile().size());
|
||||
assertEquals(1, meta.getSecurity().size());
|
||||
assertEquals(1, meta.getTag().size());
|
||||
assertEquals("tag_code2", meta.getTag().get(0).getCode());
|
||||
assertEquals("http://profile/2", meta.getProfile().get(0).getValue());
|
||||
assertEquals("seclabel_code2", meta.getSecurity().get(0).getCode());
|
||||
|
||||
/*
|
||||
* Meta-read on Version 2
|
||||
*/
|
||||
meta = myPatientDao.metaGetOperation(id.withVersion("2"));
|
||||
assertEquals(2, meta.getProfile().size());
|
||||
assertEquals(2, meta.getSecurity().size());
|
||||
assertEquals(2, meta.getTag().size());
|
||||
|
||||
/*
|
||||
* Meta-read on latest version
|
||||
*/
|
||||
meta = myPatientDao.metaGetOperation(id.toVersionless());
|
||||
assertEquals(2, meta.getProfile().size());
|
||||
assertEquals(2, meta.getSecurity().size());
|
||||
assertEquals(2, meta.getTag().size());
|
||||
assertEquals("2", meta.getVersionId());
|
||||
|
||||
/*
|
||||
* Meta-Add on previous version
|
||||
*/
|
||||
|
||||
meta = new MetaDt();
|
||||
meta.addTag().setSystem("tag_scheme1").setCode("tag_code1");
|
||||
meta.addProfile("http://profile/1");
|
||||
meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1");
|
||||
newMeta = myPatientDao.metaAddOperation(id.withVersion("1"), meta);
|
||||
assertEquals(2, newMeta.getProfile().size());
|
||||
assertEquals(2, newMeta.getSecurity().size());
|
||||
assertEquals(2, newMeta.getTag().size());
|
||||
|
||||
/*
|
||||
* Meta Read on Version
|
||||
*/
|
||||
|
||||
meta = myPatientDao.metaGetOperation(id.withVersion("1"));
|
||||
assertEquals(2, meta.getProfile().size());
|
||||
assertEquals(2, meta.getSecurity().size());
|
||||
assertEquals(2, meta.getTag().size());
|
||||
assertEquals("1", meta.getVersionId());
|
||||
|
||||
/*
|
||||
* Meta delete on latest
|
||||
*/
|
||||
|
||||
meta = new MetaDt();
|
||||
meta.addTag().setSystem("tag_scheme1").setCode("tag_code1");
|
||||
meta.addProfile("http://profile/1");
|
||||
meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1");
|
||||
newMeta = myPatientDao.metaDeleteOperation(id.toVersionless(), meta);
|
||||
assertEquals(1, newMeta.getProfile().size());
|
||||
assertEquals(1, newMeta.getSecurity().size());
|
||||
assertEquals(1, newMeta.getTag().size());
|
||||
assertEquals("tag_code2", newMeta.getTag().get(0).getCode());
|
||||
assertEquals("http://profile/2", newMeta.getProfile().get(0).getValue());
|
||||
assertEquals("seclabel_code2", newMeta.getSecurity().get(0).getCode());
|
||||
|
||||
/*
|
||||
* Meta-Add on latest version
|
||||
*/
|
||||
|
||||
meta = new MetaDt();
|
||||
meta.addTag().setSystem("tag_scheme1").setCode("tag_code1");
|
||||
meta.addProfile("http://profile/1");
|
||||
meta.addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1");
|
||||
newMeta = myPatientDao.metaAddOperation(id.toVersionless(), meta);
|
||||
assertEquals(2, newMeta.getProfile().size());
|
||||
assertEquals(2, newMeta.getSecurity().size());
|
||||
assertEquals(2, newMeta.getTag().size());
|
||||
assertEquals("2", meta.getVersionId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceInstanceMetaOperation() {
|
||||
|
||||
|
@ -1370,7 +1503,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get((IResource) results.get(1)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSortByDate() {
|
||||
Patient p = new Patient();
|
||||
|
@ -1841,5 +1973,4 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -151,6 +151,10 @@
|
|||
security labels were not always properly removed by an update that
|
||||
was trying to remove them. Also don't store duplicates.
|
||||
</action>
|
||||
<action type="fix">
|
||||
Instance $meta operations on JPA server did not previously return the
|
||||
resource version and lastUpdated time
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.1" date="2015-07-13">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue