Merge pull request #2164 from jamesagnew/im_20201029_ig_package_long_description

Truncate package descriptions that are longer than 200 characters.
This commit is contained in:
IanMMarshall 2020-11-10 12:01:53 -05:00 committed by GitHub
commit bf9e02bc16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 5 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 2164
title: "The JPA Package loader was failing if the package had a description longer than 200 characters. This has been fixed."

View File

@ -217,10 +217,16 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
}
boolean currentVersion = updateCurrentVersionFlagForAllPackagesBasedOnNewIncomingVersion(thePackageId, packageVersionId);
String packageDesc;
if (npmPackage.description().length() > NpmPackageVersionEntity.PACKAGE_DESC_LENGTH) {
packageDesc = npmPackage.description().substring(0, NpmPackageVersionEntity.PACKAGE_DESC_LENGTH - 4) + "...";
} else {
packageDesc = npmPackage.description();
}
if (currentVersion) {
getProcessingMessages(npmPackage).add("Marking package " + thePackageId + "#" + thePackageVersionId + " as current version");
pkg.setCurrentVersionId(packageVersionId);
pkg.setDescription(npmPackage.description());
pkg.setDescription(packageDesc);
myPackageDao.save(pkg);
} else {
getProcessingMessages(npmPackage).add("Package " + thePackageId + "#" + thePackageVersionId + " is not the newest version");
@ -232,7 +238,7 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
packageVersion.setPackage(pkg);
packageVersion.setPackageBinary(persistedPackage);
packageVersion.setSavedTime(new Date());
packageVersion.setDescription(npmPackage.description());
packageVersion.setDescription(packageDesc);
packageVersion.setFhirVersionId(npmPackage.fhirVersion());
packageVersion.setFhirVersion(fhirVersion);
packageVersion.setCurrentVersion(currentVersion);

View File

@ -1,7 +1,11 @@
package ca.uhn.fhir.jpa.packages;
import ca.uhn.fhir.jpa.dao.data.INpmPackageDao;
import ca.uhn.fhir.jpa.dao.data.INpmPackageVersionDao;
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.JsonUtil;
import org.hl7.fhir.utilities.npm.IPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.junit.jupiter.api.Test;
@ -10,13 +14,21 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class JpaPackageCacheTest extends BaseJpaR4Test {
@Autowired
private IPackageCacheManager myPackageCacheManager;
private IHapiPackageCacheManager myPackageCacheManager;
@Autowired
private INpmPackageDao myPackageDao;
@Autowired
private INpmPackageVersionDao myPackageVersionDao;
@Test
public void testSavePackage() throws IOException {
@ -41,6 +53,23 @@ public class JpaPackageCacheTest extends BaseJpaR4Test {
}
@Test
public void testSavePackageWithLongDescription() throws IOException {
try (InputStream stream = IgInstallerDstu3Test.class.getResourceAsStream("/packages/package-davinci-cdex-0.2.0.tgz")) {
myPackageCacheManager.addPackageToCache("hl7.fhir.us.davinci-cdex", "0.2.0", stream, "hl7.fhir.us.davinci-cdex");
}
NpmPackage pkg;
pkg = myPackageCacheManager.loadPackage("hl7.fhir.us.davinci-cdex", null);
assertEquals("0.2.0", pkg.version());
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());
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());
}
@Test
public void testSavePackageCorrectFhirVersion() {

View File

@ -54,6 +54,7 @@ import java.util.List;
public class NpmPackageVersionEntity {
public static final int VERSION_ID_LENGTH = 200;
public static final int PACKAGE_DESC_LENGTH = 200;
public static final int FHIR_VERSION_LENGTH = 10;
@SequenceGenerator(name = "SEQ_NPM_PACKVER", sequenceName = "SEQ_NPM_PACKVER")
@ -74,9 +75,9 @@ public class NpmPackageVersionEntity {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "SAVED_TIME", nullable = false)
private Date mySavedTime;
@Column(name = "PKG_DESC", nullable = true, length = 200)
@Column(name = "PKG_DESC", nullable = true, length = PACKAGE_DESC_LENGTH)
private String myDescription;
@Column(name = "DESC_UPPER", nullable = true, length = 200)
@Column(name = "DESC_UPPER", nullable = true, length = PACKAGE_DESC_LENGTH)
private String myDescriptionUpper;
@Column(name = "CURRENT_VERSION", nullable = false)
private boolean myCurrentVersion;