Package org.openbravo.base.model

Examples of org.openbravo.base.model.Entity


  // Discussion: the methods here however make use of a lot of string comparison
  // when this would be done in the Entity class then it is not allowed to
  // refer to generated classes and then property name/entity name comparisons
  // are not compile-time-checked
  public boolean hasObjectPrimitiveReference(BaseOBObject obObject) {
    final Entity entity = obObject.getEntity();
    if (entity.getName().equals(TreeNode.ENTITY_NAME)) {
      return true;
    }
    if (entity.getName().equals(Alert.ENTITY_NAME)) {
      return true;
    }
    if (entity.getName().equals(Attachment.ENTITY_NAME)) {
      return true;
    }
    if (entity.getName().equals(AccountingFact.ENTITY_NAME)) {
      return true;
    }
    return false;
  }
View Full Code Here


   *           if no Entity can be found
   */
  public Entity getPrimitiveReferencedEntity(BaseOBObject obObject, Property property) {
    if (property.getEntity().getName().equals(TreeNode.ENTITY_NAME)) {
      final TreeNode treeNode = (TreeNode) obObject;
      final Entity entity = ModelProvider.getInstance().getEntityFromTreeType(
          treeNode.getTree().getTypeArea());
      if (entity == null) {
        throw new OBException("No entity found for treetype " + treeNode.getTree().getTypeArea());
      }
      return entity;
    }
    if (property.getEntity().getName().equals(Alert.ENTITY_NAME)) {
      final Alert alert = (Alert) obObject;
      final Table table = alert.getAlertRule().getTab().getTable();
      final Entity entity = ModelProvider.getInstance().getEntity(table.getName());
      if (entity == null) {
        throw new OBException("No entity for table with name " + table.getName());
      }
      return entity;
    }
    if (property.getEntity().getName().equals(Attachment.ENTITY_NAME)) {
      final Attachment attachment = (Attachment) obObject;
      final Entity entity = ModelProvider.getInstance().getEntity(attachment.getTable().getName());
      if (entity == null) {
        throw new OBException("No entity for table with name " + attachment.getTable().getName());
      }
      return entity;
    }
    if (property.getEntity().getName().equals(AccountingFact.ENTITY_NAME)) {
      if (property.getName().equals(AccountingFact.PROPERTY_RECORDID2)) {
        return ModelProvider.getInstance().getEntity(DebtPayment.ENTITY_NAME);
      }
      final AccountingFact accountingFact = (AccountingFact) obObject;
      final Entity entity = ModelProvider.getInstance().getEntity(
          accountingFact.getTable().getName());
      if (entity == null) {
        throw new OBException("No entity for table with name "
            + accountingFact.getTable().getName());
      }
View Full Code Here

  public BaseOBObject resolve(String entityName, String id, boolean referenced) {

    Check.isNotNull(client, "Client should not be null");
    Check.isNotNull(organization, "Org should not be null");

    final Entity entity = ModelProvider.getInstance().getEntity(entityName);

    BaseOBObject result = null;
    // note id can be null if someone did not care to add it in a manual
    // xml file
    if (id != null) {
View Full Code Here

  protected void setClientOrganization(BaseOBObject bob) {

    setClientOrganizationZero();

    final Entity entity = bob.getEntity();

    // TODO: add warning if the entity is created in a different
    // client/organization than the inputted ones
    // Set the client and organization on the most detailed level
    // looking at the accesslevel of the entity
    Client setClient;
    Organization setOrg;
    if (entity.getAccessLevel() == AccessLevel.SYSTEM) {
      setClient = clientZero;
      setOrg = organizationZero;
    } else if (entity.getAccessLevel() == AccessLevel.SYSTEM_CLIENT) {
      setClient = client;
      setOrg = organizationZero;
    } else if (entity.getAccessLevel() == AccessLevel.CLIENT) {
      setClient = client;
      setOrg = organizationZero;
    } else if (entity.getAccessLevel() == AccessLevel.CLIENT_ORGANIZATION) {
      setClient = client;
      setOrg = organization;
    } else if (entity.getAccessLevel() == AccessLevel.ORGANIZATION) {
      // TODO: is this correct? That it is the same as the previous
      // one?
      setClient = client;
      setOrg = organization;
    } else if (entity.getAccessLevel() == AccessLevel.ALL) {
      setClient = client;
      setOrg = organization;
    } else {
      throw new EntityXMLException("Access level " + entity.getAccessLevel() + " not supported");
    }
    if (entity.isClientEnabled()) {
      bob.setValue(PROPERTY_CLIENT, setClient);
    }
    if (entity.isOrganizationEnabled()) {
      bob.setValue(PROPERTY_ORGANIZATION, setOrg);
    }

  }
View Full Code Here

    // own constraints
    if (!obObject.isNewOBObject()) {
      return null;
    }

    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(Expression.ne("id", id));
      }

      boolean ignoreUniqueConstraint = false;
View Full Code Here

      // note that embedded children are updated but non-embedded children
      // are not updated!
      final boolean preventRealUpdate = !writable
          || (hasReferenceAttribute && !bob.isNewOBObject());

      final Entity entity = ModelProvider.getInstance().getEntity(obElement.getName());
      boolean updated = false;

      // the onetomany properties are done in a second pass
      final List<Element> oneToManyElements = new ArrayList<Element>();

      // now parse the property elements
      for (final Element childElement : (List<Element>) obElement.elements()) {
        final Property p = entity.getProperty(childElement.getName());
        log.debug(">>> Exporting property " + p.getName());

        // TODO: make this option controlled
        final boolean isNotImportableProperty = p.isTransient(bob)
            || (p.isAuditInfo() && !isOptionImportAuditInfo()) || p.isInactive();
View Full Code Here

        // both the parent and the node should be added to the export list
        if (value != null && obObject instanceof TreeNode) {
          if (PrimitiveReferenceHandler.getInstance().isPrimitiveReference(p) && value != null
              && !value.equals("0")) {
            final String strValue = (String) value;
            final Entity referedEntity = PrimitiveReferenceHandler.getInstance()
                .getPrimitiveReferencedEntity(obObject, p);
            final BaseOBObject obValue = OBDal.getInstance().get(referedEntity.getName(), strValue);
            if (obValue == null) {
              log.error("Object (" + obObject.getEntityName() + "(" + obObject.getId()
                  + ")): The value " + strValue + " used in this object is not valid, there is no "
                  + referedEntity.getName() + " with that id");
              // Check.isNotNull(obValue, "The value " + strValue + " used in treeNode "
              // + treeNode.getId() + " is not valid, there is no " + referedEntity.getName()
              // + " with that id");
            } else {
              addToExportList((BaseOBObject) obValue);
View Full Code Here

  public void setDataSet(DataSet dataSet) {
    this.dataSet = dataSet;

    dataSetTablesByEntity = new HashMap<Entity, DataSetTable>();
    for (DataSetTable dst : dataSet.getDataSetTableList()) {
      final Entity entity = ModelProvider.getInstance().getEntityByTableName(
          dst.getTable().getDBTableName());
      dataSetTablesByEntity.put(entity, dst);
    }
  }
View Full Code Here

    getEntity().validate(this);
  }

  @Override
  public String toString() {
    final Entity e = getEntity();
    final StringBuilder sb = new StringBuilder();
    // and also display all values
    for (final Property p : e.getIdentifierProperties()) {
      Object value = get(p.getName());
      if (value != null) {
        if (sb.length() == 0) {
          sb.append("(");
        } else {
View Full Code Here

      Check
          .isNotNull(
              engine,
              "Scripting engine not found using name js, check for other scripting language names such as Mozilla Rhino");

      final Entity e = contextBob.getEntity();
      for (final Property p : e.getProperties()) {
        engine.put(p.getName(), contextBob.get(p.getName()));
      }

      final Object result = engine.eval(script);
      Check.isInstanceOf(result, Boolean.class);
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.