Beispiel #1
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();
  }
  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();
  }
Beispiel #3
0
  private void updateDisplay(TableDto tableDto) {
    getView().clear(table == null || !table.getLink().equals(tableDto.getLink()));

    table = tableDto;

    getView().setTable(tableDto);

    if (tableIsView()) {
      showViewProperties(table);
    } else {
      getView().setFromTables(null);
      getView().setWhereScript(null);
    }

    if (getView().isValuesTabSelected()) {
      valuesTablePresenter.setTable(tableDto);
      valuesTablePresenter.updateValuesDisplay("");
    }

    variableFilter = "";
    valuesFilter = null;
    valuesFilterText = "";
    updateVariables();
    updateTableIndexStatus();
    authorize();
  }
Beispiel #4
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();
  }
Beispiel #6
0
 @Override
 public void onDownloadView() {
   String downloadUrl =
       UriBuilders.DATASOURCE_VIEW.create().build(table.getDatasourceName(), table.getName())
           + "/xml";
   fireEvent(new FileDownloadRequestEvent(downloadUrl));
 }
Beispiel #7
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 addTableCompareTab(
     TableCompareDto tableCompareDto, ComparisonResult comparisonResult) {
   TableDto comparedTableDto = tableCompareDto.getCompared();
   if (tableCompareDto.hasWithTable()) {
     UriBuilder ub =
         UriBuilder.create()
             .segment(
                 "datasource",
                 targetDatasourceName,
                 "table",
                 comparedTableDto.getName(),
                 "variables");
     ResourceAuthorizationRequestBuilderFactory.newBuilder() //
         .forResource(ub.build())
         .post() //
         .authorize(new TableEditionAuthorizer(tableCompareDto, comparisonResult))
         .send();
   } else {
     UriBuilder ub = UriBuilder.create().segment("datasource", targetDatasourceName, "tables");
     ResourceAuthorizationRequestBuilderFactory.newBuilder() //
         .forResource(ub.build())
         .post() //
         .authorize(new TableEditionAuthorizer(tableCompareDto, comparisonResult))
         .send();
   }
 }
  ResourceRequestBuilder<? extends JavaScriptObject> createResourceRequestBuilder(
      TableCompareDto tableCompareDto, JsArray<VariableDto> variables) {
    TableDto compared = tableCompareDto.getCompared();
    if (!tableCompareDto.hasWithTable()) {
      // new table
      TableDto newTableDto = TableDto.create();
      newTableDto.setName(compared.getName());
      newTableDto.setEntityType(compared.getEntityType());
      newTableDto.setVariablesArray(variables);
      UriBuilder ub = UriBuilder.create().segment("datasource", targetDatasourceName, "tables");
      return ResourceRequestBuilderFactory.newBuilder()
          .post()
          .forResource(ub.build())
          .withResourceBody(stringify(newTableDto));
    }

    UriBuilder uriBuilder =
        tableCompareDto.getWithTable().hasViewLink() //
            ? UriBuilders.DATASOURCE_VIEW_VARIABLES.create() //
            : UriBuilders.DATASOURCE_TABLE_VARIABLES.create();

    return ResourceRequestBuilderFactory.newBuilder() //
        .forResource(uriBuilder.build(targetDatasourceName, compared.getName())) //
        .withResourceBody(stringify(variables)) //
        .post();
  }
Beispiel #10
0
  private void doFilterVariables() {

    new VariablesFilter() {
      @Override
      public void beforeVariableResourceCallback() {
        getView().beforeRenderRows();
      }

      @Override
      public void onVariableResourceCallback() {
        if (table.getLink().equals(TablePresenter.this.table.getLink())) {
          TablePresenter.this.table = table;

          variables = JsArrays.create();
          for (VariableDto v : results) {
            variables.push(v);
          }
          getView().renderRows(variables);
          getView().afterRenderRows();
        }
      }
    } //
    .withVariable(true) //
        .withQuery(variableFilter) //
        .withLimit(table.getVariableCount()) //
        .withSortDir(
            sortAscending == null || sortAscending
                ? VariablesFilter.SORT_ASCENDING
                : VariablesFilter.SORT_DESCENDING) //
        .filter(getEventBus(), table);
  }
  private void updateMenuDisplay(@Nullable VariableDto previous, @Nullable VariableDto next) {
    getView().setPreviousName(previous == null ? "" : previous.getName());
    getView().setNextName(next == null ? "" : next.getName());

    getView().setCategorizeMenuAvailable(!"binary".equals(variable.getValueType()));
    getView().setDeriveFromMenuVisibility(table.hasViewLink());
  }
Beispiel #12
0
  private void updateTableIndexStatus() {
    // Table indexation status
    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(table.getLink() + "/index")
        .get()
        .authorize(getView().getTableIndexStatusAuthorizer())
        .send();

    ResourceAuthorizationRequestBuilderFactory.newBuilder()
        .forResource(table.getLink() + "/index")
        .delete()
        .authorize(getView().getTableIndexEditAuthorizer())
        .send();

    updateIndexStatus();
  }
 @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();
 }
  @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();
  }
Beispiel #15
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);
 }
Beispiel #16
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();
   }
 }
 @Override
 public void onDownloadIdentifiers() {
   fireEvent(
       new FileDownloadRequestEvent(
           UriBuilder.create()
               .segment("identifiers", "mappings", "_export")
               .query("type", table.getEntityType())
               .build()));
 }
Beispiel #18
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);
 }
Beispiel #19
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();
    }
  }
  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();
  }
 private void updateDerivedVariableDisplay() {
   // if table is a view, check for a script attribute
   if (table == null || !table.hasViewLink()) {
     getView().setDerivedVariable(false, "");
     return;
   }
   String script = VariableDtos.getScript(variable);
   getView().setDerivedVariable(true, script);
   scriptEditorPresenter.setTable(table);
   scriptEditorPresenter.setScript(script);
   scriptEditorPresenter.setRepeatable(variable.getIsRepeatable());
   scriptEditorPresenter.setValueEntityType(variable.getValueType());
   scriptEditorPresenter.setCategories(variable.getCategoriesArray());
 }
  private void updateDisplay(
      TableDto tableDto,
      VariableDto variableDto,
      @Nullable VariableDto previous,
      @Nullable VariableDto next) {

    boolean sameTable =
        table != null && tableDto != null && table.getName().equals(tableDto.getName());
    boolean sameVariable =
        variable != null && variableDto != null && variable.getName().equals(variableDto.getName());
    boolean samePosition = sameTable && sameVariable;

    table = tableDto;
    variable = variableDto;

    if (!samePosition || next != null) {
      // OPAL-2746 only clears 'nextVariable' if the positional context is different
      nextVariable = next;
    }

    if (!samePosition || previous != null) {
      // OPAL-2746 only clears 'previousVariable' if the positional context is different
      previousVariable = previous;
    }

    if (variable.getLink().isEmpty()) {
      variable.setLink(variable.getParentLink().getLink() + "/variable/" + variable.getName());
    }
    updateVariableDisplay(variableDto);
    updateMenuDisplay(
        previousVariable, nextVariable); // OPAL-2746 uses the current previousVariable/nextVariable

    updateDerivedVariableDisplay();
    updateValuesDisplay();

    authorize();
  }
 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();
 }
 public void showIdentifiersTable(
     @SuppressWarnings("ParameterHidesMemberVariable") TableDto table) {
   this.table = table;
   getView().showIdentifiersTable(table);
   String uri = UriBuilders.IDENTIFIERS_TABLE_VARIABLES.create().build(table.getName());
   ResourceRequestBuilderFactory.<JsArray<VariableDto>>newBuilder() //
       .forResource(uri) //
       .withCallback(
           new ResourceCallback<JsArray<VariableDto>>() {
             @Override
             public void onResource(Response response, JsArray<VariableDto> resource) {
               getView().setVariables(JsArrays.toSafeArray(resource));
             }
           }) //
       .get()
       .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();
  }
  @Override
  public void onRemove() {
    removeConfirmation = new RemoveRunnable();

    ConfirmationRequiredEvent event;
    event =
        table.hasViewLink()
            ? ConfirmationRequiredEvent.createWithMessages(
                removeConfirmation,
                translationMessages.removeDerivedVariable(),
                translationMessages.confirmRemoveDerivedVariable())
            : ConfirmationRequiredEvent.createWithMessages(
                removeConfirmation,
                translationMessages.removeVariable(),
                translationMessages.confirmRemoveVariable());

    fireEvent(event);
  }
Beispiel #27
0
 private void showViewProperties(TableDto tableDto) {
   // Show from tables
   ResourceRequestBuilderFactory.<JsArray<ViewDto>>newBuilder()
       .forResource(tableDto.getViewLink())
       .get() //
       .withCallback(
           new ResponseCodeCallback() {
             @Override
             public void onResponseCode(Request request, Response response) {
               getView().setFromTables(null);
               getView().setWhereScript(null);
             }
           },
           SC_FORBIDDEN,
           SC_INTERNAL_SERVER_ERROR,
           SC_NOT_FOUND) //
       .withCallback(new ViewResourceCallback())
       .send();
 }
 @Override
 public void onIdentifiersRequest(
     TableDto identifiersTable, String select, final int offset, int limit) {
   String uri =
       UriBuilders.IDENTIFIERS_TABLE_VALUESETS
           .create()
           .query("select", select)
           .query("offset", Integer.toString(offset))
           .query("limit", Integer.toString(limit))
           .build(identifiersTable.getName());
   ResourceRequestBuilderFactory.<ValueSetsDto>newBuilder() //
       .forResource(uri) //
       .withCallback(
           new ResourceCallback<ValueSetsDto>() {
             @Override
             public void onResource(Response response, ValueSetsDto resource) {
               getView().setValueSets(offset, resource);
             }
           }) //
       .get()
       .send();
 }
 private boolean tableChanged(TableDto tableDto) {
   String curTableName = table != null ? table.getName() : "";
   String newTableName = tableDto != null ? tableDto.getName() : "";
   return !curTableName.equals(newTableName);
 }
 @Override
 public void onPreviousVariable() {
   placeManager.revealPlace(
       ProjectPlacesHelper.getVariablePlace(
           table.getDatasourceName(), table.getName(), previousVariable.getName()));
 }