Clean API

This commit is contained in:
GME 2019-04-15 20:58:58 +02:00
parent 3893e90630
commit 70a3b3328d
8 changed files with 57 additions and 137 deletions

View file

@ -1,21 +1,16 @@
package blockchain.configuration;
public class Config {
//TEST
public static final String u2 = "woEXRrZdwXiu";
//ORGANIZATION
public static final String ORG1_MSP = "Org1MSP";
public static final String ORG1 = "Org1";
//ADMIN
public static final String ADMIN = "admin";
public static final String ADMIN_PASSWORD = "adminpw";
//USER
//public static final String UserPWD = "ZIidLJHQbLcC";
public static final String UserPWD = "OelXVCdHnYPe";
@ -44,23 +39,17 @@ public class Config {
public static final String ORG1_PEER_0_URL = "grpc://vps577432.ovh.net:7051";
//public static final String ORG1_PEER_0_URL = "grpc://93.30.148.59:7051";
//public static final String ORG1_PEER_0_URL = "grpc://93.30.148.59:8051";
//ublic static final String ORG1_PEER_0_URL = "grpc://vps592802.ovh.net:7051";
//PEER 1
public static final String ORG_PEER = "peer1.org1.example.com";
public static final String ORG_PEER_URL = "grpc://vps592802.ovh.net:9051";
//EVENTHUB
public static final String ORG_PEER_EVENT_URL = "grpc://vps592802.ovh.net:9053";
//ADMIN FILE TEST
public static final String ADMIN_FILE_PATH = "msp/AdminFiles";
public static final String ADMIN_KEY_PATH = ADMIN_FILE_PATH+"/keystore";
public static final String ADMIN_CERT_PATH = ADMIN_FILE_PATH+"/admincerts";
}

View file

@ -27,7 +27,6 @@ public class WalletImplementation {
User user = userDao.getUserWithHash(wallet.getUser_hash());
wallet.setWallet_hash(generateWalletHash(user.getName()+wallet.getType()+user.getFirstname()+ RandomStringUtils.randomAlphabetic(10)));
transactionWrapper.sendTransaction("initWallet",new String[]{wallet.getWallet_hash(),wallet.getType(),wallet.getUser_hash()}); //Create Wallet in Blockchain
wallet.setBalance(0.0);
@ -35,17 +34,8 @@ public class WalletImplementation {
long now = Instant.now().toEpochMilli();
wallet.setCreation_date(now);
wallet.setModification_date(now);
walletDao.addWallet(wallet); // add wallet to replica DB
/*
response.put("wallet_hash",wallet.getWallet_hash());
response.put("wallet_type",wallet.getType());
response.put("wallet_balance",wallet.getBalance().toString());
response.put("owner_hash",wallet.getUser_hash());
response.put("response","true");
*/
return wallet;
}

View file

@ -20,8 +20,8 @@ public class SessionResource {
int session_id = sessionImplementation.startSession(user_hash,user_email);
return ResponseEntity.status(HttpStatus.OK).body("{\"session_id\":"+session_id+"}");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -34,8 +34,8 @@ public class SessionResource {
sessionImplementation.endSession(session_id);
return ResponseEntity.status(HttpStatus.OK).body("");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}

View file

@ -1,41 +0,0 @@
package restService;
public class StringResponse {
private String response;
private String user_hash;
private Double userBalance;
public StringResponse(String response){
this.response = response;
}
public StringResponse(String response, Double userBalance){
this.response=response;
this.userBalance=userBalance;
}
public StringResponse(String response, String userHash){
this.response=response;
this.user_hash=userHash;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public String getUserHash() {
return user_hash;
}
public void setUserHash(String userHash) {
this.user_hash = userHash;
}
public Double getUserBalance(){return userBalance;}
public void setUserBalance(Double userBalance){this.userBalance=userBalance;}
}

View file

@ -29,8 +29,8 @@ public class TransactionResource {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"response\":\""+mapResponse.get("message")+"\"}");
}
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -47,8 +47,8 @@ public class TransactionResource {
return new ResponseEntity("{\"response\":\"error\"}", HttpStatus.NOT_FOUND);
}
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -62,8 +62,8 @@ public class TransactionResource {
List<List<Transaction>> listTransaction = transactionImplementation.getAllSentTransaction(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
//GET SENT FROM WALLET
@ -75,8 +75,8 @@ public class TransactionResource {
List<Transaction> listTransaction = transactionImplementation.getSentTransaction(wallet_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -91,8 +91,8 @@ public class TransactionResource {
List<List<Transaction>> listTransaction = transactionImplementation.getAllReceivedTransaction(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
//GET RECEIVED FROM WALLET
@ -104,8 +104,8 @@ public class TransactionResource {
List<Transaction> listTransaction = transactionImplementation.getReceivedTransaction(wallet_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -117,8 +117,8 @@ public class TransactionResource {
List<Transaction> listTransaction = transactionImplementation.getLatestTransactions(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -130,8 +130,8 @@ public class TransactionResource {
List<Transaction> listTransaction = transactionImplementation.getAllTransactions(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(listTransaction);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
}

View file

@ -30,26 +30,26 @@ public class UserResource {
String r = "{\"response\":\"ok\",\"user_hash\":\""+userHashResponse.get("user_hash")+"\"}";
return ResponseEntity.status(HttpStatus.OK).body(r);
}else {
StringResponse responseS = new StringResponse("User already exist");
return ResponseEntity.status(HttpStatus.FOUND).body(responseS);
String r = "{\"response\":\"User already exist\"}";
return ResponseEntity.status(HttpStatus.FOUND).body(r);
}
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@RequestMapping(value = "/approve", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<StringResponse> approveUser(@Valid @RequestBody User user){
public ResponseEntity approveUser(@Valid @RequestBody User user){
try{
UserImplementation userImplementation = new UserImplementation();
userImplementation.approveUser(user);
StringResponse response = new StringResponse("Ok",user.getUser_hash());
return ResponseEntity.status(HttpStatus.OK).body(response);
String r = "{\"response\":\"ok\",\"user_hash\":\""+user.getUser_hash()+"\"}";
return ResponseEntity.status(HttpStatus.OK).body(r);
}catch (Exception e){
StringResponse response = new StringResponse("Error: "+e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -61,30 +61,29 @@ public class UserResource {
Map<String,String> response = userImplementation.userLogger(user);
switch (response.get("response")){
case "Not Exist" : {
StringResponse responseS = new StringResponse("Not Found");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseS);
String r = "{\"response\":\"Not Found\"}";
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(r);
}
case "Not Allowed" :{
StringResponse responseS = new StringResponse("Wrong authentication");
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
String r = "{\"response\":\"Wrong authentication\"}";
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(r);
}
case "" :{
StringResponse responseS = new StringResponse("Error");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\"Error\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
case "true":{
//StringResponse responseS = new StringResponse("Ok",response.get("user_hash"));
String r = "{\"response\":\"ok\",\"user_hash\":\""+response.get("user_hash")+"\"}";
return ResponseEntity.status(HttpStatus.OK).body(r);
}
default:{
StringResponse responseS = new StringResponse("Error");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\"Error\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -106,15 +105,15 @@ public class UserResource {
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<StringResponse> removeUser(@Valid @RequestBody User user){
public ResponseEntity removeUser(@Valid @RequestBody User user){
try{
UserImplementation userImplementation = new UserImplementation();
userImplementation.deleteUser(user);
StringResponse responseS = new StringResponse("Ok");
return ResponseEntity.status(HttpStatus.OK).body(responseS);
String r = "{\"response\":\"ok\"}";
return ResponseEntity.status(HttpStatus.OK).body(r);
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}

View file

@ -19,27 +19,10 @@ public class WalletResource {
try{
WalletImplementation walletImplementation = new WalletImplementation();
Wallet walletResponse = walletImplementation.createWallet(wallet);
/*
Wallet returnWallet = new Wallet();
returnWallet.setWallet_hash(walletResponse.get("wallet_hash"));
returnWallet.setUser_hash(wallet.getUser_hash());
returnWallet.setBalance(Double.parseDouble(walletResponse.get("wallet_balance")));
returnWallet.setType(walletResponse.get("wallet_type"));
*/
return ResponseEntity.status(HttpStatus.OK).body(walletResponse);
/*
if(Boolean.parseBoolean(walletResponse.get("response"))){
}else {
StringResponse responseS = new StringResponse("Wallet already exist");
return ResponseEntity.status(HttpStatus.FOUND).body(responseS);
}
*/
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -51,8 +34,8 @@ public class WalletResource {
JsonArray wallets = walletImplementation.getAllUserWallets(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(wallets);
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -68,8 +51,8 @@ public class WalletResource {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"response\":null}");
}
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -81,8 +64,8 @@ public class WalletResource {
walletImplementation.setBalanceToWallet(BalanceWallet.getAssociation_hash(), BalanceWallet.getAssocation_pwd(), BalanceWallet.getWallet_hash(),BalanceWallet.getAmount());
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -94,8 +77,8 @@ public class WalletResource {
walletImplementation.transferWallet(wallet.getWallet_hash(),wallet.getUser_hash());
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
} catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
@ -108,8 +91,8 @@ public class WalletResource {
walletImplementation.deleteWallet(walletHash,userHash);
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
}catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
String r = "{\"response\":\""+e.getMessage()+"\"}";
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
}
}
}

View file

@ -5,7 +5,7 @@ import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.junit.Ignore;
import org.junit.Test;
import restService.StringResponse;
import java.util.Map;
@Ignore