Package org.openbravo.base.model

Examples of org.openbravo.base.model.Property


    final String lowerFieldName = fieldName.toLowerCase();
    final String result;
    if ((result = valueCache.get(lowerFieldName)) != null) {
      return result;
    }
    final Property property = fieldNameToProperty.get(lowerFieldName);
    if (property == null) {
      throw new OBException("The fieldName " + fieldName
          + " can not be mapped to a property of the entity " + getObObject().getEntityName());
    }
    final Object objValue = getObObject().get(property.getName());
    final String strValue = convert(property, objValue);
    valueCache.put(lowerFieldName, strValue);
    return strValue;
  }
View Full Code Here


  // assumes one primary key column
  private String generateStandardID(Entity entity) {
    Check.isTrue(entity.getIdProperties().size() == 1,
        "Method can only handle primary keys with one column");
    final Property p = entity.getIdProperties().get(0);
    final StringBuffer sb = new StringBuffer();
    sb.append(TAB2 + "<id name=\"" + p.getName() + "\" type=\"" + p.getPrimitiveType().getName()
        + "\" " + getAccessorAttribute() + " column=\"" + p.getColumnName() + "\">" + NL);
    if (p.getIdBasedOnProperty() != null) {
      sb.append(TAB3 + "<generator class=\"foreign\">" + NL);
      sb.append(TAB2 + TAB2 + "<param name=\"property\">" + p.getIdBasedOnProperty().getName()
          + "</param>" + NL);
      sb.append(TAB3 + "</generator>" + NL);
    } else if (p.isUuid()) {
      sb.append(TAB3 + "<generator class=\"" + DalUUIDHexGenerator.class.getName() + "\"/>" + NL);
    }
    sb.append(TAB2 + "</id>" + NL);
    return sb.toString();
  }
