예제 #1
0
 @Override
 public Set<EventCalendar> getOwnedItems(String id) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User user = (User) pm.getObjectById(User.class, id);
   Set<EventCalendar> result = user.getOwnedCalendars();
   pm.close();
   return result;
 }
예제 #2
0
 public EventCalendar removeItem(String id, String itemId) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User user = pm.getObjectById(User.class, id);
   EventCalendarDao calDao = new EventCalendarDaoImpl();
   EventCalendar cal = calDao.get(itemId);
   user.removeCalendar(cal);
   pm.makePersistent(user);
   pm.close();
   return cal;
 }
예제 #3
0
 public User setAdministrator(User obj) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User result = this.getComplete(obj.getId(), pm);
   if (result != null) {
     result.setAdministrator(obj.isAdministrator());
   }
   pm.makePersistent(result);
   pm.close();
   return result;
 }
예제 #4
0
 public List<EventCalendar> getItems(String id, String zoneName) throws Exception {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   FetchPlan fp = pm.getFetchPlan().addGroup("userGroup");
   fp.setMaxFetchDepth(1);
   User user = pm.detachCopy(pm.getObjectById(User.class, id));
   pm.close();
   EventCalendarDaoImpl eventDao = new EventCalendarDaoImpl();
   List<EventCalendar> result = eventDao.getCalendarsById(user.getCalendarKeys(), 0);
   //	    addGeoLocatedCals(result, geoLoc, zoneName);
   return result;
 }
예제 #5
0
 public EventCalendar addOwnedItem(String id, EventCalendar cal) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   try {
     User user = pm.getObjectById(User.class, id);
     user.addOwnedCalendar(cal);
     pm.makePersistent(cal);
     pm.makePersistent(user);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     pm.close();
   }
   return cal;
 }
예제 #6
0
  private List<EventCalendar> getFollowingCals(String userId) throws Exception {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan().addGroup("userGroup");
    fp.setMaxFetchDepth(2);
    User user = pm.detachCopy(pm.getObjectById(User.class, userId));
    pm.close();

    log.info("Loading feed");
    EventCalendarDaoImpl eventDao = new EventCalendarDaoImpl();
    List<EventCalendar> cals = eventDao.getCalendarsById(user.getCalendarKeys(), 1);
    log.info("Loading feed: following cals count: " + cals.size());
    for (EventCalendar cal : cals) cal.setSource("following");
    return cals;
  }
예제 #7
0
 public void removeOwnedItem(String id, String itemId) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User user = pm.getObjectById(User.class, id);
   EventCalendar cal = null;
   Set<EventCalendar> items = user.getOwnedCalendars();
   for (EventCalendar item : items) {
     if (item.getId().equals(itemId)) {
       cal = item;
       pm.deletePersistent(cal);
     }
   }
   user.removeOwnedCalendar(cal);
   pm.makePersistent(user);
   pm.close();
 }
예제 #8
0
 public void updateOwnedItem(String id, EventCalendar cal) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User user = pm.getObjectById(User.class, id);
   Set<EventCalendar> items = user.getOwnedCalendars();
   for (EventCalendar item : items) {
     if (item.getId().equals(cal.getId())) {
       try {
         item.merge(cal);
         item.setDateLastUpdated(new Date());
         pm.makePersistent(item);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   pm.close();
 }
예제 #9
0
 @Override
 public User update(User obj) {
   PersistenceManager pm = PMF.get().getPersistenceManager();
   User result = this.getComplete(obj.getId(), pm);
   if (result != null) {
     obj.setAdministrator(result.isAdministrator());
     try {
       result.merge(obj);
       result.setDateLastUpdated(new Date());
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   pm.makePersistent(result);
   pm.close();
   return result;
 }