diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/BioimageioRepo.java b/src/main/java/io/bioimage/modelrunner/bioimageio/BioimageioRepo.java index 127d7647..eb7dd35f 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/BioimageioRepo.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/BioimageioRepo.java @@ -51,6 +51,7 @@ import io.bioimage.modelrunner.bioimageio.description.ModelDescriptorFactory; import io.bioimage.modelrunner.bioimageio.download.DownloadModel; import io.bioimage.modelrunner.bioimageio.download.DownloadTracker; +import io.bioimage.modelrunner.utils.Constants; import io.bioimage.modelrunner.utils.Log; /** @@ -652,12 +653,18 @@ public String getModelRdfUrl(String id, String version) { if (modelsInfo.get(id) == null) return null; + String rdfURL; if (version == null) { - return modelsInfo.get(id).values().stream() + rdfURL = modelsInfo.get(id).values().stream() .filter(val -> val.get("latest").equals("true")).findFirst().get().get("source"); + } else if (version != null && modelsInfo.get(id).get(version) != null) { + rdfURL = modelsInfo.get(id).get(version).get("source"); + } else { + return null; } + if (rdfURL == null) return null; - return modelsInfo.get(id).get(version).get("source"); + return rdfURL.substring(0, rdfURL.length() - Constants.RDF_FNAME.length()); } diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptor.java b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptor.java index 308a6527..c7de0e5c 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptor.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptor.java @@ -65,11 +65,6 @@ public interface ModelDescriptor { */ public String getName(); - /** - * @return The nickname of this model. - */ - public String getNickname(); - /** * @return The ID of this model. */ @@ -205,11 +200,6 @@ public static TensorSpec findTensorInList(String name, List tts) */ public Map getAttachments(); - /** - * @return the download_url - */ - public String getDownloadUrl(); - /** * @return the rdf_source */ diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV04.java b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV04.java index d8996ae8..8be4a9eb 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV04.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV04.java @@ -30,14 +30,10 @@ import java.util.Set; import java.util.stream.Collectors; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - import io.bioimage.modelrunner.bioimageio.BioimageioRepo; import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException; import io.bioimage.modelrunner.bioimageio.description.weights.ModelWeight; -import io.bioimage.modelrunner.utils.Log; +import io.bioimage.modelrunner.utils.Constants; /** @@ -80,6 +76,8 @@ public class ModelDescriptorV04 implements ModelDescriptor private String modelID; private String localModelPath; private boolean supportBioengine = false; + + private static BioimageioRepo BMZ_REPO; private ModelDescriptorV04() { @@ -700,20 +698,6 @@ public Map getAttachments() { return attachments; } - /** - * @return the download_url - */ - public String getDownloadUrl() { - return download_url; - } - - /** - * @return the rdf_source - */ - public String getRDFSource() { - return rdf_source; - } - /** * @return the version */ @@ -818,26 +802,20 @@ public void addModelPath(Path modelBasePath) { // TODO Auto-generated method stub } - - private void findDownloadURL() { - String text = BioimageioRepo.getJSONFromUrl(BioimageioRepo.location); - if (text == null) { - return; - } - JsonObject json = null; - try { - json = (JsonObject) JsonParser.parseString(text); - List entries = json.get("entries").getAsJsonArray().asList(); - entries.stream() - } catch (Exception ex) { - return; - } - } @Override public String getModelURL() { + if (this.download_url == null && BMZ_REPO == null) { + BMZ_REPO = BioimageioRepo.connect(); + } + if (this.download_url == null) - findDownloadURL(); - return download_url; + this.download_url = BMZ_REPO.getModelRdfUrl(modelID, version); + return this.download_url; + } + + @Override + public String getRDFSource() { + return getModelURL() + Constants.RDF_FNAME; } } diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV05.java b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV05.java index f5952e68..baebb5dd 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV05.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/description/ModelDescriptorV05.java @@ -31,6 +31,7 @@ import io.bioimage.modelrunner.bioimageio.BioimageioRepo; import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException; import io.bioimage.modelrunner.bioimageio.description.weights.ModelWeight; +import io.bioimage.modelrunner.utils.Constants; /** @@ -44,9 +45,11 @@ public class ModelDescriptorV05 implements ModelDescriptor { private String format_version; private String name; + private String download_url; private String timestamp; private String description; private String type; + private String git_repo; private List authors; private List maintainers; private List packaged_by; @@ -69,6 +72,8 @@ public class ModelDescriptorV05 implements ModelDescriptor private String localModelPath; private boolean supportBioengine = false; private Map yamlElements; + + private static BioimageioRepo BMZ_REPO; protected ModelDescriptorV05(Map yamlElements) throws ModelSpecsException { @@ -137,6 +142,9 @@ protected void buildModelDescription() throws ModelSpecsException case "documentation": documentation = (String) fieldElement; break; + case "git_repo": + git_repo = (String) fieldElement; + break; case "type": type = (String) fieldElement; break; @@ -638,45 +646,35 @@ public String buildInfo() { return null; } - @Override - public String getNickname() { - // TODO Auto-generated method stub - return null; - } - @Override public String getGitRepo() { - // TODO Auto-generated method stub - return null; + return this.git_repo; } @Override public List getBadges() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getDownloadUrl() { - // TODO Auto-generated method stub - return null; + return new ArrayList(); } @Override - public String getRDFSource() { + public void addModelPath(Path modelBasePath) { // TODO Auto-generated method stub - return null; + } @Override - public void addModelPath(Path modelBasePath) { - // TODO Auto-generated method stub + public String getModelURL() { + if (this.download_url == null && BMZ_REPO == null) { + BMZ_REPO = BioimageioRepo.connect(); + } + if (this.download_url == null) + this.download_url = BMZ_REPO.getModelRdfUrl(modelID, version); + return this.download_url; } @Override - public String getModelURL() { - // TODO Auto-generated method stub - return null; + public String getRDFSource() { + return getModelURL() + Constants.RDF_FNAME; } }