Search in sources :

Example 1 with GTARelativeToDates

use of org.olat.course.nodes.gta.GTARelativeToDates in project openolat by klemens.

the class GTAManagerImpl method getReferenceDate.

@Override
public DueDate getReferenceDate(int numOfDays, String relativeTo, TaskRef assignedTask, IdentityRef assessedIdentity, BusinessGroup assessedGroup, RepositoryEntry courseEntry) {
    DueDate dueDate = null;
    if (numOfDays >= 0 && StringHelper.containsNonWhitespace(relativeTo)) {
        GTARelativeToDates rel = GTARelativeToDates.valueOf(relativeTo);
        Date referenceDate = null;
        String messageKey = null;
        String messageArg = null;
        switch(rel) {
            case courseStart:
                {
                    RepositoryEntryLifecycle lifecycle = getRepositoryEntryLifecycle(courseEntry);
                    if (lifecycle != null && lifecycle.getValidFrom() != null) {
                        referenceDate = lifecycle.getValidFrom();
                    }
                    break;
                }
            case courseLaunch:
                {
                    if (assessedIdentity != null) {
                        referenceDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, assessedGroup);
                    }
                    break;
                }
            case enrollment:
                {
                    if (assessedIdentity != null) {
                        referenceDate = repositoryService.getEnrollmentDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = getEnrollmentDate(assessedGroup);
                    }
                    break;
                }
            case assignment:
                {
                    if (assignedTask != null) {
                        referenceDate = assignedTask.getAssignmentDate();
                    } else {
                        messageKey = "relative.to.assignment.message";
                        messageArg = Integer.toString(numOfDays);
                    }
                    break;
                }
        }
        if (referenceDate != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(referenceDate);
            cal.add(Calendar.DATE, numOfDays);
            dueDate = new DueDate(true, cal.getTime());
        } else if (messageKey != null) {
            dueDate = new DueDate(true, messageKey, messageArg);
        }
    }
    return dueDate;
}
Also used : GTARelativeToDates(org.olat.course.nodes.gta.GTARelativeToDates) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) DueDate(org.olat.course.nodes.gta.model.DueDate) Date(java.util.Date) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) TaskRevisionDate(org.olat.course.nodes.gta.TaskRevisionDate) DueDate(org.olat.course.nodes.gta.model.DueDate)

Example 2 with GTARelativeToDates

use of org.olat.course.nodes.gta.GTARelativeToDates in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method getReferenceDate.

@Override
public DueDate getReferenceDate(int numOfDays, String relativeTo, TaskRef assignedTask, IdentityRef assessedIdentity, BusinessGroup assessedGroup, RepositoryEntry courseEntry) {
    DueDate dueDate = null;
    if (numOfDays >= 0 && StringHelper.containsNonWhitespace(relativeTo)) {
        GTARelativeToDates rel = GTARelativeToDates.valueOf(relativeTo);
        Date referenceDate = null;
        String messageKey = null;
        String messageArg = null;
        switch(rel) {
            case courseStart:
                {
                    RepositoryEntryLifecycle lifecycle = getRepositoryEntryLifecycle(courseEntry);
                    if (lifecycle != null && lifecycle.getValidFrom() != null) {
                        referenceDate = lifecycle.getValidFrom();
                    }
                    break;
                }
            case courseLaunch:
                {
                    if (assessedIdentity != null) {
                        referenceDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, assessedGroup);
                    }
                    break;
                }
            case enrollment:
                {
                    if (assessedIdentity != null) {
                        referenceDate = repositoryService.getEnrollmentDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = getEnrollmentDate(assessedGroup);
                    }
                    break;
                }
            case assignment:
                {
                    if (assignedTask != null) {
                        referenceDate = assignedTask.getAssignmentDate();
                    } else {
                        messageKey = "relative.to.assignment.message";
                        messageArg = Integer.toString(numOfDays);
                    }
                    break;
                }
        }
        if (referenceDate != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(referenceDate);
            cal.add(Calendar.DATE, numOfDays);
            dueDate = new DueDate(true, cal.getTime());
        } else if (messageKey != null) {
            dueDate = new DueDate(true, messageKey, messageArg);
        }
    }
    return dueDate;
}
Also used : GTARelativeToDates(org.olat.course.nodes.gta.GTARelativeToDates) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) DueDate(org.olat.course.nodes.gta.model.DueDate) Date(java.util.Date) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) TaskRevisionDate(org.olat.course.nodes.gta.TaskRevisionDate) DueDate(org.olat.course.nodes.gta.model.DueDate)

Aggregations

Calendar (java.util.Calendar)2 Date (java.util.Date)2 GTARelativeToDates (org.olat.course.nodes.gta.GTARelativeToDates)2 TaskDueDate (org.olat.course.nodes.gta.TaskDueDate)2 TaskRevisionDate (org.olat.course.nodes.gta.TaskRevisionDate)2 DueDate (org.olat.course.nodes.gta.model.DueDate)2 RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)2