use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertTrue(doc != null);
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NPMPackageGenerator method buildPackageJson.
private void buildPackageJson(String canonical, PackageType kind, String web, Date date, ImplementationGuide ig, List<String> fhirVersion, boolean notForPublication) throws FHIRException, IOException {
String dtHuman = new SimpleDateFormat("EEE, MMM d, yyyy HH:mmZ", new Locale("en", "US")).format(date);
String dt = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (!ig.hasPackageId()) {
b.append("packageId");
}
if (!ig.hasVersion()) {
b.append("version");
}
if (!ig.hasFhirVersion()) {
b.append("fhirVersion");
}
if (!ig.hasLicense()) {
b.append("license");
}
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
if (!d.hasVersion()) {
b.append("dependsOn.version(" + d.getUri() + ")");
}
}
JsonObject npm = new JsonObject();
npm.addProperty("name", ig.getPackageId());
npm.addProperty("version", ig.getVersion());
igVersion = ig.getVersion();
npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
npm.addProperty("type", kind.getCode());
npm.addProperty("date", dt);
if (ig.hasLicense()) {
npm.addProperty("license", ig.getLicense().toCode());
}
npm.addProperty("canonical", canonical);
if (notForPublication) {
npm.addProperty("notForPublication", true);
}
npm.addProperty("url", web);
if (ig.hasTitle()) {
npm.addProperty("title", ig.getTitle());
}
if (ig.hasDescription()) {
npm.addProperty("description", ig.getDescription() + " (built " + dtHuman + timezone() + ")");
}
JsonArray vl = new JsonArray();
npm.add("fhirVersions", vl);
for (String v : fhirVersion) {
vl.add(new JsonPrimitive(v));
}
if (kind != PackageType.CORE) {
JsonObject dep = new JsonObject();
npm.add("dependencies", dep);
for (String v : fhirVersion) {
String vp = packageForVersion(v);
if (vp != null) {
dep.addProperty(vp, v);
}
}
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
dep.addProperty(d.getPackageId(), d.getVersion());
}
}
if (ig.hasPublisher()) {
npm.addProperty("author", ig.getPublisher());
}
JsonArray m = new JsonArray();
for (ContactDetail t : ig.getContact()) {
String email = email(t.getTelecom());
String url = url(t.getTelecom());
if (t.hasName() & (email != null || url != null)) {
JsonObject md = new JsonObject();
m.add(md);
md.addProperty("name", t.getName());
if (email != null)
md.addProperty("email", email);
if (url != null)
md.addProperty("url", url);
}
}
if (m.size() > 0)
npm.add("maintainers", m);
if (ig.getManifest().hasRendering())
npm.addProperty("homepage", ig.getManifest().getRendering());
JsonObject dir = new JsonObject();
npm.add("directories", dir);
dir.addProperty("lib", "package");
dir.addProperty("example", "example");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(npm);
try {
addFile(Category.RESOURCE, "package.json", json.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
packageJ = npm;
packageManifest = new JsonObject();
packageManifest.addProperty("version", ig.getVersion());
JsonArray fv = new JsonArray();
for (String v : fhirVersion) {
fv.add(v);
}
packageManifest.add("fhirVersion", fv);
packageManifest.addProperty("date", dt);
packageManifest.addProperty("name", ig.getPackageId());
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NpmPackageIndexBuilder method execute.
public void execute(String folder) throws IOException {
if (existsFolder(folder, "package")) {
folder = Utilities.path(folder, "package");
}
if (!existsFile(folder, "package.json")) {
throw new FHIRException("Not a proper package? (can't find package.json)");
}
start();
File dir = new File(folder);
for (File f : dir.listFiles()) {
seeFile(f.getName(), TextFile.fileToBytes(f));
}
TextFile.stringToFile(build(), Utilities.path(folder, ".index.json"));
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertNotNull(doc);
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method loadFromBuildServer.
private void loadFromBuildServer() throws IOException {
SimpleHTTPClient http = new SimpleHTTPClient();
http.trustAllhosts();
HTTPResult res = http.get("https://build.fhir.org/ig/qas.json?nocache=" + System.currentTimeMillis());
res.checkThrowException();
buildInfo = (JsonArray) new com.google.gson.JsonParser().parse(TextFile.bytesToString(res.getContent()));
List<BuildRecord> builds = new ArrayList<>();
for (JsonElement n : buildInfo) {
JsonObject o = (JsonObject) n;
if (o.has("url") && o.has("package-id") && o.get("package-id").getAsString().contains(".")) {
String u = o.get("url").getAsString();
if (u.contains("/ImplementationGuide/"))
u = u.substring(0, u.indexOf("/ImplementationGuide/"));
builds.add(new BuildRecord(u, o.get("package-id").getAsString(), getRepo(o.get("repo").getAsString()), readDate(o.get("date").getAsString())));
}
}
Collections.sort(builds, new BuildRecordSorter());
for (BuildRecord bld : builds) {
if (!ciList.containsKey(bld.getPackageId())) {
ciList.put(bld.getPackageId(), "https://build.fhir.org/ig/" + bld.getRepo());
}
}
// whether it succeeds or not
buildLoaded = true;
}
Aggregations