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(); }
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(); } }
private void loadVariables() { getView().setVariableListEnabled(false); UriBuilder uriBuilder = UriBuilder.create() .segment( "datasource", getView().getSelectedTable().getDatasourceName(), "table", getView().getSelectedTable().getName(), "variables"); ResourceRequestBuilderFactory.<JsArray<VariableDto>>newBuilder() .forResource(uriBuilder.build()) .get() .withCallback( new ResourceCallback<JsArray<VariableDto>>() { @Override public void onResource(Response response, JsArray<VariableDto> resource) { getView().setVariables(resource, preSelectedVariable); variablesByName.clear(); if (resource != null) { for (int i = 0; i < resource.length(); i++) { VariableDto variableDto = resource.get(i); variablesByName.put(variableDto.getName(), variableDto); } } getView().setVariableListEnabled(true); onVariableSelection(); } }) .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(); }
private void loadTables() { // fetch the current view to retrieve the fromTables UriBuilder ub = UriBuilder.create() .segment( "datasource", getDestinationTable().getDatasourceName(), "view", getDestinationTable().getName()); ResourceRequestBuilderFactory.<ViewDto>newBuilder() .forResource(ub.build()) .get() .withCallback( new ResourceCallback<ViewDto>() { @Override public void onResource(Response response, final ViewDto viewDto) { ResourceRequestBuilderFactory.<JsArray<TableDto>>newBuilder() .forResource("/datasources/tables") .get() .withCallback( new ResourceCallback<JsArray<TableDto>>() { @Override public void onResource(Response response, JsArray<TableDto> resource) { // When deriving from, we should only add the tables that are part of // the ViewDto.getFromTables(). JsArray<TableDto> tables = JsArrays.create(); JsArrayString fromTables = viewDto.getFromArray(); for (int i = 0; i < fromTables.length(); i++) { for (int j = 0; j < resource.length(); j++) { // add the table if its in the fromtables if (fromTables .get(i) .equals( resource.get(j).getDatasourceName() + "." + resource.get(j).getName())) { tables.push(resource.get(j)); break; } } } getView().addTableSelections(JsArrays.toSafeArray(tables)); if (table != null) { getView().selectTable(table); } onTableSelection(); loadVariables(); } }) .send(); } }) .send(); }
private void initUsernameFromSession() { // get the username UriBuilder builder = UriBuilder.create().segment("auth", "session", "_current", "username"); ResourceRequestBuilderFactory.<Subject>newBuilder() .forResource(builder.build()) .get() // .withCallback(new SubjectResourceCallback()) .send(); }
private void updateDisplay( final String datasourceName, final String tableName, final boolean withSummary) { // rely on 304 response UriBuilder ub = UriBuilders.DATASOURCE_TABLE.create(); if (withSummary) ub.query("counts", "true"); ResourceRequestBuilderFactory.<TableDto>newBuilder() .forResource(ub.build(datasourceName, tableName)) .get() .withCallback( new ResourceCallback<TableDto>() { @Override public void onResource(Response response, TableDto resource) { if (resource != null) { if (!withSummary) { updateDisplay(resource); // then get the summary updateDisplay(datasourceName, tableName, true); } else { table = resource; String variableCount = resource.hasVariableCount() ? resource.getVariableCount() + "" : "-"; String valueSetCount = resource.hasValueSetCount() ? resource.getValueSetCount() + "" : "-"; getView().setTableSummary(variableCount, valueSetCount); } } } }) // .withCallback( Response.SC_NOT_FOUND, new ResponseCodeCallback() { @Override public void onResponseCode(Request request, Response response) { fireEvent( NotificationEvent.newBuilder() .warn("NoSuchValueTable") .args(tableName) .build()); placeManager.revealPlace(ProjectPlacesHelper.getTablesPlace(datasourceName)); } }) // .withCallback( Response.SC_BAD_REQUEST, new ResponseCodeCallback() { @Override public void onResponseCode(Request request, Response response) { fireEvent( NotificationEvent.newBuilder() .error((ClientErrorDto) JsonUtils.unsafeEval(response.getText())) .build()); } }) .send(); }
private String getUri() { UriBuilder uriBuilder = tableIsView() ? UriBuilders.DATASOURCE_VIEW_VARIABLES.create() : UriBuilders.DATASOURCE_TABLE_VARIABLES.create(); for (int i = nb_deleted, added = 0; i < variableNames.length() && added < BATCH_SIZE; i++, added++) { uriBuilder.query("variable", variableNames.get(i)); } return uriBuilder.build(table.getDatasourceName(), table.getName()); }
@SuppressWarnings("ParameterHidesMemberVariable") public void configureSummaryRequest( UriBuilder uriBuilder, int entitiesCount, String datasource, String table, String variable) { cancelPendingSummaryRequest(); this.entitiesCount = entitiesCount; if (limit < entitiesCount) { uriBuilder.query("limit", String.valueOf(limit)); } resourceRequestBuilder = ResourceRequestBuilderFactory.<SummaryStatisticsDto>newBuilder() .forResource(uriBuilder.build(datasource, table, variable)) .get(); limit = Math.min(entitiesCount, limit); }
@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(); }
@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(); } }
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(); }