Package org.openbravo.base.structure

Examples of org.openbravo.base.structure.BaseOBObject


    // first check if the object was already imported in this level
    // so check if there is a new id available
    final List<String> newIds = getId(id, entity, orgId);
    if (newIds.size() > 0) {
      for (final String newId : newIds) {
        final BaseOBObject result = doSearch(newId, entity, client.getId(), orgId);
        if (result != null) {
          return result;
        }
      }
    }
View Full Code Here


        // 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;
        }
View Full Code Here

  // if there is a matching object in the db then that one should be
  // used
  protected BaseOBObject replaceByUniqueObject(BaseOBObject bob) {
    if (bob.isNewOBObject() && bob.getEntity().getUniqueConstraints().size() > 0) {
      final BaseOBObject otherUniqueObject = entityResolver.findUniqueConstrainedObject(bob);
      if (otherUniqueObject != null) {
        // now copy the imported values from the bob to
        // otherUniqueObject
        for (final Property p : bob.getEntity().getProperties()) {
          final boolean isNotImportableProperty = p.isTransient(bob) || p.isAuditInfo()
              || p.isInactive() || p.isId();
          if (isNotImportableProperty) {
            continue;
          }
          // do not change the client or organization of an
          // existing object
          if (p.isClientOrOrganization()) {
            continue;
          }
          otherUniqueObject.set(p.getName(), bob.get(p.getName()));
        }
        // and replace the bob, because the object from the db
        // should be used
        getEntityResolver().exchangeObjects(bob, otherUniqueObject);
        replacedObjects.put(bob, otherUniqueObject);
View Full Code Here

    return bob;
  }

  protected void repairReferences() {
    for (BaseOBObject bob : replacedObjects.keySet()) {
      final BaseOBObject newObject = replacedObjects.get(bob);
      repairReferences(bob, newObject);
    }
  }
View Full Code Here

    // walk through the elements
    final Set<BaseOBObject> checkDuplicates = new HashSet<BaseOBObject>();
    final List<BaseOBObject> result = new ArrayList<BaseOBObject>();
    for (final Object o : rootElement.elements()) {
      final Element element = (Element) o;
      final BaseOBObject bob = processEntityElement(element.getName(), element, false);
      // only add it if okay
      if (bob != null && !checkDuplicates.contains(bob)) {
        result.add(bob);
        checkDuplicates.add(bob);
      }
View Full Code Here

      final boolean hasReferenceAttribute = obElement
          .attributeValue(XMLConstants.REFERENCE_ATTRIBUTE) != null;

      // resolve the entity, using the id, note that
      // resolve will create a new object if none is found
      BaseOBObject bob = resolve(entityName, id, false);

      // should never be null at this point
      Check.isNotNull(bob, "The business object " + entityName + " (" + id
          + ") can not be resolved");

      // warn/error is logged below if the entity is updated
      // update is prevented below
      final boolean writable = OBContext.getOBContext().isInAdministratorMode()
          || SecurityChecker.getInstance().isWritable(bob);

      // referenced and not new, so already there, don't update
      if (hasReferenceAttribute && !bob.isNewOBObject()) {
        return bob;
      }

      if (!writable && bob.isNewOBObject()) {
        error("Object " + entityName + "(" + id + ") is new but not writable");
        return bob;
      }

      // do some checks to determine if this one should be updated
      // a referenced instance should not be updated if it is not new
      // 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();
        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

          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);
            }
          }
        }
        final String txt = XMLTypeConverter.getInstance().toXML(value);
        xmlHandler.startElement("", "", p.getName(), propertyAttrs);
        xmlHandler.characters(txt.toCharArray(), 0, txt.length());
        xmlHandler.endElement("", "", p.getName());
      } else if (p.isOneToMany()) {
        xmlHandler.startElement("", "", p.getName(), propertyAttrs);

        // get all the children and export each child
        final Collection<?> c = (Collection<?>) value;
        for (final Object o : c) {
          // embed in the parent
          if (isOptionEmbedChildren()) {
            export((BaseOBObject) o, false);
          } else {
            // add the child as a tag, the child entityname is
            // used as the tagname
            final BaseOBObject child = (BaseOBObject) o;

            // add attributes
            final AttributesImpl childAttrs = new AttributesImpl();
            childAttrs.addAttribute("", "", XMLConstants.TRANSIENT_ATTRIBUTE, "CDATA", "true");
            childAttrs.addAttribute("", "", XMLConstants.ID_ATTRIBUTE, "CDATA", DalUtil
View Full Code Here

          // https://issues.openbravo.com/view.php?id=8745
          // is solved
          continue;
        }

        final BaseOBObject bob = OBDal.getInstance().get(entity.getName(), node.getNode());
        assertTrue("Entity instance not found " + entity.getName() + " " + node.getNode(),
            bob != null);
        if (bob instanceof ClientEnabled) {
          assertEquals(newClient, ((ClientEnabled) bob).getClient());
          testDoneAtLeastOnce = true;
        }
      }
      // also ignore 0 as there is a business partner/sales region tree node with 0
      if (node.getReportSet() != null && !node.getReportSet().equals("0")) {
        final Entity entity = ModelProvider.getInstance().getEntityFromTreeType(
            node.getTree().getTypeArea());
        if (entity.getName().equals(Project.ENTITY_NAME)) {
          // can be removed when this issue:
          // https://issues.openbravo.com/view.php?id=8745
          // is solved
          continue;
        }

        final BaseOBObject bob = OBDal.getInstance().get(entity.getName(), node.getReportSet());
        assertTrue("Entity instance not found " + entity.getName() + " " + node.getReportSet(),
            bob != null);
        if (bob instanceof ClientEnabled) {
          assertEquals(newClient, ((ClientEnabled) bob).getClient());
          testDoneAtLeastOnce = true;
View Full Code Here

    final Client newClient = OBDal.getInstance().get(Client.class, newClientID);
    boolean testDoneAtLeastOnce = false;
    for (AccountingFact fact : facts.list()) {
      assertEquals(newClient, fact.getClient());
      if (fact.getRecordID() != null) {
        final BaseOBObject bob = OBDal.getInstance().get(fact.getTable().getName(),
            fact.getRecordID());
        assertTrue("Entity instance not found " + fact.getTable().getName() + " "
            + fact.getRecordID(), bob != null);
        if (bob instanceof ClientEnabled) {
          assertEquals(newClient, ((ClientEnabled) bob).getClient());
          testDoneAtLeastOnce = true;
        }
      }
      if (fact.getRecordID2() != null) {
        final BaseOBObject bob = OBDal.getInstance().get(DebtPayment.ENTITY_NAME,
            fact.getRecordID2());
        assertTrue("Entity instance not found " + DebtPayment.ENTITY_NAME + " "
            + fact.getRecordID2(), bob != null);
        if (bob instanceof ClientEnabled) {
          assertEquals(newClient, ((ClientEnabled) bob).getClient());
View Full Code Here

      fail(ir.getErrorMessages());
    }

    assertEquals(1, ir.getInsertedObjects().size());
    assertTrue(ir.getWarningMessages() == null);
    final BaseOBObject bob = ir.getInsertedObjects().get(0);
    assertEquals(id, bob.getId());
  }
View Full Code Here

TOP

Related Classes of org.openbravo.base.structure.BaseOBObject

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.