Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:com.lp.server.projekt.ejbfac.ProjektReportFacBean.java

License:Open Source License

public JasperPrintLP printProjektErledigt(ReportJournalKriterienDto reportJournalKriterienDtoI, Date dStichtag,
        Integer bereichIId, boolean interneErledigungBeruecksichtigen, TheClientDto theClientDto)
        throws EJBExceptionLP, RemoteException {
    JasperPrintLP oPrint = null;/*from w  w w.j a va2s .c o  m*/

    cAktuellerReport = ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT;
    Locale locDruck;
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    // vom Stichtag die Uhrzeit abschneiden
    dStichtag = Helper.cutDate(dStichtag);
    try {
        session = factory.openSession();
        // Hiberante Criteria fuer alle Tabellen ausgehend von meiner
        // Haupttabelle anlegen,
        // nach denen ich filtern und sortieren kann
        Criteria crit = session.createCriteria(FLRProjekt.class);
        // Einschraenkung auf den aktuellen Mandanten
        crit.add(Restrictions.eq(ProjektFac.FLR_PROJEKT_MANDANT_C_NR, theClientDto.getMandant()));
        crit.add(Restrictions.not(Restrictions.eq(ProjektFac.FLR_PROJEKT_STATUS_C_NR,
                ProjektServiceFac.PROJEKT_STATUS_STORNIERT)));

        crit.add(Restrictions.eq(ProjektFac.FLR_PROJEKT_BEREICH_I_ID, bereichIId));
        // Einschraenkung nach Status Offen, Erledigt

        if (interneErledigungBeruecksichtigen == false) {
            Collection<String> cStati = new LinkedList<String>();
            cStati.add(ProjektServiceFac.PROJEKT_STATUS_ERLEDIGT);
            crit.add(Restrictions.in(ProjektFac.FLR_PROJEKT_STATUS_C_NR, cStati));
        }

        if (reportJournalKriterienDtoI.dVon != null) {

            if (interneErledigungBeruecksichtigen == true) {

                crit.add(Restrictions.or(
                        Restrictions.and(Restrictions.isNotNull(ProjektFac.FLR_PROJEKT_T_INTERNERLEDIGT),
                                Restrictions.ge(ProjektFac.FLR_PROJEKT_T_INTERNERLEDIGT,
                                        reportJournalKriterienDtoI.dVon)),
                        Restrictions.ge(ProjektFac.FLR_PROJEKT_T_ERLEDIGUNGSDATUM,
                                reportJournalKriterienDtoI.dVon)));

            } else {
                crit.add(Restrictions.ge(ProjektFac.FLR_PROJEKT_T_ERLEDIGUNGSDATUM,
                        reportJournalKriterienDtoI.dVon));
            }
        }

        if (reportJournalKriterienDtoI.dBis != null) {

            Date d = Helper.addiereTageZuDatum(reportJournalKriterienDtoI.dBis, 1);

            if (interneErledigungBeruecksichtigen == true) {
                crit.add(Restrictions.or(
                        Restrictions.and(Restrictions.isNotNull(ProjektFac.FLR_PROJEKT_T_INTERNERLEDIGT),
                                Restrictions.lt(ProjektFac.FLR_PROJEKT_T_INTERNERLEDIGT, d)),
                        Restrictions.lt(ProjektFac.FLR_PROJEKT_T_ERLEDIGUNGSDATUM, d)));
            } else {
                crit.add(Restrictions.lt(ProjektFac.FLR_PROJEKT_T_ERLEDIGUNGSDATUM, d));
            }

        }
        // Einschraenkung nach einer bestimmten Perosn
        if (reportJournalKriterienDtoI.personalIId != null) {
            crit.add(Restrictions.eq(ProjektFac.FLR_PROJEKT_PERSONAL_I_ID_ERLEDIGER,
                    reportJournalKriterienDtoI.personalIId));
        }
        // Sortierung nach Partner,
        if (reportJournalKriterienDtoI.iSortierung == ReportJournalKriterienDto.KRIT_SORT_NACH_PARTNER) {
            crit.createCriteria(ProjektFac.FLR_PROJEKT_FLRPARTNER)
                    .addOrder(Order.asc(PartnerFac.FLR_PARTNER_NAME1NACHNAMEFIRMAZEILE1));
            crit.addOrder(Order.asc(ProjektFac.FLR_PROJEKT_T_ERLEDIGUNGSDATUM));
            crit.addOrder(Order.asc(ProjektFac.FLR_PROJEKT_C_NR));

        }

        crit.addOrder(Order.asc(ProjektFac.FLR_PROJEKT_KATEGORIE_C_NR));
        List<?> list = crit.list();
        ArrayList<Object[]> alDaten = new ArrayList<Object[]>();
        Iterator<?> it = list.iterator();

        while (it.hasNext()) {
            FLRProjekt projekt = (FLRProjekt) it.next();
            Object[] oZeile = new Object[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ANZAHL_SPALTEN];

            if (interneErledigungBeruecksichtigen == true && projekt.getT_internerledigt() != null
                    && projekt.getT_erledigungsdatum() != null) {

                // Wenn intern-Erledigt und normal erledigt, dann gilt jenes
                // Datum, das frueher war

                if (projekt.getT_internerledigt().getTime() <= projekt.getT_erledigungsdatum().getTime()) {
                    if (reportJournalKriterienDtoI.dVon != null && projekt.getT_internerledigt()
                            .getTime() < reportJournalKriterienDtoI.dVon.getTime()) {
                        continue;
                    }

                    if (reportJournalKriterienDtoI.dBis != null && projekt.getT_internerledigt()
                            .getTime() > reportJournalKriterienDtoI.dBis.getTime()) {
                        continue;
                    }

                }

            }

            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_PROJEKTTITEL] = projekt.getC_titel();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_PROJEKTKATEGORIE] = projekt
                    .getKategorie_c_nr();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_PROJEKTCNR] = projekt.getC_nr();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_TYP] = projekt.getTyp_c_nr();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_KUNDECNAME1] = projekt.getFlrpartner()
                    .getC_name1nachnamefirmazeile1();

            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_WAHRSCHEINLICHKEIT] = projekt
                    .getI_wahrscheinlichkeit();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_GEPLANTERUMSATZ] = projekt
                    .getN_umsatzgeplant();
            if (projekt.getPersonal_i_id_internerledigt() != null) {
                PersonalDto personalDto = getPersonalFac()
                        .personalFindByPrimaryKey(projekt.getPersonal_i_id_internerledigt(), theClientDto);
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_INTERNERLEDIGT_PERSON] = personalDto
                        .getPartnerDto().formatAnrede();
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_INTERNERLEDIGT_ZEIT] = projekt
                        .getT_internerledigt();
            }
            locDruck = Helper.string2Locale(projekt.getFlrpartner().getLocale_c_nr_kommunikation());
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ZIELTERMIN] = Helper
                    .formatDatum(projekt.getT_zielwunschdatum(), locDruck);
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_BELEGDATUM] = Helper
                    .formatDatum(projekt.getT_anlegen(), locDruck);
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ERLEDIGUNGSDATUM] = Helper
                    .formatDatumZeit(projekt.getT_erledigungsdatum(), locDruck);
            if (projekt.getB_verrechenbar().equals(new Integer(1).shortValue())) {
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_B_VERRECHENBAR] = "verrechenbar";
            } else {
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_B_VERRECHENBAR] = null;
            }
            if (projekt.getB_freigegeben().equals(new Integer(1).shortValue())) {
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_FREIGEGEBEN] = "freigegeben";
            } else {
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_FREIGEGEBEN] = null;
            }

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(new Date(projekt.getT_zielwunschdatum().getTime()));
            int KW = calendar.get(Calendar.WEEK_OF_YEAR); // Kalendarwochen

            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ZIELWOCHE] = "" + KW;

            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_PRIO] = projekt.getI_prio();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_TEXT] = Helper
                    .formatStyledTextForJasper(projekt.getX_freetext());
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ERZEUGER] = projekt.getFlrpersonalErzeuger()
                    .getFlrpartner().getC_name1nachnamefirmazeile1();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ZUGEWIESENER] = projekt
                    .getFlrpersonalZugewiesener().getFlrpartner().getC_name1nachnamefirmazeile1();
            if (projekt.getPersonal_i_id_erlediger() != null) {
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ERLEDIGER] = projekt
                        .getFlrpersonalErlediger().getFlrpartner().getC_name1nachnamefirmazeile1();
            }
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ZEIT] = projekt.getT_zeit();
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_DAUER] = projekt.getD_dauer();

            // Gesamte Dauer eines Projektes
            Double ddArbeitszeitist = getZeiterfassungFac().getSummeZeitenEinesBeleges(
                    LocaleFac.BELEGART_PROJEKT, projekt.getI_id(), null, null, null, null, theClientDto);
            oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_GESAMTDAUER] = ddArbeitszeitist;

            Criteria crit1 = session.createCriteria(FLRHistory.class);
            crit1.createCriteria(ProjektFac.FLR_HISTORY_FLRPROJEKT)
                    .add(Restrictions.eq(ProjektFac.FLR_PROJEKT_I_ID, projekt.getI_id()));
            List<?> resultList = crit1.list();
            Iterator<?> itHistory = resultList.iterator();
            alDaten.add(oZeile);
            while (itHistory.hasNext()) {
                FLRHistory history = (FLRHistory) itHistory.next();

                oZeile = new Object[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ANZAHL_SPALTEN];

                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_PROJEKTCNR] = projekt.getC_nr();
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ZUGEWIESENER] = projekt
                        .getFlrpersonalZugewiesener().getFlrpartner().getC_name1nachnamefirmazeile1();
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_HISTORY_MITARBEITER] = history
                        .getFlrpersonal().getFlrpartner().getC_name1nachnamefirmazeile1();
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_HISTORY_BELEGDATUM] = Helper
                        .formatDatum(history.getT_belegdatum(), locDruck);
                oZeile[ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_HISTORY_TEXT] = history.getX_text();
                alDaten.add(oZeile);

            }
        }
        Object[][] returnArray = new Object[alDaten
                .size()][ProjektReportFac.REPORT_PROJEKT_JOURNAL_ERLEDIGT_ANZAHL_SPALTEN];
        data = (Object[][]) alDaten.toArray(returnArray);

    } catch (RemoteException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_IN_ZEITDATEN, new Exception(e));
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_HIBERNATE, he);
        }
    }

    // die Parameter dem Report uebergeben
    HashMap<String, Object> parameter = new HashMap<String, Object>();
    parameter.put(LPReport.P_FILTER, buildFilterProjektErledigt(reportJournalKriterienDtoI, theClientDto));
    parameter.put("P_BEREICH", getProjektServiceFac().bereichFindByPrimaryKey(bereichIId).getCBez());
    parameter.put("P_INTERNEERLEDIGUNGBERUECKSICHTIGEN", interneErledigungBeruecksichtigen);
    parameter.put("P_TITLE",
            getTextRespectUISpr("proj.print.erledigt", theClientDto.getMandant(), theClientDto.getLocUi()));
    initJRDS(parameter, ProjektReportFac.REPORT_MODUL, cAktuellerReport, theClientDto.getMandant(),
            theClientDto.getLocUi(), theClientDto);
    oPrint = getReportPrint();
    return oPrint;
}

