Package com.tll.common.data

Examples of com.tll.common.data.ModelPayload


   * Loads model data.
   * @param request
   * @return the resultant payload
   */
  public ModelPayload load(final LoadRequest<? extends ISearch> request) {
    final ModelPayload payload = new ModelPayload();
    if(validateEntityRequest(request, payload)) {
      resolveImpl(request, payload.getStatus()).load(request.getSearch(), payload);
    }
    // load any requested auxiliary
    if(request.getAuxDataRequest() != null) {
      AuxDataHandler.getAuxData(context, request.getAuxDataRequest(), payload);
    }
View Full Code Here


   * Persists (adds or updates) model data.
   * @param request
   * @return the resultant payload
   */
  public ModelPayload persist(final PersistRequest request) {
    final ModelPayload payload = new ModelPayload();
    if(validateEntityRequest(request, payload)) {
      resolveImpl(request, payload.getStatus()).persist(request.getModel(), payload);
    }
    return payload;
  }
View Full Code Here

   * Purges model data.
   * @param request
   * @return the resultant payload
   */
  public ModelPayload purge(final PurgeRequest request) {
    final ModelPayload payload = new ModelPayload();
    if(validateEntityRequest(request, payload)) {
      if(request.getEntityRef() != null) {
        resolveImpl(request, payload.getStatus()).purge(request.getEntityRef(), payload);
      }
      else {
        resolveImpl(request, payload.getStatus()).purge(request.getModel(), payload);
      }
    }
    return payload;
  }
View Full Code Here

    addEntityToDb(a);

    final PersistServiceDelegate delegate = getDelegate();
    final PrimaryKeySearch search = new PrimaryKeySearch(new ModelKey(TestEntityType.ADDRESS, id, null));
    final LoadRequest<PrimaryKeySearch> request = new LoadRequest<PrimaryKeySearch>(search);
    final ModelPayload p = delegate.load(request);

    assert p != null;
    final Model m = p.getModel();
    assert m != null;
    assert m.getId() != null && m.getId().equals(id) && m.getEntityType() != null
    && m.getEntityType().equals(TestEntityType.ADDRESS);
  }
View Full Code Here

    m.set(new CharacterPropertyValue("mi", 'm'));
    m.set(new StringPropertyValue("phone", "1112223333"));
    m.set(new StringPropertyValue("postalCode", "48104"));
    m.set(new StringPropertyValue("province", "MI"));

    final ModelPayload p = delegate.persist(new PersistRequest(m, false));
    assert p != null;
    m = p.getModel();
    assert m != null;
    assert m.getId() != null && m.getId().equals("10000") && m.getEntityType() != null
    && m.getEntityType().equals(TestEntityType.ADDRESS);
    final Object ov = m.getProperty("version");
    assert ov != null && ov.equals(0);
View Full Code Here

    m.set(new StringPropertyValue(Model.ID_PROPERTY, id));
    m.set(new StringPropertyValue("address1", "1 changed street"));
    m.set(new StringPropertyValue("address2", "2 beechange"));
    m.set(new StringPropertyValue("city", "change city"));

    final ModelPayload p = delegate.persist(new PersistRequest(m, true));
    assert p != null;
    m = p.getModel();
    assert m != null;
    assert m.getId() != null && m.getId().equals(id) && m.getEntityType() != null
    && m.getEntityType().equals(TestEntityType.ADDRESS);
    final Object ov = m.getProperty("version");
    assert ov != null && ov.equals(1);
View Full Code Here

    final String id = a.getId();
    addEntityToDb(a);

    final PersistServiceDelegate delegate = getDelegate();
    final ModelKey origMk = new ModelKey(TestEntityType.ADDRESS, id, null);
    final ModelPayload p = delegate.purge(new PurgeRequest(origMk));
    assert p != null;
    final ModelKey mk = p.getRef();
    assert mk != null && mk.isSet() && mk.equals(origMk);
  }
View Full Code Here

    final com.tll.server.AdminContext sac =
      (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

  private static final long serialVersionUID = 2363373679538578191L;

  @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));
      p.setModel(maccount);

      return p;
    }
    catch(final RuntimeException e) {
      RpcServlet.exceptionToStatus(e, s);
View Full Code Here

TOP

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

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.