Upload
augustus-jones
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
Sakai Programmer's Café
Sakai Montreal CRIM Workshop
Sakaicode exercises
Aaron [email protected]
3
Add Permission - logic api
• Update the logic api– Add the method
• boolean viewSummary(String userId, String context)
– Don’t forget the javadoc comment!
5
Add permission - logic impl
• Update the logic impl– Add the perm using FunctionManager
• In the init method
– Implement the new method• Use SecurityService to check the
permissionAdd
6
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
7
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
8
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
9
Add page - add producer
• Create a new producer– You can do this using eclipse
• Add new class – implements ViewComponentProducer
– Can also copy an existing producer
• Connect it to the template– Set the ViewID to Summary– Add in UIOutput for the 3 rsf:ids
• Use made up strings for the values
10
Add page - requestContext
• Add a bean definition for the new producer to requestContext.xml– Make it an anonymous bean
11
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 navIntraTool part
• In Sakai, the general rule is to put internal tool navigation in the navIntraTool part (grey bar at top)
12
Add page - list producer
• Update the list producer to include a UIInternalLink to the summary page– This ties to the link in the template
UIInternalLink.make(tofill, "summary", new AddItemViewParameters(SummaryProducer.VIEW_ID, null) );
13
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
14
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
16
Add page - logic api
• Add some methods to get the 3 pieces of information we want– countAllItems()– countAllItemsByContext(String context)– countAllItemsByOwner(String userId)
17
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
18
Add page - logic impl
• Implement the 3 methods– Use the dao countByProperties– Get default values if the inputs are null
19
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
20
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
22
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
23
Add field - update hbm
• Update the hbm file with the new description field– Use text as the type<property name="description" type="text" />
24
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
25
Add field - update logic test
• Fix the logic test to use the new constructor and data model class
27
Add field - update dao preload
• Fix the dao preload to use the new constructor and data model class
28
Add field - update AddItem template
• Add a new textarea for the description to the AddItem template– Probably should use a row for the label
and another for the textarea<textarea rsf:id="item-description" cols="80"
rows="3"></textarea>
29
Add field - update AddItem producer
• Bind a UIInput to the description field– Do it for creating and updating the item
UIInput.make(addupdateitem, "item-description", "#{itemsBean.newItem.description}");
30
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
32
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
33
AnnouncementServiceString channelRef =
announcementService.channelReference(siteId, SiteService.MAIN_CONTAINER);
try {
AnnouncementChannel ac = announcementService.getAnnouncementChannel(channelRef);
ac.addAnnouncementMessage("New Item", false, null, "A new item was added called: title");
} catch (IdUnusedException e1) {
log.error("failure adding message: ref=" + channelRef,e1);
} catch (PermissionException e1) {
log.error("failure adding message: ref=" + channelRef,e1);
}
34
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