Example usage for org.hibernate.criterion Restrictions not

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

Introduction

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

Prototype

public static Criterion not(Criterion expression) 

Source Link

Document

Return the negation of an expression

Usage

From source file:org.n52.server.ses.hibernate.HibernateUtil.java

License:Open Source License

@Deprecated
@SuppressWarnings("unchecked")
public static List<ComplexRule> getAllOtherComplexRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w  w  . j a v  a  2s. c  o  m
    Criteria crit = session.createCriteria(ComplexRule.class);
    List<ComplexRule> rules = crit.add(Restrictions.not(Restrictions.eq(OWNER_ID, Integer.valueOf(userID))))
            .list();
    session.getTransaction().commit();
    return rules;
}

From source file:org.n52.server.ses.hibernate.HibernateUtil.java

License:Open Source License

@SuppressWarnings("unchecked")
public static boolean otherAdminsExist(int userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();//from ww w.j  a  v  a 2 s.c  o  m
    Criteria crit = session.createCriteria(User.class);
    List<User> users = crit
            .add(Restrictions.and(Restrictions.not(Restrictions.eq(ID, userID)), Restrictions.eq(ROLE, ADMIN)))
            .list();

    if (users.size() >= 1) {
        return true;
    }
    return false;
}

From source file:org.n52.sos.ds.hibernate.dao.ObservationDAO.java

License:Open Source License

private void addAliasAndNotRestrictionFor(Criteria c, Set<Long> procedureIds, Set<Long> observablePropertyIds,
        Set<Long> featureIds) {
    c.createAlias(Observation.PROCEDURE, "p").createAlias(Observation.OBSERVABLE_PROPERTY, "op")
            .createAlias(Observation.FEATURE_OF_INTEREST, "f");
    c.add(Restrictions.not(Restrictions.in("p." + Procedure.ID, procedureIds)));
    c.add(Restrictions.not(Restrictions.in("op." + ObservableProperty.ID, observablePropertyIds)));
    c.add(Restrictions.not(Restrictions.in("f." + FeatureOfInterest.ID, featureIds)));
}

From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesObservationDAO.java

License:Open Source License