From source file:com.mycompany.thymeleafspringapp.dao.DealsDaoImpl.java

@Override
public Deals getDeal(long userId, long dealId) throws IllegalAccessException {
    Criteria crit = sessionFactory.openSession().createCriteria(Deals.class);
    crit.add(Restrictions.and(Restrictions.eq("dealId", dealId),
            Restrictions.eq("users", usersDAO.getUserById(userId))));
    crit.setMaxResults(1);//  w  w w  .  j  a v a 2s  .c om
    List<Deals> deals = crit.list();
    if (deals.isEmpty()) {
        throw new IllegalAccessException("Unable to find the deal with given deal_id");

    }
    Deals d = deals.get(0);
    return d;
}

From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java

License:Open Source License

/** {@inheritDoc}*/
@Override/*from   ww w.  ja va2  s  .c o m*/
public List<BudgetPerformance> findByOrgCodeAndMonthAndKmkCodeJ(String orgCode, String monthly, String kmkCodeJ)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization must not be null or empty");
    }
    if (StringUtils.isEmpty(monthly)) {
        throw new IllegalArgumentException("Monthly must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<BudgetPerformance> budgetPerformances = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("pk.organization.strCode", orgCode),
                Restrictions.and(Restrictions.eq("pk.getSudo", monthly),
                        Restrictions.and(Restrictions.eq("pk.kmkCodeJ", kmkCodeJ),
                                Restrictions.eq("delKbn", Constants.STATUS_ACTIVE))));
        Criteria crit = session.createCriteria(BudgetPerformance.class);
        crit.add(criterion);

        // Execution starting
        budgetPerformances = repository.findByCriteria(crit);
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while get budget performance data by organization code " + orgCode
                        + " and monthly " + monthly + " and kmkCodeJ " + kmkCodeJ,
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return budgetPerformances;
}

