private static Command findCommand(String command) { if (command == null) { return null; } for (Command cmd : values()) { if (command.equals(cmd.getCommandName())) { return cmd; } } return null; } }
@Override public void execute() { RestService model = context.getRestService(); OperationResult result = model.testResource(options.getOid()); //todo print result } }
private void registerExtensionSchemas(SchemaRegistryImpl schemaRegistry) { try { List<String> schemas = getSchemaList(); for (String name : schemas) { String xsd = fetchSchema(name); ByteArrayInputStream bis = new ByteArrayInputStream(xsd.getBytes()); schemaRegistry.registerPrismSchema(bis, "rest " + name); } } catch (Exception ex) { throw new NinjaException("Couldn't register extension schema", ex); } }
@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); }
public void init(NinjaContext context, T options) { this.context = context; this.options = options; LogTarget target = getInfoLogTarget(); log = new Log(target, this.context); this.context.setLog(log); ConnectionOptions connection = NinjaUtils.getOptions(this.context.getJc(), ConnectionOptions.class); this.context.init(connection); }
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; }
private RestService setupRestService(ConnectionOptions options) { log.info("Initializing rest service"); String url = options.getUrl(); String username = options.getUsername(); String password = getPassword(options); if (url == null) { throw new IllegalStateException("Url is not defined"); } return new RestService(url, username, password); }
public void init(ConnectionOptions options) { boolean initialized = false; if (options.isUseWebservice()) { restService = setupRestService(options); initialized = true; } if (!initialized && options.getMidpointHome() != null) { repository = setupRepositoryViaMidPointHome(options); initialized = true; } if (!initialized) { throw new IllegalStateException("One of options must be specified: " + ConnectionOptions.P_MIDPOINT_HOME + ", " + ConnectionOptions.P_WEBSERVICE); } }
public void producerFinish() { if (state != State.STARTED) { throw new NinjaException("Can't set state " + State.PRODUCER_FINISHED + " for operation, previous state is was not " + State.STARTED); } debug("Operation: producer finished"); state = State.PRODUCER_FINISHED; }
@Override protected void init() { serializer = context.getPrismContext() .xmlSerializer() .options(SerializationOptions.createSerializeForExport()); }
private void debug(String message) { Log log = context.getLog(); log.debug(message); } }
public static RepositoryAction createRepositoryAction(String command) { Command cmd = findCommand(command); if (cmd == null) { return null; } try { if (cmd.repositoryAction == null) { return null; } return cmd.repositoryAction.newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } }
public PrismContext getPrismContext() { if (prismContext != null) { return prismContext; } if (context != null) { prismContext = context.getBean(PrismContext.class); } if (restService != null) { prismContext = restService.getPrismContext(); } return prismContext; }
public void start() { if (state != State.NOT_STARTED) { throw new NinjaException("Can't start operation, previous state is was not " + State.NOT_STARTED); } debug("Operation: started"); startTime = System.currentTimeMillis(); state = State.STARTED; }
private SearchProducerWorker createProducer(BlockingQueue<PrismObject> queue, OperationStatus operation, List<SearchProducerWorker> producers, ObjectTypes type, ObjectFilter filter) { ObjectQuery query = context.getPrismContext().queryFactory().createQuery(filter); return new SearchProducerWorker(context, options, queue, operation, producers, type, query); } }
@Override public void run() { while (!shouldConsumerStop()) { if (operation.isStarted() || operation.isProducerFinished()) { operation.print(context.getLog()); } try { Thread.sleep(NinjaUtils.COUNT_STATUS_LOG_INTERVAL); } catch (InterruptedException ex) { } } } }
public static RestAction createRestAction(String command) { Command cmd = findCommand(command); if (cmd == null) { return null; } try { if (cmd.restAction == null) { return null; } return cmd.restAction.newInstance(); } catch (Exception ex) { throw new IllegalStateException(ex); } }
public void finish() { if (state == State.NOT_STARTED) { throw new NinjaException("Can't finish operation, previous state was " + State.NOT_STARTED); } debug("Operation: finished"); finishTime = System.currentTimeMillis(); state = State.FINISHED; }
private void deleteByOid() throws SchemaException, IOException { QueryFactory queryFactory = context.getPrismContext().queryFactory(); InOidFilter filter = queryFactory.createInOid(options.getOid()); ObjectQuery query = queryFactory.createQuery(filter); deleteByFilter(query); }
private InputStream openInputStream() throws IOException { File input = options.getInput(); InputStream is; if (input != null) { if (!input.exists()) { throw new NinjaException("Import file '" + input.getPath() + "' doesn't exist"); } is = new FileInputStream(input); } else { is = System.in; } return is; }