/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of ims.assessment.configuration.domain.objects.UserDefinedObject
   *     objects.
   */
  public static ims.assessment.vo.UserDefinedObjectListVoCollection
      createUserDefinedObjectListVoCollectionFromUserDefinedObject(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.assessment.vo.UserDefinedObjectListVoCollection voList =
        new ims.assessment.vo.UserDefinedObjectListVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.assessment.configuration.domain.objects.UserDefinedObject domainObject =
          (ims.assessment.configuration.domain.objects.UserDefinedObject) iterator.next();
      ims.assessment.vo.UserDefinedObjectListVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of ims.assessment.configuration.domain.objects.UserDefinedObject
   *     objects.
   */
  public static ims.assessment.vo.UserDefinedObjectListVoCollection
      createUserDefinedObjectListVoCollectionFromUserDefinedObject(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.assessment.vo.UserDefinedObjectListVoCollection voList =
        new ims.assessment.vo.UserDefinedObjectListVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.assessment.configuration.domain.objects.UserDefinedObject domainObject =
          (ims.assessment.configuration.domain.objects.UserDefinedObject) domainObjectList.get(i);
      ims.assessment.vo.UserDefinedObjectListVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject from the ims.assessment.configuration.domain.objects.UserDefinedObject
   * object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.assessment.vo.UserDefinedObjectListVo create(
      DomainObjectMap map,
      ims.assessment.configuration.domain.objects.UserDefinedObject domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.assessment.vo.UserDefinedObjectListVo valueObject =
        (ims.assessment.vo.UserDefinedObjectListVo)
            map.getValueObject(domainObject, ims.assessment.vo.UserDefinedObjectListVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.assessment.vo.UserDefinedObjectListVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.assessment.configuration.domain.objects.UserDefinedObject
      extractUserDefinedObject(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.assessment.vo.UserDefinedObjectListVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_UserDefinedObject();
    ims.assessment.configuration.domain.objects.UserDefinedObject domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.assessment.configuration.domain.objects.UserDefinedObject)
            domMap.get(valueObject);
      }
      // ims.assessment.vo.UserDefinedObjectListVo ID_UserDefinedObject field is unknown
      domainObject = new ims.assessment.configuration.domain.objects.UserDefinedObject();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_UserDefinedObject());
      if (domMap.get(key) != null) {
        return (ims.assessment.configuration.domain.objects.UserDefinedObject) domMap.get(key);
      }
      domainObject =
          (ims.assessment.configuration.domain.objects.UserDefinedObject)
              domainFactory.getDomainObject(
                  ims.assessment.configuration.domain.objects.UserDefinedObject.class, id);

      // TODO: Not sure how this should be handled. Effectively it must be a staleobject exception,
      // but maybe should be handled as that further up.
      if (domainObject == null) return null;

      domMap.put(key, domainObject);
    }
    domainObject.setVersion(valueObject.getVersion_UserDefinedObject());

    domainObject.setComponents(
        ims.assessment.vo.domain.UserDefinedObjectComponentListVoAssembler
            .extractUserDefinedObjectComponentList(
                domainFactory, valueObject.getComponents(), domainObject.getComponents(), domMap));
    // This is to overcome a bug in both Sybase and Oracle which prevents them from storing an empty
    // string correctly
    // Sybase stores it as a single space, Oracle stores it as NULL. This fix will make them
    // consistent at least.
    if (valueObject.getName() != null && valueObject.getName().equals("")) {
      valueObject.setName(null);
    }
    domainObject.setName(valueObject.getName());
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value3 = null;
    if (null != valueObject.getObjectType()) {
      value3 = domainFactory.getLookupInstance(valueObject.getObjectType().getID());
    }
    domainObject.setObjectType(value3);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value4 = null;
    if (null != valueObject.getActiveStatus()) {
      value4 = domainFactory.getLookupInstance(valueObject.getActiveStatus().getID());
    }
    domainObject.setActiveStatus(value4);

    return domainObject;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.assessment.configuration.domain.objects.UserDefinedObject
   */
  public static ims.assessment.vo.UserDefinedObjectListVo insert(
      DomainObjectMap map,
      ims.assessment.vo.UserDefinedObjectListVo valueObject,
      ims.assessment.configuration.domain.objects.UserDefinedObject domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_UserDefinedObject(domainObject.getId());
    valueObject.setIsRIE(domainObject.getIsRIE());

    // If this is a recordedInError record, and the domainObject
    // value isIncludeRecord has not been set, then we return null and
    // not the value object
    if (valueObject.getIsRIE() != null
        && valueObject.getIsRIE().booleanValue() == true
        && !domainObject.isIncludeRecord()) return null;

    // If this is not a recordedInError record, and the domainObject
    // value isIncludeRecord has been set, then we return null and
    // not the value object
    if ((valueObject.getIsRIE() == null || valueObject.getIsRIE().booleanValue() == false)
        && domainObject.isIncludeRecord()) return null;

    // Components
    valueObject.setComponents(
        ims.assessment.vo.domain.UserDefinedObjectComponentListVoAssembler
            .createUserDefinedObjectComponentListVoCollectionFromUserDefinedObjectComponent(
                map, domainObject.getComponents()));
    // Name
    valueObject.setName(domainObject.getName());
    // ObjectType
    ims.domain.lookups.LookupInstance instance3 = domainObject.getObjectType();
    if (null != instance3) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance3.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance3.getImage().getImageId(), instance3.getImage().getImagePath());
      }
      color = instance3.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.UserDefinedObjectType voLookup3 =
          new ims.core.vo.lookups.UserDefinedObjectType(
              instance3.getId(), instance3.getText(), instance3.isActive(), null, img, color);
      ims.core.vo.lookups.UserDefinedObjectType parentVoLookup3 = voLookup3;
      ims.domain.lookups.LookupInstance parent3 = instance3.getParent();
      while (parent3 != null) {
        if (parent3.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent3.getImage().getImageId(), parent3.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent3.getColor();
        if (color != null) color.getValue();
        parentVoLookup3.setParent(
            new ims.core.vo.lookups.UserDefinedObjectType(
                parent3.getId(), parent3.getText(), parent3.isActive(), null, img, color));
        parentVoLookup3 = parentVoLookup3.getParent();
        parent3 = parent3.getParent();
      }
      valueObject.setObjectType(voLookup3);
    }
    // ActiveStatus
    ims.domain.lookups.LookupInstance instance4 = domainObject.getActiveStatus();
    if (null != instance4) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance4.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance4.getImage().getImageId(), instance4.getImage().getImagePath());
      }
      color = instance4.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.PreActiveActiveInactiveStatus voLookup4 =
          new ims.core.vo.lookups.PreActiveActiveInactiveStatus(
              instance4.getId(), instance4.getText(), instance4.isActive(), null, img, color);
      ims.core.vo.lookups.PreActiveActiveInactiveStatus parentVoLookup4 = voLookup4;
      ims.domain.lookups.LookupInstance parent4 = instance4.getParent();
      while (parent4 != null) {
        if (parent4.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent4.getImage().getImageId(), parent4.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent4.getColor();
        if (color != null) color.getValue();
        parentVoLookup4.setParent(
            new ims.core.vo.lookups.PreActiveActiveInactiveStatus(
                parent4.getId(), parent4.getText(), parent4.isActive(), null, img, color));
        parentVoLookup4 = parentVoLookup4.getParent();
        parent4 = parent4.getParent();
      }
      valueObject.setActiveStatus(voLookup4);
    }
    return valueObject;
  }