DSCS Usage Case 2

We would like to configure site and tool creation process, where we define the tools for a site via a spring bean. So for example in our UCD site-management service, we defined the following spring bean in components.xml

	<bean id="org.sakaiproject.sitemanagement.configuration.api.SitePagesAndTools"
		class="org.sakaiproject.sitemanagement.configuration.impl.SitePagesAndToolsImpl">
		<property name="pagesAndTools">
			<map>
				<entry>
					<key><value>Home</value></key>
					<list>
						<value>sakai.iframe.site</value>
						<value>sakai.synoptic.chat</value>
						<value>sakai.synoptic.announcement</value>
					</list>
				</entry>
				<entry>
					<key><value>Announcements</value></key>
					<list>
						<value>sakai.announcements</value>
					</list>
				</entry>
				<entry>
					<key><value>Assignments</value></key>
					<list>
						<value>sakai.assignment.grades</value>
					</list>
				</entry>
				<entry>
					<key><value>Chat Room</value></key>
					<list>
						<value>sakai.chat</value>
					</list>
				</entry>
				<entry>
					<key><value>Drop Box</value></key>
					<list>
						<value>sakai.dropbox</value>
					</list>
				</entry>
				<entry>
					<key><value>Email Archive</value></key>
					<list>
						<value>sakai.mailbox</value>
					</list>
				</entry>
				<entry>
					<key><value>Gradebook</value></key>
					<list>
						<value>sakai.gradebook.tool</value>
					</list>
				</entry>
				<entry>
					<key><value>Message Center</value></key>
					<list>
						<value>sakai.messagecenter</value>
					</list>
				</entry>
				<entry>
					<key><value>Modules</value></key>
					<list>
						<value>sakai.melete</value>
					</list>
				</entry>
				<entry>
					<key><value>Resources</value></key>
					<list>
						<value>sakai.resources</value>
					</list>
				</entry>
				<entry>
					<key><value>Schedule</value></key>
					<list>
						<value>sakai.schedule</value>
					</list>
				</entry>
				<entry>
					<key><value>Site Info</value></key>
					<list>
						<value>sakai.siteinfo</value>
					</list>
				</entry>
				<entry>
					<key><value>Support &amp; Training</value></key>
					<list>
						<value>sakai.iframe</value>
					</list>
				</entry>
				<entry>
					<key><value>Syllabus</value></key>
					<list>
						<value>sakai.syllabus</value>
					</list>
				</entry>
				<entry>
					<key><value>Tests &amp; Quizzes</value></key>
					<list>
						<value>sakai.samigo</value>
					</list>
				</entry>
				<entry>
					<key><value>Wiki</value></key>
					<list>
						<value>sakai.rwiki</value>
					</list>
				</entry>
			</map>
		</property>
	</bean>

The SitePagesAndToolsImpl class looks like this:

package org.sakaiproject.sitemanagement.configuration.impl;

// imports ...

public class SitePagesAndToolsImpl implements SitePagesAndTools {
	
	private Map pagesAndTools = null;
	
	// DI
	public void setPagesAndTools(Map pagesAndTools) {
		this.pagesAndTools = pagesAndTools;
	}
	
	public Map getPagesAndTools() {
		return pagesAndTools;
	}
}

Now we define the property key:

package org.sakaiproject.component.configuration.properties.api;

public interface ConfigurationProperties {

	// Site Management
	public static final String SITE_MANAGEMENT_PAGES_AND_TOOLS = "org.sakaiproject.sitemanagement.service.CourseService.SitePagesAndTools";
        // ...

Now, modify the component-impl's components.xml file.

<property name="dynamicSakaiProperties">
    <map>
        <entry key="org.sakaiproject.sitemanagement.service.CourseService.SitePagesAndTools">
	    <ref bean="org.sakaiproject.sitemanagement.configuration.api.SitePagesAndTools" />
	</entry>
    </map>
</property>

We use the SitePagesAndTools property in our CourseService class:

public class CourseServiceImpl
    extends AbstractSiteService
    implements CourseService, ConfigurationNotificationListener, ConfigurationProperties {

    // ...
    private SitePagesAndTools sitePagesAndTools;
    private DynamicServerConfigurationService dynamicServerConfigurationService;

    // Spring DSCS injection
    public void setDynamicServerConfigurationService(DynamicServerConfigurationService dynamicServerConfigurationService) {
        this.dynamicServerConfigurationService = dynamicServerConfigurationService;
    }

    // Spring Bean Init
    public void init() {
	dynamicServerConfigurationService.addNotificationListener(this, SITE_MANAGEMENT_PAGES_AND_TOOLS);
		
	try {
	    sitePagesAndTools = (SitePagesAndTools) dynamicServerConfigurationService.getDynamicObject(SITE_MANAGEMENT_PAGES_AND_TOOLS);
			
	} catch (ConfigurationObjectNotFound e) {
		LOG.error("Was not able to find configuration property");
	} catch (InvalidConfigurationKey e) {
		LOG.error("Provided invalid configuration key");
	}
    }

    // Implementing ConfigurationNotificationListener API: handleNotification
    public void handleNotification(String configurationItemKey) {
	
        try {
            if(SITE_MANAGEMENT_PAGES_AND_TOOLS.equals(configurationItemKey)) {
		sitePagesAndTools = (SitePagesAndTools) dynamicServerConfigurationService.getDynamicObject(SITE_MANAGEMENT_PAGES_AND_TOOLS);
	    }
	} catch (ConfigurationObjectNotFound e) {
	    LOG.error("Was not able to find configuration property for key = " + configurationItemKey);
	} catch (InvalidConfigurationKey e) {
	    LOG.error("Provided invalid configuration key = " + configurationItemKey);
	}
    }
}