Search in sources :

Example 1 with ContactAcct

use of org.opentransactions.otapi.ContactAcct 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;
}
Also used : ContactAcct(org.opentransactions.otapi.ContactAcct) AddressBook(org.opentransactions.otapi.AddressBook) Storable(org.opentransactions.otapi.Storable) Contact(org.opentransactions.otapi.Contact)

Example 2 with ContactAcct

use of org.opentransactions.otapi.ContactAcct 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)

Aggregations

AddressBook (org.opentransactions.otapi.AddressBook)2 Contact (org.opentransactions.otapi.Contact)2 ContactAcct (org.opentransactions.otapi.ContactAcct)2 ContactAcctDetails (com.moneychanger.core.dataobjects.ContactAcctDetails)1 Storable (org.opentransactions.otapi.Storable)1