use of com.evolveum.midpoint.ninja.opts.ConnectionOptions 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.opts.ConnectionOptions 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.opts.ConnectionOptions in project midpoint by Evolveum.
the class NinjaUtils method setupCommandLineParser.
public static JCommander setupCommandLineParser() {
BaseOptions base = new BaseOptions();
ConnectionOptions connection = new ConnectionOptions();
JCommander.Builder builder = JCommander.newBuilder().expandAtSign(false).addObject(base).addObject(connection);
for (Command cmd : Command.values()) {
builder.addCommand(cmd.getCommandName(), cmd.createOptions());
}
JCommander jc = builder.build();
jc.setProgramName("java [-Dloader.path=<jdbc_driver_jar_path>] -jar ninja.jar");
jc.setColumnSize(110);
jc.setAtFileCharset(Charset.forName(base.getCharset()));
return jc;
}
use of com.evolveum.midpoint.ninja.opts.ConnectionOptions 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.opts.ConnectionOptions in project midpoint by Evolveum.
the class Action method init.
public void init(NinjaContext context, O options) {
this.context = context;
this.options = options;
LogTarget target = getInfoLogTarget();
log = new Log(target, this.context);
this.context.setLog(log);
ConnectionOptions connection = Objects.requireNonNull(NinjaUtils.getOptions(this.context.getJc(), ConnectionOptions.class));
this.context.init(connection);
}
Aggregations