From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w  w  w  .j  a  v a  2 s  . co  m
public Map<String, BudgetPerformance> findByOrgCodeAndMonthAndKmkCodeJs(String orgCode, String monthly,
        String... kmkCodeJs) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization must not be null or empty");
    }
    if (StringUtils.isEmpty(monthly)) {
        throw new IllegalArgumentException("Monthly must not be null or empty");
    }
    if (ArrayUtils.isEmpty(kmkCodeJs)) {
        throw new IllegalArgumentException("KmkCodeJs must not be null");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Map<String, BudgetPerformance> mapBudgetPerformances = new HashMap<String, BudgetPerformance>();
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("pk.organization.strCode", orgCode),
                Restrictions.and(Restrictions.eq("pk.getSudo", monthly),
                        Restrictions.and(Restrictions.in("pk.kmkCodeJ", kmkCodeJs),
                                Restrictions.eq("delKbn", Constants.STATUS_ACTIVE))));
        Criteria crit = session.createCriteria(BudgetPerformance.class);
        crit.add(criterion);

        List<BudgetPerformance> budgetPerformances = repository.findByCriteria(crit);
        if (CollectionUtils.isNotEmpty(budgetPerformances)) {
            for (int i = 0; i < budgetPerformances.size(); i++) {
                BudgetPerformance budgetPerformance = budgetPerformances.get(i);
                mapBudgetPerformances.put(budgetPerformance.getPk().getKmkCodeJ(), budgetPerformance);
            }
        }
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while get budget performance data by organization code " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return mapBudgetPerformances;
}

