/** {@inheritDoc} */
 @Override
 public void update(Observable userDao, Object object) {
   LogbookEntry newEntry = null;
   if (this.is(object, User.class)) {
     User user = (User) object;
     if (user.hasBeenAnonymized()) {
       newEntry = this.getEntryForUserAnonymized(user.getUsernameBeforeAnonym());
     } else if (user.hasJustBeenInserted()) {
       // a new user was inserted
       newEntry = this.getEntryForUserNew(user);
     } else if (user.hasJustBeenDeleted()) {
       newEntry = this.getEntryForUserDeleted(user);
     } else {
       User old = FamDaoProxy.userDao().getUserFromUsername(user.getUsername());
       newEntry = this.getEntryForUserUpdate(old, user);
     }
   } else if (this.is(object, ContactDetail.class)) {
     ContactDetail cd = (ContactDetail) object;
     newEntry = this.getEntryForContactDetails(cd);
   }
   if (newEntry != null) {
     newEntry.insert();
   } else {
     FamLog.error("observed an unknown event: " + object.getClass(), 201403061006l);
   }
 }
 private LogbookEntry getEntryForUserNew(User newUser) {
   LogbookEntry result = this.getNewBaseEntry();
   result.setHeadline("New user: "******"%s was inserted with the role %s", newUser.getFullName(), newUser.getRoleLabel()));
   return result;
 }
 private LogbookEntry getEntryForUserUpdate(User oldUser, User newUser) {
   LogbookEntry result = this.getNewBaseEntry();
   result.setHeadline("Update user: "******"please report error 201402061143");
   }
   result.setContent(StringUtils.join(messages.toArray(), "\r\n")); // FIXME check delimiter
   return result;
 }
 /**
  * return an {@link LogbookEntry} with an admin as author, current date, english as language.
  *
  * @since 06.03.2014
  * @return base {@link LogbookEntry} for all entries made here
  */
 private LogbookEntry getNewBaseEntry() {
   LogbookEntry result = new LogbookEntry();
   result.setOfUserName(RoleConfigDao.getInstance().getUsernamesOfAdmins()[0]);
   result.setLogbookId(this.getKey());
   result.setTagsFromCsv("system");
   result.setDate();
   result.setLanguage(Locale.ENGLISH);
   return result;
 }
  @Test
  public void logbookNewsReporter() {
    try {
      NewsSource nr = new NewsSourceForLogbookEntries(false);
      assertNotNull(nr);
      List<NewsItem> nis = nr.getNews(SimpleTimeFrame.getToday(), TeztBeanSimpleFactory.getAdmin());
      int nis_size_before = nis.size();
      int assertNewLogbookEntries = 0;

      LogbookEntry logbook = TeztBeanSimpleFactory.getNewValidLogbookEntry();
      assertNewLogbookEntries++; // because a new user was inserted
      logbook.setLogbookId(TeztBeanSimpleFactory.LOGBOOK_ID1);
      logbook.setDate(new Date());
      logbook.insert();
      assertNewLogbookEntries++; // because a new logbook was inserted

      assertNotNull(logbook.getDate());

      nis = nr.getNews(SimpleTimeFrame.getToday(), TeztBeanSimpleFactory.getAdmin());
      assertEquals(nis_size_before + assertNewLogbookEntries, nis.size());

      // assert same date as lobook entry
      NewsItem back = nis.get(nis.size() - 1);
      assertEquals(back.getEventStarts().toString(), logbook.getDate().toString());

      // update entry to past
      Calendar last_year = Calendar.getInstance();
      last_year.add(Calendar.YEAR, -1);
      logbook.setDate(last_year.getTime());
      logbook.update();

      nis = nr.getNews(SimpleTimeFrame.getToday(), TeztBeanSimpleFactory.getAdmin());
      assertEquals(nis_size_before + 1, nis.size()); // + 1 because of adminLogbook still there

      assertTrue("successed", true);
    } catch (Exception e) {
      fail("should not throw exception");
    }
  }
 private LogbookEntry getEntryForUserDeleted(User user) {
   LogbookEntry result = this.getNewBaseEntry();
   result.setHeadline("Deleted user: "******"%s was deleted", user.getFullName()));
   return result;
 }
 private LogbookEntry getEntryForUserAnonymized(String username) {
   LogbookEntry result = this.getNewBaseEntry();
   result.setHeadline("Anonymized user" + username);
   result.setContent(String.format("%s is anonym now", username));
   return result;
 }
 public List<LogbookEntry> getAllEntries() {
   LogbookEntry le = new LogbookEntry();
   le.setLogbookId(this.getKey());
   return FamDaoProxy.logbookEntryDao().getObjectsLike(le);
 }
 private LogbookEntry getEntryForContactDetails(ContactDetail cd) {
   LogbookEntry result = this.getNewBaseEntry();
   result.setHeadline("contact details changed of user " + cd.getUsername());
   result.setContent(String.format("%s: %s", cd.getTitle(), cd.getDetail()));
   return result;
 }