[sakai-dev] adding course management data to Sakai 11 via a simple Java console application

classic Classic list List threaded Threaded
4 messages Options
Ethan Schulton Ethan Schulton
Reply | Threaded
Open this post in threaded view
|

[sakai-dev] adding course management data to Sakai 11 via a simple Java console application

Hello Sakai Developer Community,

Is it possible to invoke the steps demonstrated in SampleDataLoader from a simple Java console application?  The following code (when placed in the same directory as SampleDataLoader.java) compiles successfully with Maven:

---

package org.sakaiproject.coursemanagement.impl;

import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.coursemanagement.api.AcademicSession;
import org.sakaiproject.coursemanagement.api.CanonicalCourse;
import org.sakaiproject.coursemanagement.api.CourseManagementAdministration;
import org.sakaiproject.coursemanagement.api.CourseManagementService;
import org.sakaiproject.coursemanagement.api.CourseOffering;
import org.sakaiproject.coursemanagement.api.EnrollmentSet;
import org.sakaiproject.coursemanagement.api.Meeting;
import org.sakaiproject.coursemanagement.api.Section;
import org.sakaiproject.coursemanagement.api.SectionCategory;
import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.event.cover.UsageSessionService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;

public class NewDataLoad {

        public static void main(String[] args) {

                // log into Sakai
                Session sakaiSession = SessionManager.getCurrentSession();
                sakaiSession.setUserId("admin");
                sakaiSession.setUserId("admin");
                UsageSessionService.startSession("admin", "127.0.0.1", "CMSync");
                EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, null, true));

                // log off of Sakai
                sakaiSession.invalidate();
                EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGOUT, null, true));

        }
}

---

However, when I execute the class using the Maven Exec Plugin on a machine hosting an instance of Sakai 11:

mvn exec:java -Dexec.mainClass=org.sakaiproject.coursemanagement.impl.NewDataLoad

I get the following error:

Caused by: java.lang.NoClassDefFoundError: org/sakaiproject/tool/cover/SessionManager at org.sakaiproject.coursemanagement.impl.NewDataLoad.main(NewDataLoad.java:23)
...
An exception occured while executing the Java class. null: InvocationTargetException: org/sakaiproject/tool/cover/SessionManager: org.sakaiproject.tool.cover.SessionManager

Any help would be appreciated.

Thanks so much in advance,
Ethan Schulton


Ethan Schulton
Phone: <a href="tel:(503)%20966-1660" value="+15039661660" target="_blank">503-966-1660 x 103
Fax: <a href="tel:(503)%20575-7022" value="+15035757022" target="_blank">503-575-7022
ScholarChip Card, LLC

Notice: This email message, including any attachments, is for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. Please note that messages may be subject to the confidentiality provisions of the Family Education Rights and Privacy Act (FERPA).

--
You received this message because you are subscribed to the Google Groups "Sakai Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/a/apereo.org/group/sakai-dev/.
Hendrik Steller Hendrik Steller
Reply | Threaded
Open this post in threaded view
|

Re: [sakai-dev] adding course management data to Sakai 11 via a simple Java console application

On Friday 16 December 2016 17:22:26 Ethan Schulton wrote:
> Hello Sakai Developer Community,
>
> Is it possible to invoke the steps demonstrated in SampleDataLoader from a
> simple Java console application?  The following code (when placed in the
> same directory as SampleDataLoader.java) compiles successfully with Maven:

Uh, I don't know; it *might* be possible.
But I'm pretty certain that it would be faster to use the existing web
services (or write your own endpoint to do exactly what you need) or bypass
the sakai APIs and access the DB directly if I needed a console application to
import data.

Nevertheless, some thinking out loud how I would approach this (except asking
the same question you just did..):

The first thing I would do is take a nap and think about CLASSPATH issues,
which is were your error message will have come from:
There's an awful lot of stuff which is shared by all tools and "provided"
(literally and as a maven scope) at runtime by Tomcat.
All the APIs, the JDBC driver etc in tomcat/lib and then the actual
implementation of the API interfaces from the subfolders in tomcat/components.
So the first thing would be to add all that non-tomcat-related stuff you need
from tomcat/lib to your classpath.

With tomcat/components it's trickier, since that isn't a standard tomcat
folder and each component in it will expect to be loaded in its own
classloader, so just throwing everything in there into the classpath might
result in a bunch of conflicts.
Then again, that architecture isn't tomcat-standard, so there should be code
in Sakai that's responsible for sorting all that out.
Where?
Uh..something related to component management would be my guess. Maybe we're
lucky and this code works unchanged with or without tomcat (given that
components use Java's standard class loader delegation model and not the one
for application servers, the odds aren't too bad).

Apropos components:
Having the classes on your classpath isn't going to be enough.
The next thing will be to initialize the Component Manager to build the Spring
ApplicationContext backing the whole thing so that it can inject all the
dependencies into the components (the service implementations).
org.sakaiproject.component.impl.SpringCompMgr looks like a good place to have
a look at; seems like it looks for a configuration file on the classpath.

Should that all work somehow, then you could think about having the API
services you want to use injected into your application. Or ask that
CompoentManager instance which you probably created in the previous step for a
reference (which is kinda what you tried in your code snippet by using a
"cover" class).

And then we hope that everything everywhere works without an Httpsession in
the background or that one can provide a mock for it should it be needed.


And now that I've written all this rubbish, I'm waiting for a core developer
to jump in and say:

"Sure thing! Just get the sakai-swingclient maven archetype from my github and
type 'mvn spring-boot:run' for a Tetris sample application that saves the
players highscores as gradebook items" .
;-)

Hendrik


--
You received this message because you are subscribed to the Google Groups "Sakai Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/a/apereo.org/group/sakai-dev/.
Ethan Schulton Ethan Schulton
Reply | Threaded
Open this post in threaded view
|

Re: [sakai-dev] adding course management data to Sakai 11 via a simple Java console application

Hi Hendrik,

Thank you so much for your response!  I started to go down the Java console app road because I hit a brick wall with REST.  I posted the following message to [hidden email] earlier today ([hidden email] was eventually included):

Hello Sakai Community,
I am trying to add course management data to a Sakai 11 instance via REST.  I am able to successfully add Academic Sessions, Canonical Courses, Course Offerings, and Course Sets.  However, I am unsure how to associate a Course Offering with a Course Set via REST.  Any help would be appreciated.  I am new to Sakai, so if this is not the proper venue for such a question, please let me know and I will post elsewhere.
Regards,
Ethan
P.S.  My end goal is to perform many of the same operations demonstrated in SampleDataLoader via REST.  Please let me know if this is a fools errand - perhaps the REST API does not allow for performing all such operations.

So, for SampleDataLoader Tomcat provides essential run-time elements for session management.  Does this also hold for the Quartz job example?


Do Quartz jobs utilize Tomcat for session management?  I'm just trying to pin down the most robust (yet least complicated) way of loading course management data into Sakai 11.

Thanks again,
Ethan


Ethan Schulton
Phone: 503-966-1660 x 103
Fax: 503-575-7022
ScholarChip Card, LLC

On Fri, Dec 16, 2016 at 6:53 PM, Hendrik Steller <[hidden email]> wrote:
On Friday 16 December 2016 17:22:26 Ethan Schulton wrote:
> Hello Sakai Developer Community,
>
> Is it possible to invoke the steps demonstrated in SampleDataLoader from a
> simple Java console application?  The following code (when placed in the
> same directory as SampleDataLoader.java) compiles successfully with Maven:

Uh, I don't know; it *might* be possible.
But I'm pretty certain that it would be faster to use the existing web
services (or write your own endpoint to do exactly what you need) or bypass
the sakai APIs and access the DB directly if I needed a console application to
import data.

Nevertheless, some thinking out loud how I would approach this (except asking
the same question you just did..):

The first thing I would do is take a nap and think about CLASSPATH issues,
which is were your error message will have come from:
There's an awful lot of stuff which is shared by all tools and "provided"
(literally and as a maven scope) at runtime by Tomcat.
All the APIs, the JDBC driver etc in tomcat/lib and then the actual
implementation of the API interfaces from the subfolders in tomcat/components.
So the first thing would be to add all that non-tomcat-related stuff you need
from tomcat/lib to your classpath.

With tomcat/components it's trickier, since that isn't a standard tomcat
folder and each component in it will expect to be loaded in its own
classloader, so just throwing everything in there into the classpath might
result in a bunch of conflicts.
Then again, that architecture isn't tomcat-standard, so there should be code
in Sakai that's responsible for sorting all that out.
Where?
Uh..something related to component management would be my guess. Maybe we're
lucky and this code works unchanged with or without tomcat (given that
components use Java's standard class loader delegation model and not the one
for application servers, the odds aren't too bad).

Apropos components:
Having the classes on your classpath isn't going to be enough.
The next thing will be to initialize the Component Manager to build the Spring
ApplicationContext backing the whole thing so that it can inject all the
dependencies into the components (the service implementations).
org.sakaiproject.component.impl.SpringCompMgr looks like a good place to have
a look at; seems like it looks for a configuration file on the classpath.

Should that all work somehow, then you could think about having the API
services you want to use injected into your application. Or ask that
CompoentManager instance which you probably created in the previous step for a
reference (which is kinda what you tried in your code snippet by using a
"cover" class).

And then we hope that everything everywhere works without an Httpsession in
the background or that one can provide a mock for it should it be needed.


And now that I've written all this rubbish, I'm waiting for a core developer
to jump in and say:

"Sure thing! Just get the sakai-swingclient maven archetype from my github and
type 'mvn spring-boot:run' for a Tetris sample application that saves the
players highscores as gradebook items" .
;-)

Hendrik




Notice: This email message, including any attachments, is for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. Please note that messages may be subject to the confidentiality provisions of the Family Education Rights and Privacy Act (FERPA).

