public static void registerOrUnregister(
      final Context context, final String deviceRegistrationId, final boolean register) {
    final SharedPreferences settings = Util.getSharedPreferences(context);
    final String accountName = settings.getString(Util.ACCOUNT_NAME, "Unknown");
    final Intent updateUIIntent = new Intent(Util.UPDATE_UI_INTENT);

    RegistrationInfoRequest request = getRequest(context);
    RegistrationInfoProxy proxy = request.create(RegistrationInfoProxy.class);
    proxy.setDeviceRegistrationId(deviceRegistrationId);

    String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    proxy.setDeviceId(deviceId);

    Request<String> req;
    if (register) {
      req = request.register().using(proxy);
    } else {
      req = request.unregister().using(proxy);
    }

    req.fire(
        new Receiver<String>() {
          private void clearPreferences(SharedPreferences.Editor editor) {
            editor.remove(Util.ACCOUNT_NAME);
            editor.remove(Util.DEVICE_REGISTRATION_ID);
            editor.remove(Util.DEVICE_CODE);
          }

          @Override
          public void onFailure(ServerFailure failure) {
            Log.w(TAG, "Failure, got :" + failure.getMessage());
            // Clean up application state
            SharedPreferences.Editor editor = settings.edit();
            clearPreferences(editor);
            editor.commit();

            updateUIIntent.putExtra(ACCOUNT_NAME_EXTRA, accountName);
            updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
            context.sendBroadcast(updateUIIntent);
          }

          @Override
          public void onSuccess(String response) {
            SharedPreferences settings = Util.getSharedPreferences(context);
            SharedPreferences.Editor editor = settings.edit();
            if (register) {
              editor.putString(Util.DEVICE_REGISTRATION_ID, deviceRegistrationId);
              editor.putString(Util.DEVICE_CODE, response);

            } else {
              clearPreferences(editor);
            }
            editor.commit();
            updateUIIntent.putExtra(ACCOUNT_NAME_EXTRA, accountName);
            updateUIIntent.putExtra(
                STATUS_EXTRA, register ? REGISTERED_STATUS : UNREGISTERED_STATUS);
            context.sendBroadcast(updateUIIntent);
          }
        });
  }
  /**
   * Get an existing instance of LaboratoireReference
   *
   * @param entityId the id of the LaboratoireReferenceProxy to be fetched
   */
  private void fetchLaboratoireReference(String entityId) {

    LaboratoireReferenceRequest request = requestFactory.laboratoireReferenceRequest();

    /* get the LaboratoireReference instance from database */
    Request<LaboratoireReferenceProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("nom");
    fetchRequest.with("description");
    fetchRequest.with("region");
    fetchRequest.with("region.nom");
    fetchRequest.with("districtSante");
    fetchRequest.with("districtSante.nom");
    fetchRequest.with("coordonnees");
    fetchRequest.with("lieuxDits");

    fetchRequest
        .to(
            new Receiver<LaboratoireReferenceProxy>() {
              @Override
              public void onSuccess(LaboratoireReferenceProxy entity) {
                viewLaboratoireReference(entity);
              }
            })
        .fire();
  }
  @Override
  public void processActualizar() {
    if (isValidData()) {
      Date fecha = new Date();
      ContextMantenimientoLocalidad context = FACTORY.contextMantenimientoLocalidad();
      FACTORY.initialize(EVENTBUS);
      String keyPublic = UISesion.keyPublic;
      LocalidadProxy bean = context.create(LocalidadProxy.class);
      bean.setVersion(fecha.getTime());
      bean.setOperacion("A");
      bean.setDescripcion(txtDescripcion.getText().toUpperCase());
      bean.setIdLocalidad(this.bean.getIdLocalidad());
      Request<Boolean> request = context.updateLocalidad(bean, keyPublic);
      request.fire(
          new Receiver<Boolean>() {

            @Override
            public void onSuccess(Boolean response) {
              // Window.alert("Actualizado correctamente");
              Notification not =
                  new Notification(Notification.INFORMATION, "Actualizado correctamente");
              not.showPopup();
              goToUILocalidad();
            }
          });
    }
  }
  /** Persist the current instance of LaboratoireReference */
  @Override
  protected void save() {

    editor.validateFields();

    editorDriver.flush();

    // Check for errors on the client side
    if (editorDriver.hasErrors()) {
      // Window.alert("LaboratoireReference form not validated locally");
      return;
    }

    Request<Void> saveRequest = request.save(current, isNew);
    saveRequest.to(
        new Receiver<Void>() {
          @Override
          public void onSuccess(Void response) {
            requestFactory
                .getEventBus()
                .fireEvent(new SaveLaboratoireReferenceEvent(current, initField));
            closeForm();
          }

          @Override
          public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
            // Window.alert("LaboratoireReference form not validated on server");

            // TODO manage errors on client side when made available by GWT
            if (errors != null && errors.size() > 0) {
              // convert ConstraintViolation to get localized messages
              EpicamRenderer renderer = EpicamRenderer.get();
              Set<ConstraintViolation<?>> imogErrors = new HashSet<ConstraintViolation<?>>();
              for (ConstraintViolation<?> error : errors) {
                ImogConstraintViolation violation = new ImogConstraintViolation();
                violation.setLeafBean((BaseProxy) error.getLeafBean());
                violation.setPropertyPath(error.getPropertyPath());
                violation.setRootBean((BaseProxy) error.getRootBean());
                violation.setMessage(renderer.getI18nErrorMessage(error.getMessage()));
                imogErrors.add(violation);
              }
              editorDriver.setConstraintViolations(imogErrors);
            }
          }

          @Override
          public void onFailure(ServerFailure error) {
            Window.alert("Error updating the LaboratoireReference");
            super.onFailure(error);
          }
        });

    request.fire();
  }
  /**
   * this will create/lookup a user in the datastore according to the Google Login (if logged in or
   * has logged in)
   */
  private void createUser() {
    wLoading.showLoading(true, "Checking credentials...&nbsp;");
    Request<UserDataProxy> req =
        clientFactory.getRequestFactory().getUserDataRequest().createUserData();
    req.fire(
        new Receiver<UserDataProxy>() {
          public void onSuccess(UserDataProxy data) {
            wLoading.showLoading(false);
            process(data);
          }

          public void onFailure(ServerFailure error) {
            wLoading.showError(
                "Oops, I couldn't process credentials...Try reloading this page...&nbsp;");
            super.onFailure(error);
          }
        });
  }
  /**
   * Get an existing instance of LieuDit
   *
   * @param entityId the id of the LieuDitProxy to be fetched
   */
  private void fetchLieuDit(String entityId) {

    LieuDitRequest request = requestFactory.lieuDitRequest();

    /* get the LieuDit instance from database */
    Request<LieuDitProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("description");
    fetchRequest.with("coordonnees");

    fetchRequest
        .to(
            new Receiver<LieuDitProxy>() {
              @Override
              public void onSuccess(LieuDitProxy entity) {
                viewLieuDit(entity);
              }
            })
        .fire();
  }
