use of com.evolveum.midpoint.ninja.impl.NinjaContext in project midpoint by Evolveum.
the class NinjaContextTest method setupRepositoryViaMidpointHome.
@Test
public void setupRepositoryViaMidpointHome() throws Exception {
JCommander jc = NinjaUtils.setupCommandLineParser();
jc.parse("-m", "./target/midpoint-home", "-U", "jdbc:postgresql://localhost/midpoint", "-u", "midpoint", "-p", "qwe123");
ConnectionOptions options = NinjaUtils.getOptions(jc, ConnectionOptions.class);
NinjaContext ctx = new NinjaContext(null);
ctx.init(options);
RepositoryService service = ctx.getRepository();
OperationResult result = new OperationResult("get user");
PrismObject obj = service.getObject(UserType.class, SystemObjectsType.USER_ADMINISTRATOR.value(), null, result);
System.out.println(obj.debugDump());
}
use of com.evolveum.midpoint.ninja.impl.NinjaContext in project midpoint by Evolveum.
the class BaseTest method setupNinjaContext.
protected NinjaContext setupNinjaContext(String[] input) {
JCommander jc = NinjaUtils.setupCommandLineParser();
jc.parse(input);
NinjaContext context = new NinjaContext(jc);
ConnectionOptions connection = NinjaUtils.getOptions(jc, ConnectionOptions.class);
context.init(connection);
return context;
}
use of com.evolveum.midpoint.ninja.impl.NinjaContext in project midpoint by Evolveum.
the class Main method run.
protected <T> void run(String[] args) {
JCommander jc = NinjaUtils.setupCommandLineParser();
try {
jc.parse(args);
} catch (ParameterException ex) {
System.err.println(ex.getMessage());
return;
}
String parsedCommand = jc.getParsedCommand();
BaseOptions base = Objects.requireNonNull(NinjaUtils.getOptions(jc, BaseOptions.class));
if (base.isVersion()) {
try {
URL versionResource = Objects.requireNonNull(Main.class.getResource("/version"));
Path path = Paths.get(versionResource.toURI());
String version = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
System.out.println(version);
} catch (Exception ex) {
// ignored
}
return;
}
if (base.isHelp() || parsedCommand == null) {
printHelp(jc, parsedCommand);
return;
}
if (base.isVerbose() && base.isSilent()) {
System.err.println("Cant' use " + BaseOptions.P_VERBOSE + " and " + BaseOptions.P_SILENT + " together (verbose and silent)");
printHelp(jc, parsedCommand);
return;
}
NinjaContext context = null;
try {
ConnectionOptions connection = Objects.requireNonNull(NinjaUtils.getOptions(jc, ConnectionOptions.class));
Action<T> action;
if (connection.isUseWebservice()) {
action = Command.createRestAction(parsedCommand);
} else {
action = Command.createRepositoryAction(parsedCommand);
}
if (action == null) {
String strConnection = connection.isUseWebservice() ? "webservice" : "repository";
System.err.println("Action for command '" + parsedCommand + "' not found (connection: '" + strConnection + "')");
return;
}
// noinspection unchecked
T options = (T) jc.getCommands().get(parsedCommand).getObjects().get(0);
context = new NinjaContext(jc);
preInit(context);
action.init(context, options);
preExecute(context);
action.execute();
postExecute(context);
} catch (Exception ex) {
handleException(base, ex);
} finally {
cleanupResources(base, context);
}
}
use of com.evolveum.midpoint.ninja.impl.NinjaContext in project midpoint by Evolveum.
the class NinjaContextTest method setupModelClient.
@Test
public void setupModelClient() throws Exception {
NinjaContext ctx = new NinjaContext(null);
ctx.init(null);
RestService service = ctx.getRestService();
Holder object = new Holder();
Holder result = new Holder();
// service.get(UserType.COMPLEX_TYPE, SystemObjectsType.USER_ADMINISTRATOR.value(), null, object, result);
AssertJUnit.assertNotNull(object.value);
}
Aggregations