From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from  w w w. j a  v a 2s. c  om*/
public Map<String, BudgetPerformance> findByOrgCodeAndStartMonthEndMonthAndKmkCodeJs(String orgCode,
        String startMonth, String endMonth, String... kmkCodeJs) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException(
                "Organization code or current month in acton must not be null or empty");
    }
    if (StringUtils.isEmpty(startMonth)) {
        throw new IllegalArgumentException("Start month must not be null or empty");
    }
    if (StringUtils.isEmpty(endMonth)) {
        throw new IllegalArgumentException("End month month must not be null or empty");
    }
    if (ArrayUtils.isEmpty(kmkCodeJs)) {
        throw new IllegalArgumentException("KmkCodeJs must not be null");
    }

    // 
    logger.info("Find by organization code:" + orgCode + " startMonth " + startMonth + " endMonth " + endMonth
            + "kmkcodej " + StringUtils.join(kmkCodeJs, ","));
    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Map<String, BudgetPerformance> mapBudgetPerformances = new HashMap<String, BudgetPerformance>();

    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("pk.organization.strCode", orgCode),
                Restrictions.and(Restrictions.ge("pk.getSudo", startMonth),
                        Restrictions.and(Restrictions.le("pk.getSudo", endMonth),
                                Restrictions.and(Restrictions.in("pk.kmkCodeJ", kmkCodeJs),
                                        Restrictions.eq("delKbn", Constants.STATUS_ACTIVE)))));
        Criteria crit = session.createCriteria(BudgetPerformance.class);
        crit.add(criterion);

        List<BudgetPerformance> budgetPerformances = repository.findByCriteria(crit);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(budgetPerformances)) {
            throw new ObjectNotFoundException("There is no the budget performance object");
        }

        mapBudgetPerformances = new HashMap<String, BudgetPerformance>();
        for (BudgetPerformance budgetPerformance : budgetPerformances) {
            mapBudgetPerformances.put(
                    budgetPerformance.getPk().getGetSudo() + budgetPerformance.getPk().getKmkCodeJ(),
                    budgetPerformance);
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while get budget performance data by organization code " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return mapBudgetPerformances;
}