public ScrollableResults getSeriesNotMatchingSeries(Set<Long> seriesIDs, GetObservationRequest request,
        Set<String> features, Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    Criteria c = getSeriesObservationCriteriaFor(request, features, temporalFilterCriterion, null, session)
            .createAlias(SeriesObservation.SERIES, "s");
    c.add(Restrictions.not(Restrictions.in("s." + Series.ID, seriesIDs)));
    c.setProjection(Projections.property(SeriesObservation.SERIES));
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesObservationDAO.java

License:Open Source License

public ScrollableResults getSeriesNotMatchingSeries(Set<Long> seriesIDs, GetObservationRequest request,
        Set<String> features, Session session) throws OwsExceptionReport {
    Criteria c = getSeriesObservationCriteriaFor(request, features, null, null, session)
            .createAlias(SeriesObservation.SERIES, "s");
    c.add(Restrictions.not(Restrictions.in("s." + Series.ID, seriesIDs)));
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.openbravo.erpCommon.ad_process.AcctServerProcess.java

License:Open Source License

public void doExecute(ProcessBundle bundle) throws Exception {

    logger = bundle.getLogger();// w  w w.j a  v  a  2 s.  c o m
    connection = bundle.getConnection();

    VariablesSecureApp vars = bundle.getContext().toVars();
    if (vars.getClient().equals(SYSTEM_CLIENT_ID)) {
        OBCriteria<Client> obc = OBDal.getInstance().createCriteria(Client.class);
        obc.add(Restrictions.not(Restrictions.eq(Client.PROPERTY_ID, SYSTEM_CLIENT_ID)));
        for (Client c : obc.list()) {
            final VariablesSecureApp vars1 = new VariablesSecureApp(bundle.getContext().getUser(), c.getId(),
                    bundle.getContext().getOrganization());
            processClient(vars1, bundle);
        }
    } else {
        processClient(vars, bundle);
    }
}

From source file:org.openbravo.erpCommon.modules.ImportModule.java

License:Open Source License

/**
 * Returns the current installed modules with its version (with the exception of those which are
 * marked for deinstallation)/*from w  w  w .  ja va2 s  .  c  om*/
 * 
 * @return HashMap<String, String[][]> --> <ModuleId, VersionInfo[]>
 *         <ul>
 *         <li>VersionInfo [x][0] -> Type "M" Module, "D" Dependency</li>
 *         <li>VersionInfo [x][1] -> If type=="M", version number. If type =="D" dep module Id</li>
 *         <li>VersionInfo [x][2] -> If type=="M", module visibility level. If type=="D", from
 *         version</li>
 *         <li>VersionInfo [x][3] -> If type=="D", to version</li>
 *         <li>VersionInfo [x][4] -> If type=="D", "Y"/"N" is included</li>
 *         <li>VersionInfo [x][5] -> If type=="D", Dependent module name</li>
 *         <li>VersionInfo [x][6] -> If type=="D", Dependency enforcement</li>
 *         <li>VersionInfo [x][7] -> If type=="D", Instance dependency enforcement</li>
 *         </ul>
 */
public static HashMap<String, String[][]> getInstalledModulesAndDeps() {
    HashMap<String, String[][]> rt = new HashMap<String, String[][]>();
    try {
        OBContext.setAdminMode();

        String defaultMaturity = OBDal.getInstance().get(SystemInformation.class, "0").getMaturityUpdate();
        List<String> installingMods = new ArrayList<String>();

        // Taking into account modules in process of intallation. These modules have higher priority
        // over actually installed ones
        OBCriteria<ModuleInstall> qModInstall = OBDal.getInstance().createCriteria(ModuleInstall.class);
        for (ModuleInstall mod : qModInstall.list()) {
            org.openbravo.model.ad.module.Module currentDBVersion = OBDal.getInstance()
                    .get(org.openbravo.model.ad.module.Module.class, mod.getModule());

            String[][] versionInfo = new String[1][0];
            versionInfo[0] = new String[3];
            versionInfo[0][0] = "M";
            versionInfo[0][1] = mod.getVersion();
            versionInfo[0][2] = currentDBVersion == null ? defaultMaturity
                    : currentDBVersion.getMaturityUpdate();

            // Dependencies are not needed as it is a version installed from CR

            rt.put(mod.getModule(), versionInfo);
            installingMods.add(mod.getModule());
        }

        OBCriteria<org.openbravo.model.ad.module.Module> obCriteria = OBDal.getInstance()
                .createCriteria(org.openbravo.model.ad.module.Module.class);
        obCriteria.add(
                Restrictions.not(Restrictions.eq(org.openbravo.model.ad.module.Module.PROPERTY_STATUS, "U")));
        if (!installingMods.isEmpty()) {
            obCriteria.add(Restrictions
                    .not(Restrictions.in(org.openbravo.model.ad.module.Module.PROPERTY_ID, installingMods)));
        }
        List<org.openbravo.model.ad.module.Module> modules = obCriteria.list();

        boolean activeInstance = ActivationKey.getInstance().isActive();

        for (org.openbravo.model.ad.module.Module mod : modules) {

            List<org.openbravo.model.ad.module.ModuleDependency> dependencies = mod.getModuleDependencyList();

            String[][] versionInfo = new String[dependencies.size() + 1][0];
            versionInfo[0] = new String[3];
            versionInfo[0][0] = "M";
            versionInfo[0][1] = mod.getVersion();

            if (!activeInstance && mod.getMaturityUpdate() != null
                    && Integer.parseInt(mod.getMaturityUpdate()) >= MaturityLevel.CS_MATURITY) {
                // Community instances are not allowed to use GA maturity, setting it to CR
                versionInfo[0][2] = Integer.toString(MaturityLevel.QA_APPR_MATURITY);
            } else {
                versionInfo[0][2] = mod.getMaturityUpdate();
            }

            int i = 1;
            for (org.openbravo.model.ad.module.ModuleDependency dep : dependencies) {
                versionInfo[i] = new String[8];
                versionInfo[i][0] = "D";
                versionInfo[i][1] = dep.getDependentModule().getId();
                versionInfo[i][2] = dep.getFirstVersion();
                versionInfo[i][3] = dep.getLastVersion();
                versionInfo[i][4] = dep.isIncluded() ? "Y" : "N";
                versionInfo[i][5] = dep.getDependantModuleName();
                versionInfo[i][6] = dep.getDependencyEnforcement();
                versionInfo[i][7] = dep.isUserEditableEnforcement() ? dep.getInstanceEnforcement() : null;
                i++;
            }

            rt.put(mod.getId(), versionInfo);
        }

        return rt;
    } finally {
        OBContext.restorePreviousMode();
    }
}

From source file:org.openbravo.event.ADTableEventHandler.java

License:Open Source License

private void checkClassNameForDuplicates(EntityPersistenceEvent event) {
    ConnectionProvider conn = new DalConnectionProvider(false);
    String language = OBContext.getOBContext().getLanguage().getLanguage();
    String tableId = (String) event.getTargetInstance().getId();
    final Entity tableEntity = ModelProvider.getInstance().getEntity(Table.ENTITY_NAME);
    final Property javaClassNameProperty = tableEntity.getProperty(Table.PROPERTY_JAVACLASSNAME);
    Object javaClassName = event.getCurrentState(javaClassNameProperty);
    final Property packageNameProperty = tableEntity.getProperty(Table.PROPERTY_DATAPACKAGE);
    Object packageName = event.getCurrentState(packageNameProperty);
    final Property dataOriginTypeProperty = tableEntity.getProperty(Table.PROPERTY_DATAORIGINTYPE);
    Object dataOriginType = event.getCurrentState(dataOriginTypeProperty);
    if (ApplicationConstants.TABLEBASEDTABLE.equals(dataOriginType) && javaClassName != null) {
        OBCriteria<Table> tableCriteria = OBDal.getInstance().createCriteria(Table.class);
        tableCriteria.add(Restrictions.eq(Table.PROPERTY_JAVACLASSNAME, javaClassName));
        tableCriteria.add(Restrictions.eq(Table.PROPERTY_DATAPACKAGE, packageName));
        tableCriteria.add(Restrictions.not(Restrictions.eq(Table.PROPERTY_ID, tableId)));
        if (tableCriteria.count() != 0) {
            throw new OBException(Utility.messageBD(conn, "DuplicateJavaClassName", language));
        }//from   w  w w.j  a v  a 2s  . c om
    }
}

From source file:org.openbravo.service.system.DatabaseValidator.java

License:Open Source License

/**
 * Checks if old-style password columns exist which should be updated to use the new references.
 * //  ww w.  j  av a2  s. c  o  m
 */
private void checkPasswordColumns(SystemValidationResult result) {
    org.openbravo.model.ad.domain.Reference hashed = OBDal.getInstance()
            .get(org.openbravo.model.ad.domain.Reference.class, "C5C21C28B39E4683A91779F16C112E40");
    org.openbravo.model.ad.domain.Reference encrypted = OBDal.getInstance()
            .get(org.openbravo.model.ad.domain.Reference.class, "16EC6DF4A59747749FDF256B7FBBB058");

    // if one of the old-booleans is set, but not using new reference-id's -> report as warning
    SimpleExpression enc = Restrictions.eq(Column.PROPERTY_DISPLAYENCRIPTION, Boolean.TRUE);
    LogicalExpression newRefs = Restrictions.or(Restrictions.eq(Column.PROPERTY_REFERENCE, hashed),
            Restrictions.eq(Column.PROPERTY_REFERENCE, encrypted));
    OBCriteria<Column> colQuery = OBDal.getInstance().createCriteria(Column.class);
    colQuery.add(Restrictions.and(enc, Restrictions.not(newRefs)));

    // only validate given module (if given)
    if (validateModule != null) {
        colQuery.add(Restrictions.eq(Column.PROPERTY_MODULE, validateModule));
    }
    if (colQuery.count() > 0) {
        List<Column> columns = colQuery.list();
        for (Column column : columns) {
            result.addWarning(SystemValidationType.OLDSTYLE_PASSWORD_COLUMNS, "The column '"
                    + column.getTable().getName() + "'.'" + column.getName()
                    + "' is using old-style config for password-type columns. It should be changed to use one of the new references '"
                    + hashed.getName() + "' or '" + encrypted.getName() + "'");
        }
    }
}

From source file:org.openbravo.test.base.BaseTest.java

License:Open Source License

/**
 * Gets a random User (Record ID) from the available ones in the test client. The ID is one
 * different than {@link #TEST_USER_ID}/*  ww  w. java  2 s. co m*/
 * 
 * @return A record ID of a available user
 */
protected User getRandomUser() {
    if (userIds == null) {
        setTestUserContext();

        String[] excludedUserIds = { "100", TEST_USER_ID };
        OBCriteria<User> obc = OBDal.getInstance().createCriteria(User.class);
        obc.add(Restrictions.not(Restrictions.in(User.PROPERTY_ID, excludedUserIds)));
        obc.add(Restrictions.isNotEmpty(User.PROPERTY_ADUSERROLESLIST));

        if (obc.count() == 0) {
            throw new RuntimeException("Unable to initialize the list of available users");
        }
        userIds = new ArrayList<User>();
        for (User u : obc.list()) {
            userIds.add(u);
        }
    }

    Random r = new Random();
    return userIds.get(r.nextInt(userIds.size()));
}