Search in sources :

Example 36 with Tag

use of fi.otavanopisto.pyramus.domainmodel.base.Tag in project pyramus by otavanopisto.

the class SchoolController method updateSchoolTags.

public synchronized School updateSchoolTags(School school, List<String> tags) {
    Set<String> newTags = new HashSet<>(tags);
    Set<Tag> schoolTags = new HashSet<>(school.getTags());
    for (Tag schoolTag : schoolTags) {
        if (!newTags.contains(schoolTag.getText())) {
            removeSchoolTag(school, schoolTag);
        }
        newTags.remove(schoolTag.getText());
    }
    for (String newTag : newTags) {
        createSchoolTag(school, newTag);
    }
    return school;
}
Also used : Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) HashSet(java.util.HashSet)

Example 37 with Tag

use of fi.otavanopisto.pyramus.domainmodel.base.Tag in project pyramus by otavanopisto.

the class StudentController method deleteStudent.

public void deleteStudent(Student student) {
    Set<Tag> tags = new HashSet<>(student.getTags());
    for (Tag tag : tags) {
        studentDAO.removeTag(student, tag);
    }
    User defaultUser = student.getPerson().getDefaultUser();
    boolean newDefaultUser = false;
    Long personId = student.getPerson().getId();
    if (defaultUser != null) {
        if (defaultUser.getId().equals(student.getId())) {
            newDefaultUser = true;
            personDAO.updateDefaultUser(student.getPerson(), null);
        }
    }
    student = studentDAO.findById(student.getId());
    studentDAO.delete(student);
    // Do a best guess of the new default user
    if (newDefaultUser) {
        Person person = personDAO.findById(personId);
        Student latestStudent = person.getLatestStudent();
        if (latestStudent != null)
            personDAO.updateDefaultUser(person, latestStudent);
        else {
            if (!person.getStudents().isEmpty())
                personDAO.updateDefaultUser(person, person.getStudents().get(0));
            else if (!person.getStaffMembers().isEmpty())
                personDAO.updateDefaultUser(person, person.getStaffMembers().get(0));
        }
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) HashSet(java.util.HashSet)

Example 38 with Tag

use of fi.otavanopisto.pyramus.domainmodel.base.Tag in project pyramus by otavanopisto.

the class StudentGroupController method createStudentGroupTag.

public Tag createStudentGroupTag(StudentGroup studentGroup, String text) {
    Tag tag = tagDAO.findByText(text);
    if (tag == null) {
        tag = tagDAO.create(text);
    }
    studentGroup.addTag(tag);
    return tag;
}
Also used : Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 39 with Tag

use of fi.otavanopisto.pyramus.domainmodel.base.Tag in project pyramus by otavanopisto.

the class ModuleController method createModuleTag.

/* Tags */
public Tag createModuleTag(Module module, String text) {
    Tag tag = tagDAO.findByText(text);
    if (tag == null) {
        tag = tagDAO.create(text);
    }
    module.addTag(tag);
    return tag;
}
Also used : Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 40 with Tag

use of fi.otavanopisto.pyramus.domainmodel.base.Tag in project pyramus by otavanopisto.

the class UserEntityFactory method buildFromDomainObject.

public UserEntity buildFromDomainObject(Object domainObject) {
    StaffMember user = (StaffMember) domainObject;
    Set<String> emails = new HashSet<>();
    for (Email email : user.getContactInfo().getEmails()) emails.add(email.getAddress());
    int i = 0;
    String[] tags = new String[user.getTags().size()];
    for (Tag tag : user.getTags()) {
        tags[i++] = tag.getText();
    }
    // , user.getExternalId(), user.getAuthProvider(), user.getRole().name());
    return new UserEntity(user.getId(), emails.toArray(new String[0]), user.getFirstName(), user.getLastName(), tags);
}
Also used : Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) HashSet(java.util.HashSet)

Aggregations

Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)59 HashSet (java.util.HashSet)33 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)24 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)21 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)16 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)16 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)15 User (fi.otavanopisto.pyramus.domainmodel.users.User)14 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)13 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)13 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)12 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)12 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)11 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)10 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)10 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)10 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)10 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)9 ResourceDAO (fi.otavanopisto.pyramus.dao.resources.ResourceDAO)8 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)8