Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdinando Villa committed Dec 17, 2024
1 parent 31dd542 commit 79a7a4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void exportWithSchema(KlabService service, List<String> arguments) {

}

public void importWithSchema(KlabService service, List<String> arguments) {
public void importWithSchema(KlabService service, String suggestedUrn, List<String> arguments) {

ResourceTransport.Schema schema = null;
Urn result = null;
Expand All @@ -140,7 +140,7 @@ public void importWithSchema(KlabService service, List<String> arguments) {
if (arguments.get(1).contains("://")) {
try {
var url = new URI(arguments.get(1)).toURL();
result = service.importAsset(schema, schema.asset(url), null, user());
result = service.importAsset(schema, schema.asset(url), suggestedUrn, user());
} catch (Exception e) {
commandLine.getErr().println("Import failed with exception:" + org.integratedmodelling.klab.api.utils.Utils.Exceptions.stackTrace(e));
return;
Expand All @@ -149,7 +149,7 @@ public void importWithSchema(KlabService service, List<String> arguments) {
File file = new File(arguments.get(1));
if (file.exists()) {
try {
result = service.importAsset(schema, schema.asset(file), null, user());
result = service.importAsset(schema, schema.asset(file), suggestedUrn, user());
} catch (Exception e) {
commandLine.getErr().println("Import failed with exception:" + Utils.Exceptions.stackTrace(e));
return;
Expand Down Expand Up @@ -177,7 +177,7 @@ public void importWithSchema(KlabService service, List<String> arguments) {
i++;
}
try {
result = service.importAsset(schema, schema.asset(params), null, user());
result = service.importAsset(schema, schema.asset(params), suggestedUrn, user());
} catch (Throwable t) {
commandLine.getErr().println("Import failed with exception:" + Utils.Exceptions.stackTrace(t));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static class ServiceHandler {
* @param serviceType
*/
protected static void importFromSchema(KlabService.Type serviceType, boolean help,
java.util.List<String> arguments) {
String suggestedUrn, java.util.List<String> arguments) {

if (help) {

Expand All @@ -140,7 +140,7 @@ protected static void importFromSchema(KlabService.Type serviceType, boolean hel

var service = KlabCLI.INSTANCE.user().getService(serviceType.classify());
if (service != null) {
KlabCLI.INSTANCE.importWithSchema(service, arguments);
KlabCLI.INSTANCE.importWithSchema(service, suggestedUrn, arguments);
}
}

Expand Down Expand Up @@ -193,12 +193,18 @@ public static class Import implements Runnable {
required = false)
boolean help = false;

@CommandLine.Option(names = {"-u", "--urn"},
defaultValue = "X:X:X:X",
description = {"Pass suggested URN for import (result may differ)"},
required = false)
String urn;

@CommandLine.Parameters
java.util.List<String> arguments;

@Override
public void run() {
importFromSchema(KlabService.Type.RESOURCES, help, arguments);
importFromSchema(KlabService.Type.RESOURCES, help, urn, arguments);
}
}

Expand Down Expand Up @@ -245,12 +251,18 @@ public static class Import implements Runnable {
required = false)
boolean help = false;

@CommandLine.Option(names = {"-u", "--urn"},
defaultValue = "X:X:X:X",
description = {"Pass suggested URN for import (result may differ)"},
required = false)
String urn;

@CommandLine.Parameters
java.util.List<String> arguments;

@Override
public void run() {
importFromSchema(KlabService.Type.RUNTIME, help, arguments);
importFromSchema(KlabService.Type.RUNTIME, help, urn, arguments);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public interface ServicesAPI {
/**
* Asset import using either multipart file import or properties, according to passed schema. Schema ID
* must be in capabilities and a schema compatible with the media type will be looked up.
*
* If no URN is suggested, pass X:X:X:X
*/
String IMPORT = "/import/{schema}/{urn}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static class Schema {
*/
public Asset asset(File file) {
var ret = new Asset();
asset().setFile(file);
ret.setFile(file);
return ret;
}

Expand All @@ -55,7 +55,7 @@ public Asset asset(File file) {
*/
public Asset asset(URL url) {
var ret = new Asset();
asset().setUrl(url);
ret.setUrl(url);
return ret;
}

Expand All @@ -67,7 +67,7 @@ public Asset asset(URL url) {
*/
public Asset asset(Object... properties) {
var ret = new Asset();
asset().setProperties(Parameters.create(properties));
ret.setProperties(Parameters.create(properties));
return ret;
}

Expand Down

0 comments on commit 79a7a4f

Please sign in to comment.