Skip to content

Commit

Permalink
some implementation
Browse files Browse the repository at this point in the history
(cherry picked from commit 615be01f4d2884a20c462b5e3f7f8bf15d675459)
  • Loading branch information
1azyman committed Feb 27, 2020
1 parent 66e2462 commit 5467635
Show file tree
Hide file tree
Showing 30 changed files with 992 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ hs_err_pid*
target

.DS_Store

_mess
36 changes: 35 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>

<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand All @@ -22,8 +22,24 @@
<jcommander.version>1.72</jcommander.version>
<asciidoctorj.version>2.1.0</asciidoctorj.version>
<commons.io.version>2.6</commons.io.version>
<velocity.version>2.1</velocity.version>
<midpoint.client.version>4.0.1</midpoint.client.version>
<testng.version>7.1.0</testng.version>
</properties>

<repositories>
<repository>
<id>evolveum</id>
<name>Evolveum Public Releases</name>
<url>https://nexus.evolveum.com/nexus/content/groups/public/</url>
</repository>
<repository>
<id>evolveum-snapshots</id>
<name>Evolveum Snapshots</name>
<url>https://nexus.evolveum.com/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<build>
<finalName>philosopher</finalName>
<resources>
Expand Down Expand Up @@ -134,5 +150,23 @@
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity.version}</version>
</dependency>

<dependency>
<groupId>com.evolveum.midpoint.client</groupId>
<artifactId>midpoint-client-impl-rest-jaxb</artifactId>
<version>${midpoint.client.version}</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
</dependencies>
</project>
3 changes: 3 additions & 0 deletions src/main/java/com/evolveum/midpoint/philosopher/Command.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.evolveum.midpoint.philosopher;

import com.evolveum.midpoint.philosopher.generator.GenerateAction;
import com.evolveum.midpoint.philosopher.generator.GenerateOptions;

/**
* @author Viliam Repan (lazyman)
*/
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private JCommander setupCommandLineParser() {
BaseOptions base = new BaseOptions();

JCommander.Builder builder = JCommander.newBuilder()
.expandAtSign(false)
.addObject(base);

for (Command cmd : Command.values()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.evolveum.midpoint.philosopher.generator;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.evolveum.midpoint.philosopher.util.URIConverter;

/**
* Created by Viliam Repan (lazyman).
*/
@Parameters(resourceBundle = "messages")
public class ConnectionOptions {

public static final String P_URL = "-U";
public static final String P_URL_LONG = "--url";

public static final String P_USERNAME = "-u";
public static final String P_USERNAME_LONG = "--username";

public static final String P_PASSWORD = "-p";
public static final String P_PASSWORD_LONG = "--password";

public static final String P_ASK_PASSWORD = "-P";
public static final String P_ASK_PASSWORD_LONG = "--password-ask";

@Parameter(names = {P_URL, P_URL_LONG}, validateWith = URIConverter.class, descriptionKey = "connection.url")
private String url;

@Parameter(names = {P_USERNAME, P_USERNAME_LONG}, descriptionKey = "connection.username")
private String username;

@Parameter(names = {P_PASSWORD, P_PASSWORD_LONG}, descriptionKey = "connection.password")
private String password;

@Parameter(names = {P_ASK_PASSWORD, P_ASK_PASSWORD_LONG}, password = true,
descriptionKey = "connection.askPassword")
private String askPassword;

public String getAskPassword() {
return askPassword;
}

public String getPassword() {
return password;
}

public String getUrl() {
return url;
}

public String getUsername() {
return username;
}

public void setUrl(String url) {
this.url = url;
}

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setAskPassword(String askPassword) {
this.askPassword = askPassword;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.evolveum.midpoint.philosopher.generator;

/**
* Created by Viliam Repan (lazyman).
*/
public enum ExportFormat {

PDF,

HTML;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.evolveum.midpoint.philosopher.generator;

import java.io.File;
import java.io.IOException;

/**
* Created by Viliam Repan (lazyman).
*/
public interface Exporter {

void export(File adocFile, File output) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.evolveum.midpoint.philosopher.generator;

import com.evolveum.midpoint.client.api.Service;
import com.evolveum.midpoint.client.impl.restjaxb.AuthenticationType;
import com.evolveum.midpoint.client.impl.restjaxb.RestJaxbServiceBuilder;
import com.evolveum.midpoint.philosopher.Action;

/**
* Created by Viliam Repan (lazyman).
*/
public class GenerateAction implements Action<GenerateOptions> {

private GenerateOptions options;

@Override
public void init(GenerateOptions options) throws Exception {
this.options = options;
}

@Override
public void execute() throws Exception {
ConnectionOptions con = options.getConnection();

String pwd = con.getPassword() != null ? con.getPassword() : con.getAskPassword();

Service client = new RestJaxbServiceBuilder()
.url(con.getUrl())
.username(con.getUsername())
.password(pwd)
.authentication(AuthenticationType.BASIC)
.build();

Generator generator = new Generator(options, client);
generator.generate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.evolveum.midpoint.philosopher.generator;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;

import java.io.File;

/**
* Created by Viliam Repan (lazyman).
*/
@Parameters(resourceBundle = "messages", commandDescriptionKey = "generate")
public class GenerateOptions {

public static final String P_EXPORT_FORMAT = "-ef";
public static final String P_EXPORT_FORMAT_LONG = "--export-format";

public static final String P_TEMPLATE = "-t";
public static final String P_TEMPLATE_LONG = "--template";

public static final String P_OUTPUT = "-o";
public static final String P_OUTPUT_LONG = "--output";

@ParametersDelegate
private ConnectionOptions connection;

@Parameter(names = {P_EXPORT_FORMAT, P_EXPORT_FORMAT_LONG}, descriptionKey = "generate.exportFormat")
private ExportFormat exportFormat;

@Parameter(names = {P_TEMPLATE, P_TEMPLATE_LONG}, descriptionKey = "generate.template")
private File template;

@Parameter(names = {P_OUTPUT, P_OUTPUT_LONG}, descriptionKey = "generate.output")
private File output;

public ConnectionOptions getConnection() {
return connection;
}

public File getTemplate() {
return template;
}

public File getOutput() {
return output;
}

public ExportFormat getExportFormat() {
return exportFormat;
}

public void setExportFormat(ExportFormat exportFormat) {
this.exportFormat = exportFormat;
}

public void setConnection(ConnectionOptions connection) {
this.connection = connection;
}

public void setTemplate(File template) {
this.template = template;
}

public void setOutput(File output) {
this.output = output;
}
}
Loading

0 comments on commit 5467635

Please sign in to comment.