//StringBuilder P = new StringBuilder();
Hashtable ins = core.getTransNew ();
Hashtable mod = core.getTransMod ();
core.transBegin();
LMSDataFormBean lmsDataBean = new LMSDataFormBean();
lmsDataBean.setItemID(olatSahsId);
//TODO:gs pass the dataBean for use, and do not get it a second time
lmsDataBean.setNextAction("5");
lmsDataBean.setLmsAction("update");
Map cmiData = new HashMap();
//TODO:gs:c make it possible only to update the changed cmi data.
if (ins.size() > 0){
Set set = ins.keySet();
for(Iterator it = set.iterator();it.hasNext();){
String cmi = (String)it.next();
olatScoCmi.remove(cmi);
olatScoCmi.put(cmi,ins.get(cmi));
}
}
if(mod.size() > 0){
Set set = mod.keySet();
for(Iterator it = set.iterator();it.hasNext();){
String cmi = (String)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((String)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 = (String)cmiData.get("cmi.interactions."+ i +".objectives._count");
if(!StringHelper.containsNonWhitespace(objectivesCount)) {
cmiData.put("cmi.interactions."+ i +".objectives._count","0");
}
}
}
if (isACommit) {
String rawScore = (String) cmiData.get(SCORE_IDENT);
if (rawScore != null && !rawScore.equals("")) {
// we have a score set in this sco.
// persist
// to prevent problems with bad xmlhttprequest timings
synchronized(this) { //o_clusterOK by:fj: instance is spawned by the ScormAPIandDisplayController
scoresProp.put(olatSahsId, 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);
}
// notify
if (apiCallback != null) {
apiCallback.lmsCommit(olatSahsId, scoresProp);
}
}
}
}
lmsDataBean.setDataAsMap(cmiData);
odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
odatahandler.updateCMIData(olatSahsId);
return "true";
}