/**
  * Convert a client-side value into a domain value.
  *
  * @param maybeEntityProxy the client object to resolve
  * @param detectDeadEntities if <code>true</code> this method will throw a ReportableException
  *     containing a {@link DeadEntityException} if an EntityProxy cannot be resolved
  */
 public Object resolveDomainValue(Object maybeEntityProxy, boolean detectDeadEntities) {
   if (maybeEntityProxy instanceof BaseProxy) {
     AutoBean<BaseProxy> bean = AutoBeanUtils.getAutoBean((BaseProxy) maybeEntityProxy);
     Object domain = bean.getTag(Constants.DOMAIN_OBJECT);
     if (domain == null && detectDeadEntities) {
       throw new ReportableException(
           new DeadEntityException("The requested entity is not available on the server"));
     }
     return domain;
   } else if (maybeEntityProxy instanceof Collection<?>) {
     Collection<Object> accumulator;
     if (maybeEntityProxy instanceof List<?>) {
       accumulator = new ArrayList<Object>();
     } else if (maybeEntityProxy instanceof Set<?>) {
       accumulator = new HashSet<Object>();
     } else {
       throw new ReportableException(
           "Unsupported collection type " + maybeEntityProxy.getClass().getName());
     }
     for (Object o : (Collection<?>) maybeEntityProxy) {
       accumulator.add(resolveDomainValue(o, detectDeadEntities));
     }
     return accumulator;
   }
   return maybeEntityProxy;
 }
Esempio n. 2
0
  /** This method should be called when after okButton is clicked. */
  ArgumentValidator getArgumentValidator() {
    Splittable params = StringQuoter.createIndexed();

    switch (validatorTypeCB.getCurrentValue()) {
      case Regex:
        String regex = regexField.getCurrentValue();
        StringQuoter.create(regex).assign(params, 0);
        break;
      case CharacterLimit:
        int charLimit = charLimitField.getCurrentValue();
        StringQuoter.create(charLimit).assign(params, 0);
        break;

      case IntAbove:
        int intAbove = intAboveField.getCurrentValue();
        StringQuoter.create(intAbove).assign(params, 0);
        break;

      case IntBelow:
        int intBelow = intBelowField.getCurrentValue();
        StringQuoter.create(intBelow).assign(params, 0);
        break;
      case IntRange:
        int intRangeAbove = intRangeAboveField.getCurrentValue();
        int intRangeBelow = intRangeBelowField.getCurrentValue();
        StringQuoter.create(intRangeAbove).assign(params, 0);
        StringQuoter.create(intRangeBelow).assign(params, 1);
        break;

      case DoubleAbove:
        double dblAbove = dblAboveField.getCurrentValue();
        StringQuoter.create(dblAbove).assign(params, 0);
        break;
      case DoubleBelow:
        double dblBelow = dblBelowField.getCurrentValue();
        StringQuoter.create(dblBelow).assign(params, 0);
        break;

      case DoubleRange:
        double dblRangeAbove = dblRangeAboveField.getCurrentValue();
        double dblRangeBelow = dblRangeBelowField.getCurrentValue();
        StringQuoter.create(dblRangeAbove).assign(params, 0);
        StringQuoter.create(dblRangeBelow).assign(params, 1);
        break;
      default:
        break;
    }
    AutoBean<ArgumentValidator> avAutobean = factory.argumentValidator();
    avAutobean.as().setType(validatorTypeCB.getCurrentValue());
    avAutobean.as().setParams(params);

    // JDS Get the actual validator, and add it as metadata to the autobean.
    AbstractArgumentEditor.createAndAttachValidator(avAutobean.as());

    return avAutobean.as();
  }
