public <T> String encode(Class<T> clazz, T t) {
   AutoBean<T> bean = AutoBeanUtils.getAutoBean(t);
   if (bean == null) {
     bean = messageFactory.create(clazz, t);
   }
   String json = AutoBeanCodex.encode(bean).getPayload();
   return json;
 }
  @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();
  }
 /**
  * @param selection a splittable which this function assumes is a list of {@link SelectionItem}s
  */
 public void setSelection(Splittable selection) {
   selectionItemsEditor.setSuppressEvent(true);
   AppTemplateAutoBeanFactory factory = GWT.create(AppTemplateAutoBeanFactory.class);
   SelectionItemList siList =
       AutoBeanCodex.decode(
               factory,
               SelectionItemList.class,
               "{\"selectionItems\": " + selection.getPayload() + "}")
           .as();
   List<SelectionItem> items = siList.getSelectionItems();
   tree.setSelection(items);
   selectionItemsEditor.setSuppressEvent(false);
 }
    @Override
    public void onSuccess(final File file) {
      eventBus.fireEvent(new FileSavedEvent(file));

      final Splittable annotatedFile = AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(file));
      StringQuoter.create(diskResourceUtil.parseParent(file.getPath()))
          .assign(annotatedFile, "parentFolderId");
      StringQuoter.create(event.getPath()).assign(annotatedFile, "sourceUrl");

      // Create notification message
      final Splittable message = StringQuoter.createSplittable();
      StringQuoter.create("data").assign(message, "type");
      String subject =
          file.getName().isEmpty()
              ? appearance.importFailed(event.getPath())
              : appearance.fileUploadSuccess(file.getName());
      StringQuoter.create(subject).assign(message, "subject");
      StringQuoter.create(userInfo.getUsername()).assign(message, "user");

      // Create Notification payload and attach message
      final Splittable payload = StringQuoter.createSplittable();
      StringQuoter.create("file_uploaded").assign(payload, "action");

      // Attach annotated file and notification message to payload
      annotatedFile.assign(payload, "data");
      payload.assign(message, "payload");

      final String notificationMsgPayload = message.getPayload();
      userSessionService.postClientNotification(
          jsonUtil.getObject(notificationMsgPayload),
          new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
              event.getHideable().hide();
              announcer.schedule(new ErrorAnnouncementConfig(caught.getMessage()));
            }

            @Override
            public void onSuccess(String result) {
              event.getHideable().hide();
              announcer.schedule(
                  new SuccessAnnouncementConfig(appearance.importRequestSubmit(file.getName())));
            }
          });
    }
 @Override
 protected Counts convertFrom(final String json) {
   return AutoBeanCodex.decode(factory, Counts.class, json).as();
 }
 public <T> T decode(Class<T> clazz, String json) {
   AutoBean<T> bean = AutoBeanCodex.decode(messageFactory, clazz, json);
   return bean.as();
 }
 @Override
 public Splittable convertFieldValue(ReferenceGenome object) {
   return AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(object));
 }
Beispiel #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();
 }