Exemplo n.º 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();
    }
  }
  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();
  }
Exemplo n.º 3
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();
  }
Exemplo n.º 4
0
  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();
  }
Exemplo n.º 5
0
  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();
  }
Exemplo n.º 6
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();
  }
Exemplo n.º 7
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 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();
   }
 }
Exemplo n.º 9
0
 @Override
 public void onDownloadView() {
   String downloadUrl =
       UriBuilders.DATASOURCE_VIEW.create().build(table.getDatasourceName(), table.getName())
           + "/xml";
   fireEvent(new FileDownloadRequestEvent(downloadUrl));
 }
Exemplo n.º 10
0
  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();
  }
Exemplo n.º 11
0
 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();
 }
 @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();
 }
Exemplo n.º 13
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();
  }
Exemplo n.º 14
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();
   }
 }
Exemplo n.º 15
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();
    }
  }
Exemplo n.º 16
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();
  }
Exemplo n.º 17
0
 @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();
 }
Exemplo n.º 18
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();
 }
Exemplo n.º 19
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();
  }
Exemplo n.º 20
0
 private boolean tableChanged(TableDto tableDto) {
   String curTableName = table != null ? table.getName() : "";
   String newTableName = tableDto != null ? tableDto.getName() : "";
   return !curTableName.equals(newTableName);
 }
Exemplo n.º 21
0
 @Override
 public void onPreviousVariable() {
   placeManager.revealPlace(
       ProjectPlacesHelper.getVariablePlace(
           table.getDatasourceName(), table.getName(), previousVariable.getName()));
 }