/**
* Copyright © 2011 Instituto Superior Técnico
*
* This file is part of FenixEdu Teacher Credits.
*
* FenixEdu Teacher Credits is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FenixEdu Teacher Credits is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FenixEdu Teacher Credits. If not, see <http://www.gnu.org/licenses/>.
*/
package pt.ist.fenixedu.teacher.domain.credits;
import java.util.HashSet;
import java.util.Set;
import org.fenixedu.academic.domain.Person;
import org.fenixedu.academic.domain.Teacher;
import org.fenixedu.academic.domain.person.RoleType;
import org.fenixedu.bennu.core.groups.Group;
import org.fenixedu.bennu.core.groups.UnionGroup;
import org.fenixedu.bennu.core.groups.UserGroup;
public class AnnualTeachingCreditsDocument extends AnnualTeachingCreditsDocument_Base {
public AnnualTeachingCreditsDocument(AnnualTeachingCredits annualTeachingCredits, byte[] content,
boolean hasConfidencialInformation) {
super();
String filename = getFilename(annualTeachingCredits);
final Set<Group> groups = new HashSet<>();
final Teacher teacher = annualTeachingCredits.getTeacher();
if (teacher != null) {
final Person person = teacher.getPerson();
if (person != null) {
groups.add(UserGroup.of(person.getUser()));
}
}
groups.add(RoleType.SCIENTIFIC_COUNCIL.actualGroup());
init(filename, filename, content, UnionGroup.of(groups));
setAnnualTeachingCredits(annualTeachingCredits);
setHasConfidencialInformation(hasConfidencialInformation);
}
private String getFilename(AnnualTeachingCredits annualTeachingCredits) {
return (annualTeachingCredits.getTeacher().getPerson().getUsername() + "_"
+ annualTeachingCredits.getAnnualCreditsState().getExecutionYear().getYear() + ".pdf").replaceAll(" ", "_")
.replaceAll("/", "_");
}
}