Skip to content

Commit

Permalink
removed dead code from ninja (mostly rest related, not implemented at…
Browse files Browse the repository at this point in the history
… all)
  • Loading branch information
1azyman committed Apr 26, 2023
1 parent 811d743 commit 161b6cd
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 196 deletions.
4 changes: 0 additions & 4 deletions tools/ninja/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand Down
14 changes: 2 additions & 12 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.evolveum.midpoint.ninja.impl.Command;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.BaseOptions;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;

public class Main {
Expand Down Expand Up @@ -71,19 +70,10 @@ protected <T> void run(String[] args) {

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);
}
Action<T> action = Command.createRepositoryAction(parsedCommand);

if (action == null) {
String strConnection = connection.isUseWebservice() ? "webservice" : "repository";
System.err.println("Action for command '" + parsedCommand + "' not found (connection: '"
+ strConnection + "')");
System.err.println("Action for command '" + parsedCommand + "' not found");
return;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
*/
public enum Command {

IMPORT("import", ImportOptions.class, ImportRepositoryAction.class, null),
IMPORT("import", ImportOptions.class, ImportRepositoryAction.class),

EXPORT("export", ExportOptions.class, ExportRepositoryAction.class, null),
EXPORT("export", ExportOptions.class, ExportRepositoryAction.class),

DELETE("delete", DeleteOptions.class, DeleteRepositoryAction.class, null),
DELETE("delete", DeleteOptions.class, DeleteRepositoryAction.class),

COUNT("count", CountOptions.class, CountRepositoryAction.class, null),
COUNT("count", CountOptions.class, CountRepositoryAction.class),

VERIFY("verify", VerifyOptions.class, VerifyRepositoryAction.class, null),
VERIFY("verify", VerifyOptions.class, VerifyRepositoryAction.class),

KEYS("keys", ListKeysOptions.class, ListKeysRepositoryAction.class, null),
KEYS("keys", ListKeysOptions.class, ListKeysRepositoryAction.class),

INFO("info", InfoOptions.class, InfoRepositoryAction.class, null),
INFO("info", InfoOptions.class, InfoRepositoryAction.class),

IMPORT_AUDIT("importAudit", ImportAuditOptions.class, ImportAuditRepositoryAction.class, null),
IMPORT_AUDIT("importAudit", ImportAuditOptions.class, ImportAuditRepositoryAction.class),

EXPORT_AUDIT("exportAudit", ExportAuditOptions.class, ExportAuditRepositoryAction.class, null),
EXPORT_AUDIT("exportAudit", ExportAuditOptions.class, ExportAuditRepositoryAction.class),

TRACE("trace", EditTraceOptions.class, EditTraceAction.class, null);
TRACE("trace", EditTraceOptions.class, EditTraceAction.class);

// todo reencrypt, modify, bulk, etc

Expand All @@ -47,14 +47,10 @@ public enum Command {

private final Class<? extends RepositoryAction<?>> repositoryAction;

private final Class<? extends RestAction<?>> restAction;

<T> Command(String commandName, Class<T> options, Class<? extends RepositoryAction<T>> repositoryAction,
Class<? extends RestAction<T>> restAction) {
<T> Command(String commandName, Class<T> options, Class<? extends RepositoryAction<T>> repositoryAction) {
this.commandName = commandName;
this.options = options;
this.repositoryAction = repositoryAction;
this.restAction = restAction;
}

public String getCommandName() {
Expand Down Expand Up @@ -87,24 +83,6 @@ public static <T> RepositoryAction<T> createRepositoryAction(String command) {
}
}

public static <T> RestAction<T> createRestAction(String command) {
Command cmd = findCommand(command);
if (cmd == null) {
return null;
}

try {
if (cmd.restAction == null) {
return null;
}

//noinspection unchecked
return (RestAction<T>) cmd.restAction.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}

private static Command findCommand(String command) {
if (command == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
*/
package com.evolveum.midpoint.ninja.impl;

import static com.evolveum.midpoint.common.configuration.api.MidpointConfiguration.REPOSITORY_CONFIGURATION;

import java.nio.charset.Charset;

import com.beust.jcommander.JCommander;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
Expand All @@ -22,15 +30,6 @@
import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringNormalizerConfigurationType;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

import java.nio.charset.Charset;

import static com.evolveum.midpoint.common.configuration.api.MidpointConfiguration.REPOSITORY_CONFIGURATION;

/**
* Created by Viliam Repan (lazyman).
*/
Expand Down Expand Up @@ -66,8 +65,6 @@ public class NinjaContext {

private AuditService auditService;

private RestService restService;

private PrismContext prismContext;

private SchemaService schemaService;
Expand All @@ -78,19 +75,14 @@ public NinjaContext(JCommander jc) {

public void init(@NotNull ConnectionOptions options) {
boolean initialized = false;
if (options.isUseWebservice()) {
restService = setupRestService(options);
initialized = true;
}

if (!initialized && options.getMidpointHome() != null) {
if (options.getMidpointHome() != null) {
setupRepositoryViaMidPointHome(options);
initialized = true;
}

if (!initialized) {
throw new IllegalStateException("One of options must be specified: " + ConnectionOptions.P_MIDPOINT_HOME
+ ", " + ConnectionOptions.P_WEBSERVICE);
throw new IllegalStateException("Option must be defined: " + ConnectionOptions.P_MIDPOINT_HOME);
}
}

Expand Down Expand Up @@ -212,10 +204,6 @@ public AuditService getAuditService() {
return auditService;
}

public RestService getRestService() {
return restService;
}

public boolean isVerbose() {
BaseOptions base = NinjaUtils.getOptions(jc, BaseOptions.class);
return base.isVerbose();
Expand All @@ -237,10 +225,6 @@ public PrismContext getPrismContext() {
prismContext = context.getBean(PrismContext.class);
}

if (restService != null) {
prismContext = restService.getPrismContext();
}

return prismContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public class ConnectionOptions {
public static final String P_MIDPOINT_HOME = "-m";
public static final String P_MIDPOINT_HOME_LONG = "--midpoint-home";

public static final String P_WEBSERVICE = "-w";
public static final String P_WEBSERVICE_LONG = "--webservice";

public static final String P_OFFLINE_LONG = "--offline";

@Parameter(names = { P_URL, P_URL_LONG }, validateWith = URIConverter.class, descriptionKey = "connection.url")
Expand All @@ -53,10 +50,6 @@ public class ConnectionOptions {
@Parameter(names = { P_MIDPOINT_HOME, P_MIDPOINT_HOME_LONG }, descriptionKey = "connection.midpointHome")
private String midpointHome;

@Parameter(names = { P_WEBSERVICE, P_WEBSERVICE_LONG }, descriptionKey = "connection.useWebservice", hidden = true)
//todo remove hidden when implementation is done
private boolean useWebservice;

@Parameter(names = { P_OFFLINE_LONG }, descriptionKey = "connection.offline")
private boolean offline;

Expand All @@ -80,10 +73,6 @@ public String getMidpointHome() {
return midpointHome;
}

public boolean isUseWebservice() {
return useWebservice;
}

public boolean isOffline() {
return offline;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,24 @@
package com.evolveum.midpoint.ninja;

import com.beust.jcommander.JCommander;
import org.testng.annotations.Test;

import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.tools.testng.UnusedTestElement;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.ninja.impl.RestService;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import javax.xml.ws.Holder;

/**
* Created by Viliam Repan (lazyman).
*/
@UnusedTestElement("throws NPE, see ctx.init")
public class NinjaContextTest {

@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);
}

@Test
public void setupRepositoryViaMidpointHome() throws Exception {
JCommander jc = NinjaUtils.setupCommandLineParser();
Expand Down

0 comments on commit 161b6cd

Please sign in to comment.