/** * Executes request to server. * * @param request <code>DSRequest</code> being processed. * @return <code>Object</code> data from original request. */ protected Object transformRequest(DSRequest request) { String requestId = request.getRequestId(); DSResponse response = new DSResponse(); response.setAttribute("clientContext", request.getAttributeAsObject("clientContext")); // Asume success response.setStatus(0); switch (request.getOperationType()) { case FETCH: executeFetch(requestId, request, response); break; case ADD: executeAdd(requestId, request, response); break; case UPDATE: executeUpdate(requestId, request, response); break; case REMOVE: executeRemove(requestId, request, response); break; default: // Operation not implemented. break; } return request.getData(); }
@Override protected Object transformRequest(DSRequest dsRequest) { if (dsRequest.getOperationType() == DSOperationType.UPDATE) { return ClientUtils.dump(dsRequest.getData()); } return super.transformRequest(dsRequest); }
private void save() { try { Record records[] = listGrid.getRecords(); Integer mainIdList[] = new Integer[records.length]; int i = 0; for (Record record : records) { mainIdList[i++] = record.getAttributeAsInt("main_id"); } DataSource dataSource = DataSource.get("OrgDS"); com.smartgwt.client.rpc.RPCManager.startQueue(); Record record = new Record(); record.setAttribute("mainIdList", mainIdList); record.setAttribute( "loggedUserName", CommonSingleton.getInstance().getSessionPerson().getUserName()); DSRequest req = new DSRequest(); req.setAttribute("operationId", "updateMainServiceOrders"); dataSource.updateData( record, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { destroy(); tabOrganization.search(); } }, req); com.smartgwt.client.rpc.RPCManager.sendQueue(); } catch (Exception e) { e.printStackTrace(); SC.say(e.toString()); } }
private void delete(ListGridRecord listGridRecord) { try { com.smartgwt.client.rpc.RPCManager.startQueue(); Record record = new Record(); record.setAttribute( "loggedUserName", CommonSingleton.getInstance().getSessionPerson().getUser_name()); record.setAttribute( "billing_company_id", listGridRecord.getAttributeAsInt("billing_company_id")); DSRequest req = new DSRequest(); req.setAttribute("operationId", "removeBillingComp"); billingCompsGrid.removeData( record, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) {} }, req); com.smartgwt.client.rpc.RPCManager.sendQueue(); } catch (Exception e) { SC.say(e.toString()); } }
private void exportOrValidate(final Record export) { DSRequest dsRequest = new DSRequest(); dsRequest.setPromptStyle(PromptStyle.DIALOG); dsRequest.setPrompt(i18n.KrameriusExportAction_Add_Msg()); DataSource ds = ExportDataSource.getCrossref(); ds.addData( export, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { if (RestConfig.isStatusOk(response)) { Record[] data = response.getData(); RecordList erl = errorsFromExportResult(data); if (erl.isEmpty()) { String target = ""; if (data != null && data.length > 0) { target = data[0].getAttribute(ExportResourceApi.RESULT_TARGET); } SC.say( i18n.ExportResultWidget_Window_Title(), i18n.CrossrefExportAction_ExportDone_Msg(target)); } else { ExportResultWidget.showErrors(erl.toArray()); } } } }, dsRequest); }
private void search() { try { String firstname = firstNameItem.getValueAsString(); String lastname = lastNameItem.getValueAsString(); String phone = phoneItem.getValueAsString(); String street_id_str = streetItem.getValueAsString(); String city_id_str = citiesItem.getValueAsString(); String city_region_id_str = regionItem.getValueAsString(); if ((firstname == null || firstname.trim().equals("")) && (lastname == null || lastname.trim().equals("")) && (phone == null || phone.trim().equals("")) && (street_id_str == null || street_id_str.trim().equals(""))) { SC.say(CallCenter.constants.warning(), CallCenter.constants.enterAbonentSearchParam()); return; } Criteria criteria = new Criteria(); if (firstname != null && !firstname.trim().equals("")) { criteria.setAttribute("firstname_param", firstname); } if (lastname != null && !lastname.trim().equals("")) { criteria.setAttribute("lastname_param", lastname); } if (phone != null && !phone.trim().equals("")) { criteria.setAttribute("phone_param", phone); } if (street_id_str != null && !street_id_str.trim().equals("")) { String tmp = street_id_str.trim(); String arrStr[] = tmp.split(" "); int i = 1; for (String string : arrStr) { String item = string.trim(); criteria.setAttribute("street_name_geo_param" + i, item); i++; } } if (city_id_str != null && !city_id_str.trim().equals("")) { criteria.setAttribute("city_id", new Integer(city_id_str)); } if (city_region_id_str != null && !city_region_id_str.trim().equals("")) { criteria.setAttribute("city_region_id", new Integer(city_region_id_str)); } DSRequest dsRequest = new DSRequest(); dsRequest.setAttribute("operationId", "customSearchForCC"); listGrid.invalidateCache(); listGrid.fetchData( criteria, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) {} }, dsRequest); } catch (Exception e) { e.printStackTrace(); SC.say(e.toString()); } }
@Override protected Object transformRequest(DSRequest request) { DSResponse response = new DSResponse(); response.setAttribute("clientContext", request.getAttributeAsObject("clientContext")); // Asume success response.setStatus(0); switch (request.getOperationType()) { case FETCH: executeFetch(request, response); break; default: break; } return request.getData(); }
private void saveNewDigitalObject(String modelId, String pid, String mods) { Record r = new Record(); DigitalObjectDataSource ds = DigitalObjectDataSource.getInstance(); r.setAttribute(DigitalObjectDataSource.FIELD_MODEL, modelId); if (mods != null) { r.setAttribute(DigitalObjectDataSource.FIELD_MODS, mods); } if (pid != null && !pid.isEmpty()) { r.setAttribute(DigitalObjectDataSource.FIELD_PID, pid); } DSRequest dsRequest = new DSRequest(); dsRequest.setWillHandleError(true); ds.addData( r, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { if (response.getStatus() == RPCResponse.STATUS_VALIDATION_ERROR) { Map errors = response.getErrors(); newDigObject.setValidationErrors(errors); request.setWillHandleError(true); return; } if (response.getHttpResponseCode() >= 400) { // failure SC.warn("Failed to create digital object!"); } else { Record[] data = response.getData(); if (data != null && data.length > 0) { String pid = data[0].getAttribute(DigitalObjectDataSource.FIELD_PID); // here should be updated DigitalObject data stream // caches to prevent server round-trip delays StatusView.getInstance().show(i18n.DigitalObjectCreator_FinishedStep_Done_Msg()); places.goTo(new DigitalObjectEditorPlace(DatastreamEditorType.MODS, pid)); } else { SC.warn("Failed to create digital object!"); } } } }, dsRequest); }
private void search() { try { String calendar_state_id = calendarStateItem.getValueAsString(); Criteria criteria = new Criteria(); if (calendar_state_id != null && !calendar_state_id.trim().equals("")) { criteria.setAttribute("calendar_state_id", new Integer(calendar_state_id)); } String calendar_event_id = secCalendarTypeItem.getValueAsString(); if (calendar_event_id != null && !calendar_event_id.trim().equals("")) { criteria.setAttribute("calendar_event_id", new Integer(calendar_event_id)); } boolean checkedDate = byCalendarDayItem.getValueAsBoolean(); if (checkedDate) { Date calendar_day = calendarDayItem.getValueAsDate(); if (calendar_day != null) { criteria.setAttribute("calendar_day", calendar_day); } } String calendar_description = descriptionItem.getValueAsString(); if (calendar_description != null && !calendar_description.trim().equals("")) { criteria.setAttribute("calendar_description", calendar_description); } String calendar_comment = commentItem.getValueAsString(); if (calendar_comment != null && !calendar_comment.trim().equals("")) { criteria.setAttribute("calendar_comment", calendar_comment); } DSRequest dsRequest = new DSRequest(); dsRequest.setAttribute("operationId", "searchAllSecularCalendars"); listGrid.invalidateCache(); listGrid.filterData( criteria, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) {} }, dsRequest); } catch (Exception e) { SC.say(e.toString()); } }
private void search() { try { Criteria criteria = new Criteria(); String billing_company_name = billingCompNameItem.getValueAsString(); criteria.setAttribute("billing_company_name", billing_company_name); String phoneIndex = phoneIndexItem.getValueAsString(); if (phoneIndex != null && !phoneIndex.equals("")) { try { new Long(phoneIndex); } catch (Exception e) { SC.say(CallCenterBK.constants.invalidPhone()); return; } criteria.setAttribute("phoneIndex", new Integer(phoneIndex)); } String has_calculation_str = hasCalcItem.getValueAsString(); if (has_calculation_str != null && !has_calculation_str.equals("-1")) { criteria.setAttribute("has_calculation", Integer.parseInt(has_calculation_str)); } Integer operator_src = Integer.parseInt(operatorItem.getValueAsString()); criteria.setAttribute("operator_src", operator_src); DSRequest dsRequest = new DSRequest(); dsRequest.setAttribute("operationId", "searchAllBillingComps"); billingCompsGrid.invalidateCache(); billingCompsGrid.filterData( criteria, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) {} }, dsRequest); } catch (Exception e) { SC.say(e.toString()); } }
private void changeStatus(Integer calendar_id, Integer deleted) { try { com.smartgwt.client.rpc.RPCManager.startQueue(); Record record = new Record(); record.setAttribute("deleted", deleted); record.setAttribute("calendar_id", calendar_id); record.setAttribute( "loggedUserName", CommonSingleton.getInstance().getSessionPerson().getUserName()); DSRequest req = new DSRequest(); req.setAttribute("operationId", "updateSecularCalendarStatus"); listGrid.updateData( record, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) {} }, req); com.smartgwt.client.rpc.RPCManager.sendQueue(); } catch (Exception e) { SC.say(e.toString()); } }
public void executeFetch(final DSRequest request, final DSResponse response) { long ctime = -1; int maxItems = -1; // retrieve current portlet display settings if ((this.portlet != null) && (this.portlet instanceof RecentlyAddedResourcesPortlet)) { RecentlyAddedResourcesPortlet recentAdditionsPortlet = (RecentlyAddedResourcesPortlet) this.portlet; if (recentAdditionsPortlet != null) { if (getMaximumRecentlyAddedToDisplay() > 0) { maxItems = getMaximumRecentlyAddedToDisplay(); } // define the time window if (getMaximumRecentlyAddedWithinHours() > 0) { ctime = System.currentTimeMillis() - (getMaximumRecentlyAddedWithinHours() * MeasurementUtility.HOURS); setOldestDate(ctime); } } } // TODO: spinder: revisit this later. ResourceCriteria mechanism does not work. Not sure if it's // better? // ResourceCriteria c = new ResourceCriteria(); // // String p = request.getCriteria().getAttribute("parentId"); // // if (p == null) { // c.addFilterResourceCategory(ResourceCategory.PLATFORM); // c.fetchChildResources(true); // } else { // c.addFilterParentResourceId(Integer.parseInt(p)); // } // TODO GH: Enhance resourceCriteria query to support itime based filtering for // "Recently imported" resources // if logged in then proceed making server side calls if (UserSessionManager.isLoggedIn()) { GWTServiceLookup.getResourceService() .findRecentlyAddedResources( ctime, maxItems, new AsyncCallback<List<RecentlyAddedResourceComposite>>() { public void onFailure(Throwable throwable) { CoreGUI.getErrorHandler() .handleError(MSG.view_portlet_recentlyAdded_error1(), throwable); } public void onSuccess(List<RecentlyAddedResourceComposite> recentlyAddedList) { List<RecentlyAddedResourceComposite> list = new ArrayList<RecentlyAddedResourceComposite>(); for (RecentlyAddedResourceComposite recentlyAdded : recentlyAddedList) { list.add(recentlyAdded); list.addAll(recentlyAdded.getChildren()); } response.setData(buildNodes(list)); response.setTotalRows(list.size()); processResponse(request.getRequestId(), response); } }); } else { // Log.debug("user is not logged in. Not fetching recently added resource now."); // answer the datasource response.setTotalRows(0); processResponse(request.getRequestId(), response); } }
private void saveCountry() { try { String cityNameGeo = cityNameGeoItem.getValueAsString(); if (cityNameGeo == null || cityNameGeo.trim().equalsIgnoreCase("")) { SC.say("შეიყვანეთ ქართული დასახელება !"); return; } String town_code = cityCodeItem.getValueAsString(); // if (town_code == null || town_code.trim().equalsIgnoreCase("")) { // SC.say("შეიყვანეთ ქალაქის კოდი !"); // return; // } String town_code_new = cityNewCodeItem.getValueAsString(); ListGridRecord country_record = countryItem.getSelectedRecord(); if (country_record == null || country_record.getAttributeAsInt("country_id") == null) { SC.say("გთხოვთ აირჩიოთ ქვეყანა !"); return; } Integer country_id = country_record.getAttributeAsInt("country_id"); if (cityNameGeo.length() > 1005) { SC.say("ქართული დასახელება შედგება მაქსიმუმ 155 სიმბოლოსაგან !"); return; } // if (town_code.length() > 180) { // SC.say("ქალაქის კოდი შედგება მაქსიმუმ 90 სიმბოლოსაგან !"); // return; // } // if (town_code_new != null && town_code_new.length() > 180) { // SC.say("ქალაქის ახალი კოდი შედგება მაქსიმუმ 90 სიმბოლოსაგან !"); // return; // } ListGridRecord city_type_record = townTypeItem.getSelectedRecord(); if (city_type_record == null || city_type_record.getAttributeAsInt("description_id") == null) { SC.say("გთხოვთ აირჩიოთ ქალაქის ტიპი !"); return; } Integer town_type_id = city_type_record.getAttributeAsInt("description_id"); String capital_town_record = isCapitalItem.getValueAsString(); if (capital_town_record == null || capital_town_record.trim().equals("")) { SC.say("გთხოვთ აირჩიოთ ქალაქის სახეობა !"); return; } Integer capital_town = Integer.parseInt(capital_town_record); // try { // Integer.parseInt(town_code); // } catch (NumberFormatException e) { // SC.say("ქალაქის კოდის შედგება მხოლოდ ციფრებისაგან !"); // return; // } // if (town_code_new != null && !town_code_new.equals("")) { // try { // Integer.parseInt(town_code_new); // } catch (NumberFormatException e) { // SC.say("ქალაქის ახალი კოდის შედგება მხოლოდ ციფრებისაგან !"); // return; // } // } String normal_gmt = ofGmtItem.getValueAsString(); if (normal_gmt == null || normal_gmt.trim().equals("")) { SC.say("გთხოვთ შეიყვანოთ დრო !"); return; } try { Integer.parseInt(normal_gmt); } catch (NumberFormatException e) { SC.say("დრო შედგება მხოლოდ ციფრებისაგან !"); return; } String winter_gmt = ofGmtWinterItem.getValueAsString(); if (winter_gmt == null || winter_gmt.trim().equals("")) { SC.say("გთხოვთ შეიყვანოთ ზამთრის დრო !"); return; } try { Integer.parseInt(winter_gmt); } catch (NumberFormatException e) { SC.say("ზამთრის დრო შედგება მხოლოდ ციფრებისაგან !"); return; } com.smartgwt.client.rpc.RPCManager.startQueue(); Record record = new Record(); record.setAttribute("town_name", cityNameGeo); record.setAttribute("town_code", town_code); record.setAttribute("town_new_code", town_code_new); record.setAttribute("country_id", country_id); record.setAttribute("town_type_id", town_type_id); record.setAttribute("capital_town", capital_town); record.setAttribute("normal_gmt", normal_gmt); record.setAttribute("winter_gmt", winter_gmt); if (lCityRecord != null) { record.setAttribute("town_id", lCityRecord.getAttributeAsInt("town_id")); } record.setAttribute( "loggedUserName", CommonSingleton.getInstance().getSessionPerson().getUser_name()); DSRequest req = new DSRequest(); if (lCityRecord == null) { req.setAttribute("operationId", "townAdd"); cityGrid.addData( record, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { destroy(); } }, req); } else { req.setAttribute("operationId", "townUpdate"); cityGrid.updateData( record, new DSCallback() { @Override public void execute(DSResponse response, Object rawData, DSRequest request) { destroy(); } }, req); } com.smartgwt.client.rpc.RPCManager.sendQueue(); } catch (Exception e) { e.printStackTrace(); SC.say(e.toString()); } }