Sakai code exercises Aaron Zeckoski azeckoskigmail com Sakai

  • Slides: 38
Download presentation
Sakai code exercises • Aaron Zeckoski • azeckoski@gmail. com Sakai Montreal CRIM Workshop Creative

Sakai code exercises • Aaron Zeckoski • azeckoski@gmail. com Sakai Montreal CRIM Workshop Creative Commons Attribution. Non. Commercial-Share. Alike 2. 5 License Sakai Programmer's Café

Add a permission • New permission: – myapp. view. summary • Requires changing 3

Add a permission • New permission: – myapp. view. summary • Requires changing 3 files 2

Add Permission - logic api • Update the logic api – Add the method

Add Permission - logic api • Update the logic api – Add the method • boolean view. Summary(String user. Id, String context) – Don’t forget the javadoc comment! 3

Add Permission - logic test • Update the logic test – Add a test

Add Permission - logic test • Update the logic test – Add a test method • test. View. Summary. String() 4

Add permission - logic impl • Update the logic impl – Add the perm

Add permission - logic impl • Update the logic impl – Add the perm using Function. Manager • In the init method – Implement the new method • Use Security. Service to check the permission. Add 5

Add Permission - test • Test the code using the automated testing in Eclipse

Add Permission - test • Test the code using the automated testing in Eclipse • Run maven sakai – note that the new test runs • Try the app to make sure it still works – There will be no visible changes 6

Add a page (part 1) • Summary page – Shows statistics on total entries

Add a page (part 1) • Summary page – Shows statistics on total entries • For now it will just show some text – Permission protected – Accessible from the list items page • Requires adding 2 new files • Requires changing 3 files 7

Add page - add template • Create a new template – Copy the file

Add page - add template • Create a new template – Copy the file from an existing template – Name it Summary. html • Add in 3 spans or divs (or whatever) with rsf: ids like shown: – total-items – current-context-items – current-user-items 8

Add page - add producer • Create a new producer – You can do

Add page - add producer • Create a new producer – You can do this using eclipse • Add new class – implements View. Component. Producer – Can also copy an existing producer • Connect it to the template – Set the View. ID to Summary – Add in UIOutput for the 3 rsf: ids • Use made up strings for the values 9

Add page - request. Context • Add a bean definition for the new producer

Add page - request. Context • Add a bean definition for the new producer to request. Context. xml – Make it an anonymous bean 10

Add page - list template • Update the list template to include a link

Add page - list template • Update the list template to include a link to the Summary. html file <a rsf: id="summary" href="Summary. html">Summary</a> – Add it to the nav. Intra. Tool part • In Sakai, the general rule is to put internal tool navigation in the nav. Intra. Tool part (grey bar at top) 11

Add page - list producer • Update the list producer to include a UIInternal.

Add page - list producer • Update the list producer to include a UIInternal. Link to the summary page – This ties to the link in the template UIInternal. Link. make(tofill, "summary", new Add. Item. View. Parameters(Summary. Producer. VIEW_ID, null) ); 12

Add page - test • Run maven sakai – Deploy the tool • Test

Add page - test • Run maven sakai – Deploy the tool • Test in Sakai (try out the new page) – Make sure the link back to list items works 13

Add page - use perm • Update the new producer – Add a permission

Add page - use perm • Update the new producer – Add a permission check which throws an exception when a user without permission tries to view the new page – Don’t rely on security through obscurity • Update the Items producer to check the perms before rendering the link 14

Questions? • We will make the summary page functional next 15

Questions? • We will make the summary page functional next 15

Add page - logic api • Add some methods to get the 3 pieces

Add page - logic api • Add some methods to get the 3 pieces of information we want – count. All. Items() – count. All. Items. By. Context(String context) – count. All. Items. By. Owner(String user. Id) 16

Add page - logic test • Create test methods for the 3 new methods

Add page - logic test • Create test methods for the 3 new methods in the api – Check for multiple sites and multiple users – Positives and negatives 17

Add page - logic impl • Implement the 3 methods – Use the dao

Add page - logic impl • Implement the 3 methods – Use the dao count. By. Properties – Get default values if the inputs are null 18

Add page - update summary • Update the summary producer to use the security

Add page - update summary • Update the summary producer to use the security method – Throw an exception if the user does not have permission to view this page – Do not use security through obscurity 19

Add page - update list • Update the list producer to use the security

Add page - update list • Update the list producer to use the security check to render the link – Don’t give the user links or options that will not work for them 20

Questions? • Next we will update the data model 21

Questions? • Next we will update the data model 21

Add a field to the data model • Add a description field to the

Add a field to the data model • Add a description field to the data model – It should be a text field of unlimited length – It should be adjustable on the add/modify page screen 22

Add field - update hbm • Update the hbm file with the new description

Add field - update hbm • Update the hbm file with the new description field – Use text as the type <property name="description" type="text" /> 23

Add field - update model class • Update the model (value) class with the

Add field - update model class • Update the model (value) class with the description property – String – Update full constructor – Add getter and setter • Use eclipse to generate 24

Add field - update logic test • Fix the logic test to use the

Add field - update logic test • Fix the logic test to use the new constructor and data model class 25

Add field - update dao test • Fix the dao test to use the

Add field - update dao test • Fix the dao test to use the new constructor and data model class 26

Add field - update dao preload • Fix the dao preload to use the

Add field - update dao preload • Fix the dao preload to use the new constructor and data model class 27

Add field - update Add. Item template • Add a new textarea for the

Add field - update Add. Item template • Add a new textarea for the description to the Add. Item template – Probably should use a row for the label and another for the textarea <textarea rsf: id="item-description" cols="80" rows="3"></textarea> 28

Add field - update Add. Item producer • Bind a UIInput to the description

Add field - update Add. Item producer • Bind a UIInput to the description field – Do it for creating and updating the item UIInput. make(addupdateitem, "item-description", "#{items. Bean. new. Item. description}"); 29

Add field - update backing bean • Add an if statement to update the

Add field - update backing bean • Add an if statement to update the description if it is not null – In RSF the unchanged return value is null – Do it like title or hidden 30

Questions? 31

Questions? 31

Use Sakai Announcement Service • Use the Sakai Announcement Service to create an announcement

Use Sakai Announcement Service • Use the Sakai Announcement Service to create an announcement when new items are added – Need to inject the service and call it 32

Announcement. Service String channel. Ref = announcement. Service. channel. Reference(site. Id, Site. Service. MAIN_CONTAINER);

Announcement. Service String channel. Ref = announcement. Service. channel. Reference(site. Id, Site. Service. MAIN_CONTAINER); try { Announcement. Channel ac = announcement. Service. get. Announcement. Channel(channel. Ref); ac. add. Announcement. Message("New Item", false, null, "A new item was added called: title"); } catch (Id. Unused. Exception e 1) { log. error("failure adding message: ref=" + channel. Ref, e 1); } catch (Permission. Exception e 1) { log. error("failure adding message: ref=" + channel. Ref, e 1); } 33

Annc - Update the logic api • Add a method to the api to

Annc - Update the logic api • Add a method to the api to create an announcement – Needed since we are accessing it in the backing bean – Alternative: make the create item trigger a private method in the logic impl 34

Annc - Update the logic test • Use mock objects to pretend we are

Annc - Update the logic test • Use mock objects to pretend we are using the Announcement Service 35

Annc - update the logic impl • Update the logic impl to include the

Annc - update the logic impl • Update the logic impl to include the previously referenced code 36

Annc - update backing bean • Call the create announcement method when a new

Annc - update backing bean • Call the create announcement method when a new item is created 37

Questions? 38

Questions? 38