Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support private (non-HL7) publication of templates #716

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,10 @@ private String makeTemplateIndexPage() {
}

private String makeTemplateJekyllIndexPage() {
String page = "---"+
"layout: page"+
"title: {{npm}}"+
"---"+
String page = "---\r\n"+
"layout: page\r\n"+
"title: {{npm}}\r\n"+
"---\r\n"+
" <p><b>Template {{npm}}</b></p>\r\n"+
" <p>You can <a href=\"package.tgz\">download the template</a>, though you should not need to; just refer to the template as {{npm}} in your IG configuration.</p>\r\n"+
" <p>A <a href=\"{{canonical}}/history.html\">full version history is published</a></p>\r\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public String summary() {

private File xml;

private Boolean assumeValidDependencies;


// 3 parameters: source of package, package dest folder, and release note
public static void main(String[] args) throws Exception {
Expand All @@ -138,6 +140,7 @@ public static void main(String[] args) throws Exception {

private void release(String source, String dest) throws Exception {
SimpleDateFormat df = new SimpleDateFormat(RSS_DATE, new Locale("en", "US"));
assumeValidDependencies = ("YES".equals(System.getenv("PUB_ASSUME_VALID_DEPENDENCIES")));
checkDest(dest);
Map<String, String> currentPublishedVersions = scanForCurrentVersions(dest);
System.out.println("Current Published Versions");
Expand Down Expand Up @@ -215,13 +218,21 @@ private void buildIndexPage(Map<String, String> currentVersions, String path) th
for (String id : Utilities.sorted(currentVersions.keySet())) {
tr = tbl.tr();
PackageList pl = new PackageList(JsonParser.parseObject(new File(Utilities.path(path, id, "package-list.json"))));
tr.td().ah("http://fhir.org/templates/"+id).tx(pl.pid());
tr.td().ah(pl.canonical()).tx(pl.pid());
tr.td().tx(pl.title());
tr.td().ah("http://fhir.org/templates/"+id+"/"+pl.current().version()+"/package.tgz").tx(pl.current().version());
tr.td().ah(pl.canonical() + "/" + pl.current().version() + "/package.tgz").tx(pl.current().version());
tr.td().tx(pl.current().date());
}
String s = INDEX_TEMPLATE.replace("{{index}}", new XhtmlComposer(false, false).compose(tbl));
TextFile.stringToFile(s, Utilities.path(path, "index.html"), false);

String templateName = System.getenv("PUB_INDEX_TEMPLATE_FILE");
if (templateName != null) {
String s = TextFile.fileToString(templateName).replace("{{index}}", new XhtmlComposer(false, false).compose(tbl));
TextFile.stringToFile(s, Utilities.path(path, "index.html"), false);
}
else {
String s = INDEX_TEMPLATE.replace("{{index}}", new XhtmlComposer(false, false).compose(tbl));
TextFile.stringToFile(s, Utilities.path(path, "index.html"), false);
}
}

private void build(String source, VersionDecision vd, List<VersionDecision> versions) throws Exception {
Expand All @@ -242,19 +253,33 @@ private void updateVersions(String source, VersionDecision vd, List<VersionDecis
if (npm.has("dependencies")) {
JsonObject d = npm.getJsonObject("dependencies");
List<String> deps = new ArrayList<>();
for (JsonProperty e : d.getProperties()) {
deps.add(e.getName());
if (assumeValidDependencies) {
for (JsonProperty e : d.getProperties()) {
if (assumeValidDependencies && "current".equals(e.getValue().asJsonString().getValue())) {
throw new Error("When skipping dependency checks, cannot use \"current\" for "+e.getName()+" in "+vd.getId()+".");
}
}
}
for (String s : deps) {
d.remove(s);
d.add(s, findVersion(versionsList, s).newVersion);
else {
for (JsonProperty e : d.getProperties()) {
deps.add(e.getName());
}
if (!assumeValidDependencies) {
for (String s : deps) {
d.remove(s);
d.add(s, findVersion(versionsList, s).newVersion);
}
}
}
}
String jcnt = JsonParser.compose(npm, true);
TextFile.stringToFile(jcnt, Utilities.path(source, vd.getId(), "package", "package.json"));
}

private void resetVersions(String source, VersionDecision vd, List<VersionDecision> versionsList) throws FileNotFoundException, IOException {
if (assumeValidDependencies) {
return;
}
JsonObject npm = JsonParser.parseObject(new FileInputStream(Utilities.path(source, vd.getId(), "package", "package.json")));
if (npm.has("dependencies")) {
JsonObject d = npm.getJsonObject("dependencies");
Expand Down Expand Up @@ -282,7 +307,7 @@ private void updateDate(String source, VersionDecision vd, String dateFmt) throw
}
}
if (!ok) {
throw new Error("unable to find version "+vd.getNewVersion()+" in pacjage list");
throw new Error("unable to find version "+vd.getNewVersion()+" in package list");
}
TextFile.stringToFile(pl.toJson(), Utilities.path(source, vd.getId(), "package-list.json"));
}
Expand Down Expand Up @@ -356,8 +381,8 @@ private String getNewVersion(VersionChangeType t, String v) {

private void checkDependencies(String source, VersionDecision vd, List<VersionDecision> versions) throws Exception {
vd.checked = false;
List<String> dependendencies = listDependencies(source, vd.getId());
for (String s : dependendencies) {
List<String> dependencies = listDependencies(source, vd.getId());
for (String s : dependencies) {
VersionDecision v = findVersion(versions, s);
if (v.checked == null) {
checkDependencies(source, v, versions);
Expand Down Expand Up @@ -395,7 +420,7 @@ private VersionDecision findVersion(List<VersionDecision> versions, String s) {
private List<String> listDependencies(String source, String id) throws Exception {
JsonObject npm = JsonParser.parseObject(TextFile.fileToString(Utilities.path(source, id, "package", "package.json")));
List<String> res = new ArrayList<String>();
if (npm.has("dependencies")) {
if (!assumeValidDependencies && npm.has("dependencies")) {
for (JsonProperty s : npm.getJsonObject("dependencies").getProperties()) {
// if (!"current".equals(s.getValue().getAsString())) {
// throw new Exception("Dependency is not 'current'");
Expand Down