}
}
if (hasRights && !readOnly) {
// no problem, you are a boss
ProgramDTO programDTO = new ProgramDTO(programDAO.find(id), DTOPath.PROGRAM_DOC);
if (isAdmin || (programDTO.getEcmManager() != null && programDTO.getEcmManager().getId() == user.getId())
|| (programDTO.getProgramManager() != null && programDTO.getProgramManager().getId() == user.getId())) {
programDTO.enableGC4LaunchButton();
}
return programDTO;
} else if (hasRights && readOnly && readOnlySpecific) {
// simple pure reader
ProgramDTO programDTO = new ProgramDTO(programDAO.find(id), DTOPath.PROGRAM_DOC);
programDTO.freeze();
if (isAdmin || (programDTO.getEcmManager() != null && programDTO.getEcmManager().getId() == user.getId())
|| (programDTO.getProgramManager() != null && programDTO.getProgramManager().getId() == user.getId())) {
programDTO.enableGC4LaunchButton();
}
return programDTO;
}
if (hasSpecificRights || !readOnlySpecific) {
Set<ProgramDTO> specProgramsConsultation = new HashSet<ProgramDTO>();
Set<ProgramDTO> specProgramsEdition = new HashSet<ProgramDTO>();
specProgramsConsultation.addAll(user.getProgramsWithConsultationRights());
specProgramsEdition.addAll(user.getProgramsWithEditionRights());
List<Long> programsIdConsultation = new ArrayList<Long>();
List<Long> programsIdEdition = new ArrayList<Long>();
for (ProgramDTO program : specProgramsConsultation) {
programsIdConsultation.add(program.getId());
}
for (ProgramDTO program : specProgramsEdition) {
programsIdEdition.add(program.getId());
}
if (programsIdEdition.contains(id)) {
ProgramDTO programDTO = new ProgramDTO(programDAO.find(id), DTOPath.PROGRAM_DOC);
if (isAdmin || (programDTO.getEcmManager() != null && programDTO.getEcmManager().getId() == user.getId())
|| (programDTO.getProgramManager() != null && programDTO.getProgramManager().getId() == user.getId())) {
programDTO.enableGC4LaunchButton();
}
return programDTO;
}
if (specProgramsConsultation.contains(id)) {
ProgramDTO programDTO = new ProgramDTO(programDAO.find(id), DTOPath.PROGRAM_DOC);
programDTO.freeze();
if (isAdmin || (programDTO.getEcmManager() != null && programDTO.getEcmManager().getId() == user.getId())
|| (programDTO.getProgramManager() != null && programDTO.getProgramManager().getId() == user.getId())) {
programDTO.enableGC4LaunchButton();
}
return programDTO;
}
}
return null;