Search in sources :

Example 6 with AssignmentImpl

use of org.olat.modules.portfolio.model.AssignmentImpl in project openolat by klemens.

the class BinderDAO method syncAssignments.

private void syncAssignments(SectionImpl templateSection, SectionImpl currentSection) {
    List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
    List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
    for (Assignment currentAssignment : currentAssignments) {
        if (currentAssignment == null) {
            log.error("Missing assignment: " + currentSection.getKey());
            continue;
        }
        Assignment refAssignment = currentAssignment.getTemplateReference();
        if (refAssignment == null) {
            if (currentAssignment.getAssignmentStatus() != AssignmentStatus.deleted) {
                currentAssignment.setAssignmentStatus(AssignmentStatus.deleted);
                currentAssignment = dbInstance.getCurrentEntityManager().merge(currentAssignment);
            }
        } else if (!templateAssignments.contains(refAssignment)) {
        // this case is normally not possible
        // if it happens, don't do anything, let the data safe
        } else {
            templateAssignments.remove(refAssignment);
            AssignmentImpl currentImpl = (AssignmentImpl) currentAssignment;
            currentAssignment = syncAssignment(refAssignment, currentImpl);
        }
    }
    for (Assignment templateAssignment : templateAssignments) {
        if (templateAssignment != null) {
            assignmentDao.createAssignment(templateAssignment, AssignmentStatus.notStarted, currentSection);
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) ArrayList(java.util.ArrayList)

Example 7 with AssignmentImpl

use of org.olat.modules.portfolio.model.AssignmentImpl in project OpenOLAT by OpenOLAT.

the class BinderDAO method syncAssignments.

private void syncAssignments(SectionImpl templateSection, SectionImpl currentSection) {
    List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
    List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
    for (Assignment currentAssignment : currentAssignments) {
        if (currentAssignment == null) {
            log.error("Missing assignment: " + currentSection.getKey());
            continue;
        }
        Assignment refAssignment = currentAssignment.getTemplateReference();
        if (refAssignment == null) {
            if (currentAssignment.getAssignmentStatus() != AssignmentStatus.deleted) {
                currentAssignment.setAssignmentStatus(AssignmentStatus.deleted);
                currentAssignment = dbInstance.getCurrentEntityManager().merge(currentAssignment);
            }
        } else if (!templateAssignments.contains(refAssignment)) {
        // this case is normally not possible
        // if it happens, don't do anything, let the data safe
        } else {
            templateAssignments.remove(refAssignment);
            AssignmentImpl currentImpl = (AssignmentImpl) currentAssignment;
            currentAssignment = syncAssignment(refAssignment, currentImpl);
        }
    }
    for (Assignment templateAssignment : templateAssignments) {
        if (templateAssignment != null) {
            assignmentDao.createAssignment(templateAssignment, AssignmentStatus.notStarted, currentSection);
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) ArrayList(java.util.ArrayList)

Example 8 with AssignmentImpl

use of org.olat.modules.portfolio.model.AssignmentImpl in project OpenOLAT by OpenOLAT.

the class AssignmentDAO method createAssignment.

public Assignment createAssignment(String title, String summary, String content, String storage, AssignmentType type, AssignmentStatus status, Section section, boolean onlyAutoEvaluation, boolean reviewerSeeAutoEvaluation, boolean anonymousExternEvaluation, RepositoryEntry formEntry) {
    AssignmentImpl assignment = new AssignmentImpl();
    assignment.setCreationDate(new Date());
    assignment.setLastModified(assignment.getCreationDate());
    assignment.setTitle(title);
    assignment.setSummary(summary);
    assignment.setContent(content);
    assignment.setStorage(storage);
    assignment.setSection(section);
    assignment.setType(type.name());
    assignment.setStatus(status.name());
    assignment.setOnlyAutoEvaluation(onlyAutoEvaluation);
    assignment.setReviewerSeeAutoEvaluation(reviewerSeeAutoEvaluation);
    assignment.setAnonymousExternalEvaluation(anonymousExternEvaluation);
    assignment.setFormEntry(formEntry);
    ((SectionImpl) section).getAssignments().size();
    ((SectionImpl) section).getAssignments().add(assignment);
    dbInstance.getCurrentEntityManager().persist(assignment);
    dbInstance.getCurrentEntityManager().merge(section);
    return assignment;
}
Also used : AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) Date(java.util.Date)

Example 9 with AssignmentImpl

use of org.olat.modules.portfolio.model.AssignmentImpl in project OpenOLAT by OpenOLAT.

the class AssignmentDAO method moveAssignment.

public void moveAssignment(SectionImpl currentSection, Assignment assignment, SectionImpl newParentSection) {
    // load the assignments
    currentSection.getAssignments().size();
    newParentSection.getAssignments().size();
    int index = currentSection.getAssignments().indexOf(assignment);
    if (index >= 0) {
        Assignment reloadedAssignment = currentSection.getAssignments().remove(index);
        ((AssignmentImpl) reloadedAssignment).setSection(newParentSection);
        dbInstance.getCurrentEntityManager().merge(currentSection);
        newParentSection.getAssignments().add(reloadedAssignment);
        reloadedAssignment = dbInstance.getCurrentEntityManager().merge(reloadedAssignment);
        dbInstance.getCurrentEntityManager().merge(newParentSection);
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl)

Example 10 with AssignmentImpl

use of org.olat.modules.portfolio.model.AssignmentImpl in project OpenOLAT by OpenOLAT.

the class AssignmentDAO method startFormAssignment.

public Assignment startFormAssignment(Assignment assignment, Page page, Identity assignee) {
    ((AssignmentImpl) assignment).setPage(page);
    ((AssignmentImpl) assignment).setAssignee(assignee);
    ((AssignmentImpl) assignment).setLastModified(new Date());
    assignment.setAssignmentStatus(AssignmentStatus.inProgress);
    RepositoryEntry formEntry = assignment.getFormEntry();
    if (formEntry.getOlatResource().getResourceableTypeName().equals(formHandler.getSupportedType())) {
        File formFile = formHandler.getFormFile(formEntry);
        String formXml = FileUtils.load(formFile, "UTF-8");
        EvaluationFormPart formPart = new EvaluationFormPart();
        formPart.setContent(formXml);
        formPart.setFormEntry(formEntry);
        pageDao.persistPart(page.getBody(), formPart);
    }
    return dbInstance.getCurrentEntityManager().merge(assignment);
}
Also used : EvaluationFormPart(org.olat.modules.portfolio.model.EvaluationFormPart) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) File(java.io.File) Date(java.util.Date)

Aggregations

AssignmentImpl (org.olat.modules.portfolio.model.AssignmentImpl)16 Date (java.util.Date)8 File (java.io.File)4 Assignment (org.olat.modules.portfolio.Assignment)4 ArrayList (java.util.ArrayList)2 PersistenceHelper.makeFuzzyQueryString (org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString)2 Page (org.olat.modules.portfolio.Page)2 EvaluationFormPart (org.olat.modules.portfolio.model.EvaluationFormPart)2 PageImpl (org.olat.modules.portfolio.model.PageImpl)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2