Merge branch 'features1.4/user' into develop-1.4

This commit is contained in:
GME 2019-03-31 14:08:21 +02:00
commit be076b7fab
10 changed files with 85 additions and 19 deletions

View file

@ -11,7 +11,7 @@ CREATE TABLE public."T_USER"
password character varying(255) COLLATE pg_catalog."default" NOT NULL,
creation_date bigint NOT NULL,
modification_date bigint NOT NULL,
phone bigint NOT NULL,
phone character varying(255) COLLATE pg_catalog."default" NOT NULL,
association character varying(255) COLLATE pg_catalog."default" NOT NULL,
verified boolean NOT NULL,
approved boolean NOT NULL,

View file

@ -22,7 +22,7 @@ public class TransactionWrapper {
//try{
Collection<ProposalResponse> successful = new LinkedList<>();
Collection<ProposalResponse> failed = new LinkedList<>();
//Collection<ProposalResponse> failed = new LinkedList<>();
FabricClientWrapper fabricClientWrapper;
if(user != null){
@ -56,8 +56,9 @@ public class TransactionWrapper {
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
successful.add(response);
} else {
failed.add(response);
logger.info("Failed transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
throw new Exception("Error during insert into Blockchain");
//failed.add(response);
}
}

View file

@ -21,7 +21,7 @@ public class User {
@DatabaseField(canBeNull = false)
private long modification_date;
@DatabaseField(canBeNull = false)
private long phone;
private String phone;
@DatabaseField(canBeNull = false)
private String association;
@DatabaseField(canBeNull = false)
@ -36,13 +36,24 @@ public class User {
public User() {
}
public User(String name, String firstname, String email, String password) {
public User(String name, String firstname, String email, String password, String association) {
this.name = name;
this.firstname = firstname;
this.email = email;
this.password = password;
this.association = association;
}
public User(String name, String firstname, String email, String password, String phone, String association){
this.name = name;
this.firstname = firstname;
this.email = email;
this.password = password;
this.phone = phone;
this.association = association;
}
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, boolean verified, boolean approved) {
this.name = name;
this.firstname = firstname;
@ -55,7 +66,7 @@ public class User {
this.approved = approved;
}
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, long phone, String association, boolean verified, boolean approved) {
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, String phone, String association, boolean verified, boolean approved) {
this.name = name;
this.firstname = firstname;
this.user_hash = user_hash;
@ -69,14 +80,6 @@ public class User {
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
public int getUserId() {
@ -130,8 +133,8 @@ public class User {
this.modification_date = modification_date;
}
public long getPhone(){return phone;}
public void setPhone(int phone){this.phone=phone;}
public String getPhone(){return phone;}
public void setPhone(String phone){this.phone=phone;}
public String getAssociation(){return association;}
public void setAssociation(){this.association=association;}

View file

@ -63,7 +63,7 @@ public class BlockchainQueryImplementation {
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()});
@ -91,6 +91,7 @@ public class BlockchainQueryImplementation {
TransactionWrapper transactionWrapper = new TransactionWrapper();
transactionWrapper.sendTransaction("transferWallet", new String[]{walletHash,userHash});
}
*/

View file

@ -19,6 +19,10 @@ public class UserImplementation {
user.setUser_hash(hashPassword(user.getName()+user.getEmail()+user.getFirstname()+user.getAssociation()));
//REGISTER IN BLOCKCHAIN
if(user.getPhone()==null){
user.setPhone("0000000000");
}
String[] userInfos = new String[]{user.getUser_hash(),user.getName(),user.getFirstname(),""+user.getPhone(),user.getAssociation()};
transactionWrapper.sendTransaction("registerUser",userInfos);

View file

@ -19,7 +19,7 @@ public class DeleteUserTest {
try{
TransactionWrapper transactionWrapper = new TransactionWrapper();
String functionName = "deleteUser";
String[] args = new String[]{"usera"};
String[] args = new String[]{"$2a$10$6vjtplKcFKKaE0HKGd.8VOJi0xugc5Ojbf9m5LqyZ8mzU5nfcxt5."};
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
}catch (Exception e){

View file

@ -22,7 +22,7 @@ public class ReadUserTest {
try{
QueryWrapper queryWrapper = new QueryWrapper();
String functionName = "readUser";
String[] args = new String[]{"usera"};
String[] args = new String[]{"$2a$10$6vjtplKcFKKaE0HKGd.8VOJi0xugc5Ojbf9m5LqyZ8mzU5nfcxt5."};
String response = queryWrapper.sendQuery(functionName,args);
if(response != null){
JsonReader reader = Json.createReader(new StringReader(response));

View file

@ -7,6 +7,7 @@ import restImplementation.DatabaseUserImplementation;
@Ignore
public class DatabaseUserImplementationTest {
/*
@Test
public void TestUser(){
try {
@ -20,4 +21,5 @@ public class DatabaseUserImplementationTest {
e.printStackTrace();
}
}
*/
}

View file

@ -0,0 +1,53 @@
package restImplementation;
import database.user.User;
import org.apache.log4j.Logger;
import org.junit.Ignore;
import org.junit.Test;
import restService.StringResponse;
import java.util.Map;
@Ignore
public class UserImplementationTest {
private static Logger logger = Logger.getLogger(UserImplementationTest.class);
@Test
public void RegisterUserWithoutPhone() {
User userTest = new User("TotoName","TotoFirstName","TotoEmail@gmail.com","totoPassword1234$","gonette");
UserImplementation userImplementation = new UserImplementation();
try{
Map<String,String> response = userImplementation.registerUser(userTest);
logger.info("response is: "+response.get("response"));
if(Boolean.parseBoolean(response.get("response"))){
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
logger.info("StringResponse is: "+responseS.getResponse()+". User hash: "+responseS.getUserHash());
}
} catch (Exception e){
logger.warn("Error: "+e);
}
}
/*
@Test
public void RegisterUserWithPhone() {
User userTest = new User("TataName","TataFirstName","TataEmail@gmail.com","tataPassword1234$","0607080900","gonette");
UserImplementation userImplementation = new UserImplementation();
try{
Map<String,String> responseTest = userImplementation.registerUser(userTest);
logger.info("response is: "+responseTest.get("response"));
if(Boolean.parseBoolean(responseTest.get("response"))){
StringResponse responseS = new StringResponse("Ok",responseTest.get("userHash"));
logger.info("StringResponse is: "+responseS.getResponse()+". User hash: "+responseS.getUserHash());
}
}catch (Exception e){
logger.warn("Error: "+e);
}
}
*/
}

View file

@ -8,6 +8,7 @@ import java.util.Map;
@Ignore
public class UserLoggerTest {
/*
@Test
public void testLoggerUser(){
try{
@ -22,4 +23,5 @@ public class UserLoggerTest {
e.printStackTrace();
}
}
*/
}