person.setSex(Sex.MALE);
    public InfoMasterDegreeCandidate run(InfoMasterDegreeCandidate newMasterDegreeCandidate)            throws Exception {        IMasterDegreeCandidate masterDegreeCandidate = new MasterDegreeCandidate();        ISuportePersistente sp = null;        IPerson person = null;        try {            sp = PersistenceSupportFactory.getDefaultPersistenceSupport();            IPersistentExecutionDegree executionDegreeDAO = sp.getIPersistentExecutionDegree();            IPersistentMasterDegreeCandidate masterDegreeDAO = sp.getIPersistentMasterDegreeCandidate();            // Read the Execution of this degree in the current execution Year            IExecutionDegree executionDegree = (IExecutionDegree) executionDegreeDAO.readByOID(                    ExecutionDegree.class, newMasterDegreeCandidate.getInfoExecutionDegree()                            .getIdInternal());            IMasterDegreeCandidate masterDegreeCandidateFromDB = masterDegreeDAO                    .readByIdentificationDocNumberAndTypeAndExecutionDegreeAndSpecialization(                            newMasterDegreeCandidate.getInfoPerson().getNumeroDocumentoIdentificacao(),                            newMasterDegreeCandidate.getInfoPerson().getTipoDocumentoIdentificacao()                                    .getTipo(), executionDegree, newMasterDegreeCandidate                                    .getSpecialization());            if (masterDegreeCandidateFromDB != null) {                throw new ExistingServiceException();            }            // Check if the person Exists            person = sp.getIPessoaPersistente().lerPessoaPorNumDocIdETipoDocId(                    newMasterDegreeCandidate.getInfoPerson().getNumeroDocumentoIdentificacao(),                    newMasterDegreeCandidate.getInfoPerson().getTipoDocumentoIdentificacao());            if (person != null) {                sp.getIPessoaPersistente().simpleLockWrite(person);            }            // Create the Candidate            // Set the Candidate's Situation            List situations = new ArrayList();            ICandidateSituation candidateSituation = new CandidateSituation();            sp.getIPersistentCandidateSituation().simpleLockWrite(candidateSituation);            //			sp.getIPersistentCandidateSituation().writeCandidateSituation(candidateSituation);            // First candidate situation            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);            masterDegreeDAO.simpleLockWrite(masterDegreeCandidate);            masterDegreeCandidate.setSituations(situations);            masterDegreeCandidate.setPerson(person);            masterDegreeCandidate.setSpecialization(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 Person();                sp.getIPessoaPersistente().simpleLockWrite(person);                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                person.setPersonRoles(new ArrayList());                person.getPersonRoles().add(sp.getIPersistentRole().readByRoleType(RoleType.PERSON));            }            if (!person.getPersonRoles().contains(                    sp.getIPersistentRole().readByRoleType(RoleType.MASTER_DEGREE_CANDIDATE))) {                person.getPersonRoles().add(                        sp.getIPersistentRole().readByRoleType(RoleType.MASTER_DEGREE_CANDIDATE));            }            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;        }        // Return the new Candidate        InfoMasterDegreeCandidate infoMasterDegreeCandidate = Cloner                .copyIMasterDegreeCandidate2InfoMasterDegreCandidate(masterDegreeCandidate);        return infoMasterDegreeCandidate;    }