예제 #1
0
  public void start() {
    groupSystem = EJBUtil.defaultLookup(GroupSystem.class);
    personViewer = EJBUtil.defaultLookup(PersonViewer.class);
    postingBoard = EJBUtil.defaultLookup(PostingBoard.class);

    instance = this;
  }
예제 #2
0
 protected User getData1User(Block block) {
   User user;
   try {
     user = EJBUtil.lookupGuid(em, User.class, block.getData1AsGuid());
   } catch (NotFoundException e) {
     throw new RuntimeException("invalid user in data1 of " + block, e);
   }
   return user;
 }
예제 #3
0
 /**
  * Utility helper for implementing getInterestedGroups() that returns a single-member set with the
  * group stored in data1.
  *
  * @param block
  * @return
  */
 protected Set<Group> getData1GroupAsSet(Block block) {
   Group group;
   try {
     group = EJBUtil.lookupGuid(em, Group.class, block.getData1AsGuid());
   } catch (NotFoundException e) {
     throw new RuntimeException(e);
   }
   return Collections.singleton(group);
 }
예제 #4
0
 /**
  * Utility helper for implementing getInterestedUsers() that gets everyone in the group identified
  * by the group id in data1.
  *
  * @param block
  * @return
  */
 protected final Set<User> getUsersWhoCareAboutData1Group(Block block) {
   Group group;
   try {
     group = EJBUtil.lookupGuid(em, Group.class, block.getData1AsGuid());
   } catch (NotFoundException e) {
     throw new RuntimeException("invalid group in data1 of " + block, e);
   }
   Set<User> groupMembers = groupSystem.getUserMembers(SystemViewpoint.getInstance(), group);
   return groupMembers;
 }
예제 #5
0
 @Override
 protected Post loadObject(Guid guid) {
   try {
     PostingBoard board = EJBUtil.defaultLookup(PostingBoard.class);
     Post post = board.loadRawPost(SystemViewpoint.getInstance(), guid);
     // Filter group notifications from search results
     if (board.postIsGroupNotification(post)) return null;
     return post;
   } catch (NotFoundException e) {
     throw new RuntimeException(e);
   }
 }
예제 #6
0
 /**
  * This is final since you should override saveInCacheInsideExistingTransaction instead, generally
  */
 @TransactionAttribute(TransactionAttributeType.NEVER)
 public final ResultType saveInCache(
     final KeyType key, final ResultType data, final boolean refetchedWithoutCheckingCache) {
   EJBUtil.assertNoTransaction();
   try {
     return runner.runTaskRetryingOnConstraintViolation(
         new Callable<ResultType>() {
           public ResultType call() {
             return saveInCacheInsideExistingTransaction(
                 key, data, new Date(), refetchedWithoutCheckingCache);
           }
         });
   } catch (Exception e) {
     if (EJBUtil.isDatabaseException(e)) {
       logger.warn("Ignoring database exception {}: {}", e.getClass().getName(), e.getMessage());
       return data;
     } else {
       ExceptionUtils.throwAsRuntimeException(e);
       throw new RuntimeException(e); // not reached
     }
   }
 }
  @Override
  public void setAllLastUpdatedToZero(String key) {
    EJBUtil.prepareUpdate(em, CachedFacebookPhotoData.class);

    Query q =
        em.createQuery(
            "UPDATE CachedFacebookPhotoData c"
                + " SET c.lastUpdated = '1970-01-01 00:00:00' "
                + " WHERE c.userId = :userId");
    q.setParameter("userId", key);
    int updated = q.executeUpdate();
    logger.debug("{} cached items expired for key {}", updated, key);
  }
예제 #8
0
  @Override
  public IQ handleIQ(IQ packet) throws UnauthorizedException {
    Log.debug("handling IQ packet " + packet);
    IQ reply = IQ.createResultIQ(packet);
    Element iq = packet.getChildElement();
    String method = iq.attributeValue("name");
    List<String> args = new ArrayList<String>();

    // TODO Don't look this up each time
    // We currently do this to avoid problems during development
    // from reloading Jive - later we probably want to move this to
    // constructor
    XMPPMethods methods = EJBUtil.defaultLookup(XMPPMethods.class);
    SimpleAnnotatedInvoker xmppInvoker =
        new SimpleAnnotatedInvoker(XMPPRemoted.class, methods, new PersonArgumentPrepender());

    for (Object argObj : iq.elements()) {
      Node arg = (Node) argObj;
      Log.debug("parsing expected arg node " + arg);
      if (arg.getNodeType() == Node.ELEMENT_NODE) {
        String argValue = arg.getText();
        Log.debug("Adding arg value" + argValue);
        args.add(argValue);
      }
    }

    try {
      Log.debug(
          "invoking method "
              + method
              + " with ("
              + args.size()
              + ") args "
              + Arrays.toString(args.toArray()));
      @SuppressWarnings("unused")
      String replyStr = xmppInvoker.invoke(method, args, packet.getFrom());
      // Don't do anything with this yet
    } catch (Exception e) {
      Log.debug("Caught exception during client method invocation", e);
    }
    return reply;
  }
예제 #9
0
 @TransactionAttribute(TransactionAttributeType.NEVER)
 public ResultType fetchFromNet(KeyType key) {
   EJBUtil.assertNoTransaction();
   return fetchFromNetImpl(key);
 }
예제 #10
0
 @Override
 protected List<Guid> loadAllIds() {
   return EJBUtil.defaultLookup(PostingBoard.class).getAllPostIds();
 }