Search in sources :

Example 6 with AddressBook

use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.

the class AddressBookHelper method getContactAccDetails.

public static ContactAcctDetails getContactAccDetails(Contact contact, int index) {
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("getContactAccDetails - addressBook returns null");
        return null;
    }
    for (int i = 0; i < addressBook.GetContactCount(); i++) {
        Contact newContact = addressBook.GetContact(i);
        if (contact == null)
            continue;
        if (newContact.getContact_id().equals(contact.getContact_id())) {
            contact = newContact;
            break;
        }
    }
    ContactAcctDetails data = new ContactAcctDetails();
    if (contact != null && index > -1) {
        ContactAcct contactAcct = contact.GetContactAcct(index);
        if (contactAcct == null) {
            System.out.println("getContactNymDetails contact.getContactAccDetails(index) returned null");
            return null;
        }
        data.setLabel(contactAcct.getGui_label());
        data.setMemo(contactAcct.getMemo());
        data.setNymID(contactAcct.getNym_id());
        data.setAcctID(contactAcct.getAcct_id());
        data.setAssetID(contactAcct.getAsset_type_id());
        data.setServerID(contactAcct.getServer_id());
        data.setServerType(contactAcct.getServer_type());
        data.setPublicKey(contactAcct.getPublic_key());
    }
    return data;
}
Also used : ContactAcct(org.opentransactions.otapi.ContactAcct) AddressBook(org.opentransactions.otapi.AddressBook) ContactAcctDetails(com.moneychanger.core.dataobjects.ContactAcctDetails) Contact(org.opentransactions.otapi.Contact)

Example 7 with AddressBook

use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.

the class AddressBookHelper method getContactList.

public static List getContactList() {
    List contactList = new ArrayList();
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("getContactList - addressBook returns null");
        return null;
    }
    for (int i = 0; i < addressBook.GetContactCount(); i++) {
        Contact contact = addressBook.GetContact(i);
        if (contact == null)
            continue;
        String[] row = new String[2];
        row[0] = contact.getGui_label() == null ? "" : contact.getGui_label();
        System.out.println("contact.getGui_label():" + contact.getGui_label());
        row[1] = contact.getContact_id() == null ? "" : contact.getContact_id();
        contactList.add(row);
    }
    return contactList;
}
Also used : AddressBook(org.opentransactions.otapi.AddressBook) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Contact(org.opentransactions.otapi.Contact)

Example 8 with AddressBook

use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.

the class AddressBookHelper method removeContactAcct.

public static boolean removeContactAcct(String contactID, int index) {
    boolean status = false;
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("removeContactAcct - 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.RemoveContactAcct(index);
            System.out.println("removeContactAcct status contact.RemoveContactAcct:" + status);
            if (status)
                status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
            System.out.println("removeContactAcct status addressBook otapi.StoreObject:" + status);
            break;
        }
    }
    return status;
}
Also used : AddressBook(org.opentransactions.otapi.AddressBook) Contact(org.opentransactions.otapi.Contact)

Example 9 with AddressBook

use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.

the class AddressBookHelper method createContact.

public static String createContact(String name, String email, String publicKey, String memo) {
    String contactID = "error";
    System.out.println("in createContact");
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("createContact - addressBook returns null");
        return contactID;
    }
    System.out.println("in createContact,addressBook:" + addressBook);
    Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_CONTACT);
    System.out.println("in createContact, storable:" + storable);
    if (storable != null) {
        Contact contact = Contact.ot_dynamic_cast(storable);
        System.out.println("contact:" + contact);
        if (contact != null) {
            contact.setContact_id(Helpers.generateID());
            contact.setEmail(email);
            contact.setGui_label(name);
            contact.setMemo(memo);
            contact.setPublic_key(publicKey);
            boolean status = addressBook.AddContact(contact);
            System.out.println("status addressBook.AddContact:" + status);
            if (!status) {
                return contactID;
            }
            status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
            System.out.println("status addressBook otapi.StoreObject:" + status);
            if (!status) {
                return contactID;
            }
            contactID = Helpers.generateID();
        }
    }
    return contactID;
}
Also used : AddressBook(org.opentransactions.otapi.AddressBook) Storable(org.opentransactions.otapi.Storable) Contact(org.opentransactions.otapi.Contact)

Example 10 with AddressBook

use of org.opentransactions.otapi.AddressBook in project otapij by FellowTraveler.

the class AddressBookHelper method getContactDetails.

public static ContactDetails getContactDetails(String contactID, int mode) {
    ContactDetails contactDetails = null;
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("getContactDetails - addressBook returns null");
        return null;
    }
    for (int i = 0; i < addressBook.GetContactCount(); i++) {
        Contact contact = addressBook.GetContact(i);
        if (contact == null)
            continue;
        if (contactID.equals(contact.getContact_id())) {
            contactDetails = new ContactDetails();
            contactDetails.setEmail(contact.getEmail());
            contactDetails.setLabel(contact.getGui_label());
            contactDetails.setPublicKey(contact.getPublic_key());
            contactDetails.setMemo(contact.getMemo());
            contactDetails.setContact(contact);
            List data = new ArrayList();
            System.out.println("mode:" + mode + " contact.GetContactAcctCount():" + contact.GetContactAcctCount());
            if (mode == 1) {
                for (int j = 0; j < contact.GetContactAcctCount(); j++) {
                    if (contact.GetContactAcct(j) == null)
                        continue;
                    data.add(new String[] { contact.GetContactAcct(j).getGui_label() });
                }
                contactDetails.setContactAccts(data);
            } else {
                for (int j = 0; j < contact.GetContactNymCount(); j++) {
                    if (contact.GetContactNym(j) == null)
                        continue;
                    data.add(new String[] { contact.GetContactNym(j).getGui_label() });
                }
                contactDetails.setContactNyms(data);
            }
            break;
        }
    }
    return contactDetails;
}
Also used : ContactDetails(com.moneychanger.core.dataobjects.ContactDetails) AddressBook(org.opentransactions.otapi.AddressBook) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Contact(org.opentransactions.otapi.Contact)

Aggregations

AddressBook (org.opentransactions.otapi.AddressBook)10 Contact (org.opentransactions.otapi.Contact)9 Storable (org.opentransactions.otapi.Storable)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ContactAcct (org.opentransactions.otapi.ContactAcct)2 ContactAcctDetails (com.moneychanger.core.dataobjects.ContactAcctDetails)1 ContactDetails (com.moneychanger.core.dataobjects.ContactDetails)1 ContactNym (org.opentransactions.otapi.ContactNym)1 ServerInfo (org.opentransactions.otapi.ServerInfo)1