[Building Sakai] "UserDirectoryService" or "User" instances from my Tool "SelfCert"
Gautham
gautham at sankhya.net
Wed Feb 2 03:39:55 PST 2011
Hi Steve,
I am getting this Error when I am accessing the "UserDirectoryService" or
"User" instances from my Tool "SelfCert".
org.sakaiproject.portal.api.PortalHandlerException:
java.lang.IllegalArgumentException: Unable to find registered context for
tool with ID sakai.selfcert
Tomcat is showing:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid
property 'UserDirectoryService' of bean class
[org.sakaiproject.selfcert.tool.SelfCertItemsBean]: Bean property
'UserDirectoryService' is not writable or has an invalid setter method. Did
you mean 'userDirectoryService'?
I have do changes to "applicationcontext.xml" and "SelfCertItemsBean.java"
and as suggested by you
SelfCertItemsBean:
=========================
package org.sakaiproject.selfcert.tool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.selfcert.logic.ExternalLogic;
import org.sakaiproject.selfcert.logic.SelfCertLogic;
import org.sakaiproject.selfcert.model.SelfCertItem;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.User;
/**
* This is the backing bean for actions related to SelfCert Items
* @author Sakai App Builder -AZ
*/
public class SelfCertItemsBean {
private static Log log = LogFactory.getLog(SelfCertItemsBean.class);
public SelfCertItem newItem = new SelfCertItem();
public Map selectedIds = new HashMap();
private UserDirectoryService userDirectoryService;
public void setUserDirectoryService(UserDirectoryService
userDirectoryService)
{
this.userDirectoryService = userDirectoryService;
}
private User user;
public void setUser(User user)
{
this.user = user;
}
private SelfCertLogic logic;
public void setLogic(SelfCertLogic logic) {
this.logic = logic;
}
private ExternalLogic externalLogic;
public void setExternalLogic(ExternalLogic externalLogic) {
this.externalLogic = externalLogic;
}
public ArrayList messages = new ArrayList();
public void init() {
log.debug("init");
}
public SelfCertItemsBean() {
log.debug("constructor");
}
public String getCurrentUserDisplayName() {
return externalLogic.getUserDisplayName(externalLogic.getCurrentUserId());
}
/**
* @param item a SelfCertItem to check
* @return true if the current user can remove or update the item
*/
public boolean canDelete(SelfCertItem item) {
log.debug("check Delete for: " + item.getId());
return logic.canWriteItem(item, externalLogic.getCurrentLocationId(),
externalLogic.getCurrentUserId());
}
/**
* @return a List of SelfCertItem objects visible to the current user in
the current site
*/
public List getAllVisibleItems() {
return logic.getAllVisibleItems(externalLogic.getCurrentLocationId(),
externalLogic.getCurrentUserId());
}
/**
* @param id the unique id of the item
* @return a SelfCertItem or null if not found
*/
public SelfCertItem getItemById(Long id) {
return logic.getItemById(id);
}
public void addOrUpdateItem(SelfCertItem item) {
logic.saveItem(item);
}
/**
* @param item a SelfCertItem to remove
* @return true if the item can be removed by the current user, false
otherwise
*/
public boolean checkRemoveItemById(Long id) {
log.debug("check and Remove for: " + id);
SelfCertItem item = logic.getItemById(id);
if ( item != null &&
logic.canWriteItem(item, externalLogic.getCurrentLocationId(),
externalLogic.getCurrentUserId()) ) {
logic.removeItem(item);
return true;
}
return false;
}
public String getUserType() {
String userId = (String)externalLogic.getCurrentUserId();
String type="";
String currentUserId="";
//User currentUsername="";
/*try{
User currentUser = userDirectoryService.getCurrentUser();
//currentUsername = userDirectoryService.getCurrentUser();
}*/
try{
user = userDirectoryService.getUser(userId);
System.out.println("**********"+user.toString()+"****");
type = user.getType();
}
catch(org.sakaiproject.user.api.UserNotDefinedException unde)
{
System.out.println(unde.getMessage());
}
catch(Exception e)
{
type = "Type NA";
System.out.println(e.getMessage());
}
return("User");
}
==========================================
"applicationcontext.xml"
==================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<!-- This file generated by Sakai App Builder -AZ -->
<beans>
<!-- list the backing beans here -->
<bean id="itemsBean"
class="org.sakaiproject.selfcert.tool.SelfCertItemsBean"
init-method="init">
<property name="logic"
ref="org.sakaiproject.selfcert.logic.SelfCertLogic" />
<property name="externalLogic"
ref="org.sakaiproject.selfcert.logic.ExternalLogic" />
<property name="UserDirectoryService"
ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="User"
ref="org.sakaiproject.user.api.User" />
</bean>
</beans>
===============================
Does I need to add/ change any other files to access "UserDirectoryService"
or "User" instances from my Tool "SelfCert"
Any Information will be highly appreciated
--
View this message in context: http://old.nabble.com/%22UserDirectoryService%22-or-%22User%22-instances-from-my-Tool-%22SelfCert%22-tp30825250p30825250.html
Sent from the Sakai - Development mailing list archive at Nabble.com.
More information about the sakai-dev
mailing list