Esempio n. 3
0
 private String getVolumeTag(ToolVolume volume) {
   if (volume != null) {
     final AutoBean<ToolVolume> volumeAutoBean = AutoBeanUtils.getAutoBean(volume);
     String currentTag = volumeAutoBean.getTag(TOOL_VOLUME_MODEL_KEY);
     if (currentTag == null) {
       volumeAutoBean.setTag(TOOL_VOLUME_MODEL_KEY, String.valueOf(unique_volume_id++));
     }
     return volumeAutoBean.getTag(TOOL_VOLUME_MODEL_KEY);
   }
   return "";
 }
  @Override
  public ReferenceGenome convertModelValue(Splittable object) {
    if (object == null) {
      return null;
    }
    if (!object.isKeyed()) {
      return null;
    }

    AutoBean<ReferenceGenome> ab = AutoBeanCodex.decode(factory, ReferenceGenome.class, object);
    return ab.as();
  }
 /**
  * Given a domain object, return a value that can be encoded by the client.
  *
  * @param domainValue the domain object to be converted into a client-side value
  * @param assignableTo the type in the client to which the resolved value should be assignable. A
  *     value of {@code null} indicates that any resolution will suffice.
  * @param propertyRefs the property references requested by the client
  */
 public Object resolveClientValue(
     Object domainValue, Type assignableTo, Set<String> propertyRefs) {
   Resolution toReturn = resolveClientValue(domainValue, assignableTo);
   if (toReturn == null) {
     return null;
   }
   addPathsToResolution(toReturn, "", expandPropertyRefs(propertyRefs));
   while (!toProcess.isEmpty()) {
     List<Resolution> working = new ArrayList<Resolution>(toProcess);
     toProcess.clear();
     for (Resolution resolution : working) {
       if (resolution.hasWork()) {
         AutoBean<BaseProxy> bean =
             AutoBeanUtils.getAutoBean((BaseProxy) resolution.getClientObject());
         bean.accept(new PropertyResolver(resolution));
       }
     }
   }
   return toReturn.getClientObject();
 }
  /** Creates a proxy instance held by a Resolution for a given domain type. */
  private <T extends BaseProxy> Resolution resolveClientProxy(
      Object domainEntity, Class<T> proxyType, ResolutionKey key) {
    if (domainEntity == null) {
      return null;
    }

    SimpleProxyId<? extends BaseProxy> id = state.getStableId(domainEntity);

    boolean isEntityProxy = state.isEntityType(proxyType);
    Object domainVersion;

    // Create the id or update an ephemeral id by calculating its address
    if (id == null || id.isEphemeral()) {
      // The address is an id or an id plus a path
      Object domainId;
      if (isEntityProxy) {
        // Compute data needed to return id to the client
        domainId = service.getId(domainEntity);
        domainVersion = service.getVersion(domainEntity);
      } else {
        domainId = null;
        domainVersion = null;
      }
      if (id == null) {
        if (domainId == null) {
          /*
           * This will happen when server code attempts to return an unpersisted
           * object to the client. In this case, we'll assign a synthetic id
           * that is valid for the duration of the response. The client is
           * expected to assign a client-local id to this object and then it
           * will behave as though it were an object newly-created by the
           * client.
           */
          id = state.getIdFactory().allocateSyntheticId(proxyType, ++syntheticId);
        } else {
          Splittable flatValue = state.flatten(domainId);
          id = state.getIdFactory().getId(proxyType, flatValue.getPayload(), 0);
        }
      } else if (domainId != null) {
        // Mark an ephemeral id as having been persisted
        Splittable flatValue = state.flatten(domainId);
        id.setServerId(flatValue.getPayload());
      }
    } else if (isEntityProxy) {
      // Already have the id, just pull the current version
      domainVersion = service.getVersion(domainEntity);
    } else {
      // The version of a value object is always null
      domainVersion = null;
    }

    @SuppressWarnings("unchecked")
    AutoBean<T> bean = (AutoBean<T>) state.getBeanForPayload(id, domainEntity);
    bean.setTag(Constants.IN_RESPONSE, true);
    if (domainVersion != null) {
      Splittable flatVersion = state.flatten(domainVersion);
      bean.setTag(
          Constants.VERSION_PROPERTY_B64,
          SimpleRequestProcessor.toBase64(flatVersion.getPayload()));
    }

    T clientObject = bean.as();
    return makeResolution(key, clientObject);
  }
 public <T> T decode(Class<T> clazz, String json) {
   AutoBean<T> bean = AutoBeanCodex.decode(messageFactory, clazz, json);
   return bean.as();
 }
Esempio n. 8
0
 private IResponse decodeJSON(String json) {
   IResponseFactory factory = GWT.create(IResponseFactory.class);
   AutoBean<IResponse> bean = AutoBeanCodex.decode(factory, IResponse.class, json);
   return bean.as();
 }