@Override
 void process(Thesis thesis) {
   if (thesis.getState() != ThesisState.APPROVED) {
     createAnnouncement(thesis);
     thesis.approveProposal();
   }
 }
 private String getAnnouncementBody(Thesis thesis, String key, Language language) {
   return getMessage(
       key,
       new Locale(language.toString()),
       thesis.getStudent().getPerson().getName(),
       getDate(thesis.getProposedDiscussed()),
       hasPlace(thesis),
       thesis.getProposedPlace(),
       hasTime(thesis.getProposedDiscussed()),
       getTime(thesis.getProposedDiscussed()),
       getString(thesis.getTitle(), language));
 }
  @Atomic
  public static void remove(final ThesisEvaluationParticipant thesisEvaluationParticipant) {
    final Thesis thesis = thesisEvaluationParticipant.getThesis();
    if (!AccessControl.getPerson().hasRole(RoleType.SCIENTIFIC_COUNCIL)) {
      thesis.checkIsScientificCommission();
    }
    final ThesisParticipationType type = thesisEvaluationParticipant.getType();
    thesisEvaluationParticipant.delete();

    if (!thesis.isCreditsDistributionNeeded()) {
      thesis.setCoorientatorCreditsDistribution(null);
    }
  }
  @Atomic
  public static void add(
      final Thesis thesis,
      final ThesisParticipationType thesisParticipationType,
      final Person person) {
    if (person != null) {
      if (!AccessControl.getPerson().hasRole(RoleType.SCIENTIFIC_COUNCIL)) {
        thesis.checkIsScientificCommission();
      }

      new ThesisEvaluationParticipant(thesis, person, thesisParticipationType);

      if (!thesis.isCreditsDistributionNeeded()) {
        thesis.setCoorientatorCreditsDistribution(null);
      }
    }
  }
  private void createAnnouncement(Thesis thesis) {
    if (thesis.getProposedDiscussed() == null) {
      return;
    }

    AnnouncementBoard board =
        getBoard(DEGREE_ANNOUNCEMENTS_BOARD_NAME, thesis.getDegree().getUnit());

    if (board == null) {
      return;
    }

    DateTime now = new DateTime();

    Announcement announcement = new Announcement();
    announcement.setAnnouncementBoard(board);
    announcement.setCreator(AccessControl.getPerson());
    announcement.setCreationDate(now);
    announcement.setPlace(thesis.getProposedPlace());
    announcement.setVisible(true);

    announcement.setAuthor(getMessage("system.public.name"));
    announcement.setAuthorEmail(getMessage("system.public.email"));
    announcement.setPublicationBegin(now);
    announcement.setReferedSubjectBegin(thesis.getProposedDiscussed());

    MultiLanguageString subject =
        new MultiLanguageString()
            .with(
                Language.pt,
                getAnnouncementSubject(thesis, "thesis.announcement.subject", Language.pt))
            .with(
                Language.en,
                getAnnouncementSubject(thesis, "thesis.announcement.subject", Language.en));

    MultiLanguageString body =
        new MultiLanguageString()
            .with(Language.pt, getAnnouncementBody(thesis, "thesis.announcement.body", Language.pt))
            .with(
                Language.en, getAnnouncementBody(thesis, "thesis.announcement.body", Language.en));

    announcement.setSubject(subject);
    announcement.setBody(body);
  }
  @Service
  public static void run(Thesis thesis) {
    final ThesisFile thesisFile = thesis.getDissertation();

    RoleTypeGroup scientificCouncil = new RoleTypeGroup(RoleType.SCIENTIFIC_COUNCIL);
    CurrentDegreeScientificCommissionMembersGroup commissionMembers =
        new CurrentDegreeScientificCommissionMembersGroup(thesis.getDegree());
    PersonGroup student = thesis.getStudent().getPerson().getPersonGroup();
    ThesisFileReadersGroup thesisGroup = new ThesisFileReadersGroup(thesis);

    thesisFile.setPermittedGroup(
        new GroupUnion(scientificCouncil, commissionMembers, student, thesisGroup));

    final net.sourceforge.fenixedu.domain.research.result.publication.Thesis publication =
        thesis.getPublication();
    if (publication != null) {
      for (final File file : publication.getResultDocumentFilesSet()) {
        file.setPermittedGroup(thesisFile.getPermittedGroup());
      }
    }
  }
  @Atomic
  public static void run(
      DegreeCurricularPlan degreeCurricularPlan, Thesis thesis, PersonChange change)
      throws FenixServiceException {
    Person person = getPerson(change);

    if (!AccessControl.getPerson().hasRole(RoleType.SCIENTIFIC_COUNCIL)) {
      thesis.checkIsScientificCommission();
    }

    switch (change.type) {
      case orientator:
        thesis.setOrientator(person);
        break;
      case coorientator:
        thesis.setCoorientator(person);
        break;
      case president:
        thesis.setPresident(person);
        break;
      case vowel:
        if (change.target != null) {
          change.target.delete();
          if (person != null) {
            thesis.addVowel(person);
          }
        } else {
          if (person != null) {
            thesis.addVowel(person);
          }
        }

        break;
    }
  }
  @Override
  protected Collection<Person> getReceivers(Thesis thesis) {
    Person student = thesis.getStudent().getPerson();
    Person orientator = thesis.getOrientator().getPerson();
    Person coorientator = getPerson(thesis.getCoorientator());
    Person president = getPerson(thesis.getPresident());

    Set<Person> persons = personSet(student, orientator, coorientator, president);
    for (ThesisEvaluationParticipant participant : thesis.getVowels()) {
      persons.add(participant.getPerson());
    }

    // also send proposal approval to the contact team
    ExecutionYear executionYear = thesis.getEnrolment().getExecutionYear();
    for (ScientificCommission member :
        thesis.getDegree().getScientificCommissionMembers(executionYear)) {
      if (member.isContact()) {
        persons.add(member.getPerson());
      }
    }

    return persons;
  }
  @Override
  protected String getMessage(Thesis thesis) {
    Person currentPerson = AccessControl.getPerson();
    ExecutionYear executionYear = ExecutionYear.readCurrentExecutionYear();

    String title = thesis.getTitle().getContent();
    String year = executionYear.getYear();
    String degreeName = thesis.getDegree().getNameFor(executionYear).getContent();
    String studentName = thesis.getStudent().getPerson().getName();
    String studentNumber = thesis.getStudent().getNumber().toString();
    String presidentName = name(thesis.getPresident());
    String presidentAffiliation = affiliation(thesis.getPresident());
    String orientatorName = name(thesis.getOrientator());
    String orientatorAffiliation = affiliation(thesis.getOrientator());
    String coorientatorName = name(thesis.getCoorientator());
    String coorientatorAffiliation = affiliation(thesis.getCoorientator());
    String vowel1Name = name(thesis.getVowels(), 0);
    String vowel1Affiliation = affiliation(thesis.getVowels(), 0);
    String vowel2Name = name(thesis.getVowels(), 1);
    String vowel2Affiliation = affiliation(thesis.getVowels(), 1);
    String vowel3Name = name(thesis.getVowels(), 2);
    String vowel3Affiliation = affiliation(thesis.getVowels(), 2);

    String date = String.format(new Locale("pt"), "%1$td de %1$tB de %1$tY", new Date());
    String currentPersonName = currentPerson.getNickname();

    if (thesis.isCoordinator()) {
      return getMessage(
          COORDINATOR_BODY_KEY,
          year,
          degreeName,
          studentName,
          studentNumber,
          presidentName,
          presidentAffiliation,
          orientatorName,
          orientatorAffiliation,
          includeFlag(coorientatorName),
          coorientatorName,
          coorientatorAffiliation,
          includeFlag(vowel1Name),
          vowel1Name,
          vowel1Affiliation,
          includeFlag(vowel2Name),
          vowel2Name,
          vowel2Affiliation,
          includeFlag(vowel3Name),
          vowel3Name,
          vowel3Affiliation,
          date,
          currentPersonName);
    } else {
      return getMessage(
          BODY_KEY,
          year,
          degreeName,
          studentName,
          studentNumber,
          presidentName,
          presidentAffiliation,
          orientatorName,
          orientatorAffiliation,
          includeFlag(coorientatorName),
          coorientatorName,
          coorientatorAffiliation,
          includeFlag(vowel1Name),
          vowel1Name,
          vowel1Affiliation,
          includeFlag(vowel2Name),
          vowel2Name,
          vowel2Affiliation,
          includeFlag(vowel3Name),
          vowel3Name,
          vowel3Affiliation,
          date,
          currentPersonName);
    }
  }
 @Override
 protected String getSubject(Thesis thesis) {
   return getMessage(SUBJECT_KEY, thesis.getTitle().getContent());
 }
 private Integer hasPlace(Thesis thesis) {
   String place = thesis.getProposedPlace();
   return place == null || place.trim().length() == 0 ? 0 : 1;
 }
 private String getAnnouncementSubject(Thesis thesis, String key, Language language) {
   return getMessage(
       key, new Locale(language.toString()), thesis.getStudent().getPerson().getName());
 }
 @Atomic
 public static void run(Thesis thesis) {
   thesis.setConfirmmedDocuments(new DateTime());
 }