use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class FIBScoreController method sync.
@Override
public void sync(UserRequest ureq, AssessmentItemBuilder assessmentItemBuilder) {
if (itemBuilder == assessmentItemBuilder) {
List<AbstractEntry> entries = itemBuilder.getOrderedTextEntries();
for (AbstractEntry entry : entries) {
FIBEntryWrapper wrapper = getTextEntryWrapper(entry);
if (wrapper == null) {
wrappers.add(createTextEntryWrapper(entry));
}
}
// remove removed entry
for (Iterator<FIBEntryWrapper> wrapperIt = wrappers.iterator(); wrapperIt.hasNext(); ) {
Identifier responseIdentifier = wrapperIt.next().getEntry().getResponseIdentifier();
if (itemBuilder.getTextEntry(responseIdentifier.toString()) == null) {
wrapperIt.remove();
}
}
// reorder the wrappers
Map<AbstractEntry, FIBEntryWrapper> wrapperMap = new HashMap<>();
for (FIBEntryWrapper wrapper : wrappers) {
wrapperMap.put(wrapper.getEntry(), wrapper);
}
List<FIBEntryWrapper> reorderedWrappers = new ArrayList<>();
for (AbstractEntry entry : entries) {
FIBEntryWrapper wrapper = wrapperMap.get(entry);
if (wrapper != null) {
reorderedWrappers.add(wrapper);
wrapperMap.remove(entry);
}
}
if (wrapperMap.size() > 0) {
// paranoid security
for (FIBEntryWrapper wrapper : wrapperMap.values()) {
if (!reorderedWrappers.contains(wrapper)) {
reorderedWrappers.add(wrapper);
}
}
}
wrappers.clear();
wrappers.addAll(reorderedWrappers);
}
}
Aggregations