use of org.olat.modules.scorm.server.beans.LMSDataHandler in project OpenOLAT by OpenOLAT.
the class OLATApiAdapter method getNextSco.
/**
* @param recentId
* @return the next Sco itemId
*/
public Integer getNextSco(String recentId) {
// TODO:gs make method faster by chaching lmsBean, but when to set out of date?
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(recentId);
lmsDataBean.setLmsAction("get");
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
LMSResultsBean lmsBean = odatahandler.getResultsBean();
String[][] pretable = lmsBean.getPreReqTable();
String nextNavScoId = "-1";
for (int i = 0; i < pretable.length; i++) {
if (pretable[i][0].equals(recentId) && (i != pretable.length - 1)) {
nextNavScoId = pretable[++i][0];
break;
}
}
return new Integer(nextNavScoId);
}
use of org.olat.modules.scorm.server.beans.LMSDataHandler in project OpenOLAT by OpenOLAT.
the class OLATApiAdapter method olatCommit.
/**
* @param isACommit true, if the call comes from a lmscommit, false if it comes from a lmsfinish
* @return
*/
private final String olatCommit(boolean isACommit) {
if (olatScoId == null)
return "false";
core.transEnd();
@SuppressWarnings("unchecked") Hashtable<String, String> ins = core.getTransNew();
@SuppressWarnings("unchecked") Hashtable<String, String> mod = core.getTransMod();
core.transBegin();
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(olatScoId);
// TODO:gs pass the dataBean for use, and do not get it a second time
lmsDataBean.setNextAction("5");
lmsDataBean.setLmsAction("update");
Map<String, String> cmiData = new HashMap<String, String>();
// TODO:gs:c make it possible only to update the changed cmi data.
if (ins.size() > 0) {
Set<String> set = ins.keySet();
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
String cmi = it.next();
olatScoCmi.remove(cmi);
olatScoCmi.put(cmi, ins.get(cmi));
}
}
if (mod.size() > 0) {
Set<String> set = mod.keySet();
for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
String cmi = it.next();
olatScoCmi.remove(cmi);
olatScoCmi.put(cmi, mod.get(cmi));
}
}
cmiData.putAll(olatScoCmi);
// work around for missing cmi's (needed by reload code, but not used in ilias code)
if (cmiData.get("cmi.interactions._count") != null && cmiData.get("cmi.interactions._count") != "0") {
int count = Integer.parseInt(cmiData.get("cmi.interactions._count"));
for (int i = 0; i < count; i++) {
// OLAT-4271: check first if cmi.interactions.n.objectives._count exist before putting a default one
String objectivesCount = cmiData.get("cmi.interactions." + i + ".objectives._count");
if (!StringHelper.containsNonWhitespace(objectivesCount)) {
cmiData.put("cmi.interactions." + i + ".objectives._count", "0");
}
}
}
if (isACommit) {
String rawScore = cmiData.get(SCORE_IDENT);
String lessonStatus = cmiData.get(LESSON_STATUS_IDENT);
if (StringHelper.containsNonWhitespace(rawScore) || StringHelper.containsNonWhitespace(lessonStatus)) {
// to prevent problems with bad xmlhttprequest timings
synchronized (this) {
// o_clusterOK by:fj: instance is spawned by the ScormAPIandDisplayController
if (StringHelper.containsNonWhitespace(rawScore)) {
scoresProp.put(olatScoId, rawScore);
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(scorePropsFile));
scoresProp.store(os, null);
} catch (IOException e) {
throw new OLATRuntimeException(this.getClass(), "could not save scorm-properties-file: " + scorePropsFile.getAbsolutePath(), e);
} finally {
FileUtils.closeSafely(os);
}
}
if (StringHelper.containsNonWhitespace(lessonStatus)) {
lessonStatusProp.put(olatScoId, lessonStatus);
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(lessonStatusPropsFile));
lessonStatusProp.store(os, null);
} catch (IOException e) {
throw new OLATRuntimeException(this.getClass(), "could not save scorm-properties-file: " + scorePropsFile.getAbsolutePath(), e);
} finally {
FileUtils.closeSafely(os);
}
}
// notify
if (!apiCallbacks.isEmpty()) {
for (ScormAPICallback apiCallback : apiCallbacks) {
apiCallback.lmsCommit(olatScoId, scoresProp, lessonStatusProp);
}
}
}
}
// <OLATCE-289>
} else {
// if "isACommit" is false, this is a lmsFinish and the apiCallback shall save the points an passed information
if (!apiCallbacks.isEmpty()) {
String rawScore = cmiData.get(SCORE_IDENT);
if (rawScore != null && !rawScore.equals("")) {
scoresProp.put(olatScoId, rawScore);
}
String lessonStatus = cmiData.get(LESSON_STATUS_IDENT);
if (StringHelper.containsNonWhitespace(lessonStatus)) {
lessonStatusProp.put(olatScoId, lessonStatus);
}
for (ScormAPICallback apiCallback : apiCallbacks) {
apiCallback.lmsFinish(olatScoId, scoresProp, lessonStatusProp);
}
}
// </OLATCE-289>
}
try {
lmsDataBean.setDataAsMap(cmiData);
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
odatahandler.updateCMIData(olatScoId);
return "true";
} catch (Exception e) {
logError("Error during commit", e);
return "false";
}
}
use of org.olat.modules.scorm.server.beans.LMSDataHandler in project OpenOLAT by OpenOLAT.
the class OLATApiAdapter method isItemCompleted.
// </OLATCE-289>
/**
* @param itemId
* @return true if the item is completed
*/
public boolean isItemCompleted(String itemId) {
// TODO:gs make method faster by caching lmsBean, but when to set out of date?
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(itemId);
lmsDataBean.setLmsAction("get");
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
LMSResultsBean lmsBean = odatahandler.getResultsBean();
return lmsBean.getIsItemCompleted().equals("true");
}
use of org.olat.modules.scorm.server.beans.LMSDataHandler in project OpenOLAT by OpenOLAT.
the class OLATApiAdapter method getPreviousSco.
/**
* @param recentId
* @return the previos Sco itemId
*/
public Integer getPreviousSco(String recentId) {
// TODO:gs make method faster by caching lmsBean, but when to set out of date?
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(recentId);
lmsDataBean.setLmsAction("get");
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
LMSResultsBean lmsBean = odatahandler.getResultsBean();
String[][] pretable = lmsBean.getPreReqTable();
String previousNavScoId = "-1";
for (int i = 0; i < pretable.length; i++) {
if (pretable[i][0].equals(recentId) && (i != 0)) {
previousNavScoId = pretable[--i][0];
break;
}
}
return new Integer(previousNavScoId);
}
use of org.olat.modules.scorm.server.beans.LMSDataHandler in project openolat by klemens.
the class OLATApiAdapter method hasItemPrerequisites.
/**
* @param itemId
* @return true if item has any not fullfilled preconditions
*/
public boolean hasItemPrerequisites(String itemId) {
// TODO:gs make method faster by caching lmsBean, but when to set out of date?
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(itemId);
lmsDataBean.setLmsAction("get");
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
LMSResultsBean lmsBean = odatahandler.getResultsBean();
return lmsBean.getHasPrerequisites().equals("true");
}
Aggregations