[Building Sakai] A question about how to use some APIs in project Profile2

Hai Vo Thanh v0thanhhai at yahoo.com
Thu Nov 12 22:01:39 PST 2009


i've just injected GradebookService in to SakaiProxy like this:

in SakaiProxy.java : add a prototype int getNumberOfAssignment(String gradebookUid);

in SakaiProxyImpl.java: 

            import some package:
                import org.sakaiproject.service.gradebook.shared.*;
                import org.sakaiproject.service.gradebook.shared.GradebookService;
                import org.sakaiproject.service.gradebook.shared.Assignment;
                //import org.sakaiproject.tool.gradebook.Assignment;
                import org.sakaiproject.assignment.api.*;

            create a setter for the GradebookService :
                private GradebookService gradebookService;
                 public void setGradebookService(GradebookService gradebookService){
                   this.gradebookService = gradebookService;
                }

            implement the api:
                public int getNumberOfAssignment(String gradebookUid){
                    return gradebookService.getAssignments(gradebookUid).size();
                }

in components.xml: add the following line into the bean.
                <property name="gradebookService"><ref bean="org.sakaiproject.service.gradebook.shared.GradebookService"/></property>


and when i deploy. These errors appeared:
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[40,0] package org.sakaiproject.service.gradebook.shared does not exist

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[41,49] package org.sakaiproject.service.gradebook.shared does not exist

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[42,49] package org.sakaiproject.service.gradebook.shared does not exist

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[44,0] package org.sakaiproject.assignment.api does not exist

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[913,16] cannot find symbol
symbol  : class GradebookService
location: class org.sakaiproject.profile2.logic.SakaiProxyImpl

C:\sakai\myprofile2\impl\src\java\org\sakaiproject\profile2\logic\SakaiProxyImpl
.java:[914,40] cannot find symbol
symbol  : class GradebookService
location: class org.sakaiproject.profile2.logic.SakaiProxyImpl


Did i miss any stage?
Thanks 
---------------
Hai Vo



________________________________
From: Steve Swinsburg <steve.swinsburg at gmail.com>
To: Hai Vo Thanh <v0thanhhai at yahoo.com>
Cc: sakai-dev <sakai-dev at collab.sakaiproject.org>
Sent: Fri, November 13, 2009 5:41:14 AM
Subject: Re: [Building Sakai] A question about how to use some APIs in project  Profile2

Hi,

You'll need a setter for the gradebookService API that you are injecting. Might be easiest to inject into SakaiProxy, you can see the config in components.xml already. Then add a setter to it like the rest of the Sakai services are. Then add your method stub to SakaiProxy.java and implement it in SakaiProxyImpl.java

I posted a message about which service to use in a different thread, keep an eye on responses there as well.

cheers,
Steve

On Fri, Nov 13, 2009 at 8:48 AM, Hai Vo Thanh <v0thanhhai at yahoo.com> wrote:

Hi Mr Steve Swinsburg, i am his co-worker, we are doing some expansion for the Profile2 project. At this time, we are creating a new page in the display screen ( same as My profile, Connections, Search....) this page is using for display all grades of student have had. Whenever he come to this page, he can see all his grades profile. Cause we do not want to change the original project, we created some new class in the package org.sakaiproject.profile2.tool.pages . at this time, we can get a LinkedList<String> of all site id of all course that one user joined and display it on my new page. Cause the siteId is also the gradebookUid, we try to use the GradebookService to get all the Assignment of each site, and at this state we encountered the problem.
>
>I created a new class called
> MyGradebookApi to inject the GradebookService in to our application. For testing i've create two method 
>
>   public int getNumberOfAss(String gradebookUid){
>        return gradebookService.getAssignments(gradebookUid).size();
>    }
>
>
>and......
>
>    public LinkedList<String> getAssNameList(String gradebookUid){
>   
>     LinkedList<String> assNameList =new LinkedList();
>        LinkedList<Assignment> assList = new LinkedList();
>        
>        List<Assignment> tempList = gradebookService.getAssignments(gradebookUid);
>        assList.addAll(tempList);
>   
>     
>        
>        while(!assList.isEmpty()){
>            Assignment tempAss = assList.remove();
>            String name = tempAss.getName();
>            assNameList.add(name);
>        }
>        return assNameList;
>    }
> but it seem the GradeBookService do not work, i created a cousre site, i got its siteId, i created some sample Assignment, then in my page, i called the method getNumberOfAss and try to display in my page, but nothing happened.
>
>The tool deployed sucessful, cause i modified the pom.xml to add some dependencies.
>In my class i imported:
>    import org.sakaiproject.service.gradebook.shared.*;
>    import
> org.sakaiproject.service.gradebook.shared.Assignment;
>    //import org.sakaiproject.tool.gradebook.Assignment;
>    import org.sakaiproject.assignment.api.*;
>    import java.util.LinkedList;
>    import java.util.List;
>>and create a private variable: private GradebookService gradebookService;
>
>Did i miss any step? Could you give me some advices please?
>
>Thanks and regards
>========
>Hai Vo
>
>    
>
>
________________________________
From: Steve Swinsburg <steve.swinsburg at gmail.com>
>To: Small Cat <shadowless4288 at gmail.com>
>Cc: sakai-dev at collab.sakaiproject.org
>Sent: Fri, November 13, 2009 4:08:48 AM
>Subject: Re: [Building Sakai] A question about how to use some APIs in project Profile2
>
>
>>If using Spring, inject the actual API, not the static cover. However, don't inject into the tool. 
>
>
>Since you seem to be modifying Profile2, inject the GradebookService into SakaiProxy.java which is where I have kept all Sakai related API calls. That is already injected into all Tool pages so you can just call sakaiProxy.someMethod() to do things.
>
>
>
>Could you let me know what additions you are making to Profile2? Are you wanting to contribute them back to the main release of Profile2?
>
>
>cheers,
>Steve
>
>
>
>
>On 13/11/2009, at 6:26 AM, Small Cat wrote:
>
>... I want to add a new page using gradebook service into profile 2, I name this page "MyHello.html" and implement it in MyHello.java & MyQuery.java (this class in a new package org.sakaiproject.profile2.tool.mysql    )
>>
>>I've already use some other service like database api, site service  by using cover (but I fell in using methods of adding bean in compponents.xml >"<). But the problem is that I can't found gradebook cover ...
>>>>I tried to inject it follow these steps :( I use sakai 2.5.5 )
>>- add dependency in maven file
>><dependency>
>>            <groupId>org.sakaiproject</groupId>
>>>>            <artifactId>sakai-gradebook-service-api</artifactId>
>>            <version>${sakai.version}</version>
>>        </dependency>
>>- add bean in components
>><bean id="org.sakaiproject.profile2.tool.mysql.MyQuery"
>>        class="org.sakaiproject.profile2.tool.mysql.MyQuery">
>>        <property name="gradebookService"
>>           
>> ref="org.sakaiproject.service.gradebook.shared.*">
>>        </property>
>>    </bean>
>>- coding...and this is a test function to get some assignment name ( I think gradebookId = coursesiteID , it is right ? )
>>// courseList is a list of course site id
>>public LinkedList<String> getAssignmentNameList(
>>            LinkedList<String> courseList) {
>>        LinkedList<Assignment> assignmentList = new LinkedList();
>>>>        try {
>>            while (!courseList.isEmpty()) {
>>                String tmpString =
>> courseList.remove();
>>                List<Assignment> tmpList = gradebookService
>>                        .getAssignments(tmpString);
>>                assignmentList.addAll(tmpList);
>>            }
>>        } catch (Exception e) {
>>>>            e.printStackTrace();
>>        }
>>
>>        LinkedList<String> assignmentNameList = new LinkedList();
>>        try {
>>            while (!assignmentList.isEmpty()) {
>>       
>>         assignmentNameList.add(assignmentList.remove().getName());
>>            }
>>        } catch (Exception e) {
>>            e.printStackTrace();
>>        }
>>        return assignmentNameList;
>>    }
>>>>/**************************************************************/
>>
>> I tried like that in Sakai and it return nothing >"<. 
>>Can anyone help me ?
>>
>>
>>
>>
>>>>2009/11/6 Steve Swinsburg <steve.swinsburg at gmail.com>
>>
>>You've got a ; in the bean definitions, not sure if that matters too much though. But as for the dependency in the pom, if matters if you are on 2.5 or 2.6+. If 2.6 then you don't need that dependency as its in the kernel but for 2.5 you will.
>>>
>>>
>>>Also, are you modifying the current Profile2 tool? ie 
>>>http://confluence.sakaiproject.org/display/PROFILE/Profile2
>>>
>>>
>>>I am currently polishing up release of Profile2 for possible inclusion in 2.7 so it would be good to coordinate efforts here.
>>>
>>>
>>>cheers,
>>>Steve
>>>
>>>
>>>
>>>
>>>On 06/11/2009, at 3:47 PM, Small Cat wrote:
>>>
>>>Hi,
>>>>In the components.xml, I added a bean for my class as :
>>>>
>>>><!--  MyPortfolios -->
>>>>    <bean id = "org.sakaiproject.profile2.tool.myportfolios.MyPortfolios;" 
>>>>>>>>        class="org.sakaiproject.profile2.tool.myportfolios.MyPortfolios;">
>>>>        
>>>>        <property name="siteService" ref="org.sakaiproject.site.api.SiteService"/>
>>>>>>>>        
>>>>    </bean>
>>>>In relevant pom.xml , I added :
>>>><dependency>
>>>>               
>>>>     <groupId>org.sakaiproject</groupId>
>>>>                    <artifactId>sakai-site-api</artifactId>
>>>>                    <scope>provided</scope>
>>>>                </dependency>
>>>>
>>>>Is this right ?
>>>>Thanks ,
>>>>
>>>>
>>>>
>>>>2009/11/6 Steve Swinsburg <steve.swinsburg at gmail.com>
>>>>
>>>>Hi,
>>>>>
>>>>>
>>>>>Are you making an addition to
>>>>> Profile2 that you might like to contribute back? If so, thats great! Could you possibly Jira it here:
>>>>>http://jira.sakaiproject.org/browse/PRFL
>>>>>
>>>>>
>>>>>For your issue, it's most likely an API injection issue. You'll need to make sure you have the dependency in the relevant POM and in the components.xml so Spring can inject it into the beans. However if you Jira this task we can go over the goal and implementation details.
>>>>>
>>>>>
>>>>>cheers,
>>>>>Steve
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>On 06/11/2009, at 1:51 AM, Small Cat wrote:
>>>>>
>>>>>Dear all,
>>>>>>I want to add some functions for Profile2, and one of them can show all scores of assigments in all course sites...
>>>>>>But I can't use some APIs as getSites.... ( I can use it in other
>>>>>> tools, but in Profile2 I don't know why it can't )
>>>>>>This is error when I deploy :
>>>>>>
>>>>>>[ERROR] BUILD FAILURE
>>>>>>[INFO] ------------------------------------------------------------------------
>>>>>>[INFO] Compilation failure
>>>>>>
>>>>>>C:\sakai\profile2-1.2.1\tool\src\java\org\sakaiproject\profile2\tool\myportfolio
>>>>>>s\MyPortfolios.java:[22,52] cannot access org.sakaiproject.entity.api.EntityProd
>>>>>>ucer
>>>>>>file org\sakaiproject\entity\api\EntityProducer.class not found
>>>>>>>>>>>>                        courseSiteList = siteService.getSites(SelectionType.ACCE
>>>>>>SS,
>>>>>>
>>>>>>C:\sakai\profile2-1.2.1\tool\src\java\org\sakaiproject\profile2\tool\myportfolio
>>>>>>s\MyPortfolios.java:[35,60] cannot access org.sakaiproject.entity.api.Edit
>>>>>>>>>>>>file org\sakaiproject\entity\api\Edit.class not
>>>>>> found
>>>>>>                        courseList.add(courseSiteList.remove(0).getTitle());
>>>>>>
>>>>>>How to use getSites in Profile2 , if can not, what methods I can use to replace ?
>>>>>>Thank you,
>>>>>>-- 
>>>>>>>>>>>>Regards,
>>>>>>Tran Trung Kien
>>>>>>_______________________________________________
>>>>>>sakai-dev mailing list
>>>>>>sakai-dev at collab.sakaiproject.org
>>>>>>http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>
>>>>>>TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"
>>>>>
>>>>
>>>>
>>>>-- 
>>>>Regards,
>>>>Tran Trung Kien
>>>>
>>>
>>
>>
>>-- 
>>>>Regards,
>>Tran Trung Kien
>><MyHello.html><MyQuery.java><MyHello.java>
>
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20091112/93ca72b3/attachment.html 


More information about the sakai-dev mailing list