Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Where should the logic behind the app should be placed?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m developing an E-learning app using JavaFX. I started by having just one app - all the database operations are executed on client side. From what I ve read this is not a very good approach so I ve decided to separate the client side from the server side. So in the client app there will be the FXML files with their associated controllers. The server will contain the logic behind. From what I ve read the server app will be structured as follows: a persistence layer - which will take care of DAO operations and only that and a service layer which will take care of business logic. Here's come my question. Let's assume a simple situation like when the user attempts to sign up. First I need to verify if the username already exists in the database, next to check if password match etc (validations). Where should I put these validations. Basically in the controller class I think there will be a call to a method of service layer (so I don't make any validations in the controller class - the controller class is only responsible for transferring information from the view to the service). Correct me if I am wrong. I would appreciate if someone could tell me the right way of that mechanism
 
Marshal
Posts: 68917
275
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ilin wrote:. . . all the database operations are executed on client side. . . . this is not a very good approach

No, you want the logic to be completely separate. I have a rule of thumb that you should be able to run the business logic, which here includes the database operations, without any GUI at all. You should be able to see everything running from a terminal/command line. That makes it easy to keep the logic close to the database.
Also running database access from the client side risks exposing your logic to insecure connections.
You will also find your database access runs slowly because of the delay between client and server.

. . . separate the client side from the server side.

That sounds better.

So in the client app there will be the FXML files . . .

I don't know any FXML, but please explain why you want them out at client side.

From what I ve read the server app will be structured as follows . . .

Please confirm that you have decided the functionality of your app before you tried working out those implementation details.
 
Robert Ilin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JavaFX FXML is an XML format that enables you to compose JavaFX GUIs in a fashion similar to how you compose web GUIs in HTML.  


Example:



So basically the GUI is buiild using FXML files. Every FXML file should have one controller in which you have direct access to the FXML items (like buttons, labels etc). I thought it's a good idea to store the FXML files on the client side. I don't know why, it seemed correct for me. Do you have another option? Please let me know. I'm willing to learn as much as possible since I haven't developed another client-server type app till now.

Ok, now I'm going to detail how my app should work. The user will have to login/sign up in the app first (like I've asked in the first post, I want to know where I should put the logic behind the log in mechanism. Like I said, the FXML controller should only be responsible for passing infos between the view and the service. Please tell me if my logic is good. So in the database I will have the table User.

After Sign up/ log in the app should show content specific to the category to which the user belongs (beginner / intermediate / advanced). The level of experience of the user will be determined by a Sign Up quiz.
Here comes another question. I will keep learning material in simple .txt files like:
I will have a filled called Structure.txt with the following format
ChapterName Lesson1 Lesson2...LessonN. So it will have multiple lines (one line for every chapter). I think this is a good approach for later modifications of the content (I won't have to modify the code, but only the files). So there will be one of this structure file for every category (3 in total). Next every lesson will be in its separate file like : Lesson1.txt. When the user log in, the app should load the associated files based on user level and build the GUI. Now, where these files should be saved? I don't think it's a good idea to store on user side. And if I store them on server side, how do I do to load them from the client app? Should I have some methods in the server? For server side I ve seen that it usually uses a REST API for database operations. So should I implement these load_file operations in the REST API? Please make me understand.
In the database there will be another table, like user_completed_lessons which will information about the user progress, like when the user complete a lessons I will insert a record in this table (user id + lesson id). I will use this to change the GUI accordingly (like check marks on completed lessons).
There will be a testing section too.. But I will not go into details. The mechanism is similar.


My biggest dilemmas are how to access the service in the client application and the part with loading files in th GUI.

I would appreciate if you could give some directions.

Thanks
 
Sheriff
Posts: 7056
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never created a JavaFX program that was client/server, but I suspect the FXML files need to be near the controller classes -- if you store the controller in the FXML documents.  So if the controller classes are on the server, maybe the FXML needs to be there also?  The reason I think that is because you only store the controller class in the FXML, but FXML can be loaded from a URL.  Alternatively, I'm not sure how a JavaFX program would work with the controllers on a server, so maybe both the FXML and the controllers need to be local?  But then you have the security problems that Campbell spoke of.

As you can see, I have more questions than answers.  
 
Robert Ilin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you detail more the security problems your are talking about? I don't really understand what you mean by that..
 
Knute Snortum
Sheriff
Posts: 7056
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm assuming you would be using JDBC.  In order for you to get a connection, you need a user and password and that user was to be able to read and write to the tables.  There are ways to obfuscate the password but you still have a lot of clients with the password out there.  I believe that is what Campbell was speaking of.
 
Saloon Keeper
Posts: 11899
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just create an FXML client like you normally would, and then you let your FXML controllers call methods of a service proxy.

I gave examples of a web service interface in your other topic. For a REST API, you can create a proxy using the ClientBuilder class of the JAX-RS library:

Now all you need to do is pass an instance of StudentControllerProxy to your FXML controller, and you can call the actions on the proxy as if you're immediately calling the actions on the service implementation. Here's a simple example main method. I'll leave writing it as an FXML application to you:

Here is the POM:
 
Stephan van Hulst
Saloon Keeper
Posts: 11899
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I mentioned in your other thread though, this is NOT how you are supposed to build a REST application that will stand the test of time.

In a proper REST application, when you access a resource, the response you get will also contain links to other resources that you can access from there, comparable to how you can navigate between web pages through links that the web service has sent you. The client application then only needs to know the URL of the entry point of the REST API, and from there it can discover the rest of the API by having the service send it links.

The example code that I have given you is enough for your current needs. Just keep in mind that it is NOT RESTful, despite that we're using JAX-RS.

When you've gotten all of it to work for your own application, create a separate thread for the security aspects, like accessing service endpoint that perform privileged operations such as accessing a user's private information.
 
Robert Ilin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So basically if I would deliver the app to the client I would make a jar that would contain the FXML controllers and views, the proxy and the service? But if providing service to the client doesn't mean that they could mess up the app by reverse engineering? Or am I thinking too far?  Or if I don't include the service Impl thery can't do anything bad to the app? What about the login/registe? Do I need to create another endpoins in the API and POST the username and password?
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic