Commit 46f92d15 authored by David Koch's avatar David Koch
Browse files

Updated Client

parent 0ec1eb69
package de.uniko.digicom.carsandco.client;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import com.google.gson.Gson;
import de.uniko.digicom.capitol.api.RestResponse;
import de.uniko.digicom.capitol.api.client.RestApiClient;
import de.uniko.digicom.carsandco.messages.PaymentNotification;
import de.uniko.digicom.carsandco.messages.RepairContract;
public class CarsandcoApiClient {
public class CarsandcoApiClient extends RestApiClient{
protected static String PAYMENT_NOTIFICATION = "http://camunda-carsandco.iwvi.uni-koblenz.de:8080/carsandco/api/contract/payment";
protected static String NEW_CONTRACT = "http://camunda-carsandco.iwvi.uni-koblenz.de:8080/carsandco/api/contract/new";
/**
* This method sends a new RepairContract to Cars and Co and starts their processes for a car reparation.
......@@ -21,74 +18,16 @@ public class CarsandcoApiClient {
*/
public RestResponse sendContract(RepairContract contract){
Gson gson = new Gson();
String newContract = gson.toJson(contract);
RestResponse response = new RestResponse();
try {
URL url = new URL("http://camunda-carsandco.iwvi.uni-koblenz.de:8080/carsandco/api/contract/new");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(newContract);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while (in.readLine() != null) {
}
in.close();
response.setSuccess(true);
response.setMessage("Cars and Co Contract-REST Service Invoked Successfully..");
return response;
} catch (Exception e) {
response.setSuccess(false);
response.setMessage("Error while calling Cars and Co Contract-REST Service: \n" + e.toString());
return response;
}
return executeRequest(NEW_CONTRACT, contract, RestResponse.class);
}
/**
* This method sends a notification that an invoice is payed to Cars and Co.
* @param note The PaymentNotification Object to send
*/
public RestResponse sendPaymentNotification(PaymentNotification note){
public RestResponse sendPaymentNotification(PaymentNotification note){
return executeRequest(PAYMENT_NOTIFICATION, note, RestResponse.class);
Gson gson = new Gson();
String paymentNote = gson.toJson(note);
RestResponse response = new RestResponse();
try {
URL url = new URL("http://camunda-carsandco.iwvi.uni-koblenz.de:8080/carsandco/api/contract/payment");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(paymentNote);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while (in.readLine() != null) {
}
in.close();
response.setSuccess(true);
response.setMessage("Cars and Co Contract-REST Service Invoked Successfully..");
return response;
} catch (Exception e) {
response.setSuccess(false);
response.setMessage("Error while calling Cars and Co Contract-REST Service: \n" + e.toString());
return response;
}
}
}
......@@ -2,21 +2,22 @@ package de.uniko.digicom.carsandco.messages;
import java.util.Date;
public class PaymentNotification {
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.uniko.digicom.capitol.api.SerializationContainer;
public class PaymentNotification extends SerializationContainer {
/**
* Creates an object to notify Cars and Co about an executed payment of an invoice
* @param transactionKey key to identify transactions
*/
public PaymentNotification(String transactionKey){
this.setTransactionKey(transactionKey);
@JsonCreator
public PaymentNotification(@JsonProperty("transactionKey")String transactionKey){
super(transactionKey);
}
/**
* Unique key to identify the transaction the request/response belongs to
*/
private String transactionKey;
/**
* The purpose of the invoice that was received from Cars and Co and is now payed.
*/
......@@ -29,14 +30,6 @@ public class PaymentNotification {
private Date dateOfPayment;
//Getter-Setter below
public String getTransactionKey() {
return transactionKey;
}
public void setTransactionKey(String transactionKey) {
this.transactionKey = transactionKey;
}
public Date getDateOfPayment() {
return dateOfPayment;
}
......
package de.uniko.digicom.carsandco.messages;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.uniko.digicom.capitol.api.SerializationContainer;
import de.uniko.digicom.capitol.api.contracting.Car;
public class RepairContract {
public class RepairContract extends SerializationContainer{
/**
* Creates an object for a new repair contract with Cars and Co
* @param transactionKey key to identify transactions
*/
public RepairContract(String transactionKey){
this.setTransactionKey(transactionKey);
@JsonCreator
public RepairContract(@JsonProperty("transactionKey")String transactionKey){
super(transactionKey);
}
/**
* Unique key to identify the transaction the request/response belongs to
*/
private String transactionKey;
/**
* The reference to the customer that places a repair/maintainance order
*/
......@@ -84,11 +86,4 @@ public class RepairContract {
this.problemDescription = problemDescription;
}
public String getTransactionKey() {
return transactionKey;
}
public void setTransactionKey(String transactionKey) {
this.transactionKey = transactionKey;
}
}
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Constant Field Values (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CarsandcoApiClient (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......@@ -148,13 +148,13 @@ extends <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colFirst"><code>de.uniko.digicom.capitol.api.RestResponse</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../de/uniko/digicom/carsandco/client/CarsandcoApiClient.html#sendContract-de.uniko.digicom.carsandco.messages.RepairContract-">sendContract</a></span>(<a href="../../../../../de/uniko/digicom/carsandco/messages/RepairContract.html" title="class in de.uniko.digicom.carsandco.messages">RepairContract</a>&nbsp;contract)</code>
<div class="block">This method sends a new RepairContract to Cars and Co and starts their processes for a car reparation.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colFirst"><code>de.uniko.digicom.capitol.api.RestResponse</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../de/uniko/digicom/carsandco/client/CarsandcoApiClient.html#sendPaymentNotification-de.uniko.digicom.carsandco.messages.PaymentNotification-">sendPaymentNotification</a></span>(<a href="../../../../../de/uniko/digicom/carsandco/messages/PaymentNotification.html" title="class in de.uniko.digicom.carsandco.messages">PaymentNotification</a>&nbsp;note)</code>
<div class="block">This method sends a notification that an invoice is payed to Cars and Co.</div>
</td>
......@@ -204,7 +204,7 @@ extends <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?
<ul class="blockList">
<li class="blockList">
<h4>sendContract</h4>
<pre>public&nbsp;void&nbsp;sendContract(<a href="../../../../../de/uniko/digicom/carsandco/messages/RepairContract.html" title="class in de.uniko.digicom.carsandco.messages">RepairContract</a>&nbsp;contract)</pre>
<pre>public&nbsp;de.uniko.digicom.capitol.api.RestResponse&nbsp;sendContract(<a href="../../../../../de/uniko/digicom/carsandco/messages/RepairContract.html" title="class in de.uniko.digicom.carsandco.messages">RepairContract</a>&nbsp;contract)</pre>
<div class="block">This method sends a new RepairContract to Cars and Co and starts their processes for a car reparation.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
......@@ -218,7 +218,7 @@ extends <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?
<ul class="blockListLast">
<li class="blockList">
<h4>sendPaymentNotification</h4>
<pre>public&nbsp;void&nbsp;sendPaymentNotification(<a href="../../../../../de/uniko/digicom/carsandco/messages/PaymentNotification.html" title="class in de.uniko.digicom.carsandco.messages">PaymentNotification</a>&nbsp;note)</pre>
<pre>public&nbsp;de.uniko.digicom.capitol.api.RestResponse&nbsp;sendPaymentNotification(<a href="../../../../../de/uniko/digicom/carsandco/messages/PaymentNotification.html" title="class in de.uniko.digicom.carsandco.messages">PaymentNotification</a>&nbsp;note)</pre>
<div class="block">This method sends a notification that an invoice is payed to Cars and Co.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Class de.uniko.digicom.carsandco.client.CarsandcoApiClient (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.client (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.client (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.client Class Hierarchy (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Package de.uniko.digicom.carsandco.client (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PaymentNotification (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RepairContract (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Class de.uniko.digicom.carsandco.messages.PaymentNotification (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
</head>
......@@ -104,7 +104,7 @@
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colFirst"><code>de.uniko.digicom.capitol.api.RestResponse</code></td>
<td class="colLast"><span class="typeNameLabel">CarsandcoApiClient.</span><code><span class="memberNameLink"><a href="../../../../../../de/uniko/digicom/carsandco/client/CarsandcoApiClient.html#sendPaymentNotification-de.uniko.digicom.carsandco.messages.PaymentNotification-">sendPaymentNotification</a></span>(<a href="../../../../../../de/uniko/digicom/carsandco/messages/PaymentNotification.html" title="class in de.uniko.digicom.carsandco.messages">PaymentNotification</a>&nbsp;note)</code>
<div class="block">This method sends a notification that an invoice is payed to Cars and Co.</div>
</td>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Class de.uniko.digicom.carsandco.messages.RepairContract (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
</head>
......@@ -104,7 +104,7 @@
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colFirst"><code>de.uniko.digicom.capitol.api.RestResponse</code></td>
<td class="colLast"><span class="typeNameLabel">CarsandcoApiClient.</span><code><span class="memberNameLink"><a href="../../../../../../de/uniko/digicom/carsandco/client/CarsandcoApiClient.html#sendContract-de.uniko.digicom.carsandco.messages.RepairContract-">sendContract</a></span>(<a href="../../../../../../de/uniko/digicom/carsandco/messages/RepairContract.html" title="class in de.uniko.digicom.carsandco.messages">RepairContract</a>&nbsp;contract)</code>
<div class="block">This method sends a new RepairContract to Cars and Co and starts their processes for a car reparation.</div>
</td>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.messages (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.messages (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>de.uniko.digicom.carsandco.messages Class Hierarchy (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
......@@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_45) on Thu Jan 28 22:45:51 CET 2016 -->
<!-- Generated by javadoc (1.8.0_72) on Sat Jan 30 19:41:32 CET 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Package de.uniko.digicom.carsandco.messages (External Cars and Co API 0.0.1-SNAPSHOT API)</title>
<meta name="date" content="2016-01-28">
<meta name="date" content="2016-01-30">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
......
Supports Markdown
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