final Integer maxNumber = grantOwner.readGrantContractWithMaximumContractNumber().getContractNumber();
GrantContract maxGrantContract = grantOwner.readGrantContractWithMaximumContractNumber(); final Integer maxNumber = (maxGrantContract != null) ? maxGrantContract.getContractNumber() : 0;
    public void run(InfoGrantContract infoGrantContract) throws FenixServiceException,            ExcepcaoPersistencia {        final GrantOwner grantOwner = rootDomainObject.readGrantOwnerByOID(infoGrantContract.getGrantOwnerInfo().getIdInternal());        final GrantContract grantContract;        if (infoGrantContract.getContractNumber() == null) {            final Integer maxNumber = grantOwner.readGrantContractWithMaximumContractNumber().getContractNumber();            final Integer newContractNumber = Integer.valueOf(maxNumber + 1);            infoGrantContract.setContractNumber(newContractNumber);            grantContract = DomainFactory.makeGrantContract();        } else {            grantContract = grantOwner.readGrantContractByNumber(infoGrantContract.getContractNumber());         }        grantContract.setGrantOwner(grantOwner);        GrantType grantType = GrantType.readBySigla(infoGrantContract.getGrantTypeInfo().getSigla());        if (grantType == null) {            throw new GrantTypeNotFoundException();        }        grantContract.setGrantType(grantType);        GrantOrientationTeacher grantOrientationTeacher = rootDomainObject                .readGrantOrientationTeacherByOID(infoGrantContract.getGrantOrientationTeacherInfo()                        .getIdInternal());        if (grantOrientationTeacher == null) {            if (infoGrantContract.getIdInternal() != null                    || !infoGrantContract.getIdInternal().equals(Integer.valueOf(0))) {                                grantOrientationTeacher = grantContract.readActualGrantOrientationTeacher();            }            if (grantOrientationTeacher == null) {                grantOrientationTeacher = createNewGrantOrientationTeacher(infoGrantContract                        .getGrantOrientationTeacherInfo(), grantContract);            } else {                final Teacher teacher = Teacher                        .readByNumber(infoGrantContract.getGrantOrientationTeacherInfo()                                .getOrientationTeacherInfo().getTeacherNumber());                grantOrientationTeacher.setOrientationTeacher(teacher);            }        }        grantContract.addGrantOrientationTeachers(grantOrientationTeacher);        if (infoGrantContract.getGrantCostCenterInfo() != null                && infoGrantContract.getGrantCostCenterInfo().getNumber() != null) {            GrantCostCenter grantCostCenter = GrantCostCenter                    .readGrantCostCenterByNumber(infoGrantContract.getGrantCostCenterInfo().getNumber());            if (grantCostCenter == null) {                throw new InvalidGrantPaymentEntityException();            }            grantContract.setGrantCostCenter(grantCostCenter);        } else {            grantContract.setGrantCostCenter(null);        }        grantContract.setContractNumber(infoGrantContract.getContractNumber());        grantContract.setDateAcceptTerm(infoGrantContract.getDateAcceptTerm());        grantContract.setEndContractMotive(infoGrantContract.getEndContractMotive());    }