Skip to content

Commit 881193c

Browse files
author
ianmarshall
committed
Truncate package descriptions that are longer than 200 characters.
1 parent 22fe942 commit 881193c

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/JpaPackageCache.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ public NpmPackage addPackageToCache(String thePackageId, String thePackageVersio
217217
}
218218

219219
boolean currentVersion = updateCurrentVersionFlagForAllPackagesBasedOnNewIncomingVersion(thePackageId, packageVersionId);
220+
String packageDesc;
221+
if (npmPackage.description().length() > NpmPackageVersionEntity.PACKAGE_DESC_LENGTH) {
222+
packageDesc = npmPackage.description().substring(0, NpmPackageVersionEntity.PACKAGE_DESC_LENGTH - 4) + "...";
223+
} else {
224+
packageDesc = npmPackage.description();
225+
}
220226
if (currentVersion) {
221227
getProcessingMessages(npmPackage).add("Marking package " + thePackageId + "#" + thePackageVersionId + " as current version");
222228
pkg.setCurrentVersionId(packageVersionId);
223-
pkg.setDescription(npmPackage.description());
229+
pkg.setDescription(packageDesc);
224230
myPackageDao.save(pkg);
225231
} else {
226232
getProcessingMessages(npmPackage).add("Package " + thePackageId + "#" + thePackageVersionId + " is not the newest version");
@@ -232,7 +238,7 @@ public NpmPackage addPackageToCache(String thePackageId, String thePackageVersio
232238
packageVersion.setPackage(pkg);
233239
packageVersion.setPackageBinary(persistedPackage);
234240
packageVersion.setSavedTime(new Date());
235-
packageVersion.setDescription(npmPackage.description());
241+
packageVersion.setDescription(packageDesc);
236242
packageVersion.setFhirVersionId(npmPackage.fhirVersion());
237243
packageVersion.setFhirVersion(fhirVersion);
238244
packageVersion.setCurrentVersion(currentVersion);

hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package ca.uhn.fhir.jpa.packages;
22

3+
import ca.uhn.fhir.jpa.dao.data.INpmPackageDao;
4+
import ca.uhn.fhir.jpa.dao.data.INpmPackageVersionDao;
35
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
6+
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
47
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
8+
import ca.uhn.fhir.util.JsonUtil;
59
import org.hl7.fhir.utilities.npm.IPackageCacheManager;
610
import org.hl7.fhir.utilities.npm.NpmPackage;
711
import org.junit.jupiter.api.Test;
@@ -10,13 +14,21 @@
1014
import java.io.IOException;
1115
import java.io.InputStream;
1216

17+
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.Matchers.contains;
1319
import static org.junit.jupiter.api.Assertions.assertEquals;
1420
import static org.junit.jupiter.api.Assertions.fail;
1521

1622
public class JpaPackageCacheTest extends BaseJpaR4Test {
1723

1824
@Autowired
19-
private IPackageCacheManager myPackageCacheManager;
25+
private IHapiPackageCacheManager myPackageCacheManager;
26+
27+
@Autowired
28+
private INpmPackageDao myPackageDao;
29+
@Autowired
30+
private INpmPackageVersionDao myPackageVersionDao;
31+
2032

2133
@Test
2234
public void testSavePackage() throws IOException {
@@ -41,6 +53,23 @@ public void testSavePackage() throws IOException {
4153
}
4254

4355

56+
@Test
57+
public void testSavePackageWithLongDescription() throws IOException {
58+
try (InputStream stream = IgInstallerDstu3Test.class.getResourceAsStream("/packages/package-davinci-cdex-0.2.0.tgz")) {
59+
myPackageCacheManager.addPackageToCache("hl7.fhir.us.davinci-cdex", "0.2.0", stream, "hl7.fhir.us.davinci-cdex");
60+
}
61+
62+
NpmPackage pkg;
63+
64+
pkg = myPackageCacheManager.loadPackage("hl7.fhir.us.davinci-cdex", null);
65+
assertEquals("0.2.0", pkg.version());
66+
67+
assertEquals("This IG provides detailed guidance that helps implementers use FHIR-based interactions and resources relevant to support specific exchanges of clinical information between provider and payers (or ...", myPackageDao.findByPackageId("hl7.fhir.us.davinci-cdex").get().getDescription());
68+
assertEquals("This IG provides detailed guidance that helps implementers use FHIR-based interactions and resources relevant to support specific exchanges of clinical information between provider and payers (or ...", myPackageVersionDao.findByPackageIdAndVersion("hl7.fhir.us.davinci-cdex", "0.2.0").get().getDescription());
69+
70+
}
71+
72+
4473
@Test
4574
public void testSavePackageCorrectFhirVersion() {
4675

Binary file not shown.

hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionEntity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
public class NpmPackageVersionEntity {
5555

5656
public static final int VERSION_ID_LENGTH = 200;
57+
public static final int PACKAGE_DESC_LENGTH = 200;
5758
public static final int FHIR_VERSION_LENGTH = 10;
5859

5960
@SequenceGenerator(name = "SEQ_NPM_PACKVER", sequenceName = "SEQ_NPM_PACKVER")
@@ -74,9 +75,9 @@ public class NpmPackageVersionEntity {
7475
@Temporal(TemporalType.TIMESTAMP)
7576
@Column(name = "SAVED_TIME", nullable = false)
7677
private Date mySavedTime;
77-
@Column(name = "PKG_DESC", nullable = true, length = 200)
78+
@Column(name = "PKG_DESC", nullable = true, length = PACKAGE_DESC_LENGTH)
7879
private String myDescription;
79-
@Column(name = "DESC_UPPER", nullable = true, length = 200)
80+
@Column(name = "DESC_UPPER", nullable = true, length = PACKAGE_DESC_LENGTH)
8081
private String myDescriptionUpper;
8182
@Column(name = "CURRENT_VERSION", nullable = false)
8283
private boolean myCurrentVersion;

0 commit comments

Comments
 (0)