Changes for page Your First Rest Project
Last modified by Steve Peery on 2013/09/06 11:02
From version 39.1
edited by Pascal Robert
on 2012/12/12 08:01
on 2012/12/12 08:01
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. probert1 +XWiki.franc - Content
-
... ... @@ -25,7 +25,6 @@ 25 25 | title | string(255) | 26 26 | content | string(4000) | 27 27 | creationDate | timestamp | 28 -| lastModified | timestamp | 29 29 | author | integer | relation with Author 30 30 31 31 Author will have the following columns: ... ... @@ -75,11 +75,10 @@ 75 75 |= Attribute name |= Column |= Prototype 76 76 | content | content | longtext 77 77 | creationDate | creationDate | dateTime 78 -| lastModified | lastModified | dateTime 79 79 80 80 If you did everything well, the list of attributes should look like this: 81 81 82 -You will notice that the attributes have a column with a lock in it. When a lock is present, it will use the value of that attribute for //UPDATE ... WHERE attribute = ''// statement. This is to do optimistic locking, aka to prevent data conflict when the data object was modified by two different users. Using timestamps for optimistic locking is not a good idea because for certain RDBMS, the value can be different because of milliseconds, so remove the locks on the **creationDate** attribute. The final list should look like this: 80 +You will notice that the attributes have a column with a lock in it. When a lock is present, it will use the value of that attribute for //UPDATE ... WHERE attribute = ''// statement. This is to do optimistic locking, aka to prevent data conflict when the data object was modified by two different users. Using timestamps for optimistic locking is not a good idea because for certain RDBMS, the value can be different because of milliseconds, so remove the locks on the **lastModified** and **creationDate** attributes. The final list should look like this: 83 83 84 84 Next step is to create the **Author** entity. Create a new entity with **Author** at its name (and also as the table name), and for the class name, use **your.app.model.Author**. The attributes for this entity are: 85 85 ... ... @@ -90,7 +90,7 @@ 90 90 91 91 Final list of attributes should look like this: 92 92 93 -Now, it's time to link the two entities together. A nAuthor can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on **Author** and select **New Relationship**. On your right, select **BlogEntry** in the list. On your left, select **to many BlogEntries**, and on your right, select **to one Author**. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure **and a new foreign key named** is checked (it is checked by default). The **Create Relationship** pane should look like this:91 +Now, it's time to link the two entities together. A Author can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on **Author** and select **New Relationship**. On your right, select **BlogEntry** in the list. On your left, select **to many BlogEntries**, and on your right, select **to one Author**. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure **and a new foreign key named** is checked (it is checked by default). The **Create Relationship** pane should look like this: 94 94 95 95 If you check in the **Outline** tab, you should see that **Author** now have a **blogEntries** relationship, and **BlogEntry** have a **author** relationship. 96 96 ... ... @@ -126,7 +126,7 @@ 126 126 127 127 == Using migrations == 128 128 129 -Migrations allow you to create the tables and columns (and some types of constraint). **Entity Modeler** ha ssupport to generate the code for the first migration, which is called "migration 0". To do that, open the EOModel (**BlogModel EOModel** in the **Resources** folder), right-click on the model name and select **Generate Migration**.127 +Migrations allow you to create the tables and columns (and some types of constraint). **Entity Modeler** have support to generate the code for the first migration, which is called "migration 0". To do that, open the EOModel (**BlogModel EOModel** in the **Resources** folder), right-click on the model name and select **Generate Migration**. 130 130 131 131 Copy the generated code in the clipboard. Close **Entity Modeler** and in the main Eclipse window, right-click on **Sources**, select **New** and select **Class**. 132 132 ... ... @@ -208,7 +208,7 @@ 208 208 In Project Wonder, *Action* at the end of a method is a convention for REST and Direct Actions, when you call those methods from certain components, you don't need to add the *Action* part. 209 209 {{/info}} 210 210 211 -For this tutorial, we will implement the **createAction** and ** indexAction** methods. But first, we need to create a key filter. A key filter will... filter the input and the output of REST request so that you don't have to send all attributes for a blog entry. For example, we want to show the details for an author, but we don't want to show the password for the author (in real-life, the password would be encrypted)209 +For this tutorial, we will implement the **createAction** and **showAction** methods. But first, we need to create a key filter. A key filter will... filter the input and the output of REST request so that you don't have to send all attributes for a blog entry. For example, we want to show the details for an author, but we don't want to show the password for the author (in real-life, the password would be encrypted) 212 212 213 213 Add this method in **BlogEntryController**: 214 214 ... ... @@ -227,7 +227,7 @@ 227 227 228 228 {{/code}} 229 229 230 -Now, let's implement the **creat eAction** method:228 +Now, let's implement the **creationAction** method: 231 231 232 232 {{code}} 233 233 ... ... @@ -241,7 +241,7 @@ 241 241 242 242 In 3 lines of code, you can create an object based on the request, save the new object to the database and return the new object in the response. Not bad, eh? 243 243 244 -Last step in the controller: implementing the ** indexAction** method. Again, the code is simple:242 +Last step in the controller: implementing the **showAction** method. Again, the code is simple: 245 245 246 246 {{code}} 247 247 ... ... @@ -321,7 +321,7 @@ 321 321 322 322 Switching the return value of this method says that we will follow a certain convention for HTML components. The convention for automatic HTML routing is that the component should be named <EntityName><Action>Page.wo. So in our case, the component will be **BlogEntryIndexPage**. Right-click on the project name in Eclipse and select **New** > **WOComponent**. Change the name to **BlogEntryIndexPage** and check the **Create HTML contents** button. Click **Finish**. 323 323 324 -The next step to get it to work is to make **BlogEntryIndexPage** to implement the **er.rest.routes.IERXRouteComponent** interface. 322 +The next step to get it to work is to make **BlogEntryIndexPage** to implements the **er.rest.routes.IERXRouteComponent** interface. 325 325 326 326 {{code}} 327 327 ... ... @@ -375,7 +375,7 @@ 375 375 376 376 Now that we have a list of blog entries, let's make a page to show the content of a blog entry. Create a new component named **BlogEntryShowPage**. 377 377 378 -Open **BlogEntryShowPage.java** and make sure the class implements **er.rest.routes.IERXRouteComponent**.376 +Open **BlogEntryShowPage.java** and make sure the class extends from **er.rest.routes.IERXRouteComponent**. 379 379 380 380 {{code}} 381 381 ... ... @@ -433,4 +433,4 @@ 433 433 434 434 Save the component and run the app. Go to [[http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.html]] to get the list of posts, and you should see a link on the title. Click on it, and now you get the full details of the blog entry 435 435 436 -The REST part of this tutorial is now complete, [[you can nowmoveto the next part of the tutorial>>Your First Framework]].434 +The REST part of this tutorial is now complete, you can now switch to the next part of the tutorial.