Web-app source code

Hello!

I’m currently working on understanding the web-app source code and i have some questions. In auditSynthesisController the function prepareSynthesisSiteData returns: TgolKeyStore.SYNTHESIS_SITE_VIEW_NAME. Where is this function called and where and how is the returned value used? I suppose that it is somehow connected to the view SynthesisSite.jsp. I’m trying to understand how the html code is produced.

Also if i want to change something in a view for example if i want to add a link or something should i change only the .jsp file or is it more complex? Thanks a lot!

I think that some of the answers are here for anybody who wants to understand the functionality: https://spring.io/guides/gs/serving-web-content/
http://docs.oracle.com/javaee/5/tutorial/doc/bnaaw.html

Spring MVC supplies a mechanism to render pages based on a key.
If you need more details, take a look at

We currently use an ResourceBundleViewResolver, all the magical is handled by the view.properties file in the resources folder of the webapp.

Each view, represented by its key (the string returned by methods in the controller) has to set at least 2 properties :

  • $myViewName.(class) => (Here you can have JstlView or RedirectView)
  • $myViewName.url => gives the path to the jsp file (from the webapp folder)

Hope it helps
Regards

Koj

3 Likes

About your second question, to add a link to the page, just add your html in the jsp.

If the code you want to add uses data from the model, you need to add an entry in the model Object in the controller method. This is a classical map, key/value.

Once in the model, the data can be simply accessed by using ${myKeyInTheModelMap} in the jsp. That will then interpreted before being rendered by the server.

Regarding the kind of Java object you associate to the key in the map, you can for instance :

  • access to the any attribute of the object : ${myKeyInTheModelMap.myClassAttribute}. The class must simply define a method called “getMyClassAttribute”
  • iterate over a collection with a <c:forEach tag,
  • and so many other stuffs.

Enjoy and thanks for your interest
Feel free to ask other questions

Regards

Koj

3 Likes

Ok thanks a lot! Let’s say that i want to add another graph to the html identical for example to the score graph but i want this to be computed with a different formula computed by java code that i will write. How complex would something like that be? Or what if i would like to create a new view containing some graphs which would display some of the data from the database?

2 Likes

Hi,

It depends on what kind of graphics you want to create.
We currently use the d3.js library to build our graphics.

To do so, we create in the jsp a table with the data, that is then used by some javascript code to collect dara, build the graphics and then hide the original data by css.

You may use another way, we can discuss about it, if you have any idea.

Regards

Jerome

1 Like

And what about creating an extra view? Of course a controller is essential and a new .jsp i suppose. What else?

Furthermore, how could i make changes to the source code using an IDE and test the results on my browser?

1 Like

hi @nivak91,

For Linux users, with docker and maven:

git clone https://github.com/Asqatasun/Asqatasun.git
cd Asqatasun
git checkout develop
 
# make changes to the source code using an IDE 
# (...)

# builds with maven, builds docker image and runs a new docker contenair
docker/compile_and_build_docker_image.sh -l -s ${PWD} -d docker/single-container-SNAPSHOT-local

In your browser, go to
http://127.0.0.1:8085/asqatasun/

Thanks a lot @fabrice! I hadn’t installed asqatasun with docker. Should i reinstall using docker?

1 Like

You can have a standard Asqatasun
on http://127.0.0.1:8080/asqatasun/

and another for testing your changes
on http://127.0.0.1:8085/asqatasun/
with Docker

Ok @fabrice i tried to do it this way but the compile takes too much time and i want to test very often the changes i make. Do i need to compile everytime or a refresh on the browser is enough?
I have made some changes such as putting a link in home.jsp:

<div class="span16">
   <h1><fmt:message key="home.h1"/></h1>
   <a href="<c:url value="mypage.htm"/>"My Page</a>
</div>

but after running :

docker/compile_and_build_docker_image.sh -l -s ${PWD} -d docker/single-container-SNAPSHOT-local 

the link i added is absent in http://127.0.0.1:8085/asqatasun/home.html although it exists on home.jsp.
Also i added a simple view named mypage.jsp and this controller:

@Controller
public class MyPageController{         
    @RequestMapping(value = TgolKeyStore.MY_PAGE, method = RequestMethod.GET)
    //@Secured({TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY})
    public String MyPage(HttpServletRequest request,
            HttpServletResponse response,
            Model model){
        return TgolKeyStore.MY_PAGE_VIEW_NAME;
    }
}

Of course i added: public static final String MY_PAGE = "/mypage";
and : public static final String MY_PAGE_VIEW_NAME = "My-page" in TgolKeyStore.java and configured view.properties by adding:

My-page.(class)=org.springframework.web.servlet.view.JstlView
My-page.url=/WEB-INF/view/MyPage.jsp

But when i go to http://127.0.0.1:8085/asqatasun/mypage it says i am not allowed to access this resource.

Any ideas would be very helpful. Thanks!

1 Like

Problems solved! Instead of typing http://127.0.0.1:8085/asqatasun/mypage i should type http://127.0.0.1:8085/asqatasun/mypage.html (i don’t know why) and for compiling i added mvn clean install -Dmaven.test.skip=true to the script.

1 Like

My new question is whether each time i compile and run a new container a new database is created? I already have an asqatasun database from the installation without docker with the default credentials, so if it is created how could it be the same?

1 Like

for compile_and_build_docker_image.sh script
you can use –skip-build option

first compile Asqatasun

cd Asqatasun
mvn clean install

after, compile only webapp

cd Asqatasun/web-app
mvn clean install

and run a new docker contenair with –skip-build option

cd Asqatasun
docker/compile_and_build_docker_image.sh --skip-build -l -s ${PWD} -d docker/single-container-SNAPSHOT-local
1 Like

[quote=“nivak91, post:15, topic:259, full:true”]
My new question is whether each time i compile and run a new container a new database is created? [/quote]
when you run a new Docker container, a new database is created inside this new container.

1 Like

Hi again. I’m trying to find the methods which when an audit is launched, write the results to the database. Could you help me?

Also another question that i have is where are the parameters of draw function of score-min.js set? I would like too use this script in order to make more than one score graphs in a page. Is that possible by changing those parameters?

And how can i have access to this database? Port 3306 is already used by asqatasun running on http://127.0.0.1:8080/asqatasun/

Hello again! If i make changes to the database how are the native SQL queries affected? For example if i add a new table or add to an existing table should i change them?

1 Like