コード例 #1
0
    private void removeDerivedVariable() {

      ResponseCodeCallback callbackHandler =
          new ResponseCodeCallback() {

            @Override
            public void onResponseCode(Request request, Response response) {
              if (response.getStatusCode() == SC_OK) {
                gotoTable();
              } else {
                String errorMessage =
                    response.getText().isEmpty() ? "UnknownError" : response.getText();
                fireEvent(NotificationEvent.newBuilder().error(errorMessage).build());
              }
            }
          };

      ResourceRequestBuilderFactory.newBuilder() //
          .forResource(
              UriBuilders.DATASOURCE_VIEW_VARIABLE
                  .create()
                  .build(table.getDatasourceName(), table.getName(), variable.getName())) //
          .withCallback(
              callbackHandler, SC_OK, SC_FORBIDDEN, SC_INTERNAL_SERVER_ERROR, SC_NOT_FOUND) //
          .delete()
          .send();
    }
コード例 #2
0
  private void authorize() {
    // summary
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(variable.getLink() + "/summary")
        .get()
        .authorize(new CompositeAuthorizer(getView().getSummaryAuthorizer(), new SummaryUpdate()))
        .send();

    // values
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(variable.getParentLink().getLink() + "/valueSets")
        .get()
        .authorize(getView().getValuesAuthorizer())
        .send();

    // edit variable
    if (table.hasViewLink()) {
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(
              UriBuilders.DATASOURCE_VIEW_VARIABLE
                  .create()
                  .build(table.getDatasourceName(), table.getName(), variable.getName()))
          .put()
          .authorize(getView().getEditAuthorizer())
          .send();
    } else {
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(
              UriBuilders.DATASOURCE_TABLE_VARIABLE
                  .create()
                  .build(table.getDatasourceName(), table.getName(), variable.getName()))
          .put()
          .authorize(getView().getEditAuthorizer())
          .send();
    }

    // set permissions
    ResourceAuthorizationRequestBuilderFactory.newBuilder() //
        .forResource(
            UriBuilders.PROJECT_PERMISSIONS_VARIABLE
                .create()
                .build(table.getDatasourceName(), table.getName(), variable.getName())) //
        .authorize(
            new CompositeAuthorizer(
                getView().getPermissionsAuthorizer(), new PermissionsUpdate())) //
        .post()
        .send();
  }
コード例 #3
0
  @Override
  public void onDeleteAttribute(List<JsArray<AttributeDto>> selectedItems) {
    VariableDto dto = getVariableDto();

    JsArray<AttributeDto> filteredAttributes = JsArrays.create().cast();
    List<AttributeDto> allAttributes = JsArrays.toList(dto.getAttributesArray());

    for (AttributeDto attribute : allAttributes) {
      boolean keep = true;
      for (JsArray<AttributeDto> toRemove : selectedItems) {
        if (attribute.getName().equals(toRemove.get(0).getName())
            && attribute.getNamespace().equals(toRemove.get(0).getNamespace())) {
          keep = false;
          break;
        }
      }

      if (keep) {
        filteredAttributes.push(attribute);
      }
    }

    dto.setAttributesArray(filteredAttributes);

    UriBuilder uriBuilder =
        table.hasViewLink()
            ? UriBuilders.DATASOURCE_VIEW_VARIABLE.create()
            : UriBuilders.DATASOURCE_TABLE_VARIABLE.create();

    ResourceRequestBuilderFactory.newBuilder() //
        .forResource(
            uriBuilder.build(table.getDatasourceName(), table.getName(), variable.getName())) //
        .withResourceBody(VariableDto.stringify(dto)) //
        .withCallback(
            SC_OK,
            new ResponseCodeCallback() {
              @Override
              public void onResponseCode(Request request, Response response) {
                fireEvent(new VariableRefreshEvent());
              }
            }) //
        .withCallback(SC_BAD_REQUEST, new ErrorResponseCallback(getView().asWidget())) //
        .put()
        .send();
  }
コード例 #4
0
  private void updateVariableDisplay(VariableDto variableDto) {
    variable = variableDto;
    getView().setVariable(variable);
    if (variable.getLink().isEmpty()) {
      variable.setLink(variable.getParentLink().getLink() + "/variable/" + variable.getName());
    }

    getView().renderCategoryRows(variable.getCategoriesArray());

    // Attributes editable depending on authorization
    UriBuilder builder =
        table.hasViewLink()
            ? UriBuilders.DATASOURCE_VIEW_VARIABLE.create()
            : UriBuilders.DATASOURCE_TABLE_VARIABLE.create();
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(builder.build(table.getDatasourceName(), table.getName(), variable.getName()))
        .put()
        .authorize(getView().getVariableAttributesAuthorizer(variable))
        .send();
  }