mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
Now convert pure numeric ids to "npm-<id>".
This commit is contained in:
parent
e8ac24b4df
commit
320e8379b3
@ -1,4 +1,5 @@
|
||||
---
|
||||
type: add
|
||||
issue: 2590
|
||||
title: "When resources are created using package load, the new resources will use the same IDs as were provided in with the resource definitions in the package, if they exist"
|
||||
title: "When resources are created using package load, the new resources will use the same IDs as were provided in with the resource definitions in the package, if they exist.
|
||||
If the ids are numeric, a prefix of 'npm-' will be added."
|
||||
|
@ -337,12 +337,15 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
|
||||
createResource(dao, theResource);
|
||||
ourLog.info("Created resource with new id");
|
||||
} else {
|
||||
if (id.isIdPartValidLong()) {
|
||||
String newIdPart = "npm-" + id.getIdPart();
|
||||
id.setParts(id.getBaseUrl(), id.getResourceType(), newIdPart, id.getVersionIdPart());
|
||||
}
|
||||
updateResource(dao, theResource);
|
||||
ourLog.info("Created resource with existing id");
|
||||
}
|
||||
} else {
|
||||
|
||||
ourLog.info("Updating existing resource matching {}", map.toNormalizedQueryString(myFhirContext));
|
||||
ourLog.info("Updating existing resource matching {}", map.toNormalizedQueryString(myFhirContext));
|
||||
theResource.setId(searchResult.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless());
|
||||
DaoMethodOutcome outcome = updateResource(dao, theResource);
|
||||
if (!outcome.isNop()) {
|
||||
|
@ -262,6 +262,30 @@ public class NpmR4Test extends BaseJpaR4Test {
|
||||
IBaseResource resource = result.getResources(0, 1).get(0);
|
||||
assertEquals("CodeSystem/shorthand-code-system/_history/1", resource.getIdElement().toString());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumericIdsInstalledWithNpmPrefix() throws Exception {
|
||||
myDaoConfig.setAllowExternalReferences(true);
|
||||
|
||||
// Load a copy of hl7.fhir.uv.shorthand-0.12.0, but with id set to 1 instead of "shorthand-code-system"
|
||||
byte[] bytes = loadClasspathBytes("/packages/hl7.fhir.uv.shorthand-0.13.0.tgz");
|
||||
myFakeNpmServlet.myResponses.put("/hl7.fhir.uv.shorthand/0.13.0", bytes);
|
||||
|
||||
PackageInstallationSpec spec = new PackageInstallationSpec().setName("hl7.fhir.uv.shorthand").setVersion("0.13.0").setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL);
|
||||
PackageInstallOutcomeJson outcome = myPackageInstallerSvc.install(spec);
|
||||
// Be sure no further communication with the server
|
||||
JettyUtil.closeServer(myServer);
|
||||
|
||||
// Search for the installed resource
|
||||
runInTransaction(() -> {
|
||||
SearchParameterMap map = SearchParameterMap.newSynchronous();
|
||||
map.add(StructureDefinition.SP_URL, new UriParam("http://hl7.org/fhir/uv/shorthand/CodeSystem/shorthand-code-system"));
|
||||
IBundleProvider result = myCodeSystemDao.search(map);
|
||||
assertEquals(1, result.sizeOrThrowNpe());
|
||||
IBaseResource resource = result.getResources(0, 1).get(0);
|
||||
assertEquals("CodeSystem/npm-1/_history/1", resource.getIdElement().toString());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user