Search in sources :

Example 1 with ContactNym

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

the class AddressBookHelper method getContactNymDetails.

public static ContactNymDetails getContactNymDetails(Contact contact, int index) {
    ContactNymDetails data = new ContactNymDetails();
    List serverList = new ArrayList();
    if (contact != null && index > -1) {
        ContactNym contactNYM = contact.GetContactNym(index);
        if (contactNYM == null) {
            System.out.println("getContactNymDetails contact.GetContactNym(index) returned null");
            return null;
        }
        data.setLabel(contactNYM.getGui_label());
        data.setMemo(contactNYM.getMemo());
        data.setNymID(contactNYM.getNym_id());
        data.setNymType(contactNYM.getNym_type());
        data.setPublicKey(contactNYM.getPublic_key());
        for (int i = 0; i < contactNYM.GetServerInfoCount(); i++) {
            String[] servers = new String[2];
            if (contactNYM.GetServerInfo(i) == null)
                continue;
            servers[0] = contactNYM.GetServerInfo(i).getServer_id();
            servers[0] = contactNYM.GetServerInfo(i).getServer_type();
            serverList.add(servers);
        }
        data.setServerList(serverList);
    }
    return data;
}
Also used : ContactNym(org.opentransactions.otapi.ContactNym) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ContactNymDetails(com.moneychanger.core.dataobjects.ContactNymDetails)

Example 2 with ContactNym

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

Aggregations

ContactNym (org.opentransactions.otapi.ContactNym)2 ContactNymDetails (com.moneychanger.core.dataobjects.ContactNymDetails)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AddressBook (org.opentransactions.otapi.AddressBook)1 Contact (org.opentransactions.otapi.Contact)1 ServerInfo (org.opentransactions.otapi.ServerInfo)1 Storable (org.opentransactions.otapi.Storable)1