use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.
the class Helpers method getAddressBook.
public static AddressBook getAddressBook() {
AddressBook addressBook = null;
Storable storable = null;
if (otapi.Exists("moneychanger", "gui_contacts.dat")) {
storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_ADDRESS_BOOK, "moneychanger", "gui_contacts.dat");
if (storable == null) {
return null;
}
addressBook = AddressBook.ot_dynamic_cast(storable);
} else {
storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_ADDRESS_BOOK);
if (storable == null) {
return null;
}
addressBook = AddressBook.ot_dynamic_cast(storable);
}
return addressBook;
}
use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.
the class AddressBookHelper method createContactNym.
public static boolean createContactNym(int index, String contactID, String label, String nymID, String nymType, String[] serverID, String[] serverType, String publickey, String memo) {
boolean status = false;
AddressBook addressBook = Helpers.getAddressBook();
if (addressBook == null) {
System.out.println("createContactNym - addressBook returns null");
return false;
}
int count = (int) addressBook.GetContactCount();
for (int i = 0; i < count; i++) {
Contact contact = addressBook.GetContact(i);
if (contact == null) {
continue;
}
if (contactID.equals(contact.getContact_id())) {
System.out.println("createContactNym - contactID matches");
ContactNym contactNYM = null;
if (index == -1) {
Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_CONTACT_NYM);
if (storable != null) {
contactNYM = ContactNym.ot_dynamic_cast(storable);
}
} else {
contactNYM = contact.GetContactNym(index);
}
if (contactNYM != null) {
contactNYM.setGui_label(label);
contactNYM.setMemo(memo);
contactNYM.setNym_id(nymID);
contactNYM.setNym_type(nymType);
contactNYM.setPublic_key(publickey);
while (contactNYM.GetServerInfoCount() > 0) {
contactNYM.RemoveServerInfo(0);
}
for (int j = 0; j < serverID.length; j++) {
Storable storable1 = otapi.CreateObject(StoredObjectType.STORED_OBJ_SERVER_INFO);
if (storable1 != null) {
ServerInfo serverInfo = ServerInfo.ot_dynamic_cast(storable1);
if (serverInfo != null) {
serverInfo.setServer_id(serverID[j]);
System.out.println("serverType[j]:" + serverType[j]);
serverInfo.setServer_type(serverType[j]);
contactNYM.AddServerInfo(serverInfo);
}
}
}
contact.AddContactNym(contactNYM);
status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
System.out.println("createContactNym status addressBook otapi.StoreObject:" + status);
// Set other values here
}
break;
}
}
return status;
}
use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.
the class AddressBookHelper method removeContact.
public static boolean removeContact(String contactID) {
boolean status = false;
AddressBook addressBook = Helpers.getAddressBook();
if (addressBook == null) {
System.out.println("removeContact - addressBook returns null");
return false;
}
for (int i = 0; i < addressBook.GetContactCount(); i++) {
Contact contact = addressBook.GetContact(i);
if (contact == null) {
continue;
}
if (contactID.equals(contact.getContact_id())) {
status = addressBook.RemoveContact(i);
System.out.println("removeContact status addressBook otapi.RemoveContact:" + status);
if (status) {
status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
}
System.out.println("removeContact status addressBook otapi.StoreObject:" + status);
break;
}
}
return status;
}
use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.
the class AddressBookHelper method createContactAccount.
public static boolean createContactAccount(int index, String contactID, String label, String nymID, String acctID, String assetID, String serverID, String serverType, String publickey, String memo) {
System.out.println("createContactAccount contactID:" + contactID);
boolean status = false;
AddressBook addressBook = Helpers.getAddressBook();
if (addressBook == null) {
System.out.println("createContactAccount - addressBook returns null");
return false;
}
int count = (int) addressBook.GetContactCount();
for (int i = 0; i < count; i++) {
Contact contact = addressBook.GetContact(i);
if (contact == null) {
continue;
}
if (contactID.equals(contact.getContact_id())) {
System.out.println("createContactAccount - contactID matches, index=" + index);
ContactAcct contactAcct = null;
if (index == -1) {
System.out.println("createContactAccount new obj");
Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_CONTACT_ACCT);
if (storable != null) {
contactAcct = ContactAcct.ot_dynamic_cast(storable);
}
} else {
contactAcct = contact.GetContactAcct(index);
System.out.println("createContactAccount old obj, contactAcct :" + contactAcct);
}
if (contactAcct != null) {
contactAcct.setGui_label(label);
contactAcct.setMemo(memo);
contactAcct.setNym_id(nymID);
contactAcct.setAcct_id(acctID);
contactAcct.setAsset_type_id(assetID);
contactAcct.setPublic_key(publickey);
contactAcct.setServer_id(serverID);
contactAcct.setServer_type(serverType);
contact.AddContactAcct(contactAcct);
status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
System.out.println("createContactAccount status addressBook otapi.StoreObject:" + status);
// Set other values here
}
break;
}
}
return status;
}
use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.
the class AddressBookHelper method removeContactNym.
public static boolean removeContactNym(String contactID, int index) {
boolean status = false;
AddressBook addressBook = Helpers.getAddressBook();
if (addressBook == null) {
System.out.println("removeContactNym - addressBook returns null");
return false;
}
for (int i = 0; i < addressBook.GetContactCount(); i++) {
Contact contact = addressBook.GetContact(i);
if (contact == null)
continue;
if (contactID.equals(contact.getContact_id())) {
status = contact.RemoveContactNym(index);
System.out.println("removeContactNym status contact.RemoveContactNym:" + status);
if (status)
status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
System.out.println("removeContactNym status addressBook otapi.StoreObject:" + status);
break;
}
}
return status;
}
Aggregations