@Override
 public void removeRepresentations() throws ResourceException {
   Phonebook privatePhonebook = m_phonebookManager.getPrivatePhonebook(getUser());
   if (privatePhonebook != null) {
     Collection<PhonebookEntry> entries = privatePhonebook.getEntries();
     ArrayList<String> ids = new ArrayList<String>();
     for (PhonebookEntry entry : entries) {
       ids.add(String.valueOf(entry.getId()));
     }
     if (ids.contains(m_entryId)) {
       PhonebookEntry entry = m_phonebookManager.getPhonebookEntry(Integer.parseInt(m_entryId));
       m_phonebookManager.deletePhonebookEntry(entry);
     }
   }
 }
 @Override
 public Representation represent(Variant variant) throws ResourceException {
   Phonebook privatePhonebook = m_phonebookManager.getPrivatePhonebook(getUser());
   if (privatePhonebook != null) {
     Collection<PhonebookEntry> entries = privatePhonebook.getEntries();
     ArrayList<String> ids = new ArrayList<String>();
     for (PhonebookEntry entry : entries) {
       ids.add(String.valueOf(entry.getId()));
     }
     if (ids.contains(m_entryId)) {
       PhonebookEntry entry = m_phonebookManager.getPhonebookEntry(Integer.parseInt(m_entryId));
       PhonebookEntry reprEntry = (PhonebookEntry) entry.duplicate();
       return new PhonebookEntryRepresentation(variant.getMediaType(), reprEntry);
     }
   }
   return null;
 }
  @Override
  public void acceptRepresentation(Representation entity) throws ResourceException {
    PhonebookEntryRepresentation representation = new PhonebookEntryRepresentation(entity);
    PhonebookEntry newEntry = representation.getObject();
    if (!validatePhonebookEntry(newEntry)) {
      return;
    }

    if (m_phonebookManager.getDuplicatePhonebookEntry(newEntry, getUser()) != null) {
      setDuplicateEntryStatus();
      return;
    }

    User user = getUser();
    Phonebook privatePhonebook = m_phonebookManager.getPrivatePhonebookCreateIfRequired(user);
    newEntry.setPhonebook(privatePhonebook);
    (privatePhonebook.getEntries()).add(newEntry);
    m_phonebookManager.savePhonebook(privatePhonebook);
  }
  @Override
  public void storeRepresentation(Representation entity) throws ResourceException {
    PhonebookEntryRepresentation representation = new PhonebookEntryRepresentation(entity);
    PhonebookEntry newEntry = representation.getObject();
    if (!validatePhonebookEntry(newEntry)) {
      return;
    }

    PhonebookEntry duplicateEntry =
        m_phonebookManager.getDuplicatePhonebookEntry(newEntry, getUser());
    if (duplicateEntry != null && !duplicateEntry.getId().equals(Integer.parseInt(m_entryId))) {
      setDuplicateEntryStatus();
      return;
    }

    Phonebook privatePhonebook = m_phonebookManager.getPrivatePhonebook(getUser());
    if (privatePhonebook != null) {
      newEntry.setPhonebook(privatePhonebook);
      PhonebookEntry entry = m_phonebookManager.getPhonebookEntry(Integer.parseInt(m_entryId));
      entry.update(newEntry);
      m_phonebookManager.updatePhonebookEntry(entry);
    }
  }