Commit 52816a70 authored by Matija Obreza's avatar Matija Obreza

Moved model to genesys-shell

parent 8a9071c0
......@@ -33,9 +33,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.genesys2.client.rest.model.KPIDimension;
import org.genesys2.client.rest.model.KPIExecution;
import org.genesys2.client.rest.model.KPIParameter;
import org.scribe.exceptions.OAuthConnectionException;
import org.scribe.model.Token;
import org.scribe.model.Verb;
......@@ -126,7 +123,6 @@ public class CLI {
System.out.println("1 Datasets");
System.out.println("2 Traits");
System.out.println("3 Crops");
System.out.println("9 KPI");
System.out.println("0 Custom");
System.out.println("Q QUIT");
......@@ -137,110 +133,11 @@ public class CLI {
doTraits();
else if ("3".equals(line))
doCrops();
else if ("9".equals(line))
doKPI();
else if ("0".equals(line))
doCustom();
} while (!"Q".equalsIgnoreCase(line));
}
private void doKPI() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, IOException {
String line = null;
do {
System.out.println("1 List parameters");
System.out.println("2 Update parameter");
System.out.println("3 List dimensions");
System.out.println("4 Update dimension");
System.out.println("5 List executions");
System.out.println("6 Executions");
System.out.println("9 Execute");
System.out.println("0 Back");
line = in.nextLine();
if ("1".equals(line))
System.out.println("Parameters: " + genesysClient.listParameters());
else if ("2".equals(line))
doKPIParameter();
else if ("3".equals(line))
System.out.println("Dimensions: " + genesysClient.listDimensions());
else if ("4".equals(line))
doKPIDimension();
else if ("5".equals(line))
System.out.println("Executions: " + genesysClient.listExecutions());
else if ("6".equals(line))
doKPIExecutions();
else if ("9".equals(line))
doKPIExec();
else if ("0".equalsIgnoreCase(line))
return;
} while (!("0".equalsIgnoreCase(line)));
}
private void doKPIExec() throws IOException, OAuthAuthenticationException, PleaseRetryException, GenesysApiException {
System.out.println("Execution id: ");
String id = in.nextLine().trim();
if (StringUtils.isBlank(id)) {
return;
}
ObjectNode node = (ObjectNode) mapper.readTree(genesysClient.getExecution(Long.parseLong(id)));
System.out.println(">> " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node));
String res = genesysClient.kpiExecute(Long.parseLong(id));
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(res)));
}
private void doKPIExecutions() throws IOException, OAuthAuthenticationException, PleaseRetryException, GenesysApiException {
System.out.println("Execution id: ");
String id = in.nextLine().trim();
ObjectNode node = null;
if (StringUtils.isBlank(id)) {
node = (ObjectNode) mapper.readTree(mapper.writeValueAsString(new KPIExecution()));
} else {
node = (ObjectNode) mapper.readTree(genesysClient.getExecution(Long.parseLong(id)));
}
updateJsonData("kpiexecution", node);
System.out.println(">> " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node));
System.out.println(genesysClient.putExecution(node));
}
private void doKPIDimension() throws IOException, OAuthAuthenticationException, PleaseRetryException, GenesysApiException {
System.out.println("Dimension ID: ");
String id = in.nextLine().trim();
String type = null;
ObjectNode node = null;
if (StringUtils.isBlank(id)) {
System.out.println("Dimension type: ");
System.out.println("\torg.genesys2.server.model.kpi.NumericListDimension");
System.out.println("\torg.genesys2.server.model.kpi.StringListDimension");
System.out.println("\torg.genesys2.server.model.kpi.BooleanDimension");
System.out.println("\torg.genesys2.server.model.kpi.JpaDimension");
type = in.nextLine().trim();
node = (ObjectNode) mapper.readTree(mapper.writeValueAsString(new KPIDimension()));
node.put("@class", type);
} else {
node = (ObjectNode) mapper.readTree(genesysClient.getDimension(Long.parseLong(id)));
type = node.get("@class").textValue();
}
updateJsonData("kpidimension", node);
System.out.println(">> " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node));
System.out.println(genesysClient.putDimension(node));
}
private void doKPIParameter() throws IOException, OAuthAuthenticationException, PleaseRetryException, GenesysApiException {
System.out.println("Parameter name: ");
String name = in.nextLine().trim();
ObjectNode node = null;
if (StringUtils.isBlank(name)) {
node = (ObjectNode) mapper.readTree(mapper.writeValueAsString(new KPIParameter()));
} else {
node = (ObjectNode) mapper.readTree(genesysClient.getParameter(name));
}
updateJsonData("kpiparameter", node);
System.out.println(">> " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node));
System.out.println(genesysClient.putParameter(node));
}
private void updateJsonData(String label, JsonNode n) {
if (n.isArray()) {
updateJsonArray(label, (ArrayNode) n);
......
package org.genesys2.client.rest.model;
public class KPIDimension {
public String name;
public String title;
}
package org.genesys2.client.rest.model;
import java.util.ArrayList;
import java.util.List;
public class KPIExecution {
public String title;
public String parameter;
public List<KPIExecutionDimension> dimensions = new ArrayList<KPIExecutionDimension>();
}
package org.genesys2.client.rest.model;
public class KPIExecutionDimension {
public long dimensionId;
public String link;
public String field;
}
package org.genesys2.client.rest.model;
public class KPIParameter {
public String name;
public String title;
public String description;
public String entity;
public String condition;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment