@SuppressWarnings("unchecked")
  private void addUpdateVariablesResourceRequest(
      ConclusionStepPresenter conclusionStepPresenter, TableCompareDto tableCompareDto) {
    JsArray<VariableDto> newVariables =
        JsArrays.toSafeArray(tableCompareDto.getNewVariablesArray());
    JsArray<VariableDto> modifiedVariables =
        JsArrays.toSafeArray(tableCompareDto.getModifiedVariablesArray());

    JsArray<VariableDto> variablesToStringify = (JsArray<VariableDto>) JsArray.createArray();
    JsArrays.pushAll(variablesToStringify, newVariables);
    if (!getView().ignoreAllModifications()) {
      JsArrays.pushAll(variablesToStringify, modifiedVariables);
    }

    if (variablesToStringify.length() > 0) {
      conclusionStepPresenter.setTargetDatasourceName(targetDatasourceName);
      conclusionStepPresenter.addResourceRequest(
          tableCompareDto.getCompared().getName(),
          "/datasource/"
              + targetDatasourceName
              + "/table/"
              + tableCompareDto.getCompared().getName(),
          createResourceRequestBuilder(tableCompareDto, variablesToStringify));
    }
  }
 @Override
 public void setVocabulary(VocabularyDto vocabulary, JsArrayString locales) {
   name.setText(vocabulary.getName());
   titles.setLocaleTexts(vocabulary.getTitleArray(), JsArrays.toList(locales));
   descriptions.setLocaleTexts(vocabulary.getDescriptionArray(), JsArrays.toList(locales));
   repeatable.setValue(vocabulary.hasRepeatable() && vocabulary.getRepeatable());
 }
Beispiel #3
0
 @Override
 public void onFilterUpdate(String filter) {
   if (Strings.isNullOrEmpty(filter)) {
     getView().setVocabularies(taxonomy.getVocabulariesArray());
   } else {
     JsArray<VocabularyDto> filtered = JsArrays.create();
     for (VocabularyDto vocabulary : JsArrays.toIterable(taxonomy.getVocabulariesArray())) {
       if (vocabularyMatches(vocabulary, filter)) {
         filtered.push(vocabulary);
       }
     }
     getView().setVocabularies(filtered);
   }
 }
Beispiel #4
0
    @Override
    public void onResource(Response response, JsArray<TableIndexStatusDto> resource) {

      // Hide contingency table and show only if up to date or outdated
      getView().hideContingencyTable();
      if (response.getStatusCode() == SC_OK) {
        getView().setIndexStatusVisible(true);
        statusDto = TableIndexStatusDto.get(JsArrays.toSafeArray(resource));
        getView().setIndexStatusAlert(statusDto);

        // Refetch if in progress
        if (statusDto.getStatus().getName().equals(TableIndexationStatus.IN_PROGRESS.getName())) {

          // Hide the Cancel button if progress is 100%
          getView().setCancelVisible(Double.compare(statusDto.getProgress(), 1d) < 0);

          indexProgressTimer =
              new Timer() {
                @Override
                public void run() {
                  updateIndexStatus();
                }
              };

          // Schedule the timer to run once in X seconds.
          indexProgressTimer.schedule(DELAY_MILLIS);
        } else if (statusDto.getStatus().isTableIndexationStatus(TableIndexationStatus.UPTODATE)
            || statusDto.getStatus().isTableIndexationStatus(TableIndexationStatus.OUTDATED)) {
          updateContingencyTableVariables();
        }
      }
    }
Beispiel #5
0
 public boolean hasPermission(Acls acls) {
   String decodedResource = URL.decodePathSegment(resource);
   for (Acl acl : JsArrays.toIterable(acls.getAclsArray())) {
     if (acl.getResource().equals(decodedResource) && hasAction(acl)) return true;
   }
   return false;
 }
  @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 #7
0
 private void redrawVocabularies(TaxonomyDto taxonomy, FlowPanel panelTaxonomy) {
   JsArrayString vocabularies = JsArrays.toSafeArray(taxonomy.getVocabulariesArray());
   if (vocabularies.length() > 0) {
     panelTaxonomy.add(new Heading(5, translations.vocabulariesLabel()));
     FlowPanel vocabulariesPanel = new FlowPanel();
     for (int i = 0; i < vocabularies.length(); i++) {
       vocabulariesPanel.add(getVocabularyLink(getUiHandlers(), taxonomy, vocabularies.get(i)));
     }
     panelTaxonomy.add(vocabulariesPanel);
   }
 }
Beispiel #8
0
  @Override
  public void onMoveDownVocabulary(VocabularyDto vocabularyDto) {
    List<VocabularyDto> vocabularies = JsArrays.toList(taxonomy.getVocabulariesArray());
    int idx = vocabularies.indexOf(vocabularyDto);

    if (idx > -1 && idx < vocabularies.size() - 1) {
      Collections.swap(vocabularies, idx, idx + 1);
      getView().setDirty(true);
      getView().setTaxonomy(taxonomy);
    }
  }
  public void addUpdateVariablesResourceRequests(ConclusionStepPresenter conclusionStepPresenter) {
    final List<String> selectedTableNames = getView().getSelectedTables();
    Iterable<TableCompareDto> filteredTables =
        Iterables.filter(
            JsArrays.toIterable(authorizedComparedTables),
            new Predicate<TableCompareDto>() {

              @Override
              public boolean apply(TableCompareDto input) {
                return selectedTableNames.contains(input.getCompared().getName());
              }
            });
    for (TableCompareDto tableCompareDto : filteredTables) {
      addUpdateVariablesResourceRequest(conclusionStepPresenter, tableCompareDto);
    }
  }
Beispiel #10
0
  @Override
  public void onSortVocabularies(final boolean isAscending) {
    if (taxonomy.getVocabulariesCount() > 1) {
      Collections.sort(
          JsArrays.toList(taxonomy.getVocabulariesArray()),
          new Comparator<VocabularyDto>() {
            @Override
            public int compare(VocabularyDto o1, VocabularyDto o2) {
              return (isAscending ? 1 : -1) * o1.getName().compareTo(o2.getName());
            }
          });

      getView().setDirty(true);
      getView().setTaxonomy(taxonomy);
    }
  }
Beispiel #11
0
  @Override
  public void onDeleteVariables(List<VariableDto> variableDtos) {
    if (variableDtos.isEmpty()) {
      fireEvent(NotificationEvent.newBuilder().error("DeleteVariableSelectAtLeastOne").build());
    } else {
      JsArrayString variableNames = JsArrays.create().cast();
      for (VariableDto variable : variableDtos) {
        variableNames.push(variable.getName());
      }

      deleteVariablesConfirmation = new RemoveVariablesRunnable(variableNames);

      fireEvent(
          ConfirmationRequiredEvent.createWithMessages(
              deleteVariablesConfirmation,
              translationMessages.removeVariables(),
              translationMessages.confirmRemoveVariables(variableNames.length())));
    }
  }
 @Override
 public void onResource(Response response, DatasourceCompareDto resource) {
   Set<TableCompareDto> comparedTables =
       sortComparedTables(JsArrays.toSafeArray(resource.getTableComparisonsArray()));
   conflictsExist = false;
   for (TableCompareDto tableComparison : comparedTables) {
     ComparisonResult comparisonResult = getTableComparisonResult(tableComparison);
     addTableCompareTab(tableComparison, comparisonResult);
     if (comparisonResult == ComparisonResult.CONFLICT) {
       conflictsExist = true;
     } else if (tableComparison.getModifiedVariablesArray() != null) {
       modificationsExist = true;
     }
   }
   getView().setIgnoreAllModificationsEnabled(conflictsExist || modificationsExist);
   if (datasourceCreatedCallback != null) {
     datasourceCreatedCallback.onSuccess(factory, datasourceResource);
   }
 }
 public Request compare(
     String sourceDatasourceName,
     @SuppressWarnings("ParameterHidesMemberVariable") String targetDatasourceName,
     DatasourceCreatedCallback datasourceCreatedCallback,
     DatasourceFactoryDto factory,
     DatasourceDto datasourceResource) {
   this.targetDatasourceName = targetDatasourceName;
   getView().clearDisplay();
   authorizedComparedTables = JsArrays.create();
   String resourceUri =
       UriBuilder.create()
           .segment("datasource", sourceDatasourceName, "compare", targetDatasourceName)
           .build();
   return ResourceRequestBuilderFactory.<DatasourceCompareDto>newBuilder() //
       .forResource(resourceUri) //
       .get() //
       .withCallback(
           new DatasourceCompareResourceCallback(
               datasourceCreatedCallback, factory, datasourceResource)) //
       .withCallback(SC_INTERNAL_SERVER_ERROR, new CompareErrorRequestCallback()) //
       .send();
 }
