Example usage for org.hibernate.criterion Restrictions ne

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

Introduction

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

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

From source file:org.openbravo.client.application.event.ElementValueEventHandler.java

License:Open Source License

List<ElementValue> getAccountList(ElementValue account) {
    OBCriteria<ElementValue> obc = OBDal.getInstance().createCriteria(ElementValue.class);
    obc.add(Restrictions.eq(ElementValue.PROPERTY_ACCOUNTINGELEMENT, account.getAccountingElement()));
    obc.add(Restrictions.eq(ElementValue.PROPERTY_ACTIVE, true));
    obc.add(Restrictions.le(ElementValue.PROPERTY_SEARCHKEY, account.getSearchKey()));
    obc.add(Restrictions.ne(ElementValue.PROPERTY_ID, account.getId()));
    obc.addOrder(Order.desc(ElementValue.PROPERTY_SEARCHKEY));
    obc.setMaxResults(1);//from  w  w w . j  a  va2s . c o  m
    obc.setFilterOnReadableClients(false);
    obc.setFilterOnReadableOrganization(false);
    return obc.list();
}

From source file:org.openbravo.client.application.event.RemoveImagesEventHandler.java

License:Open Source License

private static boolean checkImageUtilization(String productId, Image bob) {
    final OBCriteria<Product> obCriteria = OBDal.getInstance().createCriteria(Product.class);
    obCriteria.add(Restrictions.eq(Product.PROPERTY_IMAGE, bob));
    obCriteria.add(Restrictions.ne(Product.PROPERTY_ID, productId));
    obCriteria.setFilterOnActive(false);
    obCriteria.setFilterOnReadableClients(false);
    obCriteria.setFilterOnReadableOrganization(false);
    obCriteria.setMaxResults(1);/*from   w  w w . j  ava  2s  .c  om*/
    Product product = (Product) obCriteria.uniqueResult();

    if (product != null) {
        return true;
    }
    return false;
}

From source file:org.openbravo.client.application.event.RoleAccessUniqueHandler.java

License:Open Source License

private void checkUniqueness(EntityPersistenceEvent event) {
    Entity entity = event.getTargetInstance().getEntity();

    Role newRole = (Role) event.getCurrentState(entity.getProperty("role"));

    // securedObjectProperty is the property (different based on the observed entity) that links to
    // the secured object. This property together with role must be unique
    Property securedObjectProperty;//  www. j  av  a 2s. c o m
    if (entity.equals(WIDGET_CLASS_ACCESS_ENTITY)) {
        securedObjectProperty = WIDGET_CLASS_ACCESS_ENTITY.getProperty(WidgetClassAccess.PROPERTY_WIDGETCLASS);
    } else if (entity.equals(PROCESS_DEF_ACCESS_ENTITY)) {
        securedObjectProperty = PROCESS_DEF_ACCESS_ENTITY.getProperty(ProcessAccess.PROPERTY_OBUIAPPPROCESS);
    } else {
        securedObjectProperty = VIEW_ACCESS_ENTITY.getProperty(ViewRoleAccess.PROPERTY_VIEWIMPLEMENTATION);
    }

    OBCriteria<BaseOBObject> q = OBDal.getInstance().createCriteria(entity.getName());

    q.add(Restrictions.eq("role", newRole));
    q.add(Restrictions.eq(securedObjectProperty.getName(), event.getCurrentState(securedObjectProperty)));

    if (event instanceof EntityUpdateEvent) {
        // do not count itself when updating
        q.add(Restrictions.ne("id", event.getId()));
    }

    if (q.count() > 0) {
        throw new OBException(OBMessageUtils.getI18NMessage("OBUIAPP_DuplicateAccess",
                new String[] { ((BaseOBObject) event.getCurrentState(securedObjectProperty)).getIdentifier(),
                        newRole.getName() }));
    }
}

From source file:org.openbravo.client.application.event.TableTreeEventHandler.java

License:Open Source License

/**
 * Checks that no other ADTree structured tree exists for this table, throws an exception if this
 * occurs//from   w  w w. jav a 2s  .  co m
 * 
 * @param table
 *          table being checked
 * @param treeStructure
 *          treestructure of the added/updated tree
 * @param recordId
 *          null if a new record is being created or id of the record being modified
 */
private void checkTreeStructure(Table table, String treeStructure, String recordId) {
    if (ADTREE_STRUCTURE.equals(treeStructure)) {
        // Check that there is no other ADTree Defined for this table
        OBCriteria<TableTree> obq = OBDal.getInstance().createCriteria(TableTree.class);
        obq.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table));
        obq.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, treeStructure));
        if (recordId != null) {
            obq.add(Restrictions.ne(TableTree.PROPERTY_ID, recordId));
        }
        if (obq.count() > 0) {
            String language = OBContext.getOBContext().getLanguage().getLanguage();
            ConnectionProvider conn = new DalConnectionProvider(false);
            throw new OBException(Utility.messageBD(conn, "OBUIAPP_OneADTreePerTable", language));
        }
    }
}

From source file:org.openbravo.costing.CostAdjustmentProcess.java

License:Open Source License

private void checkPermanentelyAdjustedTrx(String strCostAdjId) throws OBException {
    OBCriteria<CostAdjustmentLine> critLines = OBDal.getInstance().createCriteria(CostAdjustmentLine.class);
    critLines.createAlias(CostAdjustmentLine.PROPERTY_INVENTORYTRANSACTION, "trx");
    critLines.createAlias(CostAdjustmentLine.PROPERTY_COSTADJUSTMENT, "ca");
    critLines.add(Restrictions.eq("ca.id", strCostAdjId));
    critLines.add(Restrictions.eq("trx." + MaterialTransaction.PROPERTY_ISCOSTPERMANENT, Boolean.TRUE));
    critLines.add(Restrictions.ne(CostAdjustmentLine.PROPERTY_ADJUSTMENTAMOUNT, BigDecimal.ZERO));
    critLines.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_UNITCOST, Boolean.TRUE));
    critLines.addOrder(Order.asc(CostAdjustmentLine.PROPERTY_LINENO));

    ScrollableResults lines = critLines.scroll(ScrollMode.FORWARD_ONLY);
    long count = 1L;
    try {/*from  w w w .  ja  v a  2 s .c  om*/
        String strLines = "";
        while (lines.next()) {
            CostAdjustmentLine line = (CostAdjustmentLine) lines.get()[0];
            strLines += line.getLineNo() + ", ";

            if (count % 10000 == 0) {
                OBDal.getInstance().flush();
                OBDal.getInstance().getSession().clear();
            }
            count++;
        }
        if (!strLines.isEmpty()) {
            strLines = strLines.substring(0, strLines.length() - 2);
            String errorMessage = OBMessageUtils.messageBD("CostAdjustmentWithPermanentLines");
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("lines", strLines);
            throw new OBException(OBMessageUtils.parseTranslation(errorMessage, map));
        }
        OBDal.getInstance().flush();
        OBDal.getInstance().getSession().clear();
    } finally {
        lines.close();
    }
}

From source file:org.openbravo.costing.CostingMigrationProcess.java

License:Open Source License

private static List<Client> getClients() {
    OBCriteria<Client> obcClient = OBDal.getInstance().createCriteria(Client.class);
    obcClient.setFilterOnReadableClients(false);
    obcClient.add(Restrictions.ne(Client.PROPERTY_ID, "0"));
    return obcClient.list();
}

From source file:org.openbravo.dal.service.OBDal.java

License:Open Source License

/**
 * Retrieves a list of baseOBObjects using the unique-constraints defined for the entity. The
 * passed BaseOBObject and the unique-constraints are used to construct a query searching for
 * matching objects in the database.//w  ww .  j a  v a2 s. c  om
 * <p/>
 * Note that multiple unique constraints are used, so therefore the result can be more than one
 * object.
 * 
 * @param obObject
 *          this property values of this obObject is used to find other objects in the database
 *          with the same property values for the unique constraint properties
 * @return a list of objects which match the passed obObject on the unique constraint properties
 * @see Entity#getUniqueConstraints()
 */
public List<BaseOBObject> findUniqueConstrainedObjects(BaseOBObject obObject) {
    final Entity entity = obObject.getEntity();
    final List<BaseOBObject> result = new ArrayList<BaseOBObject>();
    final Object id = obObject.getId();
    for (final UniqueConstraint uc : entity.getUniqueConstraints()) {
        final OBCriteria<BaseOBObject> criteria = createCriteria(entity.getName());
        if (id != null) {
            criteria.add(Restrictions.ne("id", id));
        }
        for (final Property p : uc.getProperties()) {
            final Object value = obObject.getValue(p.getName());
            criteria.add(Restrictions.eq(p.getName(), value));
        }
        final List<BaseOBObject> queryResult = criteria.list();
        // this is not fast, but the list should be small normally
        // if performance becomes a problem then a hashset should
        // be used.
        for (final BaseOBObject queriedObject : queryResult) {
            if (!result.contains(queriedObject)) {
                result.add(queriedObject);
            }
        }
    }

    return result;
}

From source file:org.openbravo.dal.xml.EntityResolver.java

License:Open Source License

protected BaseOBObject findUniqueConstrainedObject(BaseOBObject obObject) {
    // an existing object should not be able to violate his/her
    // own constraints
    if (!obObject.isNewOBObject()) {
        return null;
    }/*w w  w  . jav  a 2 s . c  o m*/

    final Entity entity = obObject.getEntity();
    final Object id = obObject.getId();
    for (final UniqueConstraint uc : entity.getUniqueConstraints()) {
        final OBCriteria<BaseOBObject> criteria = OBDal.getInstance().createCriteria(entity.getName());
        if (id != null) {
            criteria.add(Restrictions.ne("id", id));
        }

        boolean ignoreUniqueConstraint = false;
        for (final Property p : uc.getProperties()) {
            final Object value = obObject.getValue(p.getName());

            // a special check, the property refers to an
            // object which is also new, presumably this object
            // is also added in the import
            // in this case the
            // uniqueconstraint can never fail
            // so move on to the next
            if (value instanceof BaseOBObject && ((BaseOBObject) value).isNewOBObject()) {
                ignoreUniqueConstraint = true;
                break;
            }

            criteria.add(Restrictions.eq(p.getName(), value));
        }
        if (ignoreUniqueConstraint) {
            continue;
        }

        criteria.setFilterOnActive(false);
        criteria.setFilterOnReadableOrganization(false);
        criteria.setFilterOnReadableClients(false);
        criteria.setMaxResults(1);

        final List<BaseOBObject> queryResult = criteria.list();
        if (queryResult.size() > 0) {

            // check if the found unique match is a valid
            // object to use
            // TODO: this can be made faster by
            // adding client/organization filtering above in
            // the criteria
            final BaseOBObject searchResult = searchInstance(entity, (String) queryResult.get(0).getId());
            if (searchResult == null) {
                // not valid return null
                return null;
            }
            return queryResult.get(0);
        }
    }

    return null;
}

From source file:org.openbravo.erpCommon.ad_callouts.SL_ModuleCallout.java

License:Open Source License

/**
 * Checks if there are multiple templates in development. If so, unsets the is indevelopment
 * property from the current record./*from  w  w  w  .j ava 2s.co  m*/
 */
private void templateInDev(HttpServletResponse response, VariablesSecureApp vars, String strADModuleID)
        throws IOException, ServletException {
    // Check whether there are more templates in development
    OBCriteria<Module> obc = OBDal.getInstance().createCriteria(Module.class);
    obc.add(Restrictions.eq(Module.PROPERTY_TYPE, "T"));
    obc.add(Restrictions.eq(Module.PROPERTY_INDEVELOPMENT, true));
    if (strADModuleID != null && !strADModuleID.equals("")) {
        obc.add(Restrictions.ne(Module.PROPERTY_ID, strADModuleID));
    }
    String devTemplates = "";
    for (Module template : obc.list()) {
        devTemplates += template.getName() + " ";
    }

    StringBuffer result = new StringBuffer();

    if (!devTemplates.equals("")) {
        // There are other template(s) in dev
        result.append("new Array(\"MESSAGE\", \"" + devTemplates + " "
                + Utility.messageBD(this, "MultipleDevelopmentTemplates", vars.getLanguage()) + "\"),\n");
        result.append("new Array(\"inpisindevelopment\", \"N\")");
    }

    printPageResult(response, result.toString());
}

From source file:org.openbravo.erpCommon.ad_callouts.SL_Preference.java

License:Open Source License

@Override
protected void execute(CalloutInfo info) throws ServletException {
    boolean selected = info.getStringParameter("inpselected", booleanFilter).equals("Y");
    if (selected) {
        OBCriteria<Preference> qPref = OBDal.getInstance().createCriteria(Preference.class);

        String prefId = info.getStringParameter("inpadPreferenceId", idFilter);
        if (!prefId.isEmpty()) {
            qPref.add(Restrictions.ne(Preference.PROPERTY_ID, prefId));
        }//from w  w w  .j  ava2s.c o  m

        if (info.getStringParameter("inpispropertylist", booleanFilter).equals("Y")) {
            qPref.add(Restrictions.eq(Preference.PROPERTY_PROPERTY,
                    info.getStringParameter("inpproperty", null)));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_ATTRIBUTE,
                    info.getStringParameter("inpattribute", null)));
        }

        qPref.add(Restrictions.eq(Preference.PROPERTY_SELECTED, true));

        String client = info.getStringParameter("inpvisibleatClientId", idFilter);
        if (client.isEmpty() || client.equals("0")) {
            qPref.add(Restrictions.or(Restrictions.isNull(Preference.PROPERTY_VISIBLEATCLIENT),
                    Restrictions.eq(Preference.PROPERTY_VISIBLEATCLIENT + ".id", "0")));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_VISIBLEATCLIENT + ".id", client));
        }

        String org = info.getStringParameter("inpvisibleatOrgId", idFilter);
        if (org.isEmpty() || org.equals("0")) {
            qPref.add(Restrictions.or(Restrictions.isNull(Preference.PROPERTY_VISIBLEATORGANIZATION),
                    Restrictions.eq(Preference.PROPERTY_VISIBLEATORGANIZATION + ".id", "0")));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_VISIBLEATORGANIZATION + ".id", org));
        }

        String user = info.getStringParameter("inpadUserId", idFilter);
        if (user.isEmpty()) {
            qPref.add(Restrictions.isNull(Preference.PROPERTY_USERCONTACT));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_USERCONTACT + ".id", user));
        }

        String role = info.getStringParameter("inpvisibleatRoleId", idFilter);
        if (role.isEmpty()) {
            qPref.add(Restrictions.isNull(Preference.PROPERTY_VISIBLEATROLE));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_VISIBLEATROLE + ".id", role));
        }

        String window = info.getStringParameter("inpadWindowId", idFilter);
        if (window.isEmpty()) {
            qPref.add(Restrictions.isNull(Preference.PROPERTY_WINDOW));
        } else {
            qPref.add(Restrictions.eq(Preference.PROPERTY_WINDOW + ".id", window));
        }

        if (qPref.count() > 0) {
            info.addResult("inpselected", "N");
            info.addResult("MESSAGE", Utility.messageBD(this, "MultipleSelectedPreferences",
                    OBContext.getOBContext().getLanguage().getLanguage()));
        }
    }
}