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 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(); }
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 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(); }
@Override public void onSummaryRequest(SummaryRequiredEvent event) { datasource = event.getDatasource(); table = event.getTable(); variable = event.getVariable(); getView().setLimit(DEFAULT_LIMIT); UriBuilder resourceUri = event.getResourceUri(); resourceUri.query("fullIfCached", "true"); configureSummaryRequest(resourceUri, event.getMax(), datasource, table, variable); requestSummary(); }
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()); }
private void addDistinctValuesMapping() { final List<String> derivedCategories = DerivationHelper.getDestinationCategories(getDerivedVariable()); getView().populateValues(new ArrayList<ValueMapEntry>(), derivedCategories); String uri = UriBuilder.create() .fromPath(getOriginalVariable().getLink()) .segment("summary") .query("nature", "categorical", "distinct", "true") .build(); ResourceRequestBuilderFactory.<SummaryStatisticsDto>newBuilder() // .forResource(uri) // .withCallback( new ResourceCallback<SummaryStatisticsDto>() { @Override public void onResource( Response response, SummaryStatisticsDto summaryStatisticsDto) { CategoricalSummaryDto categoricalSummaryDto = summaryStatisticsDto .getExtension( CategoricalSummaryDto.SummaryStatisticsDtoExtensions.categorical) .cast(); derivationHelper.addDistinctValues(categoricalSummaryDto); getView().enableFrequency(true); getView() .populateValues(derivationHelper.getValueMapEntries(), derivedCategories); } }) // .get() .send(); }
@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 onDownloadIdentifiers() { fireEvent( new FileDownloadRequestEvent( UriBuilder.create() .segment("identifiers", "mappings", "_export") .query("type", table.getEntityType()) .build())); }
@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(); }
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 submitJob(ImportCommandOptionsDto dto) { ResourceRequestBuilderFactory.newBuilder() // .forResource( UriBuilder.create() .segment("datasource", dto.getDestination(), "commands", "_import") .build()) // .post() // .withResourceBody(ImportCommandOptionsDto.stringify(dto)) // .withCallback( new SubmitJobResponseCodeCallBack(), SC_CREATED, SC_BAD_REQUEST, SC_INTERNAL_SERVER_ERROR) // .send(); }
private void revealCurrentPlace() { ResourceRequestBuilderFactory.<DatabasesStatusDto>newBuilder() .forResource(UriBuilder.create().segment("system", "status", "databases").build()) .get() .withCallback(new DatabasesStatusResourceCallback()) .withCallback( new ResponseCodeCallback() { @Override public void onResponseCode(Request request, Response response) { placeManager.revealCurrentPlace(); } }, Response.SC_FORBIDDEN) // .send(); }
@Override public void run() { ResourceRequestBuilderFactory.newBuilder() // .forResource(UriBuilder.create().segment(isUser ? "user" : "group", name).build()) // .withCallback( Response.SC_OK, new ResponseCodeCallback() { @Override public void onResponseCode(Request request, Response response) { getEventBus() .fireEvent(isUser ? new UsersRefreshedEvent() : new GroupsRefreshedEvent()); } }) // .delete() .send(); }
private void deleteTransientDatasource() { if (importConfig.getTransientDatasourceName() == null) return; ResourceRequestBuilderFactory.newBuilder() // .forResource( UriBuilder.create() .segment("datasource", importConfig.getTransientDatasourceName()) .build()) // .delete() // .withCallback( ResponseCodeCallbacks.NO_OP, SC_OK, SC_FORBIDDEN, SC_INTERNAL_SERVER_ERROR, SC_NOT_FOUND) // .send(); }
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(); }
@Override public void onResponseCode(Request request, Response response) { if (response.getStatusCode() == SC_OK) { String uri = UriBuilder.create() .segment("datasource", "{}", "view", "{}", "variable", "{}") .query("comment", getView().getComment()) .build(table.getDatasourceName(), table.getName(), variable.getName()); ResourceRequestBuilderFactory.newBuilder() // .forResource(uri) // .withResourceBody(VariableDto.stringify(newVariable)) // .withCallback(new UpdateVariableCallbackHandler(), SC_OK, SC_BAD_REQUEST) // .put() .send(); } else { NotificationEvent notificationEvent = new JSErrorNotificationEventBuilder() .build((ClientErrorDto) JsonUtils.unsafeEval(response.getText())); fireEvent(notificationEvent); } }
private String getIndexResource(String datasource, String tableName) { return UriBuilder.create() .segment("datasource", "{}", "table", "{}", "index") .build(datasource, tableName); }