Exemplo n.º 7
0
  @Override
  public void onFinish(IUploader uploader) {

    if (uploader.getStatus().equals(Status.SUCCESS)) {

      UploadedInfo info = uploader.getServerInfo();
      if (info != null && info.message != null && !info.message.equals("noid")) {
        String entityId = info.message;

        BinaryRequest binaryRequest = requestFactory.binaryRequest();
        Request<BinaryProxy> binaryFileRequest = binaryRequest.getBinary(entityId);

        binaryFileRequest.fire(
            new Receiver<BinaryProxy>() {
              @Override
              public void onSuccess(BinaryProxy response) {
                value = response;
                uploading = false;
              }

              @Override
              public void onFailure(ServerFailure error) {
                Window.alert("Error retrieving the Binary Description");
                super.onFailure(error);
              }
            });

        if (thumbnail != null && info.ctype.contains("image")) {
          // Attach thumbnail
          OnLoadPreloadedImageHandler showImage =
              new OnLoadPreloadedImageHandler() {
                public void onLoad(PreloadedImage image) {
                  thumbnail.setUrl(image.getUrl());
                }
              };
          new PreloadedImage("servlet.gupld?show=" + entityId, showImage);
        }
      }
    }
    if (uploader.getStatus().equals(Status.CANCELED)) {
      setNew();
    }
  }
  /**
   * Get an existing instance of TransfertReference
   *
   * @param entityId the id of the TransfertReferenceProxy to be fetched
   */
  private void fetchTransfertReference(String entityId) {

    TransfertReferenceRequest request = requestFactory.transfertReferenceRequest();

    /* get the TransfertReference instance from database */
    Request<TransfertReferenceProxy> fetchRequest = request.findById(entityId);
    fetchRequest.with("region");
    fetchRequest.with("region.nom");
    fetchRequest.with("districtSante");
    fetchRequest.with("districtSante.nom");
    fetchRequest.with("CDTDepart");
    fetchRequest.with("patient");
    fetchRequest.with("regionArrivee");
    fetchRequest.with("regionArrivee.nom");
    fetchRequest.with("districtSanteArrivee");
    fetchRequest.with("districtSanteArrivee.nom");
    fetchRequest.with("CDTArrivee");

    fetchRequest
        .to(
            new Receiver<TransfertReferenceProxy>() {
              @Override
              public void onSuccess(TransfertReferenceProxy entity) {
                viewTransfertReference(entity);
              }
            })
        .fire();
  }