Beispiel #14
0
  private void redraw() {
    panel.clear();
    for (TaxonomyDto taxonomy : JsArrays.toIterable(taxonomies)) {
      FlowPanel panelTaxonomy = new FlowPanel();
      panelTaxonomy.addStyleName("item");

      Widget taxonomyLink = newTaxonomyLink(getUiHandlers(), taxonomy);
      panelTaxonomy.add(taxonomyLink);

      for (int i = 0; i < taxonomy.getDescriptionsCount(); i++) {
        if (!taxonomy.getDescriptions(i).getText().isEmpty()) {
          panelTaxonomy.add(
              new LocalizedLabel(
                  taxonomy.getDescriptions(i).getLocale(), taxonomy.getDescriptions(i).getText()));
        }
      }

      redrawVocabularies(taxonomy, panelTaxonomy);

      panel.add(panelTaxonomy);
    }
  }
 private ComparisonResult getTableComparisonResult(TableCompareDto tableComparison) {
   if (JsArrays.toSafeArray(tableComparison.getConflictsArray()).length() > 0 //
       || JsArrays.toSafeArray(tableComparison.getModifiedVariablesArray()).length()
               + JsArrays.toSafeArray(tableComparison.getUnmodifiedVariablesArray()).length()
               + JsArrays.toSafeArray(tableComparison.getNewVariablesArray()).length()
           == 0) {
     return ComparisonResult.CONFLICT;
   }
   if (!tableComparison.hasWithTable()) {
     return ComparisonResult.CREATION;
   }
   if (JsArrays.toSafeArray(tableComparison.getModifiedVariablesArray()).length() > 0
       || JsArrays.toSafeArray(tableComparison.getNewVariablesArray()).length() > 0) {
     return ComparisonResult.MODIFICATION;
   }
   return ComparisonResult.SAME;
 }
 @Override
 public void onEditAttributes(final List<JsArray<AttributeDto>> selectedItems) {
   if (selectedItems == null || selectedItems.isEmpty()) return;
   boolean sameNamespace = true;
   String namespace = null;
   for (JsArray<AttributeDto> selectedArray : selectedItems) {
     for (AttributeDto attr : JsArrays.toIterable(selectedArray)) {
       if (namespace == null) {
         namespace = attr.hasNamespace() ? attr.getNamespace() : null;
       } else {
         sameNamespace = attr.hasNamespace() ? attr.getNamespace().equals(namespace) : true;
       }
     }
   }
   if (!sameNamespace || namespace == null) {
     showEditCustomAttributes(selectedItems);
   } else {
     final String ns = namespace;
     ResourceRequestBuilderFactory.<TaxonomiesDto>newBuilder()
         .forResource(UriBuilders.SYSTEM_CONF_TAXONOMIES_SUMMARIES.create().build())
         .get()
         .withCallback(
             new ResourceCallback<TaxonomiesDto>() {
               @Override
               public void onResource(Response response, TaxonomiesDto resource) {
                 for (TaxonomiesDto.TaxonomySummaryDto summary :
                     JsArrays.toIterable(resource.getSummariesArray())) {
                   if (summary.getName().equals(ns)) {
                     showEditTaxonomyAttributes(selectedItems);
                     return;
                   }
                 }
                 showEditCustomAttributes(selectedItems);
               }
             })
         .send();
   }
 }
Beispiel #17
0
 private boolean textsContains(JsArray<LocaleTextDto> texts, String token) {
   for (LocaleTextDto text : JsArrays.toIterable(texts)) {
     if (text.getText().contains(token)) return true;
   }
   return false;
 }
Beispiel #18
0
 @Override
 public void onResource(Response response, JsArray<ViewDto> resource) {
   ViewDto viewDto = ViewDto.get(JsArrays.toSafeArray(resource));
   getView().setFromTables(viewDto.getFromArray());
   getView().setWhereScript(viewDto.hasWhere() ? viewDto.getWhere() : null);
 }
Beispiel #19
0
 @Override
 public void renderRows(JsArray<TableDto> rows) {
   dataProvider.setList(JsArrays.toList(JsArrays.toSafeArray(rows)));
   pager.firstPage();
 }
Beispiel #20
0
 @Override
 protected JsArray<AttributeDto> getAttributes(AttributeDto object) {
   JsArray<AttributeDto> attrs = JsArrays.create();
   attrs.push(object);
   return attrs;
 }