package org.sakaiproject.scormcloudservice.impl;

import org.sakaiproject.scormcloudservice.api.ScormException;
import org.sakaiproject.scormcloudservice.api.ScormCloudService;

import com.rusticisoftware.hostedengine.client.Configuration;
import com.rusticisoftware.hostedengine.client.CourseService;
import com.rusticisoftware.hostedengine.client.ScormCloud;


class ScormCloudServiceImpl implements ScormCloudService {

    public String getScormPlayerUrl(String externalId) {
        return "http://www.sakaiproject.org";
    }

    public void addCourse(String siteId, String externalId, String resourceId) throws ScormException {
        new ScormJobStore().add(siteId, externalId, resourceId);
    }

    public void init() {
        Configuration config = new Configuration("http://thweeble:2345", "poop", "poop", "nyuclasses.10.4");
        ScormCloud.setConfiguration(config);

        try {
            CourseService service = ScormCloud.getCourseService();

            // service
            System.err.println("\n*** DEBUG " + System.currentTimeMillis() + "[ScormCloudServiceImpl.java:26 f6c163]: " + "\n    service => " + (service) + "\n");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void destroy() {
    }

}

@@ -355,16 +355,85 @@
 Cloud;%0A%0A
+import org.sakaiproject.component.cover.ServerConfigurationService;%0A%0A
 %0Aclass S
@@ -826,20 +826,19 @@
 onfig = 
-new 
+get
 Configur
@@ -847,65 +847,8 @@
 ion(
-%22http://thweeble:2345%22, %22poop%22, %22poop%22, %22nyuclasses.10.4%22
 );%0A 
@@ -1244,32 +1244,32 @@
        %7D%0A    %7D%0A%0A
-
     public void 
@@ -1287,10 +1287,770 @@
 %0A    %7D%0A%0A
+%0A    public Configuration getConfiguration() %7B%0A        String appId = ServerConfigurationService.getString(%22scormcloudservice.appid%22, %22%22);%0A        String secret = ServerConfigurationService.getString(%22scormcloudservice.secret%22, %22%22);%0A%0A        if (appId.isEmpty() %7C%7C secret.isEmpty()) %7B%0A            throw new RuntimeException(%22You need to specify scormcloudservice.appid and scormcloudservice.secret%22);%0A        %7D%0A%0A        return new Configuration(ServerConfigurationService.getString(%22scormcloudservice.url%22, %22http://cloud.scorm.com/api%22),%0A                ServerConfigurationService.getString(%22scormcloudservice.appid%22, %22%22),%0A                ServerConfigurationService.getString(%22scormcloudservice.secret%22, %22%22),%0A                %22sakai.scormcloudservice%22);%0A    %7D%0A%0A
 %7D%0A

Read config from sakai.properties