View Full Code Here

    Check.isTrue(e.hasCompositeId(),
        "Method can only handle primary keys with more than one column");
    final StringBuffer sb = new StringBuffer();
    sb.append(TAB2 + "<composite-id name=\"id\" class=\"" + e.getClassName() + "$Id\""
        + getAccessorAttribute() + ">" + NL);
    final Property compId = e.getIdProperties().get(0);
    Check
        .isTrue(compId.isCompositeId(), "Property " + compId + " is expected to be a composite Id");
    for (final Property p : compId.getIdParts()) {
      if (p.isPrimitive()) {
        String type = p.getPrimitiveType().getName();
        if (boolean.class.isAssignableFrom(p.getPrimitiveType().getClass())
            || Boolean.class == p.getPrimitiveType()) {
          type = "yes_no";
View Full Code Here

  }

  private void checkDataType(Column adColumn, org.apache.ddlutils.model.Column dbColumn,
      SystemValidationResult result, org.apache.ddlutils.model.Table dbTable) {

    final Property property = getProperty(dbTable.getName(), dbColumn.getName());

    // disabled because mandatory is always false
    // if (property != null && !property.isMandatory() && dbColumn.isRequired()) {
    // result.addError(
    // SystemValidationResult.SystemValidationType.NOT_NULL_IN_DB_NOT_MANDATORY_IN_AD, "Column "
    // + dbTable.getName() + "." + dbColumn.getName()
    // + " is required (not-null) but in the Application Dictonary"
    // + " it is set as non-mandatory");
    //
    // final Property p = getProperty(dbTable.getName(), dbColumn.getName());
    // updateSql
    // .append("update ad_column set ismandatory='Y' where ad_column_id in (select c.ad_column_id from ad_column c, ad_table t "
    // + "where c.ad_table_id=t.ad_table_id and t.tablename='"
    // + p.getEntity().getTableName() + "' and c.columnname='" + p.getColumnName() + "');\n");
    //
    // }

    // disabled this check, will be done in 2.60
    // if (property != null && property.isMandatory() && !dbColumn.isRequired()) {
    // result.addError(SystemValidationType.MANDATORY_IN_AD_NULLABLE_IN_DB, "Column "
    // + dbTable.getName() + "." + dbColumn.getName()
    // + " is not-required (null-allowed) but in the Application Dictonary"
    // + " it is set as mandatory");
    // }

    // check the default value
    if (property != null && property.getActualDefaultValue() != null) {
      try {
        property.checkIsValidValue(property.getActualDefaultValue());
      } catch (Exception e) {
        // actually a ValidationException is thrown but this is not
        // accepted by the compiler
        result.addError(SystemValidationType.INCORRECT_DEFAULT_VALUE, e.getMessage());
      }
    }

    if (dbColumn.isPrimaryKey()) {
      // there is a special case, the ad_script_sql has a
      // seqno has key
      if (!dbTable.getName().equalsIgnoreCase("ad_script_sql")) {
        checkType(dbColumn, dbTable, result, "VARCHAR");
        checkLength(dbColumn, dbTable, result, 32);
      }
    } else if (property != null && property.getAllowedValues().size() > 0) {
      checkType(dbColumn, dbTable, result, "VARCHAR");
      checkLength(dbColumn, dbTable, result, 60);
    } else if (property != null && property.isOneToMany()) {
      // ignore those
    } else if (property != null && !property.isPrimitive()) {

      checkType(dbColumn, dbTable, result, "VARCHAR");
      if (property.getReferencedProperty() != null) {
        checkLength(dbColumn, dbTable, result, property.getReferencedProperty().getFieldLength());
      } else {
        checkLength(dbColumn, dbTable, result, 32);
      }
    } else if (property != null && property.getPrimitiveObjectType() != null) {
      final Class<?> prim = property.getPrimitiveObjectType();
      if (prim == String.class) {
        checkType(dbColumn, dbTable, result, new String[] { "VARCHAR", "NVARCHAR", "CHAR", "NCHAR",
            "CLOB" });
      } else if (prim == Long.class) {
        checkType(dbColumn, dbTable, result, "DECIMAL");
View Full Code Here

  private void checkType(org.apache.ddlutils.model.Column dbColumn,
      org.apache.ddlutils.model.Table dbTable, SystemValidationResult result, String expectedType) {
    if (!dbColumn.getType().equals(expectedType)) {
      if (dbColumn.getName().toUpperCase().equals("USER1_ID")
          || dbColumn.getName().toUpperCase().equals("USER2_ID")) {
        final Property p = getProperty(dbTable.getName(), dbColumn.getName());
        updateSql
            .append("update ad_column set ad_reference_id='10', ad_reference_value_id=NULL where ad_column_id in (select c.ad_column_id from ad_column c, ad_table t "
                + "where c.ad_table_id=t.ad_table_id and t.tablename='"
                + p.getEntity().getTableName()
                + "' and c.columnname='"
                + p.getColumnName()
                + "');\n");
      }

      result.addError(SystemValidationType.WRONG_TYPE, "Column " + dbTable.getName() + "."
          + dbColumn.getName() + " has incorrect type, expecting " + expectedType + " but was "
View Full Code Here

   */
  public static Serializable getReferencedPropertyValue(Property referencingProperty,
      Object referedObject) {
    Check.isTrue(referencingProperty.getReferencedProperty() != null, "This property "
        + referencingProperty + " does not have a referenced Property");
    final Property referencedProperty = referencingProperty.getReferencedProperty();
    if (referencedProperty.isId()) {
      if (referedObject instanceof HibernateProxy)
        return ((HibernateProxy) referedObject).getHibernateLazyInitializer().getIdentifier();
      if (referedObject instanceof BaseOBObject)
        return (Serializable) ((BaseOBObject) referedObject).getId();
    } else if (referedObject instanceof BaseOBObject) {
      return (Serializable) ((BaseOBObject) referedObject).get(referencedProperty.getName());
    }

    throw new ArgumentException("Argument is not a BaseOBObject and not a HibernateProxy");
  }
View Full Code Here

        if (isAtEndElement(xmlReader, entityName)) {
          break;
        }

        final LocalElement childElement = getElement(xmlReader);
        final Property p = entity.getProperty(childElement.getName());
        log.debug(">>> Importing property " + p.getName());

        // TODO: make this option controlled
        final boolean isNotImportableProperty = p.isTransient(bob)
            || (p.isAuditInfo() && !isOptionImportAuditInfo()) || p.isInactive();
        if (isNotImportableProperty) {
          log.debug("Property " + p + " is inactive, transient or auditinfo, ignoring it");
          skipElement(xmlReader);
          continue;
        }

        // ignore the id properties as they are already set, or should
        // not be set
        if (p.isId()) {
          skipElement(xmlReader);
          continue;
        }

        if (p.isOneToMany()) {
          throw new EntityXMLException("This XML converter can not handle one-to-many properties");
        }

        final Object currentValue = bob.get(p.getName());

        // do the primitive values
        if (p.isPrimitive()) {

          // NOTE: I noticed a difference between running from Eclipse and from the commandline
          // after some searching, there is a jar file wstx-asl-3.0.2.jar used in
          // src-db/database/lib
          // which provides the woodstox XMLStreamReader. From the commandline the xerces
          // XMLStreamReader
          // is used. They differ in the handling of the getText method in handling entities. For
          // example the following text: <text>Tom&amp;Jerry</text> now assume that the pointer is
          // at the content of the text tag, and you do getText, then woodstox will return Tom&Jerry
          // while xerces will return Tom, this because the &amp; is an entity which is a separate
          // event.
          // below we use the getElementText which works correctly in both cases apparently

          // element value, note that getElementText means that it is not required anymore
          // to go to element end, that is done by the xmlReader
          final String elementText = xmlReader.getElementText();
          Object newValue = XMLTypeConverter.getInstance().fromXML(p.getPrimitiveType(),
              elementText);

          // correct the value
          newValue = replaceValue(bob, p, newValue);

          log.debug("Primitive property with value " + newValue);

          // only update if changed
          if ((currentValue != null && newValue == null)
              || (currentValue == null && newValue != null)
              || (currentValue != null && newValue != null && !currentValue.equals(newValue))) {
            log.debug("Value changed setting it");
            if (!preventRealUpdate) {
              bob.set(p.getName(), newValue);
              updated = true;
            }
          }
        } else {
          Check.isTrue(!p.isOneToMany(), "One to many property not allowed here");
          // never update the org or client through xml!
          final boolean clientUpdate = bob instanceof ClientEnabled
              && p.getName().equals(Organization.PROPERTY_CLIENT);
          final boolean orgUpdate = bob instanceof OrganizationEnabled
              && p.getName().equals(Client.PROPERTY_ORGANIZATION);
          if (!isOptionClientImport() && currentValue != null && (clientUpdate || orgUpdate)) {
            skipElement(xmlReader);
            continue;
          }

          // determine the referenced entity
          Object newValue;

          // handle null value
          if (childElement.getAttributes().get(XMLConstants.ID_ATTRIBUTE) == null) {
            newValue = null;
          } else {
            // get the info and resolve the reference
            final String refId = childElement.getAttributes().get(XMLConstants.ID_ATTRIBUTE);
            final String refEntityName = p.getTargetEntity().getName();
            newValue = resolve(refEntityName, refId, true);
          }
          newValue = replaceValue(bob, p, newValue);

          final boolean hasChanged = (currentValue == null && newValue != null)
              || (currentValue != null && newValue != null && !currentValue.equals(newValue));
          if (hasChanged) {
            log.debug("Setting value " + newValue);
            if (!preventRealUpdate) {
              bob.set(p.getName(), newValue);
              updated = true;
            }
          }
          checkEndElement(xmlReader, childElement.getName());
        }
View Full Code Here

      // 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();
        if (isNotImportableProperty) {
          log.debug("Property " + p + " is inactive, transient or auditinfo, " + "ignoring it");
          continue;
        }

        // ignore the id properties as they are already set, or should
        // not be set
        if (p.isId()) {
          continue;
        }

        final Object currentValue = bob.get(p.getName());

        // do the primitive values
        if (p.isPrimitive()) {
          Object newValue = XMLTypeConverter.getInstance().fromXML(p.getPrimitiveType(),
              childElement.getText());
          // correct the value
          newValue = replaceValue(bob, p, newValue);

          log.debug("Primitive property with value " + newValue);

          // only update if changed
          if ((currentValue == null && newValue != null)
              || (currentValue != null && newValue == null)
              || (currentValue != null && newValue != null && !currentValue.equals(newValue))) {
            log.debug("Value changed setting it");
            if (!preventRealUpdate) {
              bob.set(p.getName(), newValue);
              updated = true;
            }
          }
        } else if (p.isOneToMany()) {
          // resolve the content of the list
          final List<BaseOBObject> newValues = new ArrayList<BaseOBObject>();
          for (final Object o : childElement.elements()) {
            final Element listElement = (Element) o;
            newValues.add(processEntityElement(listElement.getName(), listElement, true));
          }
          // get the currentvalue and compare
          final List<BaseOBObject> currentValues = (List<BaseOBObject>) currentValue;

          if (!newValues.equals(currentValues)) {
            if (!preventRealUpdate) {
              // TODO: is this efficient? Or will it even work
              // with hibernate first removing all?
              currentValues.clear();
              currentValues.addAll(newValues);
              updated = true;
            }
          }
        } else {
          Check.isTrue(!p.isOneToMany(), "One to many property not allowed here");
          // never update the org or client through xml!
          final boolean clientUpdate = bob instanceof ClientEnabled
              && p.getName().equals(Organization.PROPERTY_CLIENT);
          final boolean orgUpdate = bob instanceof OrganizationEnabled
              && p.getName().equals(Client.PROPERTY_ORGANIZATION);
          if (!isOptionClientImport() && currentValue != null && (clientUpdate || orgUpdate)) {
            continue;
          }

          // determine the referenced entity
          Object newValue;

          // handle null value
          if (childElement.attribute(XMLConstants.ID_ATTRIBUTE) == null) {
            newValue = null;
          } else {
            // get the info and resolve the reference
            final String refId = childElement.attributeValue(XMLConstants.ID_ATTRIBUTE);
            final String refEntityName = p.getTargetEntity().getName();
            newValue = resolve(refEntityName, refId, true);
          }
          newValue = replaceValue(bob, p, newValue);

          final boolean hasChanged = (currentValue == null && newValue != null)
              || (currentValue != null && newValue != null && !currentValue.equals(newValue));
          if (hasChanged) {
            log.debug("Setting value " + newValue);
            if (!preventRealUpdate) {
              bob.set(p.getName(), newValue);
              updated = true;
            }
          }

        }
View Full Code Here

  private void setDataValue(String propName, Object value) {
    if (data == null) {
      data = new Object[getEntity().getProperties().size()];
    }
    final Property p = getEntity().getProperty(propName);
    data[p.getIndexInEntity()] = value;
  }
View Full Code Here

   * @param propName
   *          the name of the {@link Property Property} for which the value is requested
   * @throws OBSecurityException
   */
  public Object get(String propName) {
    final Property p = getEntity().getProperty(propName);
    checkDerivedReadable(p);
    return getDataValue(p);
  }
View Full Code Here

TOP

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

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.