Search in sources :

Example 26 with Package

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);
}
Also used : Package(org.hl7.fhir.utilities.graphql.Package) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with Package

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());
}
Also used : Locale(java.util.Locale) JsonArray(com.google.gson.JsonArray) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ImplementationGuideDependsOnComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent) JsonPrimitive(com.google.gson.JsonPrimitive) GsonBuilder(com.google.gson.GsonBuilder) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 28 with Package

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"));
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 29 with Package

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);
}
Also used : Package(org.hl7.fhir.utilities.graphql.Package) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 30 with Package

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;
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Aggregations

File (java.io.File)25 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 TextFile (org.hl7.fhir.utilities.TextFile)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)15 JsonObject (com.google.gson.JsonObject)12 FileNotFoundException (java.io.FileNotFoundException)11 FileInputStream (java.io.FileInputStream)9 IniFile (org.hl7.fhir.utilities.IniFile)9 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)9 ParseException (java.text.ParseException)8 HashMap (java.util.HashMap)7 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 JsonElement (com.google.gson.JsonElement)5 FileOutputStream (java.io.FileOutputStream)5 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)5 CSFile (org.hl7.fhir.utilities.CSFile)5