I am using RESTFUL webservices using Spring framework.Some information is displayed on the user interface using the data returned by webservices. There is a webservice, which gets the usernames and their roles from the database. For a particular user , I would like to have all the webservices display data in the form of ####,#### for first name,lastname ; ##/##/#### for date of birth etc. Since I am using JDBC to connect to the database, here's what I was thinking of doing:
Should I consider passing an additional parameter (maybe sending a value 0 or 1 ; 0 for all other users and 1 for user for which I want to hide the information) to each and every GET webservice so that when it comes to getting data from the database in the JDBC code part,I could check whether the flag is set to 1 or 0 and based on this, I could do something like this in the JDBC code :
// Code for a case when flag is set to `0`. Hence retrieving information from the database.
while(rs.next()) {
EmployeeList empList = new EmployeeList();
empList.setEmpId(empId);
empList.setEmployeeName(rs.getString("name"));
employeeList.add(empList);
}
// Code for a case when flag is set to `1`. Hence hiding information and not retrieving information from the database.
while(rs.next()) {
EmployeeList empList = new EmployeeList();
empList.setEmpId(empId);
empList.setEmployeeName("####,######");
employeeList.add(empList);
}
I am wondering, if this is an appropriate way to achieve my task or is there some other way around?
Edit:More clarifications on my requirements:
I am using jqxWidget in the UI to display the information I am getting from a RESTFUL webservice in JSON format. For example, let's consider this example and the screenshot for better understanding of my requirement:
1) Let's say I am getting all the information from the JSON response which I am populating in the jQXWidget as shown in the screenshot above.
2) In the above widget, I would like to hide say for example, First Name, Last Name and Quantity like the following:
First Name = XXXXX
Last Name = XXXXX
Quantity = ####
In my application, if a user clicks on a particular row , a new page is displayed with some additional information. After click, new sets of web services are called and those web services takes First Name, Last Name and Quantity as input parameters. My concern is that, if I somehow replace the First Name with XXXXX, Last Name with XXXXX and Quantity with #### using any approach, when a user clicks on any of the row of the widget, the next set of web services
are going to get XXXX and #### as input and eventually will fail. Please correct me if my understanding until this point is not correct.
Thanks
I am using Spring 4.2.5 version.
This depends on what sort of information hiding you want to achieve. Typically you shouldn't do this manually.
You can use, for example, role-based authorization. Exact details depends on the web-service framework you are using.
For spring MVC, you can use something similar to this:
Custom authorization in Spring MVC
Related
I have working Spring REST app with client side pagination, default by DataTables and everything works. Now i need to change it to server-side pagination i have problem, because have no idea how to get information from DataTables what page number client want to see. I can't find anything usefull in DT manual.
When you say Datatable I assume you are talking about DataTables jQuery plugin.
To activate serverside pagination you need to pass
"serverSide": true,
like this:
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "/your_url"
});
Doing the above will activate your server-side pagination. But you need to do few changes on the server-side too. Let's see them step by step.
1. What happens when you mark serverSide as true
DataTables plugin adds custom parameters to the AJAX call with information like
order: asc
start: 20
length: 10
// and many more.
You can inspect this demo link and see the parameters passed in request when you click the next page button.
2. Similarly, DataTables plugin expects some fields in response in order to preserve pagination logic.
"draw": 3, // unique ID
"recordsTotal": 57, // total number of records
"recordsFiltered": 57 // total number of filtered records
You can inspect this demo link and see response data this time.
3. Now changes are on serverside in your API
You need to add these parameters as queryParam for GET and attr in POST call in your controller API:
order: asc
start: 20
length: 10
4. Service Layer Changes - DB query
In-Service Layer where you get details from a database.
You need to get the total number of records and in search query pass a LIMIT clause LIMIT 10, 10 in case of MySQL.
E.g.:
SELECT * FROM User LIMIT 20,10;
Use start and length to calculate the next set of records.
It can be trickier but if you understand and implement properly it's fun.
Read more in detail here which also contains code and live demo.
Please see the sample about DataTables server-side processing:
https://datatables.net/examples/server_side/simple.html
After change page, you can capture the request to server as following format:
https://.../server_processing.php?draw=3&columns...&order=0&dir=asc&start=20&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1534436781912
That means DataTable requests page number 3 (draw=3), order by first column ascending, ....
At server side (REST), you can get page number by (for example) request.getParameter("draw")
I wish to display some data from my SQL server into my application.
Let me explain throw an example what have i done until now, and please tell me how should i go on with my work:
(1) I have a database named: 'DB1'
(2) In my database i have table named 'users':
Id, Name, LastName
1 Dave Stone
2 Rose Mary
3 Gray Lone
(3) I created 3 php files: 1/ config.php (sets up my database log in information like password...)
2/ DBConnection.php : `
// Connecting to database
public function connect() {
require_once 'Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
?>
3/ GetUsers.php which i dont know how should i write it - this would be the code which will echo whatever i want from the table.
(4) Inside my android studio project i have a MainActivity.java and i want to get all the LastNames of all the users in the database and do whatever with them... like print them into a text box it doesn't really matter (let's say i don't know how many users I have).
I need some one to help me get stages (3)3/ + (4) done / explained.
I think what you mean is a good method to retrieve and set values from app to database, the best and most prominent way is using basic REST services that convert your db values to JSON then you load the json using your api key as authentication, it might sound really stressful but is in fact very easy and flexible to implement, the only way you can directly set and get db values on android is using sqlite (android local inbuilt db)
The best tutorial and major explanation for exactly what you want to achieve is here
http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/
Then this one for further works
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
It covers how you make a rest service yourself
I had created one search page using custom viewcriteria with five parameters.In my search page working perfect.I have one doubt,we are entering the some parameters in the search page to get the details from one table, Here i need that values which we are entered in that boxes for using that values into a one java class.
How get those values?
Maybe ,This link can help you.you should glance
http://www.awasthiashish.com/2013/07/implementing-custom-search-form-in-adf.html
You can read the search value from a custom BC method (either on AM or VO impl level):
ViewCriteriaImpl applyVC =
(ViewCriteriaImpl)myViewObject.getViewCriteria("MyViewCriteriaName")
while(applyVC.hasNext) { Row vcrow = applyVC.next(); .... }
I am getting familiar with Java through involvement on a servlet web service project that is now up and running. But the stakeholders want a front end that will allow them to examine the audit table set up in a SQL server database. I am trying to quickly put one together in JSP with initial success but now stuck.
I want a drop down list to provide a list of all the users (Unique). I have acheived this using a JSTL taglib method following the link below with the following SQL;
"SELECT DISTINCT(USER_ID) FROM AUDIT_MESSAGE".
http://www.apekshit.com/t/205/JSTL-SQL-Query-Tag-Example
Now I want, when the user clicks on one of the users names it automatically populates another drop down list with a list of times that user logged in with the following SQL;
SELECT SESSION_ID, EventTIME FROM dbo.AUDIT_MESSAGE
WHERE OPERATION = 'loginResponse' AND RESULTS = 'OK'
AND USER_ID = 'firstdropdownlistselection'
Then when an item from the second drop down list option is selected a third SQL statement of;
Select * FROM dbo.AUDIT_MESSAGE
WHERE SESSION_ID = 'seconddropdownlistselection'
This is then used to populate a list box of the Users events at the selected time.
I have found the following link below offering another method but I am unsure whether to continue with the method I have started with or is there a better way. Can someone please advise me on what method would work best?
Multiple ResultSets
Thanks in advance
AJF
You could display the whole database table information(minus the ids) if this is what they want.
If you want to do it in these steps (select user, select session, display information) what you are doing is correct.
In Google app engine, how can i delete multiple data selected in check box. For a sample i had attached the image below. here i had selected the multiple check boxes and the data shown are stored in the Google app engine.
i have my jsp code for check box like this,
<input name="delete" type="checkbox"/>
can anyone suggest me how to select the data and delete it from Google app engine.
Edited:
For storing the data i used,
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity employee = new Entity("Employee");
employee.setProperty("First Name", fname);
datastore.put(employee);
For retrieving the data i used,
Query query = new Query("Employee");
List<Entity> emp = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));
for (Entity user : emp){
// inside the table
user.getProperty("File Name")}
By this i can retrieve the data.
First of all, I recommend that you use two frameworks to make your life easier:
Stripes
Objectify
OK, here you go: I'm not sure to which degree your question is a basic JSP/Servlet question or a specific Appengine question. However, you have to do the follwoing:
Have a list of checkboxes on your JSP page, like this: <stripes:checkbox name="employees[${loop.index}].id" value="${employee.id}"/> (see: http://www.stripesframework.org/display/stripes/Indexed+Properties)
Pass a list of IDs (of the entities that should be deleted) to the Servlet.
Delete the entities based on these IDs.
Here's the catch: Appengine can terminate the request before all entities are deleted. That can happen if the request takes too long. Therefore you should delete the entities asynchronously, using chunks of data. See this answer for further information.