示例#1
0
  private void updateIndexStatus() {
    // If cancellation, call the delete ws
    if (cancelIndexation) {
      ResourceRequestBuilderFactory.<JsArray<TableIndexStatusDto>>newBuilder()
          .forResource(getIndexResource(table.getDatasourceName(), table.getName()))
          .delete()
          .withCallback(
              new TableIndexStatusUnavailableCallback(),
              SC_INTERNAL_SERVER_ERROR,
              SC_FORBIDDEN,
              SC_NOT_FOUND,
              SC_SERVICE_UNAVAILABLE)
          .withCallback(new TableIndexStatusResourceCallback())
          .send();

      cancelIndexation = false;
    } else {
      ResourceRequestBuilderFactory.<JsArray<TableIndexStatusDto>>newBuilder()
          .forResource(getIndexResource(table.getDatasourceName(), table.getName()))
          .get()
          .withCallback(
              new TableIndexStatusUnavailableCallback(),
              SC_INTERNAL_SERVER_ERROR,
              SC_FORBIDDEN,
              SC_NOT_FOUND,
              SC_SERVICE_UNAVAILABLE)
          .withCallback(new TableIndexStatusResourceCallback())
          .send();
    }
  }
  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();
  }
  private void updateDisplay(
      final String datasourceName, final String tableName, final String variableName) {
    if (table != null
        && table.getDatasourceName().equals(datasourceName)
        && table.getName().equals(tableName)
        && variable != null
        && variable.getName().equals(variableName)) return;

    if (variableUpdatePending) return;
    ResourceRequestBuilderFactory.<VariableDto>newBuilder()
        .forResource(
            UriBuilders.DATASOURCE_TABLE_VARIABLE
                .create()
                .build(datasourceName, tableName, variableName))
        .withCallback(
            new ResourceCallback<VariableDto>() {
              @Override
              public void onResource(Response response, VariableDto resource) {
                variableUpdatePending = false;
              }
            }) //
        .withCallback(
            Response.SC_NOT_FOUND,
            new VariableNotFoundCallback(variableName, datasourceName, tableName))
        .get()
        .send();
  }
示例#4
0
  @Override
  public void onIndexCancel() {
    ResponseCodeCallback callback =
        new ResponseCodeCallback() {

          @Override
          public void onResponseCode(Request request, Response response) {
            if (response.getStatusCode() == SC_OK) {
              cancelIndexation = true;
              updateIndexStatus();
            } else {
              ClientErrorDto error = JsonUtils.unsafeEval(response.getText());
              fireEvent(
                  NotificationEvent.newBuilder()
                      .error(error.getStatus())
                      .args(error.getArgumentsArray())
                      .build());
            }
          }
        };
    ResourceRequestBuilderFactory.<JsArray<TableIndexStatusDto>>newBuilder() //
        .forResource(
            UriBuilders.DATASOURCE_TABLE_INDEX
                .create()
                .build(table.getDatasourceName(), table.getName())) //
        .withCallback(callback, SC_OK, SC_SERVICE_UNAVAILABLE)
        .delete()
        .send();
  }
示例#5
0
 @Override
 public void onDownloadView() {
   String downloadUrl =
       UriBuilders.DATASOURCE_VIEW.create().build(table.getDatasourceName(), table.getName())
           + "/xml";
   fireEvent(new FileDownloadRequestEvent(downloadUrl));
 }
示例#6
0
  @Override
  public void onIndexNow() {
    ResponseCodeCallback callback =
        new ResponseCodeCallback() {

          @Override
          public void onResponseCode(Request request, Response response) {
            if (response.getStatusCode() == SC_OK) {
              // Wait a few seconds for the task to launch before checking its status
              indexProgressTimer =
                  new Timer() {
                    @Override
                    public void run() {
                      updateIndexStatus();
                    }
                  };
              // Schedule the timer to run once in X seconds.
              indexProgressTimer.schedule(DELAY_MILLIS);

            } else {
              fireEvent(NotificationEvent.newBuilder().error(response.getText()).build());
            }
          }
        };
    ResourceRequestBuilderFactory.<JsArray<TableIndexStatusDto>>newBuilder() //
        .forResource(getIndexResource(table.getDatasourceName(), table.getName())) //
        .withCallback(callback, SC_OK, SC_SERVICE_UNAVAILABLE)
        .put()
        .send();
  }
  private void compileScript(final VariableDto newVariable) {
    UriBuilder ub =
        UriBuilder.create()
            .segment("datasource", table.getDatasourceName(), "table", table.getName())
            .query("counts", "false");
    ResourceRequestBuilderFactory.<TableDto>newBuilder()
        .forResource(ub.build()) //
        .withCallback(
            new ResourceCallback<TableDto>() {
              @Override
              public void onResource(Response response, TableDto resource) {
                String uri =
                    UriBuilder.create()
                        .fromPath(resource.getViewLink()) //
                        .segment("variable", "_transient", "_compile") //
                        .query(
                            "valueType",
                            newVariable.getValueType(), //
                            "repeatable",
                            String.valueOf(newVariable.getIsRepeatable())) //
                        .build();

                ResourceRequestBuilderFactory.newBuilder()
                    .forResource(uri) //
                    .withFormBody("script", VariableDtos.getScript(newVariable)) //
                    .withCallback(
                        new ScriptEvaluationCallback(newVariable), SC_BAD_REQUEST, SC_OK) //
                    .post() //
                    .send();
              }
            }) //
        .get()
        .send();
  }
示例#8
0
 @Override
 public void onCopyData() {
   DataCopyPresenter provider = dataCopyModalProvider.get();
   Set<TableDto> copyTables = new HashSet<>();
   copyTables.add(table);
   provider.setCopyTables(copyTables, false);
   provider.setDatasourceName(table.getDatasourceName());
   provider.setValuesQuery(valuesFilter, valuesFilterText);
 }
示例#9
0
 @Override
 public void onExportData() {
   DataExportPresenter provider = dataExportModalProvider.get();
   Set<TableDto> tables = new HashSet<>();
   tables.add(table);
   provider.setExportTables(tables, false);
   provider.setDatasourceName(table.getDatasourceName());
   provider.setValuesQuery(valuesFilter, valuesFilterText);
 }
 @Override
 void initialize(
     TableDto originalTable,
     TableDto destinationTable,
     VariableDto originalVariable,
     VariableDto derivedVariable) {
   super.initialize(originalTable, destinationTable, originalVariable, derivedVariable);
   getView().setNumberType(originalVariable.getValueType());
   summaryTabPresenter.configureSummaryRequest(
       UriBuilders.DATASOURCE_TABLE_VARIABLE_SUMMARY.create(),
       originalTable.getValueSetCount(),
       originalTable.getDatasourceName(),
       originalTable.getName(),
       originalVariable.getName());
   summaryTabPresenter.forgetSummary();
   summaryTabPresenter.onReset();
 }
示例#11
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();
  }
示例#12
0
 @Override
 public void onEditWhere() {
   if (table.hasViewLink()) {
     UriBuilder ub = UriBuilders.DATASOURCE_VIEW.create();
     ResourceRequestBuilderFactory.<ViewDto>newBuilder()
         .forResource(ub.build(table.getDatasourceName(), table.getName()))
         .get()
         .withCallback(
             new ResourceCallback<ViewDto>() {
               @Override
               public void onResource(Response response, ViewDto viewDto) {
                 ViewWhereModalPresenter p = viewWhereModalProvider.get();
                 p.initialize(viewDto);
               }
             })
         .send();
   }
 }
示例#13
0
  @Override
  public void onCrossVariables() {
    // If both variables have been selected
    String selectedVariableName = getView().getSelectedVariableName();
    final String crossWithVariableName = getView().getCrossWithVariableName();

    if (!selectedVariableName.isEmpty() && !crossWithVariableName.isEmpty()) {
      ResourceRequestBuilderFactory.<VariableDto>newBuilder() //
          .forResource(
              UriBuilders.DATASOURCE_TABLE_VARIABLE
                  .create()
                  .build(table.getDatasourceName(), table.getName(), selectedVariableName)) //
          .get() //
          .withCallback(new SelectedVariableCallback(crossWithVariableName))
          .withCallback(
              new VariableNotFoundCallback(selectedVariableName), Response.SC_NOT_FOUND) //
          .send();
    }
  }
示例#14
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();
  }
示例#15
0
 private void fireSummaryRequiredEvent(final VariableDto selection) {
   String tableUri =
       UriBuilders.DATASOURCE_TABLE
           .create()
           .query("counts", "true")
           .build(table.getDatasourceName(), table.getName());
   ResourceRequestBuilderFactory.<TableDto>newBuilder() //
       .forResource(tableUri) //
       .withCallback(
           new ResourceCallback<TableDto>() {
             @Override
             public void onResource(Response response, TableDto resource) {
               fireEvent(
                   new SummaryRequiredEvent(
                       UriBuilders.DATASOURCE_TABLE_VARIABLE_SUMMARY.create(),
                       resource.getValueSetCount(),
                       table.getDatasourceName(),
                       table.getName(),
                       selection.getName()));
             }
           }) //
       .get()
       .send();
 }
示例#16
0
  private void authorize() {
    if (table == null) return;

    // export data
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(UriBuilders.PROJECT_COMMANDS_EXPORT.create().build(table.getDatasourceName()))
        .post() //
        .authorize(getView().getExportDataAuthorizer()) //
        .send();
    // copy data
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(UriBuilders.PROJECT_COMMANDS_COPY.create().build(table.getDatasourceName()))
        .post()
        .authorize(getView().getCopyDataAuthorizer())
        .send();

    // export variables in excel
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(table.getLink() + "/variables/excel")
        .get()
        .authorize(getView().getExcelDownloadAuthorizer())
        .send();

    if (table.hasViewLink()) {
      // download view
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(table.getViewLink() + "/xml")
          .get()
          .authorize(getView().getViewDownloadAuthorizer())
          .send();
      // remove view
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(table.getViewLink())
          .delete()
          .authorize(getView().getRemoveAuthorizer())
          .send();
      // edit view
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(table.getViewLink())
          .put()
          .authorize(getView().getEditAuthorizer())
          .send();
    } else {
      // download view
      getView().getViewDownloadAuthorizer().unauthorized();

      // edit table
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(table.getLink())
          .put()
          .authorize(getView().getEditAuthorizer())
          .send();

      // Drop table
      ResourceAuthorizationRequestBuilderFactory.newBuilder()
          .forResource(table.getLink())
          .delete()
          .authorize(getView().getRemoveAuthorizer())
          .send();
    }

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

    // set permissions
    ResourceAuthorizationRequestBuilderFactory.newBuilder() //
        .forResource(
            UriBuilders.PROJECT_PERMISSIONS_TABLE
                .create()
                .build(table.getDatasourceName(), table.getName())) //
        .authorize(
            new CompositeAuthorizer(
                getView().getPermissionsAuthorizer(), new PermissionsUpdate())) //
        .post()
        .send();
  }
示例#17
0
 @Override
 public void onPreviousVariable() {
   placeManager.revealPlace(
       ProjectPlacesHelper.getVariablePlace(
           table.getDatasourceName(), table.getName(), previousVariable.getName()));
 }