use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project OpenOLAT by OpenOLAT.
the class DataStepForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_bulk_assessment_data");
// hide data input field in case the element does not have any score, passed or comment field enabled
BulkAssessmentSettings settings = new BulkAssessmentSettings(courseNode);
boolean onlyReturnFiles = (!settings.isHasScore() && !settings.isHasPassed() && !settings.isHasUserComment());
setFormTitle("data.title");
if (!onlyReturnFiles) {
setFormDescription("data.description");
}
setFormContextHelp("Using Course Tools#bulkassessment_data");
String dataVal = "";
if (savedDatas != null && StringHelper.containsNonWhitespace(savedDatas.getDataBackupFile())) {
OlatRootFileImpl file = new OlatRootFileImpl(savedDatas.getDataBackupFile(), null);
InputStream in = file.getInputStream();
try {
dataVal = IOUtils.toString(in, "UTF-8");
} catch (IOException e) {
logError("", e);
} finally {
IOUtils.closeQuietly(in);
}
}
dataEl = uifactory.addTextAreaElement("data", "data", -1, 6, 60, true, dataVal, formLayout);
dataEl.showLabel(false);
String[] values = new String[] { translate("form.step3.delimiter.tab"), translate("form.step3.delimiter.comma") };
delimiter = uifactory.addRadiosVertical("delimiter", "form.step3.delimiter", formLayout, keys, values);
// preset delimiter type to first appearance of either tab or comma when data is available, default to tab for no data
int firstComma = dataVal.indexOf(",");
int firstTab = dataVal.indexOf("\t");
if (firstComma > -1 && (firstTab == -1 || firstTab > firstComma)) {
delimiter.select("comma", true);
} else {
delimiter.select("tab", true);
}
// hide data input field in case the element does not have any score, passed or comment field enabled
if (onlyReturnFiles) {
dataEl.setVisible(false);
delimiter.setVisible(false);
}
// return files only when configured
if (settings.isHasReturnFiles()) {
returnFileEl = uifactory.addFileElement(getWindowControl(), "returnfiles", "return.files", formLayout);
Set<String> mimes = new HashSet<String>();
mimes.add(WebappHelper.getMimeType("file.zip"));
returnFileEl.limitToMimeType(mimes, "return.mime", null);
if (savedDatas != null && StringHelper.containsNonWhitespace(savedDatas.getReturnFiles())) {
targetArchive = new OlatRootFileImpl(savedDatas.getReturnFiles(), null);
if (targetArchive.exists()) {
returnFileEl.setInitialFile(targetArchive.getBasefile());
}
}
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.
the class VFSManager method resolveFile.
/**
* @see org.olat.core.util.vfs.VFSItem#resolveFile(java.lang.String)
*/
public static VFSItem resolveFile(VFSContainer rootContainer, String path) {
path = VFSManager.sanitizePath(path);
if (path.equals("/")) {
// slash or empty path -> return this vfsitem
return rootContainer;
}
// to be returned as, the proper type of, VFSItem.
if (rootContainer instanceof LocalFolderImpl) {
String childName = extractChild(path);
LocalFolderImpl l = (LocalFolderImpl) rootContainer;
File t = new File(l.getBasefile().getAbsolutePath(), childName);
if (t.exists()) {
String bcroot = FolderConfig.getCanonicalRoot();
String fsPath = t.getAbsolutePath();
if (t.isDirectory()) {
VFSContainer subContainer;
if (fsPath.startsWith(bcroot)) {
fsPath = fsPath.substring(bcroot.length(), fsPath.length());
subContainer = new OlatRootFolderImpl(fsPath, rootContainer);
} else {
subContainer = new LocalFolderImpl(t, rootContainer);
}
String subPath = path.substring(childName.length() + 1);
return resolveFile(subContainer, subPath);
} else {
if (fsPath.startsWith(bcroot)) {
fsPath = fsPath.replace(bcroot, "");
return new OlatRootFileImpl(fsPath, rootContainer);
} else {
return new LocalFileImpl(t, rootContainer);
}
}
} else {
return null;
}
}
// leave original code block as fall-back for non-file-system-based implementations
String childName = extractChild(path);
List<VFSItem> children = rootContainer.getItems();
for (VFSItem child : children) {
String curName = child.getName();
if (childName.equals(curName)) {
// found , let child further resolve if needed
return child.resolve(path.substring(childName.length() + 1));
}
}
return null;
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.
the class BulkAssessmentTask method doProcess.
private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
final DB dbInstance = DBFactory.getInstance();
final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
final ICourse course = CourseFactory.loadCourse(courseRes);
final AssessableCourseNode courseNode = getCourseNode();
final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
final boolean hasUserComment = courseNode.hasCommentConfigured();
final boolean hasScore = courseNode.hasScoreConfigured();
final boolean hasPassed = courseNode.hasPassedConfigured();
final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
if (hasReturnFiles) {
try {
OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
String tmp = FolderConfig.getCanonicalTmpDir();
unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
unzipped.mkdirs();
ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
} catch (Exception e) {
log.error("Cannot unzip the return files during bulk assessment", e);
}
}
Float min = null;
Float max = null;
Float cut = null;
if (hasScore) {
min = courseNode.getMinScoreConfiguration();
max = courseNode.getMaxScoreConfiguration();
}
if (hasPassed) {
cut = courseNode.getCutValueConfiguration();
}
int count = 0;
List<BulkAssessmentRow> rows = datas.getRows();
for (BulkAssessmentRow row : rows) {
Long identityKey = row.getIdentityKey();
if (identityKey == null) {
feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
// nothing to do
continue;
}
Identity identity = securityManager.loadIdentityByKey(identityKey);
IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
// update comment, empty string will reset comment
String userComment = row.getComment();
if (hasUserComment && userComment != null) {
// Update userComment in db
courseNode.updateUserUserComment(userComment, uce, coachIdentity);
// LD: why do we have to update the efficiency statement?
// EfficiencyStatementManager esm = EfficiencyStatementManager.getInstance();
// esm.updateUserEfficiencyStatement(uce);
}
// update score
Float score = row.getScore();
if (hasScore && score != null) {
// score < minimum score
if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
// "bulk.action.lessThanMin";
} else // score > maximum score
if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
// "bulk.action.greaterThanMax";
} else {
// score between minimum and maximum score
ScoreEvaluation se;
if (hasPassed && cut != null) {
Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
se = new ScoreEvaluation(score, passed);
} else {
se = new ScoreEvaluation(score, null);
}
// Update score,passed properties in db, and the user's efficiency statement
courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
}
}
Boolean passed = row.getPassed();
if (hasPassed && passed != null && cut == null) {
// Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
Float oldScore = seOld.getScore();
ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
// Update score,passed properties in db, and the user's efficiency statement
boolean incrementAttempts = false;
courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
}
boolean identityHasReturnFile = false;
if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
String assessedId = row.getAssessedId();
File assessedFolder = new File(unzipped, assessedId);
identityHasReturnFile = assessedFolder.exists();
if (identityHasReturnFile) {
processReturnFile(courseNode, row, uce, assessedFolder);
}
}
if (courseNode instanceof GTACourseNode) {
// push the state further
GTACourseNode gtaNode = (GTACourseNode) courseNode;
if ((hasScore && score != null) || (hasPassed && passed != null)) {
// pushed to graded
updateTasksState(gtaNode, uce, TaskProcess.grading);
} else if (hasReturnFiles) {
// push to revised
updateTasksState(gtaNode, uce, TaskProcess.correction);
}
}
if (count++ % 5 == 0) {
dbInstance.commitAndCloseSession();
} else {
dbInstance.commit();
}
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.
the class DataStepForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_bulk_assessment_data");
// hide data input field in case the element does not have any score, passed or comment field enabled
BulkAssessmentSettings settings = new BulkAssessmentSettings(courseNode);
boolean onlyReturnFiles = (!settings.isHasScore() && !settings.isHasPassed() && !settings.isHasUserComment());
setFormTitle("data.title");
if (!onlyReturnFiles) {
setFormDescription("data.description");
}
setFormContextHelp("Using Course Tools#bulkassessment_data");
String dataVal = "";
if (savedDatas != null && StringHelper.containsNonWhitespace(savedDatas.getDataBackupFile())) {
OlatRootFileImpl file = new OlatRootFileImpl(savedDatas.getDataBackupFile(), null);
InputStream in = file.getInputStream();
try {
dataVal = IOUtils.toString(in, "UTF-8");
} catch (IOException e) {
logError("", e);
} finally {
IOUtils.closeQuietly(in);
}
}
dataEl = uifactory.addTextAreaElement("data", "data", -1, 6, 60, true, dataVal, formLayout);
dataEl.showLabel(false);
String[] values = new String[] { translate("form.step3.delimiter.tab"), translate("form.step3.delimiter.comma") };
delimiter = uifactory.addRadiosVertical("delimiter", "form.step3.delimiter", formLayout, keys, values);
// preset delimiter type to first appearance of either tab or comma when data is available, default to tab for no data
int firstComma = dataVal.indexOf(",");
int firstTab = dataVal.indexOf("\t");
if (firstComma > -1 && (firstTab == -1 || firstTab > firstComma)) {
delimiter.select("comma", true);
} else {
delimiter.select("tab", true);
}
// hide data input field in case the element does not have any score, passed or comment field enabled
if (onlyReturnFiles) {
dataEl.setVisible(false);
delimiter.setVisible(false);
}
// return files only when configured
if (settings.isHasReturnFiles()) {
returnFileEl = uifactory.addFileElement(getWindowControl(), "returnfiles", "return.files", formLayout);
Set<String> mimes = new HashSet<String>();
mimes.add(WebappHelper.getMimeType("file.zip"));
returnFileEl.limitToMimeType(mimes, "return.mime", null);
if (savedDatas != null && StringHelper.containsNonWhitespace(savedDatas.getReturnFiles())) {
targetArchive = new OlatRootFileImpl(savedDatas.getReturnFiles(), null);
if (targetArchive.exists()) {
returnFileEl.setInitialFile(targetArchive.getBasefile());
}
}
}
}
use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.
the class FileCopyController method fileAlreadyExists.
private void fileAlreadyExists(UserRequest ureq) {
renamedFilename = proposedRenamedFilename(existingVFSItem);
boolean locked = vfsLockManager.isLockedForMe(existingVFSItem, getIdentity(), ureq.getUserSession().getRoles());
if (locked) {
// the file is locked and cannot be overwritten
removeAsListenerAndDispose(lockedFileDialog);
lockedFileDialog = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("ul.lockedFile.title"), translate("ul.lockedFile.text", new String[] { existingVFSItem.getName(), renamedFilename }), asList(translate("ul.overwrite.threeoptions.rename", renamedFilename), translate("ul.overwrite.threeoptions.cancel")));
listenTo(lockedFileDialog);
lockedFileDialog.activate();
} else if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
Versionable versionable = (Versionable) existingVFSItem;
Versions versions = versionable.getVersions();
String relPath = null;
if (existingVFSItem instanceof OlatRootFileImpl) {
relPath = ((OlatRootFileImpl) existingVFSItem).getRelPath();
}
int maxNumOfRevisions = FolderConfig.versionsAllowed(relPath);
if (maxNumOfRevisions == 0) {
// it's possible if someone change the configuration
// let calling method decide what to do.
removeAsListenerAndDispose(overwriteDialog);
overwriteDialog = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("ul.overwrite.threeoptions.title"), translate("ul.overwrite.threeoptions.text", new String[] { existingVFSItem.getName(), renamedFilename }), asList(translate("ul.overwrite.threeoptions.overwrite"), translate("ul.overwrite.threeoptions.rename", renamedFilename), translate("ul.overwrite.threeoptions.cancel")));
listenTo(overwriteDialog);
overwriteDialog.activate();
} else if (versions.getRevisions().isEmpty() || maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
// let calling method decide what to do.
removeAsListenerAndDispose(overwriteDialog);
overwriteDialog = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("ul.overwrite.threeoptions.title"), translate("ul.versionoroverwrite", new String[] { existingVFSItem.getName(), renamedFilename }), asList(translate("ul.overwrite.threeoptions.newVersion"), translate("ul.overwrite.threeoptions.rename", renamedFilename), translate("ul.overwrite.threeoptions.cancel")));
listenTo(overwriteDialog);
overwriteDialog.activate();
} else {
String title = translate("ul.tooManyRevisions.title", new String[] { Integer.toString(maxNumOfRevisions), Integer.toString(versions.getRevisions().size()) });
String description = translate("ul.tooManyRevisions.description", new String[] { Integer.toString(maxNumOfRevisions), Integer.toString(versions.getRevisions().size()) });
removeAsListenerAndDispose(revisionListCtr);
revisionListCtr = new RevisionListController(ureq, getWindowControl(), versionable, null, description, false);
listenTo(revisionListCtr);
removeAsListenerAndDispose(revisionListDialogBox);
revisionListDialogBox = new CloseableModalController(getWindowControl(), translate("delete"), revisionListCtr.getInitialComponent(), true, title);
listenTo(revisionListDialogBox);
revisionListDialogBox.activate();
}
} else {
// let calling method decide what to do.
// for this, we put a list with "existing name" and "new name"
overwriteDialog = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("ul.overwrite.threeoptions.title"), translate("ul.overwrite.threeoptions.text", new String[] { existingVFSItem.getName(), renamedFilename }), asList(translate("ul.overwrite.threeoptions.overwrite"), translate("ul.overwrite.threeoptions.rename", renamedFilename), translate("ul.overwrite.threeoptions.cancel")));
listenTo(overwriteDialog);
overwriteDialog.activate();
}
}
Aggregations