--
You received this message because you are subscribed to the Google Groups "Sakai Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/a/apereo.org/group/sakai-dev/.
Shoji Kajita-2 Shoji Kajita-2
Reply | Threaded
Open this post in threaded view
|

Re: [sakai-dev] adding course management data to Sakai 11 via a simple Java console application

Dear Ethan,
Cc: Sakai Dev

At Kyoto University, we are also trying to add course management data to a Sakai 11 instance via REST APIs, but we were able to add successfully Academic Sessions only.

Could you share your sample codes with us to add other data including Canonical Courses, Course Offerings and Course Sets?

Best regards,
Shoji

On Dec 17, 2016, at 9:34, Ethan Schulton <[hidden email]> wrote:

Hi Hendrik,

Thank you so much for your response!  I started to go down the Java console app road because I hit a brick wall with REST.  I posted the following message to [hidden email] earlier today ([hidden email] was eventually included):

Hello Sakai Community,
I am trying to add course management data to a Sakai 11 instance via REST.  I am able to successfully add Academic Sessions, Canonical Courses, Course Offerings, and Course Sets.  However, I am unsure how to associate a Course Offering with a Course Set via REST.  Any help would be appreciated.  I am new to Sakai, so if this is not the proper venue for such a question, please let me know and I will post elsewhere.
Regards,
Ethan
P.S.  My end goal is to perform many of the same operations demonstrated in SampleDataLoader via REST.  Please let me know if this is a fools errand - perhaps the REST API does not allow for performing all such operations.

So, for SampleDataLoader Tomcat provides essential run-time elements for session management.  Does this also hold for the Quartz job example?


Do Quartz jobs utilize Tomcat for session management?  I'm just trying to pin down the most robust (yet least complicated) way of loading course management data into Sakai 11.

Thanks again,
Ethan


Ethan Schulton
Phone: 503-966-1660 x 103
Fax: 503-575-7022
ScholarChip Card, LLC

On Fri, Dec 16, 2016 at 6:53 PM, Hendrik Steller <[hidden email]> wrote:
On Friday 16 December 2016 17:22:26 Ethan Schulton wrote:
> Hello Sakai Developer Community,
>
> Is it possible to invoke the steps demonstrated in SampleDataLoader from a
> simple Java console application?  The following code (when placed in the
> same directory as SampleDataLoader.java) compiles successfully with Maven:

Uh, I don't know; it *might* be possible.
But I'm pretty certain that it would be faster to use the existing web
services (or write your own endpoint to do exactly what you need) or bypass
the sakai APIs and access the DB directly if I needed a console application to
import data.

Nevertheless, some thinking out loud how I would approach this (except asking
the same question you just did..):

The first thing I would do is take a nap and think about CLASSPATH issues,
which is were your error message will have come from:
There's an awful lot of stuff which is shared by all tools and "provided"
(literally and as a maven scope) at runtime by Tomcat.
All the APIs, the JDBC driver etc in tomcat/lib and then the actual
implementation of the API interfaces from the subfolders in tomcat/components.
So the first thing would be to add all that non-tomcat-related stuff you need
from tomcat/lib to your classpath.

With tomcat/components it's trickier, since that isn't a standard tomcat
folder and each component in it will expect to be loaded in its own
classloader, so just throwing everything in there into the classpath might
result in a bunch of conflicts.
Then again, that architecture isn't tomcat-standard, so there should be code
in Sakai that's responsible for sorting all that out.
Where?
Uh..something related to component management would be my guess. Maybe we're
lucky and this code works unchanged with or without tomcat (given that
components use Java's standard class loader delegation model and not the one
for application servers, the odds aren't too bad).

Apropos components:
Having the classes on your classpath isn't going to be enough.
The next thing will be to initialize the Component Manager to build the Spring
ApplicationContext backing the whole thing so that it can inject all the
dependencies into the components (the service implementations).
org.sakaiproject.component.impl.SpringCompMgr looks like a good place to have
a look at; seems like it looks for a configuration file on the classpath.

Should that all work somehow, then you could think about having the API
services you want to use injected into your application. Or ask that
CompoentManager instance which you probably created in the previous step for a
reference (which is kinda what you tried in your code snippet by using a
"cover" class).

And then we hope that everything everywhere works without an Httpsession in
the background or that one can provide a mock for it should it be needed.


And now that I've written all this rubbish, I'm waiting for a core developer
to jump in and say:

"Sure thing! Just get the sakai-swingclient maven archetype from my github and
type 'mvn spring-boot:run' for a Tetris sample application that saves the
players highscores as gradebook items" .
;-)

Hendrik




Notice: This email message, including any attachments, is for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. Please note that messages may be subject to the confidentiality provisions of the Family Education Rights and Privacy Act (FERPA).


-- 
You received this message because you are subscribed to the Google Groups "Sakai Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/a/apereo.org/group/sakai-dev/.

--
You received this message because you are subscribed to the Google Groups "Sakai Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/a/apereo.org/group/sakai-dev/.