final ExecutionDegree executionDegree = rootDomainObject.readExecutionDegreeByOID(executionDegreeID); Person person = Person.readByDocumentIdNumberAndIdDocumentType(identificationDocumentNumber, identificationDocumentType);
final ExecutionDegree executionDegree = rootDomainObject .readExecutionDegreeByOID(executionDegreeID); Person person = Person.readByDocumentIdNumberAndIdDocumentType(identificationDocumentNumber, identificationDocumentType);  if (person == null) {  person = DomainFactory.makePerson(name, identificationDocumentNumber, identificationDocumentType, Gender.MALE, "T" + System.currentTimeMillis()); } else { MasterDegreeCandidate existingMasterDegreeCandidate = person .getMasterDegreeCandidateByExecutionDegree(executionDegree); if (existingMasterDegreeCandidate != null) { throw new ExistingServiceException(); } }  person.addPersonRoleByRoleType(RoleType.MASTER_DEGREE_CANDIDATE); person.addPersonRoleByRoleType(RoleType.PERSON);
    public InfoMasterDegreeCandidate run(Specialization degreeType, Integer executionDegreeID,            String name, String identificationDocumentNumber, IDDocumentType identificationDocumentType)            throws Exception {        // Read the Execution of this degree in the current execution Year        final ExecutionDegree executionDegree = rootDomainObject.readExecutionDegreeByOID(executionDegreeID);        Person person = Person.readByDocumentIdNumberAndIdDocumentType(identificationDocumentNumber, identificationDocumentType);                MasterDegreeCandidate masterDegreeCandidate = person.getMasterDegreeCandidateByExecutionDegree(executionDegree);        if (masterDegreeCandidate != null) {            throw new ExistingServiceException();        }        // Set the Candidate's Situation        CandidateSituation candidateSituation = DomainFactory.makeCandidateSituation();        // First candidate situation        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());        // Create the Candidate        masterDegreeCandidate = DomainFactory.makeMasterDegreeCandidate();        masterDegreeCandidate.addSituations(candidateSituation);        masterDegreeCandidate.setSpecialization(degreeType);        masterDegreeCandidate.setExecutionDegree(executionDegree);        masterDegreeCandidate.setCandidateNumber(executionDegree.generateCandidateNumberForSpecialization(degreeType));        Role personRole = Role.getRoleByRoleType(RoleType.PERSON);        if (person == null) {            // Create the new Person            person = DomainFactory.makePerson(name, identificationDocumentNumber,                    identificationDocumentType, Gender.MALE, "T" + System.currentTimeMillis());        }        if (!person.hasRole(RoleType.PERSON)) {            person.addPersonRoles(personRole);        }        masterDegreeCandidate.setPerson(person);        if (!person.hasRole(RoleType.MASTER_DEGREE_CANDIDATE)) {            person.addPersonRoles(Role.getRoleByRoleType(RoleType.MASTER_DEGREE_CANDIDATE));        }        // Return the new Candidate        InfoMasterDegreeCandidate infoMasterDegreeCandidate = InfoMasterDegreeCandidateWithInfoPerson                .newInfoFromDomain(masterDegreeCandidate);        InfoExecutionDegree infoExecutionDegree = InfoExecutionDegreeWithInfoExecutionYearAndDegreeCurricularPlan                .newInfoFromDomain(masterDegreeCandidate.getExecutionDegree());        infoMasterDegreeCandidate.setInfoExecutionDegree(infoExecutionDegree);        return infoMasterDegreeCandidate;    }