Ejemplo n.º 1
0
 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 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
 public Splittable convertFieldValue(ReferenceGenome object) {
   return AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(object));
 }