From source file:com.nec.harvest.service.impl.BusinessDayServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w  w  w  .  ja va  2 s . co m
public BusinessDay findByEigyobiCode(String eigCode) throws ServiceException {
    if (StringUtils.isEmpty(eigCode)) {
        throw new IllegalArgumentException("Eigyobi code must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    BusinessDay businessDay = null;
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("eigCode", eigCode),
                Restrictions.eq("delKbn", Constants.STATUS_ACTIVE));
        Criteria criteria = repository.getCriteria(session, BusinessDay.class);
        criteria.add(criterion);
        List<BusinessDay> businessDates = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(businessDates)) {
            throw new ObjectNotFoundException("There is no businessDay with eigCode of " + eigCode);
        }

        if (businessDates.size() > 1) {
            throw new TooManyObjectsException("Found too many business days are the same with " + eigCode);
        }

        businessDay = businessDates.get(0);
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("Could not find any record for business day code " + eigCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return businessDay;
}

From source file:com.nec.harvest.service.impl.MenuGroupServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   ww  w. j  a  v a2  s  .co m
public List<MenuH> findByUserRole(String userRole) throws ServiceException {
    if (StringUtils.isEmpty(userRole)) {
        throw new IllegalArgumentException("User's role must not be empty or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<MenuH> menuGroups = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("proKGCode", userRole),
                Restrictions.eq("proGEnable", "T"));
        Criteria criteria = repository.getCriteria(session, MenuH.class);
        criteria.add(criterion);
        menuGroups = repository.findByCriteria(criteria);
        if (CollectionUtils.isEmpty(menuGroups)) {
            throw new ObjectNotFoundException("Could not find any menu group matches with role " + userRole);
        }
        for (MenuH group : menuGroups) {
            // Sorting MenuD Object on natural order - ascending (ASC)
            Collections.sort(group.getChildren());
        }
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred when getting menu groups for role " + userRole, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return menuGroups;
}

From source file:com.nec.harvest.service.impl.OrganizationServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from  ww  w. j a va  2 s. c  o m*/
public Organization findByOrgCode(String strCode) throws ServiceException {
    if (StringUtils.isEmpty(strCode)) {
        throw new IllegalArgumentException("The organization's code must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Organization organization = null;
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("strCode", strCode),
                Restrictions.eq("delKbn", Constants.STATUS_ACTIVE));
        Criteria criteria = repository.getCriteria(session, Organization.class);
        criteria.add(criterion);
        List<Organization> organizations = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(organizations)) {
            throw new ObjectNotFoundException("Could not find any organization matches with code " + strCode);
        }

        if (organizations.size() > 1) {
            throw new TooManyObjectsException("Too many organization objects are matches with code " + strCode);
        }
        organization = organizations.get(0);
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding a organization by " + strCode
                + " and delKbn " + Constants.STATUS_ACTIVE, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return organization;
}

From source file:com.nec.harvest.service.impl.StampedServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override// w w  w. ja  v a 2s.co  m
public double findStampedLackingByOrgCode(String orgCode) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("User's organization code must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    double isStamped = 0;
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("pk.organization.strCode", orgCode),
                Restrictions.eq("delKbn", "2"));
        Criteria criteria = repository.getCriteria(session, Stamp.class);
        criteria.add(criterion);
        List<Stamp> stamps = repository.findByCriteria(criteria);
        if (CollectionUtils.isNotEmpty(stamps)) {
            isStamped = stamps.get(0).getNinzu();
        }
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred when getting all the number of stamped lacking "
                + "for the organization's code " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return isStamped;
}

From source file:com.nec.harvest.service.impl.UserServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//w  ww .j a  va  2s  . c  o  m
public User findByUsrCode(String strCode) throws ServiceException {
    if (StringUtils.isEmpty(strCode)) {
        throw new IllegalArgumentException("User's code must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    User user = null;
    try {
        tx = session.beginTransaction();
        Criterion criterion = Restrictions.and(Restrictions.eq("usrCode", strCode),
                Restrictions.eq("delKbn", Constants.STATUS_ACTIVE));
        Criteria criteria = repository.getCriteria(session, User.class);
        criteria.add(criterion);
        List<User> users = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(users)) {
            throw new ObjectNotFoundException("Could not find any user matches with code " + strCode);
        }

        if (users.size() > 1) {
            throw new TooManyObjectsException("Found too many users are matched with code " + strCode);
        }

        user = users.get(0);
    } catch (JDBCConnectionException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ConnectionException(ex.getMessage(), ex);
    } catch (org.hibernate.ObjectNotFoundException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw ex;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding a logged in user for name " + strCode,
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return user;
}