role = sp.getIPersistentRole().readByRoleType(RoleType.PERSON);
person.getPersonRoles().add(sp.getIPersistentRole().readByRoleType(RoleType.PERSON));
	public InfoMasterDegreeCandidate run(InfoMasterDegreeCandidate newMasterDegreeCandidate)		throws Exception{		IMasterDegreeCandidate masterDegreeCandidate = new MasterDegreeCandidate();				ISuportePersistente sp = null;		IRole role = null;		IPessoa person = null;				try {			sp = SuportePersistenteOJB.getInstance();						// Check if the person Exists						person = sp.getIPessoaPersistente().lerPessoaPorNumDocIdETipoDocId(newMasterDegreeCandidate.getInfoPerson().getNumeroDocumentoIdentificacao(), 							 newMasterDegreeCandidate.getInfoPerson().getTipoDocumentoIdentificacao());						// Read the Execution of this degree in the current execution Year						ICursoExecucao executionDegree = sp.getICursoExecucaoPersistente().readByDegreeCodeAndExecutionYear(						 newMasterDegreeCandidate.getInfoExecutionDegree().getInfoDegreeCurricularPlan().getInfoDegree().getSigla(),						 Cloner.copyInfoExecutionYear2IExecutionYear(newMasterDegreeCandidate.getInfoExecutionDegree().getInfoExecutionYear()));						// Create the Candidate						// Set the Candidate's Situation			Set situations = new HashSet();			ICandidateSituation candidateSituation = new CandidateSituation();			candidateSituation.setMasterDegreeCandidate(masterDegreeCandidate);			candidateSituation.setRemarks("Pr-Candidatura. Pagamento da candidatura por efectuar.");			candidateSituation.setSituation(new SituationName(SituationName.PRE_CANDIDATO));			candidateSituation.setValidation(new State(State.ACTIVE));						Calendar actualDate = Calendar.getInstance();			candidateSituation.setDate(actualDate.getTime());						situations.add(candidateSituation);						masterDegreeCandidate.setSituations(situations);			masterDegreeCandidate.setPerson(person);			masterDegreeCandidate.setSpecialization(new Specialization(newMasterDegreeCandidate.getSpecialization()));			masterDegreeCandidate.setExecutionDegree(executionDegree);			// Generate the Candidate's number				Integer number = sp.getIPersistentMasterDegreeCandidate().generateCandidateNumber(								masterDegreeCandidate.getExecutionDegree().getExecutionYear().getYear(),								masterDegreeCandidate.getExecutionDegree().getCurricularPlan().getDegree().getSigla(), 								masterDegreeCandidate.getSpecialization());			masterDegreeCandidate.setCandidateNumber(number);						if (person == null) {				// Create the new Person								person = new Pessoa();				person.setNome(newMasterDegreeCandidate.getInfoPerson().getNome());				person.setNumeroDocumentoIdentificacao(newMasterDegreeCandidate.getInfoPerson().getNumeroDocumentoIdentificacao());				person.setTipoDocumentoIdentificacao(newMasterDegreeCandidate.getInfoPerson().getTipoDocumentoIdentificacao());								// Generate Person Username								String username = GenerateUsername.getCandidateUsername(masterDegreeCandidate);				person.setUsername(username);								// Give the Person Role				role = sp.getIPersistentRole().readByRoleType(RoleType.PERSON);			}						masterDegreeCandidate.setPerson(person);						// Write the new Candidate			sp.getIPersistentMasterDegreeCandidate().writeMasterDegreeCandidate(masterDegreeCandidate);				} catch (ExistingPersistentException ex) {			throw new ExistingServiceException(ex);		} catch (ExcepcaoPersistencia ex) {			FenixServiceException newEx = new FenixServiceException("Persistence layer error");			newEx.fillInStackTrace();			throw newEx;		} 		try {			// Give the Master Degree Candidate Role			IPersonRole candidateRole = new PersonRole();			role = sp.getIPersistentRole().readByRoleType(RoleType.MASTER_DEGREE_CANDIDATE);			person.getPersonRoles().add(role);			sp.getIPessoaPersistente().escreverPessoa(person);		} catch (ExistingPersistentException ex) {			// This person is already a Candidate. No need to give the role again		} catch (ExcepcaoPersistencia ex) {			FenixServiceException newEx = new FenixServiceException("Persistence layer error");			newEx.fillInStackTrace();			throw newEx;		} 				// Return the new Candidate		return Cloner.copyIMasterDegreeCandidate2InfoMasterDegreCandidate(masterDegreeCandidate);		}