Package com.tll.common.data

Examples of com.tll.common.data.Status


    if(source != null) source.fireEvent(new RpcEvent(RpcEvent.Type.ERROR));

    // fire status event
    String msg = caught.getMessage();
    if(msg == null) msg = "An unknown RPC error occurred";
    final Status status = new Status(msg, MsgLevel.ERROR, (Msg.MsgAttr.STATUS.flag | Msg.MsgAttr.EXCEPTION.flag) );
    StatusEventDispatcher.get().fireEvent(new StatusEvent(status));
  }
View Full Code Here


  ListingPayload<Model> process(final String sessionId, final ListingContext context,
      final ListingRequest request) {

    if(context == null) throw new IllegalStateException("Null listing context");

    final Status status = new Status();

    if(request == null) {
      status.addMsg("No listing request specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
    }

    final String listingId = request == null ? null : request.getListingId();
    if(listingId == null) {
      status.addMsg("No listing name specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
    }

    final ListingOp listingOp = request == null ? null : request.getListingOp();
    if(listingOp == null) {
      status.addMsg("No listing op specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
    }

    ListingHandler<Model> handler = null;
    ListingStatus listingStatus = null;

    if(!status.hasErrors() && request != null) {
      if(sessionId == null) {
        status.addMsg("No session id specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
      }
      else {
        Integer offset = request.getOffset();
        Sorting sorting = request.getSorting();

        // get listing state (if cached)
        final ListingState state = ListingCache.getState(sessionId, listingId);
        if(state != null) {
          if(log.isDebugEnabled())
            log.debug("Found cached state for listing '" + listingId + "': " + state.toString());
          if(offset == null) {
            offset = state.getOffset();
            assert offset != null;
            if(log.isDebugEnabled())
              log.debug("Setting offset (" + offset + ") from cache for listing:" + listingId);
          }
          if(sorting == null) {
            sorting = state.getSorting();
            assert sorting != null;
            if(log.isDebugEnabled())
              log.debug("Setting sorting (" + sorting.toString() + ") from cache for listing:" + listingId);
          }
        }

        handler = ListingCache.getHandler(sessionId, listingId);
        listingStatus = (handler == null ? ListingStatus.NOT_CACHED : ListingStatus.CACHED);
        if(log.isDebugEnabled()) log.debug("Listing status: " + listingStatus);

        try {
          // acquire the listing handler
          if(handler == null || listingOp == ListingOp.REFRESH) {

            if(log.isDebugEnabled()) log.debug("Generating listing handler for listing: '" + listingId + "'...");

            final RemoteListingDefinition<? extends IListingSearch> listingDef = request.getListingDef();
            if(listingDef != null) {
              final IListingSearch search = listingDef.getSearchCriteria();
              if(search == null) {
                throw new ListingException(listingId, "No search criteria specified.");
              }

              // translate client side criteria to server side criteria
              final Criteria<? extends IEntity> criteria;
              try {
                // delegate
                criteria = context.getSearchTranslator().translateListingSearchCriteria(context, search);
              }
              catch(final IllegalArgumentException iae) {
                throw new ListingException(listingId, "Unable to translate listing search criteria: "
                    + request.descriptor(), iae);
              }

              // resolve the listing handler data provider
              final IListingDataProvider dataProvider = context.getListingDataProviderResolver().resolve(request);

              // resolve the list handler type
              final ListHandlerType lht = listingDef.getListHandlerType();
              if(lht == null) {
                throw new ListingException(listingId, "No list handler type specified.");
              }
              // resolve the sorting to use
              sorting = (sorting == null ? listingDef.getInitialSorting() : sorting);
              if(sorting == null) {
                throw new ListingException(listingId, "No sorting directive specified.");
              }
              IListHandler<SearchResult<?>> listHandler = null;
              try {
                listHandler = ListHandlerFactory.create(criteria, sorting, lht, dataProvider);
              }
              catch(final InvalidCriteriaException e) {
                throw new ListingException(listingId, "Invalid criteria: " + e.getMessage(), e);
              }
              catch(final EmptyListException e) {
                // we proceed to allow client to still show the listing
                status.addMsg(e.getMessage(), MsgLevel.WARN, MsgAttr.STATUS.flag);
              }
              catch(final ListHandlerException e) {
                // shouldn't happen
                throw new IllegalStateException("Unable to instantiate the list handler: " + e.getMessage(), e);
              }

              // transform to marshaling list handler
              MarshalOptions mo;
              try {
                mo = context.getMarshalOptionsResolver().resolve(search.getEntityType());
              }
              catch(final IllegalArgumentException e) {
                mo = MarshalOptions.NO_REFERENCES;
              }
              final MarshalingListHandler marshalingListHandler =
                new MarshalingListHandler(listHandler, context.getMarshaler(), mo, listingDef.getPropKeys());

              // instantiate the handler
              handler = new ListingHandler<Model>(marshalingListHandler, listingId, listingDef.getPageSize());
            }
          }

          // do the query related listing op
          if(handler != null && listingOp != null && listingOp.isQuery()) {
            if(log.isDebugEnabled())
              log.debug("Performing : '" + listingOp.getName() + "' for '" + listingId + "'...");
            try {
              handler.query(offset.intValue(), sorting, (listingOp == ListingOp.REFRESH));
              status.addMsg(listingOp.getName() + " for '" + listingId + "' successful.", MsgLevel.INFO,
                  MsgAttr.STATUS.flag);
            }
            catch(final EmptyListException e) {
              // we proceed to allow client to still show the listing
              status.addMsg(e.getMessage(), MsgLevel.WARN, MsgAttr.STATUS.flag);
            }
            catch(final ListingException e) {
              throw new ListingException(listingId, "An unexpected error occurred performing listing operation: "
                  + e.getMessage(), e);
            }
          }
        }
        catch(final ListingException e) {
          RpcServlet.exceptionToStatus(e, status);
          context.getExceptionHandler().handleException(e);
        }
        catch(final RuntimeException re) {
          context.getExceptionHandler().handleException(re);
          throw re;
        }

        // do caching
        if(listingOp == ListingOp.CLEAR) {
          // clear
          if(log.isDebugEnabled()) log.debug("Clearing listing '" + listingId + "'...");
          ListingCache.clearHandler(sessionId, listingId);
          if(!request.getRetainStateOnClear()) {
            ListingCache.clearState(sessionId, listingId);
          }
          listingStatus = ListingStatus.NOT_CACHED;
          status.addMsg("Cleared listing data for " + listingId, MsgLevel.INFO, MsgAttr.STATUS.flag);
        }
        else if(listingOp == ListingOp.CLEAR_ALL) {
          // clear all
          if(log.isDebugEnabled()) log.debug("Clearing ALL listings...");
          ListingCache.clearHandler(sessionId, listingId);
          if(!request.getRetainStateOnClear()) {
            ListingCache.clearAll(request.getRetainStateOnClear());
          }
          listingStatus = ListingStatus.NOT_CACHED;
          status.addMsg("Cleared ALL listing data", MsgLevel.INFO, MsgAttr.STATUS.flag);
        }
        else if(handler != null && !status.hasErrors()) {
          // cache listing handler
          if(log.isDebugEnabled()) log.debug("[Re-]Caching listing '" + listingId + "'...");
          ListingCache.storeHandler(sessionId, listingId, handler);
          // cache listing state
          if(log.isDebugEnabled()) log.debug("[Re-]Caching listing state '" + listingId + "'...");
          ListingCache.storeState(sessionId, listingId, new ListingState(handler.getOffset(), handler.getSorting()));
          listingStatus = ListingStatus.CACHED;
        }
      }
    } // !status.hasErrors()

    final ListingPayload<Model> p = new ListingPayload<Model>(status, listingId, listingStatus);

    // only provide page data when it is needed at the client and there are no
    // errors
    if(handler != null && !status.hasErrors() && (listingOp != null && !listingOp.isClear())) {
      if(log.isDebugEnabled()) log.debug("Sending page data for '" + listingId + "'...");
      final List<Model> list = handler.getElements();
      final Model[] arr = list == null ? new Model[0] : list.toArray(new Model[list.size()]);
      p.setPageData(handler.size(), arr, handler.getOffset(), handler.getSorting());
    }
View Full Code Here

      }
    }
  }

  public void onStatusEvent(StatusEvent event) {
    final Status status = event.getStatus();
    if(status != null) {
      handleStatus(status);
    }
  }
View Full Code Here

    return (ForgotPasswordServiceContext) getThreadLocalRequest().getSession(false).getServletContext().getAttribute(
        ForgotPasswordServiceContext.KEY);
  }

  public Payload requestPassword(final String emailAddress) {
    final Status status = new Status();
    final Payload p = new Payload(status);
    final Map<String, Object> data = new HashMap<String, Object>();

    if(StringUtil.isEmpty(emailAddress)) {
      status.addMsg("An email address must be specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
    }
    else {
      final ForgotPasswordServiceContext context = getContext();
      try {
        final IForgotPasswordHandler handler = context.getForgotPasswordHandler();
        final IUserRef user = handler.getUserRef(emailAddress);
        final String rp = handler.resetPassword(user.getId());
        data.put("username", user.getUsername());
        data.put("emailAddress", user.getEmailAddress());
        data.put("password", rp);
        final MailManager mailManager = context.getMailManager();
        final MailRouting mr = mailManager.buildAppSenderMailRouting(user.getEmailAddress());
        final IMailContext mailContext = mailManager.buildTextTemplateContext(mr, EMAIL_TEMPLATE_NAME, data);
        mailManager.sendEmail(mailContext);
        status.addMsg("Password reminder email was sent.", MsgLevel.INFO, MsgAttr.STATUS.flag);
      }
      catch(final EntityNotFoundException nfe) {
        exceptionToStatus(nfe, status);
        context.getExceptionHandler().handleException(nfe);
      }
View Full Code Here

  public AdminContextPayload getAdminContext() {
    final RequestContext rc = getRequestContext();
    final PersistContext mec = (PersistContext) rc.getServletContext().getAttribute(PersistContext.KEY);
    final AppContext ac = (AppContext) rc.getServletContext().getAttribute(AppContext.KEY);

    final Status status = new Status();

    final com.tll.server.AdminContext sac =
      (com.tll.server.AdminContext) rc.getSession().getAttribute(
          com.tll.server.AdminContext.KEY);
    if(sac == null) {
      // presume not logged in yet
      status.addMsg("Admin Context not found.", MsgLevel.INFO, MsgAttr.STATUS.flag);
      return new AdminContextPayload(status, ac.isDebug(), ac.getEnvironment(), null, null);
    }

    final Marshaler entityMarshaller = mec.getMarshaler();
    assert entityMarshaller != null : "No marshaler present";

    final Model user = entityMarshaller.marshalEntity(sac.getUser(), new MarshalOptions(true, 1, null));
    // NOTE: we want a distinct copy of the account here so we separately
    // marshall the account as opposed to grabbing the nested account from the
    // just marshaled user
    final Model account = entityMarshaller.marshalEntity(sac.getUser().getAccount(), MarshalOptions.NON_RELATIONAL);

    status.addMsg("Admin Context retrieved.", MsgLevel.INFO, MsgAttr.STATUS.flag);
    return new AdminContextPayload(status, ac.isDebug(), ac.getEnvironment(), user, account);
  }
View Full Code Here

      (com.tll.server.AdminContext) rc.getSession().getAttribute(com.tll.server.AdminContext.KEY);
    final Marshaler em = mec.getMarshaler();
    assert delegate != null && em != null && sac != null;

    final ModelPayload ep = delegate.load(new LoadRequest<PrimaryKeySearch>(new PrimaryKeySearch(accountRef)));
    final Status status = ep.getStatus();

    status.addMsg("Admin Context current account retrieved for " + accountRef.descriptor(), MsgLevel.INFO,
        MsgAttr.STATUS.flag);
    return new AdminContextPayload(status, ep.getModel());
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public ModelPayload add(AddAccountRequest request) {
    final ModelPayload p = new ModelPayload();
    final Status s = p.getStatus();

    final AppContext ac = (AppContext) getServletContext().getAttribute(AppContext.KEY);
    assert ac != null;
    final com.tll.service.entity.account.AddAccountService svc = ac.getAddAccountService();
    final PersistContext pc = (PersistContext) getServletContext().getAttribute(PersistContext.KEY);
    assert svc != null && pc != null;
    final Marshaler mlr = pc.getMarshaler();

    Class<? extends Account> accountClass;
    try {
      accountClass = (Class<? extends Account>) pc.getEntityTypeResolver().resolveEntityClass(request.getEntityType());
    }
    catch(final ClassCastException e) {
      s.addMsg("Invalid account type.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
      return p;
    }
    Model maccount = request.getAccount();
    if(maccount == null) {
      s.addMsg("No account specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
      return p;
    }
    final Collection<Model> maios = request.getAccountInterfaces();
    if(maios == null) {
      s.addMsg("No account interface options specified.", MsgLevel.ERROR, MsgAttr.STATUS.flag);
      return p;
    }
    final Collection<Model> musers = request.getUsers();

    try {
      // un-marshal
      Account account = mlr.marshalModel(maccount, accountClass);

      final ArrayList<AccountInterface> aios = new ArrayList<AccountInterface>(maios.size());
      for(final Model maio : maios) {
        aios.add(mlr.marshalModel(maio, AccountInterface.class));
      }

      final ArrayList<User> users = musers == null ? null : new ArrayList<User>(musers.size());
      if(musers != null) {
        for(final Model muser : musers) {
          users.add(mlr.marshalModel(muser, User.class));
        }
      }

      if(Isp.class == accountClass) {
        account = svc.addIsp((Isp) account, aios, users);
        s.addMsg("Isp added", MsgLevel.INFO, MsgAttr.STATUS.flag);
      }
      else if(Merchant.class == accountClass) {
        account = svc.addMerchant((Merchant) account, aios, users);
        s.addMsg("Merchant added", MsgLevel.INFO, MsgAttr.STATUS.flag);
      }
      else if(Customer.class == accountClass) {
        account = svc.addCustomer((Customer) account, aios, users);
        s.addMsg("Customer added", MsgLevel.INFO, MsgAttr.STATUS.flag);
      }
      else {
        s.addMsg("Unhandled account type: " + accountClass, MsgLevel.ERROR, MsgAttr.STATUS.flag);
        return p;
      }

      // marshal the added account
      maccount = mlr.marshalEntity(account, pc.getMarshalOptionsResolver().resolve(SmbizEntityType.ACCOUNT));
View Full Code Here

      super.onUnload();
      StatusEventDispatcher.get().removeStatusHandler(this);
    }

    public void onStatusEvent(StatusEvent event) {
      final Status status = event.getStatus();
      if(status != null) {
        final List<Msg> gms = status.getMsgs(MsgAttr.EXCEPTION.flag);
        if(gms != null && gms.size() > 0) {
          Msgs.post(gms, this, Position.CENTER, -1, true);
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.tll.common.data.Status

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.