Update
set back api
This commit is contained in:
parent
a8bf518845
commit
26ed8856f2
|
@ -20,6 +20,10 @@ public class User {
|
||||||
private long creation_date;
|
private long creation_date;
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false)
|
||||||
private long modification_date;
|
private long modification_date;
|
||||||
|
@DatabaseField
|
||||||
|
private long phone;
|
||||||
|
@DatabaseField
|
||||||
|
private String association;
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false)
|
||||||
private boolean verified;
|
private boolean verified;
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false)
|
||||||
|
@ -51,6 +55,14 @@ public class User {
|
||||||
this.approved = approved;
|
this.approved = approved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User(String name, String firstname, String user_hash, int phone, String association){
|
||||||
|
this.name = name;
|
||||||
|
this.firstname = firstname;
|
||||||
|
this.user_hash = user_hash;
|
||||||
|
this.phone = phone;
|
||||||
|
this.association = association;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Getters and Setters
|
//Getters and Setters
|
||||||
public int getUserId() {
|
public int getUserId() {
|
||||||
|
@ -111,6 +123,10 @@ public class User {
|
||||||
this.modification_date = modification_date;
|
this.modification_date = modification_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getPhone(){return phone;}
|
||||||
|
|
||||||
|
public void setPhone(int phone){this.phone=phone;}
|
||||||
|
|
||||||
public boolean isVerified() {
|
public boolean isVerified() {
|
||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,104 @@
|
||||||
package restImplementation;
|
package restImplementation;
|
||||||
|
|
||||||
import blockchain.query.QueryWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
|
import blockchain.query.TransactionWrapper;
|
||||||
|
import org.hyperledger.fabric.sdk.BlockEvent;
|
||||||
|
|
||||||
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
import javax.json.JsonReader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockchainQueryImplementation {
|
public class BlockchainQueryImplementation {
|
||||||
|
|
||||||
/*
|
public Double getWalletSold(String walletHash){
|
||||||
public Double getUserBalance(String userHash){
|
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
String result = queryWrapper.getUserBalance(userHash);
|
Double sold = 0.0;
|
||||||
Double balance = Double.parseDouble(result);
|
|
||||||
return balance;
|
String result = queryWrapper.sendQuery("readWallet", new String[]{walletHash});
|
||||||
|
if(result != null) {
|
||||||
|
JsonReader reader = Json.createReader(new StringReader(result));
|
||||||
|
JsonObject walletInfo = reader.readObject();
|
||||||
|
sold = walletInfo.getJsonNumber("sold").doubleValue();
|
||||||
}
|
}
|
||||||
*/
|
return sold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getUserAssociation(String userHash){
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
String result = queryWrapper.sendQuery("readUser", new String[]{userHash});
|
||||||
|
String association = null;
|
||||||
|
if(result != null){
|
||||||
|
JsonReader reader = Json.createReader(new StringReader(result));
|
||||||
|
JsonObject userInfo = reader.readObject();
|
||||||
|
association = userInfo.getString("userAssociation");
|
||||||
|
}
|
||||||
|
return association;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<HashMap> getUserWallets(String userHash){
|
||||||
|
List<HashMap> wallets = new ArrayList<>();
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
String response = queryWrapper.sendQuery("queryWalletsByOwner",new String[]{userHash});
|
||||||
|
|
||||||
|
if(response != null){
|
||||||
|
JsonReader reader = Json.createReader(new StringReader(response));
|
||||||
|
JsonArray walletInfo = reader.readArray();
|
||||||
|
|
||||||
|
for(Object obj : walletInfo){
|
||||||
|
HashMap<String,String> wallet = new HashMap<String, String>();
|
||||||
|
JsonObject o = (JsonObject) obj;
|
||||||
|
o = o.get("Record").asJsonObject();
|
||||||
|
wallet.put("walletHash",o.getString("id"));
|
||||||
|
wallet.put("walletType",o.getString("walletType"));
|
||||||
|
wallet.put("sold",o.getJsonNumber("sold").toString());
|
||||||
|
wallets.add(wallet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wallets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String sendTransaction(String sourceWallet, String destinationWallet, Double amount){
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
BlockEvent.TransactionEvent transactionEvent = transactionWrapper.sendTransaction("transaction",new String[]{sourceWallet,destinationWallet,amount.toString()});
|
||||||
|
return transactionEvent.getTransactionID();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerUser(List<String> userInfo){
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
transactionWrapper.sendTransaction("registerUser",new String[]{userInfo.get(0),userInfo.get(1),userInfo.get(2),userInfo.get(3),userInfo.get(4)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void deleteWallet(String walletHash){
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
transactionWrapper.sendTransaction("deleteWallet",new String[]{walletHash});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermission(String userHash){
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
transactionWrapper.sendTransaction("setUserPermission",new String[]{userHash});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transferWallet(String walletHash, String userHash){
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
transactionWrapper.sendTransaction("transferWallet", new String[]{walletHash,userHash});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,41 @@
|
||||||
package restService;
|
package restService;
|
||||||
|
|
||||||
|
import database.user.User;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import restImplementation.BlockchainQueryImplementation;
|
import restImplementation.BlockchainQueryImplementation;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "/api/rest/query")
|
@RequestMapping(value = "/api/rest/query")
|
||||||
public class BlockchainQueryResource {
|
public class BlockchainQueryResource {
|
||||||
|
|
||||||
/*
|
|
||||||
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"userHash"},produces = "application/json")
|
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"walletHash"},produces = "application/json")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "userHash") String userHash){
|
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "walletHash") String walletHash){
|
||||||
try{
|
try{
|
||||||
BlockchainQueryImplementation blockchainQueryImplementation = new BlockchainQueryImplementation();
|
BlockchainQueryImplementation blockchainQueryImplementation = new BlockchainQueryImplementation();
|
||||||
Double result = blockchainQueryImplementation.getUserBalance(userHash);
|
Double result = blockchainQueryImplementation.getWalletSold(walletHash);
|
||||||
StringResponse response = new StringResponse("Ok",result);
|
StringResponse response = new StringResponse("Ok",result);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
StringResponse response = new StringResponse("Error");
|
StringResponse response = new StringResponse("Error");
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@RequestMapping(value = "/registerUser", method = RequestMethod.POST, produces = "application/json")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ public class TransactionTest {
|
||||||
String functionName = "transaction";
|
String functionName = "transaction";
|
||||||
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5hdsf1515","200"};
|
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5hdsf1515","200"};
|
||||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
String txID = responseEvent.getTransactionID();
|
||||||
|
logger.info("Event transaction id : "+txID); //print transaction id
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class DeleteWalletTest {
|
||||||
try{
|
try{
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
String functionName = "deleteWallet";
|
String functionName = "deleteWallet";
|
||||||
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
String[] args = new String[]{"qerh654d5f5hdsf16"};
|
||||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
|
@ -19,7 +19,8 @@ public class InitWalletTest {
|
||||||
try{
|
try{
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
String functionName = "initWallet";
|
String functionName = "initWallet";
|
||||||
String[] args = new String[]{"qerh654d5f5hdsf1515","client","usera"};
|
//String[] args = new String[]{"qerh654d5f5hdsf1515","client","usera"};
|
||||||
|
String[] args = new String[]{"qerh654d5f5hdsf16","fournisseur","bitman"};
|
||||||
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
|
@ -7,6 +7,12 @@ import org.apache.log4j.Logger;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
import javax.json.JsonReader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryWalletByOwnerTest {
|
public class QueryWalletByOwnerTest {
|
||||||
|
@ -18,10 +24,24 @@ public class QueryWalletByOwnerTest {
|
||||||
try{
|
try{
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
String functionName = "queryWalletsByOwner";
|
String functionName = "queryWalletsByOwner";
|
||||||
String[] args = new String[]{"usera"};
|
//String[] args = new String[]{"usera"};
|
||||||
//String[] args = new String[]{"bitman"};
|
String[] args = new String[]{"bitman"};
|
||||||
String response = queryWrapper.sendQuery(functionName,args);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
logger.info("response : "+response);
|
logger.info("response : "+response);
|
||||||
|
|
||||||
|
if(response != null) {
|
||||||
|
JsonReader reader = Json.createReader(new StringReader(response));
|
||||||
|
JsonArray walletInfo = reader.readArray();
|
||||||
|
logger.info("walletInfo : "+walletInfo);
|
||||||
|
|
||||||
|
for(Object obj : walletInfo){
|
||||||
|
JsonObject o = (JsonObject) obj;
|
||||||
|
o = o.get("Record").asJsonObject();
|
||||||
|
logger.info("JsonObject : "+o);
|
||||||
|
logger.info("walletInfo ID : "+o.getString("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class ReadWalletTest {
|
||||||
try{
|
try{
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
String functionName = "readWallet";
|
String functionName = "readWallet";
|
||||||
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00"};
|
||||||
String response = queryWrapper.sendQuery(functionName,args);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
logger.info("response : "+response);
|
logger.info("response : "+response);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
20
src/test/java/restImplementation/GetUserAssociationTest.java
Normal file
20
src/test/java/restImplementation/GetUserAssociationTest.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package restImplementation;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class GetUserAssociationTest {
|
||||||
|
private static Logger logger = Logger.getLogger(GetUserAssociationTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void GetUserAssociationTest() {
|
||||||
|
BlockchainQueryImplementation queryImplementation = new BlockchainQueryImplementation();
|
||||||
|
String association = queryImplementation.getUserAssociation("bitman");
|
||||||
|
logger.info("association : "+association);
|
||||||
|
}
|
||||||
|
}
|
22
src/test/java/restImplementation/GetUserWalletsTest.java
Normal file
22
src/test/java/restImplementation/GetUserWalletsTest.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package restImplementation;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class GetUserWalletsTest {
|
||||||
|
private static Logger logger = Logger.getLogger(GetWalletSoldTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void GetUserWalletsTest() {
|
||||||
|
BlockchainQueryImplementation queryImplementation = new BlockchainQueryImplementation();
|
||||||
|
List<HashMap> wallets = queryImplementation.getUserWallets("bitman");
|
||||||
|
for(HashMap w : wallets){
|
||||||
|
logger.info("walletHash : "+w.get("walletHash")+". walletType : "+w.get("walletType")+". sold : "+w.get("sold"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
src/test/java/restImplementation/GetWalletSoldTest.java
Normal file
20
src/test/java/restImplementation/GetWalletSoldTest.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package restImplementation;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public class GetWalletSoldTest {
|
||||||
|
private static Logger logger = Logger.getLogger(GetWalletSoldTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void GetWalletSold() {
|
||||||
|
BlockchainQueryImplementation queryImplementation = new BlockchainQueryImplementation();
|
||||||
|
Double sold = queryImplementation.getWalletSold("qerh654d5f5h46q4fdh6h65fh00");
|
||||||
|
logger.info("result sold : "+sold);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue