public Set<Contact> getContacts(int... ids) {
   boolean isRealId = false;
   /** @param isRealId stores whether or not we found a contact with the id */
   int offendingId = 0;
   /** @param offendingId stores an id that does not correspond to a real contact */
   Set<Contact> setToReturn = new HashSet<Contact>();
   if (contactSet.isEmpty()) {
     throw new NullPointerException("No Contacts in Contact Manager!");
   } else {
     for (int id : ids) {
       for (Contact contact : contactSet) {
         if (id == contact.getId()) {
           isRealId = true;
           setToReturn.add(contact);
           break;
         } else isRealId = false;
         offendingId = id;
       }
       if (!isRealId) {
         throw new IllegalArgumentException("Contact with id " + offendingId + " does not exist");
       }
     }
     return setToReturn;
   }
 }
Exemple #2
0
 private void getPhoneNumbers(PIMList list, Contact c) {
   // printAttr (c);
   int nbValues = c.countValues(Contact.TEL);
   for (int i = 0; i < nbValues; i++) {
     String s = getString(c, Contact.TEL, i);
     int a = c.getAttributes(Contact.TEL, i);
     if (hasAttribute(a, Contact.ATTR_MOBILE)) {
       if (hasAttribute(a, Contact.ATTR_HOME)) {
         m_info[PIM_MOBILE_HOME] = s;
       } else if (hasAttribute(a, Contact.ATTR_WORK)) {
         m_info[PIM_MOBILE_WORK] = s;
       } else {
         m_info[PIM_MOBILE] = s;
       }
     } else if (hasAttribute(a, Contact.ATTR_HOME)) {
       m_info[PIM_HOME] = s;
     } else if (hasAttribute(a, Contact.ATTR_WORK)) {
       m_info[PIM_WORK] = s;
     } else if (hasAttribute(a, Contact.ATTR_FAX)) {
       m_info[PIM_FAX] = s;
     } else {
       m_info[PIM_OTHER] = s;
     }
     if (hasAttribute(a, Contact.ATTR_PREFERRED)) {
       m_info[PIM_PREFERRED] = s;
     }
   }
 }
  @Test
  @Transactional
  public void testAddContactToEventMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(event, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(event, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    contactService.attendEvent(newContact, event);

    event = eventService.findById(event.getId());
    assertTrue(event.getAttendees().contains(newContact));

    newContact = contactService.findById(newContact.getId());
    assertTrue(newContact.getAttendedEvents().contains(event));
  }
  /**
   * Method executeTask.
   *
   * @param object
   *     <p>incomingRequest
   */
  public Object executeTask(Object object) throws Exception {
    Object ret = null;
    try {
      Map incomingRequest = (Map) object;
      Contact contact = (Contact) incomingRequest.get("contact");
      String vendorId = "";

      if (contact != null) {
        vendorId = contact.getComp_id().getVendorId();
      }

      incomingRequest.put("Vendor_vendorId", vendorId);
      incomingRequest.put("Address_addressType", vendorId);
      incomingRequest.put("VendorCommRel_vendorId", vendorId);
      // for alternate contacts
      incomingRequest.put("Contact_vendorId", vendorId);
      incomingRequest.put("Contact_contactType", "ALTERNATE");
      // incomingRequest.put("Contact_contactCode", "002");

      this.setStatus(Status.SUCCEEDED);
    } catch (Exception e) {
      Log.error(this, e.toString());
      this.setStatus(Status.FAILED);
    }
    return ret;
  }
  /**
   * Adds resources for contact.
   *
   * @param tip the tool tip
   * @param protocolContact the protocol contact, which resources we're looking for
   */
  private void addContactResourceTooltipLines(ExtendedTooltip tip, Contact protocolContact) {
    Collection<ContactResource> contactResources = protocolContact.getResources();

    if (contactResources == null) return;

    Iterator<ContactResource> resourcesIter = contactResources.iterator();

    while (resourcesIter.hasNext()) {
      ContactResource contactResource = resourcesIter.next();

      // We only add the status icon if we have more than one resources,
      // otherwise it will always be identical to the contact status icon.
      ImageIcon protocolStatusIcon = null;
      if (contactResources.size() > 1) {
        protocolStatusIcon =
            ImageLoader.getIndexedProtocolIcon(
                ImageUtils.getBytesInImage(contactResource.getPresenceStatus().getStatusIcon()),
                protocolContact.getProtocolProvider());
      }

      String resourceName =
          (contactResource.getPriority() >= 0)
              ? contactResource.getResourceName() + " (" + contactResource.getPriority() + ")"
              : contactResource.getResourceName();

      if (protocolStatusIcon == null) tip.addSubLine(protocolStatusIcon, resourceName, 27);
      else tip.addSubLine(protocolStatusIcon, resourceName, 20);
    }

    tip.revalidate();
    tip.repaint();
  }
 public ContactIterator(Contact contact) {
   if (contact.isLeaf()) {
     nextLeaf = contact;
   } else {
     unfinishedIterators.push(contact.children());
   }
 }
  public void send(Message message, String footer) {
    String msgToSent = message.getContent() + "\n\n" + footer;

    for (Contact contact : message.getDestinations()) {
      send(contact.getNumber(), msgToSent);
    }
  }
  /**
   * Loads groups meta-data for all groups associated with all constituent raw contacts' accounts.
   */
  private void loadGroupMetaData(Contact result) {
    StringBuilder selection = new StringBuilder();
    ArrayList<String> selectionArgs = new ArrayList<String>();
    for (RawContact rawContact : result.getRawContacts()) {
      final String accountName = rawContact.getAccountName();
      final String accountType = rawContact.getAccountTypeString();
      final String dataSet = rawContact.getDataSet();
      if (accountName != null && accountType != null) {
        if (selection.length() != 0) {
          selection.append(" OR ");
        }
        selection.append("(" + Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=?");
        selectionArgs.add(accountName);
        selectionArgs.add(accountType);

        if (dataSet != null) {
          selection.append(" AND " + Groups.DATA_SET + "=?");
          selectionArgs.add(dataSet);
        } else {
          selection.append(" AND " + Groups.DATA_SET + " IS NULL");
        }
        selection.append(")");
      }
    }
    final ImmutableList.Builder<GroupMetaData> groupListBuilder =
        new ImmutableList.Builder<GroupMetaData>();
    final Cursor cursor =
        getContext()
            .getContentResolver()
            .query(
                Groups.CONTENT_URI,
                GroupQuery.COLUMNS,
                selection.toString(),
                selectionArgs.toArray(new String[0]),
                null);
    if (cursor != null) {
      try {
        while (cursor.moveToNext()) {
          final String accountName = cursor.getString(GroupQuery.ACCOUNT_NAME);
          final String accountType = cursor.getString(GroupQuery.ACCOUNT_TYPE);
          final String dataSet = cursor.getString(GroupQuery.DATA_SET);
          final long groupId = cursor.getLong(GroupQuery.ID);
          final String title = cursor.getString(GroupQuery.TITLE);
          final boolean defaultGroup =
              cursor.isNull(GroupQuery.AUTO_ADD) ? false : cursor.getInt(GroupQuery.AUTO_ADD) != 0;
          final boolean favorites =
              cursor.isNull(GroupQuery.FAVORITES)
                  ? false
                  : cursor.getInt(GroupQuery.FAVORITES) != 0;

          groupListBuilder.add(
              new GroupMetaData(
                  accountName, accountType, dataSet, groupId, title, defaultGroup, favorites));
        }
      } finally {
        cursor.close();
      }
    }
    result.setGroupMetaData(groupListBuilder.build());
  }
  @Override
  public void deliverResult(Contact result) {
    unregisterObserver();

    // The creator isn't interested in any further updates
    if (isReset() || result == null) {
      return;
    }

    mContact = result;

    if (result.isLoaded()) {
      mLookupUri = result.getLookupUri();

      if (!result.isDirectoryEntry()) {
        Log.i(TAG, "Registering content observer for " + mLookupUri);
        if (mObserver == null) {
          mObserver = new ForceLoadContentObserver();
        }
        getContext().getContentResolver().registerContentObserver(mLookupUri, true, mObserver);
      }

      if (mPostViewNotification) {
        // inform the source of the data that this contact is being looked at
        postViewNotificationToSyncAdapter();
      }
    }

    super.deliverResult(mContact);
  }
  /**
   * Handle HTTP POST Method.
   *
   * @param entity contact to create.
   * @return The new contact URI representation (Header Content-Location).
   */
  @Post
  public Representation createContact(Representation entity) {
    Form form = new Form(entity);

    try {
      int id = Integer.parseInt(form.getFirstValue(ID, "-1"));
      if (id == -1) {
        System.out.println("id = -1");
        setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED, "Must provide 'id' field.");
        return null;
      }

      Contact contact = getContact(id) == null ? new Contact(id) : getContact(id);
      contact.setFirstName(form.getFirstValue(FIRST_NAME, "N/A"));
      contact.setLastName(form.getFirstValue(LAST_NAME, "N/A"));
      contact.setPhone(form.getFirstValue(PHONE, "N/A"));
      contact.setMail(form.getFirstValue(MAIL, "N/A"));

      Status createStatus = super.addContact(contact);
      setStatus(createStatus);

      Representation rep = new StringRepresentation("Contact created", MediaType.TEXT_PLAIN);
      rep.setLocationRef(String.format("%s/%s", getRequest().getResourceRef().getIdentifier(), id));
      return rep;
    } catch (Exception e) {
      e.printStackTrace();
      setStatus(Status.SERVER_ERROR_INTERNAL);
      return null;
    }
  }
  @Test
  public void tooLongSender() throws Exception {
    Mailbox mbox =
        MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129));
    Contact contact =
        mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);

    DbConnection conn = DbPool.getConnection(mbox);

    Assert.assertEquals(
        Strings.repeat("F", 128),
        DbUtil.executeQuery(
                conn,
                "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?",
                mbox.getId(),
                contact.getId())
            .getString(1));

    fields.put(ContactConstants.A_firstName, null);
    fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129));
    mbox.modifyContact(null, contact.getId(), new ParsedContact(fields));

    Assert.assertEquals(
        Strings.repeat("L", 128),
        DbUtil.executeQuery(
                conn,
                "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?",
                mbox.getId(),
                contact.getId())
            .getString(1));

    conn.closeQuietly();
  }
  /**
   * Handle HTTP GET method / Json
   *
   * @return a JSON list of contacts.
   */
  @Get("json")
  public Representation toJSON() {
    // System.out.println("Request Original Ref " + getOriginalRef());
    // System.out.println("Request Entity " + getRequest().getEntityAsText()
    // +
    // " entity mediaType " + getRequest().getEntity().getMediaType());

    try {
      JSONArray jcontacts = new JSONArray();
      Reference ref = getRequest().getResourceRef();
      final String baseURL = ref.getHierarchicalPart();
      Form formQuery = ref.getQueryAsForm();

      Iterator<Contact> it =
          getSortedContacts(formQuery.getFirstValue(REQUEST_QUERY_SORT, LAST_NAME)).iterator();

      while (it.hasNext()) {
        Contact contact = it.next();

        JSONObject jcontact = new JSONObject();
        jcontact.put(ID, String.format("%s", contact.getId()));
        jcontact.put(URL, String.format("%s/%s", baseURL, contact.getId()));
        jcontact.put(FIRST_NAME, contact.getFirstName());
        jcontact.put(LAST_NAME, contact.getLastName());
        jcontacts.put(jcontact);
      }

      JSONObject contacts = new JSONObject();
      contacts.put(CONTACTS, jcontacts);
      return new JsonRepresentation(contacts);
    } catch (Exception e) {
      setStatus(Status.SERVER_ERROR_INTERNAL);
      return null;
    }
  }
  /**
   * Sends the given file through this chat transport file transfer operation set.
   *
   * @param file the file to send
   * @return the <tt>FileTransfer</tt> object charged to transfer the file
   * @throws Exception if anything goes wrong
   */
  public FileTransfer sendFile(File file) throws Exception {
    // If this chat transport does not support instant messaging we do
    // nothing here.
    if (!allowsFileTransfer()) return null;

    OperationSetFileTransfer ftOpSet =
        contact.getProtocolProvider().getOperationSet(OperationSetFileTransfer.class);

    if (FileUtils.isImage(file.getName())) {
      // Create a thumbnailed file if possible.
      OperationSetThumbnailedFileFactory tfOpSet =
          contact.getProtocolProvider().getOperationSet(OperationSetThumbnailedFileFactory.class);

      if (tfOpSet != null) {
        byte[] thumbnail = getFileThumbnail(file);

        if (thumbnail != null && thumbnail.length > 0) {
          file =
              tfOpSet.createFileWithThumbnail(
                  file, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, "image/png", thumbnail);
        }
      }
    }
    return ftOpSet.sendFile(contact, file);
  }
  /**
   * Sends a typing notification state.
   *
   * @param typingState the typing notification state to send
   * @return the result of this operation. One of the TYPING_NOTIFICATION_XXX constants defined in
   *     this class
   */
  public int sendTypingNotification(int typingState) {
    // If this chat transport does not support sms messaging we do
    // nothing here.
    if (!allowsTypingNotifications()) return -1;

    ProtocolProviderService protocolProvider = contact.getProtocolProvider();
    OperationSetTypingNotifications tnOperationSet =
        protocolProvider.getOperationSet(OperationSetTypingNotifications.class);

    // if protocol is not registered or contact is offline don't
    // try to send typing notifications
    if (protocolProvider.isRegistered()
        && contact.getPresenceStatus().getStatus() >= PresenceStatus.ONLINE_THRESHOLD) {
      try {
        tnOperationSet.sendTypingNotification(contact, typingState);

        return ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT;
      } catch (Exception ex) {
        logger.error("Failed to send typing notifications.", ex);

        return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
      }
    }

    return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Log.d("DEBUG", "onCreateView");

    // view
    View v = inflater.inflate(R.layout.detail_contact, container, false);

    // set back icon in toolbar
    Toolbar tl = MainActivity.getToolbar();
    tl.setTitle(contact.getName());
    tl.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    tl.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            getActivity().onBackPressed();
          }
        });

    // find views and put data on it
    ImageView icon = (ImageView) v.findViewById(R.id.detail_icon);
    TextView status = (TextView) v.findViewById(R.id.detail_status);
    TextView name = (TextView) v.findViewById(R.id.detail_name);

    status.setText(contact.getStatus());
    icon.setImageResource(contact.getIcon());
    name.setText(contact.getName());

    return v;
  }
Exemple #16
0
 private void setContact() {
   Contact contact = new Contact(id);
   firstName = contact.getName();
   surname = contact.getSurname();
   designation = contact.getDesignation();
   phone = new Phone(contact.getId()).getNumber();
 }
    public void fetchKey(String pin) throws UnsupportedEncodingException {
      HttpPost httppost = new HttpPost("https://blooming-cliffs-4171.herokuapp.com/user/key");

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
      nameValuePairs.add(new BasicNameValuePair("pin", pin));
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      try {
        HttpResponse response = TorWrapper.getInstance().execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
          String responseString = EntityUtils.toString(entity);
          System.out.println(responseString);
          JSONObject responseJSON = new JSONObject(responseString);
          String contactKey = responseJSON.get("response").toString();
          System.out.println("User fetched with key: " + contactKey);

          newContact = new Contact();
          newContact.pin = pin;
          newContact.pubKey = contactKey;
          newContact.save();

          System.out.println(newContact.pubKey);
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
Exemple #18
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.saveNew:
       int can = 1;
       if (activityName.getText().toString().length() == 0) {
         can = 0;
       }
       if (activityTime.getText().toString().length() == 0) {
         can = 0;
       }
       if (can == 1) {
         fileUtils.saveContent(
             addNew.this, activityName.getText().toString(), Content.getText().toString());
         Contact contact = new Contact();
         contact.setTime(activityTime.getText().toString());
         contact.setName(activityName.getText().toString());
         myDatebaseHelper.insert(contact);
         Intent intent = new Intent(addNew.this, jishiben.class);
         startActivity(intent);
         addNew.this.finish();
       } else {
         Toast.makeText(addNew.this, "Please enter a valid time and theme", Toast.LENGTH_SHORT)
             .show();
       }
       break;
   }
 }
Exemple #19
0
  public static Contact getMergedContact(Context c, long contactID, Account account) {

    Uri ContactUri =
        RawContacts.CONTENT_URI
            .buildUpon()
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
            .build();

    Cursor cursor =
        c.getContentResolver()
            .query(
                ContactUri,
                new String[] {BaseColumns._ID, RawContacts.DISPLAY_NAME_PRIMARY},
                RawContacts.CONTACT_ID + " = '" + contactID + "'",
                null,
                null);
    if (cursor.getCount() > 0) {
      cursor.moveToFirst();
      Contact contact = new Contact();
      contact.ID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
      contact.name = cursor.getString(cursor.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY));
      cursor.close();
      return contact;
    }
    cursor.close();
    return null;
  }
Exemple #20
0
 public boolean filterData(String query) {
   items.clear();
   boolean isFound = false;
   if (query == null || query.isEmpty()) {
     originalContactList.clear();
     refreshList();
   } else {
     query = query.toLowerCase();
     if (originalContactList.isEmpty()) {
       Protocol p = RosterHelper.getInstance().getProtocol();
       for (Contact contact : p.getContactItems().values()) {
         originalContactList.add(contact);
       }
     }
     for (Contact contact : originalContactList) {
       boolean isSearch = contact.getText().toLowerCase().contains(query);
       if (isSearch) {
         items.add(contact);
       }
     }
     isFound = !items.isEmpty();
     notifyDataSetChanged();
   }
   return isFound;
 }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    Contact contact = ((ContactAdapter) getListAdapter()).getItem(info.position);
    switch (item.getItemId()) {
      case R.id.profile:
        Intent profileIntent = new Intent(getBaseContext(), ContactViewActivity.class);
        profileIntent.putExtra("ContactID", contact.getId());
        startActivity(profileIntent);
        return true;
      case R.id.edit:
        Intent editIntent = new Intent(getBaseContext(), ContactEditActivity.class);
        editIntent.putExtra("ContactID", contact.getId());
        startActivity(editIntent);
        return true;
      case R.id.delete:
        // TODO Maybe a confirmation???
        ContactRepositoryInterface datasource =
            ContactRepositoryFactory.getInstance().getContactRepository(this, this);
        this.contact_adapter.remove(contact);
        datasource.open();
        datasource.delete(contact);
        datasource.close();

        refreshList();
        return true;
      default:
        return super.onContextItemSelected(item);
    }
  }
 private ArrayList<String> getContactNames(ArrayList<Contact> friends) {
   ArrayList<String> friendNames = new ArrayList<String>();
   for (Contact c : friends) {
     friendNames.add(c.getName());
   }
   return friendNames;
 }
Exemple #23
0
  /**
   * Searches for additional phone numbers found in contact information
   *
   * @return additional phone numbers found in contact information;
   */
  private List<UIContactDetail> getAdditionalNumbers(boolean onlyMobile) {
    List<UIContactDetail> telephonyContacts = new ArrayList<UIContactDetail>();

    Iterator<Contact> contacts = getMetaContact().getContacts();

    while (contacts.hasNext()) {
      Contact contact = contacts.next();
      OperationSetServerStoredContactInfo infoOpSet =
          contact.getProtocolProvider().getOperationSet(OperationSetServerStoredContactInfo.class);
      Iterator<GenericDetail> details;
      ArrayList<String> phones = new ArrayList<String>();

      if (infoOpSet != null) {
        details = infoOpSet.getAllDetailsForContact(contact);

        while (details.hasNext()) {
          GenericDetail d = details.next();

          boolean process = false;

          if (onlyMobile) {
            if (d instanceof MobilePhoneDetail) process = true;
          } else if (d instanceof PhoneNumberDetail
              && !(d instanceof PagerDetail)
              && !(d instanceof FaxDetail)) {
            process = true;
          }

          if (process) {
            PhoneNumberDetail pnd = (PhoneNumberDetail) d;
            if (pnd.getNumber() != null && pnd.getNumber().length() > 0) {
              // skip phones which were already added
              if (phones.contains(pnd.getNumber())) continue;

              phones.add(pnd.getNumber());

              UIContactDetail cd =
                  new UIContactDetailImpl(
                      pnd.getNumber(),
                      pnd.getNumber() + " (" + getLocalizedPhoneNumber(d) + ")",
                      null,
                      new ArrayList<String>(),
                      GuiActivator.getResources().getImage("service.gui.icons.EXTERNAL_PHONE"),
                      null,
                      null,
                      pnd) {
                    @Override
                    public PresenceStatus getPresenceStatus() {
                      return null;
                    }
                  };
              telephonyContacts.add(cd);
            }
          }
        }
      }
    }

    return telephonyContacts;
  }
  /**
   * Permanently removes locally stored message history for the metacontact, remove any recent
   * contacts if any.
   */
  public void eraseLocallyStoredHistory(MetaContact contact) throws IOException {
    List<ComparableEvtObj> toRemove = null;
    synchronized (recentMessages) {
      toRemove = new ArrayList<ComparableEvtObj>();
      Iterator<Contact> iter = contact.getContacts();
      while (iter.hasNext()) {
        Contact item = iter.next();
        String id = item.getAddress();
        ProtocolProviderService provider = item.getProtocolProvider();

        for (ComparableEvtObj msc : recentMessages) {
          if (msc.getProtocolProviderService().equals(provider)
              && msc.getContactAddress().equals(id)) {
            toRemove.add(msc);
          }
        }
      }

      recentMessages.removeAll(toRemove);
    }
    if (recentQuery != null) {
      for (ComparableEvtObj msc : toRemove) {
        recentQuery.fireContactRemoved(msc);
      }
    }
  }
  public synchronized List<Contact> findAll(String stringFilter) {
    ArrayList arrayList = new ArrayList();
    for (Contact contact : contacts.values()) {
      try {
        boolean passesFilter =
            (stringFilter == null || stringFilter.isEmpty())
                || contact.toString().toLowerCase().contains(stringFilter.toLowerCase());
        if (passesFilter) {
          arrayList.add(contact.clone());
        }
      } catch (CloneNotSupportedException ex) {
        Logger.getLogger(ContactService.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    Collections.sort(
        arrayList,
        new Comparator<Contact>() {

          @Override
          public int compare(Contact o1, Contact o2) {
            return (int) (o2.getId() - o1.getId());
          }
        });
    return arrayList;
  }
Exemple #26
0
  /**
   * Get a list of collisions at the current time for a given body
   *
   * @param body The body to check for
   * @return The list of collision events describing the current contacts
   */
  public CollisionEvent[] getContacts(Body body) {
    ArrayList collisions = new ArrayList();

    for (int i = 0; i < arbiters.size(); i++) {
      Arbiter arb = arbiters.get(i);

      if (arb.concerns(body)) {
        for (int j = 0; j < arb.getNumContacts(); j++) {
          Contact contact = arb.getContact(j);
          CollisionEvent event =
              new CollisionEvent(
                  0,
                  arb.getBody1(),
                  arb.getBody2(),
                  contact.getPosition(),
                  contact.getNormal(),
                  contact.getSeparation());

          collisions.add(event);
        }
      }
    }

    return (CollisionEvent[]) collisions.toArray(new CollisionEvent[0]);
  }
  @Test
  @Transactional
  public void testAddContactToOrganizationMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(organization, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(organization, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    contactService.addContactToOrganization(newContact, organization);

    newContact = contactService.findById(newContact.getId());
    assertTrue(newContact.getOrganizations().contains(organization));

    group = groupService.findById(group.getId());
    assertTrue(group.getAggregations().contains(organization));

    secondGroup = groupService.findById(secondGroup.getId());
    assertTrue(secondGroup.getAggregations().contains(organization));

    organization = organizationService.findById(organization.getId());
    assertTrue(organization.getMembers().contains(newContact));
  }
Exemple #28
0
 public void printContact(Contact contact) {
   System.out.println("First Name: " + contact.getFirstName());
   System.out.println("Surname: " + contact.getSurName());
   System.out.println("Home Number: " + contact.getHomeNumber());
   System.out.println("Mobile Number: " + contact.getMobileNumber());
   System.out.println("City: " + contact.getCity());
 }
  public ArrayList<Contact> getAllContacts() {

    ArrayList<Contact> contactList = new ArrayList<Contact>();

    String selectQuery = "SELECT  * FROM " + TABLE_DETAILS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) { // if (cursor != null)
      do {
        Contact contact = new Contact();
        contact.setName(cursor.getString(1));
        contact.setAddress(cursor.getString(4));
        contact.setPhone(cursor.getString(5));

        String interest = getInterest(cursor.getInt(0));
        contact.setInterest(interest);

        contactList.add(contact);

      } while (cursor.moveToNext());
    }
    return contactList;
  }
Exemple #30
0
 private static void realizeStringArrayField(
     Contact contact,
     int field,
     int indexField,
     int index,
     int attributes,
     java.lang.String value,
     int action)
     throws PIMException {
   if (s_PIMList.isSupportedArrayElement(field, indexField)) {
     Logger.println(
         "DEBUG : realizeStringArrayField " + field + " and " + attributes + " supported");
     String[] values = new String[s_PIMList.stringArraySize(field)];
     for (int i = 0; i < values.length; i++) {
       values[i] = "";
     }
     values[indexField] = value;
     if (action == ADD_FIELD) {
       contact.addStringArray(field, attributes, values);
     } else {
       contact.setStringArray(field, index, attributes, values);
     }
     contact.commit();
   } else
     Logger.println(
         "DEBUG : realizeStringArrayField " + field + " and " + attributes + "not supported");
 }