use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.
the class NewTaskController method getTaskDefinition.
public TaskDefinition getTaskDefinition() {
TaskDefinition taskDef = new TaskDefinition();
taskDef.setTitle(titleEl.getValue());
taskDef.setFilename(getFilename());
taskDef.setDescription(descriptionEl.getValue());
return taskDef;
}
use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.
the class GTACourseNode method validateInternalConfiguration.
private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
List<StatusDescription> sdList = new ArrayList<>(5);
ModuleConfiguration config = getModuleConfiguration();
boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
if (hasScoring) {
if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
}
}
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
}
}
// at least one step
if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
}
if (cev != null) {
// check assignment
GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
ICourse course = CourseFactory.loadCourse(courseRe);
if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
if (!TaskHelper.hasDocuments(taskDirectory)) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
} else {
addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
} else {
List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
if (taskList == null || taskList.isEmpty()) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
} else {
addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
} else {
String[] filenames = taskDirectory.list();
for (TaskDefinition taskDef : taskList) {
boolean found = false;
for (String filename : filenames) {
if (filename.equals(taskDef.getFilename())) {
found = true;
break;
}
}
if (!found) {
addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
}
}
}
}
// check solutions
if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
if (!TaskHelper.hasDocuments(solutionDirectory)) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
} else {
addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
}
}
}
List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
if (participants.size() > 0) {
UserManager um = CoreSpringFactory.getImpl(UserManager.class);
StringBuilder sb = new StringBuilder();
for (IdentityRef participant : participants) {
String fullname = um.getUserDisplayName(participant.getKey());
if (sb.length() > 0)
sb.append(", ");
sb.append(fullname);
}
String[] params = new String[] { getShortTitle(), sb.toString() };
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
sd.setDescriptionForUnit(getIdent());
sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
sdList.add(sd);
}
}
return sdList;
}
use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.
the class GTACoachController method getTaskDefinition.
private TaskDefinition getTaskDefinition(Task task) {
if (task == null)
return null;
TaskDefinition taskDef = null;
List<TaskDefinition> availableTasks = gtaManager.getTaskDefinitions(courseEnv, gtaNode);
for (TaskDefinition availableTask : availableTasks) {
if (availableTask.getFilename() != null && availableTask.getFilename().equals(task.getTaskName())) {
taskDef = availableTask;
break;
}
}
return taskDef;
}
use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.
the class EditTaskController method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true;
titleEl.clearError();
if (!StringHelper.containsNonWhitespace(titleEl.getValue())) {
titleEl.setErrorKey("form.mandatory.hover", null);
allOk &= false;
}
fileEl.clearError();
if (fileEl.getInitialFile() == null && fileEl.getUploadFile() == null) {
fileEl.setErrorKey("form.mandatory.hover", null);
allOk &= false;
} else if (!FileUtils.validateFilename(fileEl.getUploadFileName())) {
fileEl.setErrorKey("error.file.invalid", null);
allOk = false;
} else if (!replaceFile && fileEl.getUploadFile() != null) {
String filename = fileEl.getUploadFileName();
File target = new File(taskContainer, filename);
if (target.exists()) {
fileEl.setErrorKey("error.file.exists", new String[] { filename });
allOk &= false;
}
} else if (replaceFile && fileEl.getUploadFile() != null) {
String filename = fileEl.getUploadFileName();
if (currentDefinitions != null) {
for (TaskDefinition definition : currentDefinitions) {
if (filename.equals(definition.getFilename()) && !task.getTitle().equals(definition.getTitle())) {
fileEl.setErrorKey("error.file.exists", new String[] { filename });
allOk &= false;
}
}
}
}
return allOk & super.validateFormLogic(ureq);
}
use of org.olat.course.nodes.gta.model.TaskDefinition in project openolat by klemens.
the class EditTaskController method formOK.
@Override
protected void formOK(UserRequest ureq) {
task.setTitle(titleEl.getValue());
task.setDescription(descriptionEl.getValue());
if (fileEl.getUploadFile() != null) {
if (replaceFile && StringHelper.containsNonWhitespace(task.getFilename())) {
int usage = 0;
if (currentDefinitions != null) {
for (TaskDefinition definition : currentDefinitions) {
if (task.getFilename().equals(definition.getFilename())) {
usage++;
}
}
}
if (usage == 1) {
File currentFile = new File(taskContainer, task.getFilename());
if (currentFile.exists()) {
currentFile.delete();
}
}
}
String filename = fileEl.getUploadFileName();
task.setFilename(filename);
try {
Path upload = fileEl.getUploadFile().toPath();
File target = new File(taskContainer, filename);
Files.move(upload, target.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception ex) {
logError("", ex);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations