Package org.openbravo.base.model

Examples of org.openbravo.base.model.Entity


   * @see DataSetTable
   */
  public boolean hasData(DataSet dataSet) {
    long totalCnt = 0;
    for (DataSetTable dataSetTable : dataSet.getDataSetTableList()) {
      final Entity entity = ModelProvider.getInstance().getEntityByTableName(
          dataSetTable.getTable().getDBTableName());
      final OBCriteria<BaseOBObject> obc = OBDal.getInstance().createCriteria(entity.getName());
      totalCnt += obc.count();
      if (totalCnt > 0) {
        return true;
      }
    }
View Full Code Here


   * @return true if there is at least one object which has changed since afterDate, false
   *         afterwards
   */
  public <T extends BaseOBObject> boolean hasChanged(DataSet dataSet, Date afterDate) {
    for (DataSetTable dataSetTable : dataSet.getDataSetTableList()) {
      final Entity entity = ModelProvider.getInstance().getEntityByTableName(
          dataSetTable.getTable().getDBTableName());
      final OBCriteria<T> obc = OBDal.getInstance().createCriteria(entity.getName());
      obc.add(Expression.gt(Organization.PROPERTY_UPDATED, afterDate));
      // todo: count is slower than exists, is exists possible?
      List<?> list = obc.list();
      if (obc.count() < 20 && obc.count() > 0) {
        log
View Full Code Here

    // do the part which can be done as super user separately from the
    // actual read of the db

    OBContext.getOBContext().setInAdministratorMode(true);
    final String entityName = dataSetTable.getTable().getName();
    final Entity entity = ModelProvider.getInstance().getEntity(entityName);

    if (entity == null) {
      log.error("Entity not found using table name " + entityName);
      return new ArrayList<BaseOBObject>();
    }

    String whereClause = dataSetTable.getSQLWhereClause();

    final Map<String, Object> existingParams = new HashMap<String, Object>();
    if (whereClause != null) {
      if (parameters != null) {
        for (final String name : parameters.keySet()) {
          if (whereClause.indexOf(":" + name) != -1) {
            existingParams.put(name, parameters.get(name));
          }
        }
      }
    }

    if (moduleId != null && whereClause != null) {
      while (whereClause.indexOf("@moduleid@") != -1) {
        whereClause = whereClause.replace("@moduleid@", "'" + moduleId + "'");
      }
      if (whereClause.indexOf(":moduleid") != -1 && parameters.get("moduleid") == null) {
        existingParams.put("moduleid", moduleId);
      }
    }

    final OBQuery<BaseOBObject> oq = OBDal.getInstance().createQuery(entity.getName(), whereClause);
    oq.setFilterOnActive(false);
    oq.setNamedParameters(existingParams);

    if (OBContext.getOBContext().getRole().getId().equals("0")
        && OBContext.getOBContext().getCurrentClient().getId().equals("0")) {
View Full Code Here

   */
  public Iterator<BaseOBObject> getExportableObjectsIterator(DataSetTable dataSetTable,
      String moduleId, Map<String, Object> parameters) {

    final String entityName = dataSetTable.getTable().getName();
    final Entity entity = ModelProvider.getInstance().getEntity(entityName);

    if (entity == null) {
      log.error("Entity not found using table name " + entityName);
      return new ArrayList<BaseOBObject>().iterator();
    }

    String whereClause = dataSetTable.getSQLWhereClause();
    final Map<String, Object> existingParams = new HashMap<String, Object>();
    for (final String name : parameters.keySet()) {
      if (whereClause.indexOf(":" + name) != -1) {
        existingParams.put(name, parameters.get(name));
      }
    }
    if (moduleId != null && whereClause != null) {
      while (whereClause.indexOf("@moduleid@") != -1) {
        whereClause = whereClause.replace("@moduleid@", "'" + moduleId + "'");
      }
      if (whereClause.indexOf(":moduleid") != -1 && parameters.get("moduleid") == null) {
        existingParams.put("moduleid", moduleId);
      }
    }

    // set the order by, first detect if there is an alias
    String alias = "";
    // this is a space on purpose
    if (whereClause != null && whereClause.toLowerCase().trim().startsWith("as")) {
      // strip the as
      final String strippedWhereClause = whereClause.toLowerCase().trim().substring(2).trim();
      // get the next space
      final int index = strippedWhereClause.indexOf(" ");
      alias = strippedWhereClause.substring(0, index);
      alias += ".";
    }

    final OBQuery<BaseOBObject> oq = OBDal.getInstance().createQuery(entity.getName(),
        (whereClause != null ? whereClause : "") + " order by " + alias + "id");
    oq.setFilterOnActive(false);
    oq.setNamedParameters(existingParams);

    if (OBContext.getOBContext().getRole().getId().equals("0")
View Full Code Here

   * @return the list of properties which are exportable
   */
  public List<Property> getExportableProperties(BaseOBObject bob, DataSetTable dataSetTable,
      List<DataSetColumn> dataSetColumns, boolean exportTransients) {

    final Entity entity = bob.getEntity();
    final List<Property> exportables;
    // check if all are included, except the excluded
    if (dataSetTable.isIncludeAllColumns()) {
      exportables = new ArrayList<Property>(entity.getProperties());
      // now remove the excluded
      for (final DataSetColumn dsc : dataSetColumns) {
        if (dsc.isExcluded()) {
          exportables.remove(entity.getPropertyByColumnName(dsc.getColumn().getDBColumnName()));
        }
      }
    } else {
      // not all included, go through the DataSetcolumns
      // and add the not excluded
      exportables = new ArrayList<Property>();
      for (final DataSetColumn dsc : dataSetColumns) {
        if (!dsc.isExcluded()) {
          exportables.add(entity.getPropertyByColumnName(dsc.getColumn().getDBColumnName()));
        }
      }
    }
    // remove the transients
    if (!exportTransients) {
View Full Code Here

      }
    }
    for (BaseOBObject objectToRepair : repairReferences) {
      if (objectToRepair instanceof TreeNode) {
        final TreeNode tn = (TreeNode) objectToRepair;
        final Entity entity = ModelProvider.getInstance().getEntityFromTreeType(
            tn.getTree().getTypeArea());
        if (entity == null) {
          if (ir.getWarningMessages() == null) {
            ir.setWarningMessages("Imported tree nodes belong to a tree with a tree type "
                + tn.getTree().getTypeArea() + " which is not related to any entity.");
          } else {
            ir.setWarningMessages(ir.getWarningMessages()
                + "\nImported tree nodes belong to a tree with a tree type "
                + tn.getTree().getTypeArea() + " which is not related to any entity.");
          }
          continue;
        }
      }
      for (Property p : PrimitiveReferenceHandler.getInstance().getPrimitiveReferences(
          objectToRepair.getEntity())) {
        final String value = (String) objectToRepair.get(p.getName());
        // also ignore 0 as there is a business partner tree node with 0
        if (value != null && !value.equals("0")) {
          final Entity entity = PrimitiveReferenceHandler.getInstance()
              .getPrimitiveReferencedEntity(objectToRepair, p);
          final BaseOBObject referencedBob = (BaseOBObject) entityResolver.resolve(
              entity.getName(), value, true);
          if (referencedBob == null) {
            if (ir.getErrorMessages() == null) {
              ir.setErrorMessages("The object " + objectToRepair
                  + " references an object (entity: " + entity + ") with id " + value
                  + " which does not exist in the database or in the import set.");
View Full Code Here

    // in a previous objectgraph
    if (inserted.contains(toInsert)) {
      return;
    }
    inserted.add(toInsert);
    final Entity entity = toInsert.getEntity();
    for (final Property property : entity.getProperties()) {
      if (!property.isPrimitive() && !property.isOneToMany()) {
        final Object value = toInsert.get(property.getName());
        if (value instanceof BaseOBObject && ((BaseOBObject) value).isNewOBObject()) {
          insertObjectGraph((BaseOBObject) value, inserted);
        }
View Full Code Here

          + dbTable.getName() + " has no primary key columns.");
    }
  }

  private Property getProperty(String tableName, String columnName) {
    final Entity entity = ModelProvider.getInstance().getEntityByTableName(tableName);
    if (entity == null) {
      // can happen with mismatches
      return null;
    }
    for (Property property : entity.getProperties()) {
      if (property.getColumnName() != null && property.getColumnName().equalsIgnoreCase(columnName)) {
        return property;
      }
    }
    return null;
View Full Code Here

    }
    return null;
  }

  private void checkForeignKeys(org.apache.ddlutils.model.Table table, SystemValidationResult result) {
    final Entity entity = ModelProvider.getInstance().getEntityByTableName(table.getName());
    if (entity == null) {
      // can happen with mismatches
      return;
    }
    for (Property property : entity.getProperties()) {
      if (!property.isPrimitive() && !property.isOneToMany() && !property.isAuditInfo()) {
        // check if the property column is present in a foreign key

        // special case that a property does not have a column, if it is
        // like a virtual property see ClientInformation.client
        if (property.getColumnName() == null) {
          continue;
        }

        final String colName = property.getColumnName().toUpperCase();

        // ignore this specific case
        if (entity.getTableName().equalsIgnoreCase("ad_module_log")
            && colName.equalsIgnoreCase("ad_module_id")) {
          continue;
        }

        boolean found = false;
View Full Code Here

  }

  // checks for all entities if the reference to the client indeed has the name client
  // and the same for the organization property
  private void checkIncorrectClientOrganizationName(SystemValidationResult result) {
    final Entity orgEntity = ModelProvider.getInstance().getEntity(Organization.ENTITY_NAME);
    final Entity clientEntity = ModelProvider.getInstance().getEntity(Client.ENTITY_NAME);
    for (Entity entity : ModelProvider.getInstance().getModel()) {
      boolean hasClientReference = false;
      boolean hasOrgReference = false;
      boolean hasValidOrg = false;
      String invalidOrgName = null;
View Full Code Here

TOP

Related Classes of org.openbravo.base.model.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.