Example #1
0
  def test_change_dimension_and_check_consistency(self):
    # make sure _checkConsistency does not complain about a cell
    # having an id outside the len of the dimension after a dimension
    # change if id is within acceptable values
    matrix = self.matrix

    cell_range = [['1', '2',], ['a', 'b',]]
    kwd = {'base_id' : 'quantity'}
    matrix.setCellRange(*cell_range, **kwd)

    for place in cartesianProduct(cell_range):
      matrix.newCell(*place, **kwd)

    cell = matrix.getCell('2', 'b', **kwd)
    self.assertEqual('quantity_1_1', cell.getId())
    cell.setTitle('This one')
    self.tic()

    cell_range = [['2', ], ['b',]]
    matrix.setCellRange(*cell_range, **kwd)
    self.commit()
    self.assertEquals(set(["quantity_1_1"]), set([
      x.getId() for x in matrix.objectValues()]))

    cell = matrix.getCell('2', 'b', **kwd)
    self.assertEqual('quantity_1_1', cell.getId())
    self.assertEqual('This one', cell.getTitle())

    self.assertEqual(XMLMatrix._checkConsistency(matrix), [])
    cell.setId('quantity_2_1')
    error_list = XMLMatrix._checkConsistency(matrix)
    self.assertEqual(1, len(error_list))
    self.assertTrue(error_list[0][3].find("is out of bound") > 0)
Example #2
0
    def _checkConsistency(self, fixit=0):
        """
        Check the constitency of transformation elements
    """
        transformation = self.getParentValue()
        transformation_category_list = transformation.getVariationCategoryList(
        )

        error_list = XMLMatrix._checkConsistency(self, fixit=fixit)

        # Quantity should be empty if no variation
        q_range = self.getCellRange(base_id='quantity')
        if q_range is not None:
            range_is_empty = 1
            for q_list in q_range:
                if q_list is not None:
                    range_is_empty = 0
                    break
            if range_is_empty:
                matrix_is_not_empty = 0
                for k in self.getCellIds(base_id='quantity'):
                    if hasattr(self, k): matrix_is_not_empty = 1
                if matrix_is_not_empty:
                    if fixit:
                        self.delCells(base_id='quantity')
                        error_message = "Variation cells for quantity should be empty (fixed)"
                    else:
                        error_message = "Variation cells for quantity should be empty"
                    error_list += [(self.getRelativeUrl(),
                                    'TransformedResource inconsistency', 100,
                                    error_message)]

        # First quantity
        # We build an attribute equality and look at all cells
        q_constraint = Constraint.AttributeEquality(
            domain_base_category_list=self.getQVariationBaseCategoryList(),
            predicate_operator='SUPERSET_OF',
            mapped_value_property_list=['quantity'])
        for kw in self.getCellKeys(base_id='quantity'):
            kwd = {'base_id': 'quantity'}
            c = self.getCell(*kw, **kwd)
            if c is not None:
                predicate_value_list = []
                categories_list = []
                for p in kw:
                    if p is not None:
                        if p in transformation_category_list:
                            if p not in predicate_value_list:
                                predicate_value_list.append(p)
                        else:
                            if p not in categories_list:
                                categories_list.append(p)
                q_constraint.edit(predicate_value_list=predicate_value_list,
                                  categories_list=categories_list)
                if fixit:
                    error_list += q_constraint.fixConsistency(c)
                else:
                    error_list += q_constraint.checkConsistency(c)

        return error_list
Example #3
0
    def getCell(self, *kw , **kwd):
      """
          This method can be overriden
      """
      if 'base_id' not in kwd:
        kwd['base_id'] = 'movement'

      return XMLMatrix.getCell(self, *kw, **kwd)
Example #4
0
    def newCell(self, *kw, **kwd):
      """
          This method creates a new cell
      """
      if 'base_id' not in kwd:
        kwd['base_id'] = 'movement'

      return XMLMatrix.newCell(self, *kw, **kwd)
Example #5
0
  def newCell(self, *kw, **kwd):
    """
    This method creates a new cell
    """
    if 'base_id' not in kwd:
      kwd['base_id'] = 'movement'

    return XMLMatrix.newCell(self, *kw, **kwd)
Example #6
0
  def getCell(self, *kw , **kwd):
    """
    This method can be overriden
    """
    if 'base_id' not in kwd:
      kwd['base_id'] = 'movement'

    return XMLMatrix.getCell(self, *kw, **kwd)
Example #7
0
    def _checkConsistency(self, fixit=0):
      """
        Check the constitency of transformation elements
      """
      transformation = self.getParentValue()
      transformation_category_list = transformation.getVariationCategoryList()

      error_list = XMLMatrix._checkConsistency(self, fixit=fixit)

      # Quantity should be empty if no variation
      q_range = self.getCellRange(base_id = 'quantity')
      if q_range is not None:
        range_is_empty = 1
        for q_list in q_range:
          if q_list is not None:
            range_is_empty = 0
            break
        if range_is_empty:
          matrix_is_not_empty = 0
          for k in self.getCellIds(base_id = 'quantity'):
            if hasattr(self, k):matrix_is_not_empty = 1
          if matrix_is_not_empty:
            if fixit:
              self.delCells(base_id = 'quantity')
              error_message =  "Variation cells for quantity should be empty (fixed)"
            else:
              error_message =  "Variation cells for quantity should be empty"
            error_list += [(self.getRelativeUrl(),
                          'TransformedResource inconsistency', 100, error_message)]

      # First quantity
      # We build an attribute equality and look at all cells
      q_constraint = Constraint.AttributeEquality(
        domain_base_category_list = self.getQVariationBaseCategoryList(),
        predicate_operator = 'SUPERSET_OF',
        mapped_value_property_list = ['quantity'] )
      for kw in self.getCellKeys(base_id = 'quantity'):
        kwd={'base_id': 'quantity'}
        c = self.getCell(*kw, **kwd)
        if c is not None:
          predicate_value_list = []
          categories_list = []
          for p in kw:
            if p is not None:
              if p in transformation_category_list:
                if p not in predicate_value_list:
                  predicate_value_list.append(p)
              else:
                if p not in categories_list:
                  categories_list.append(p)
          q_constraint.edit(predicate_value_list = predicate_value_list,
                            categories_list = categories_list)
          if fixit:
            error_list += q_constraint.fixConsistency(c)
          else:
            error_list += q_constraint.checkConsistency(c)

      return error_list
Example #8
0
    def test_change_dimension_and_check_consistency(self):
        # make sure _checkConsistency does not complain about a cell
        # having an id outside the len of the dimension after a dimension
        # change if id is within acceptable values
        matrix = self.matrix

        cell_range = [[
            '1',
            '2',
        ], [
            'a',
            'b',
        ]]
        kwd = {'base_id': 'quantity'}
        matrix.setCellRange(*cell_range, **kwd)

        for place in cartesianProduct(cell_range):
            matrix.newCell(*place, **kwd)

        cell = matrix.getCell('2', 'b', **kwd)
        self.assertEqual('quantity_1_1', cell.getId())
        cell.setTitle('This one')
        self.tic()

        cell_range = [[
            '2',
        ], [
            'b',
        ]]
        matrix.setCellRange(*cell_range, **kwd)
        self.commit()
        self.assertEquals(set(["quantity_1_1"]),
                          set([x.getId() for x in matrix.objectValues()]))

        cell = matrix.getCell('2', 'b', **kwd)
        self.assertEqual('quantity_1_1', cell.getId())
        self.assertEqual('This one', cell.getTitle())

        self.assertEqual(XMLMatrix._checkConsistency(matrix), [])
        cell.setId('quantity_2_1')
        error_list = XMLMatrix._checkConsistency(matrix)
        self.assertEqual(1, len(error_list))
        self.assertTrue(error_list[0][3].find("is out of bound") > 0)
Example #9
0
 def hasCellContent(self, base_id='movement'):
   """Return true if the object contains cells.
   """
   # Do not use XMLMatrix.hasCellContent, because it can generate
   # inconsistency in catalog
   # Exemple: define a line and set the matrix cell range, but do not create
   # cell.
   # Line was in this case consider like a movement, and was catalogued.
   # But, getVariationText of the line was not empty.
   # So, in ZODB, resource as without variation, but in catalog, this was
   # the contrary...
   cell_range = XMLMatrix.getCellRange(self, base_id=base_id)
   return (cell_range is not None and len(cell_range) > 0)
Example #10
0
 def hasCellContent(self, base_id='movement'):
   """Return true if the object contains cells.
   """
   # Do not use XMLMatrix.hasCellContent, because it can generate
   # inconsistency in catalog
   # Exemple: define a line and set the matrix cell range, but do not create
   # cell.
   # Line was in this case consider like a movement, and was catalogued.
   # But, getVariationText of the line was not empty.
   # So, in ZODB, resource as without variation, but in catalog, this was
   # the contrary...
   cell_range = XMLMatrix.getCellRange(self, base_id=base_id)
   return (cell_range is not None and len(cell_range) > 0)
Example #11
0
 def getCell(self, *args, **kw):
   '''Overload the function getCell to be able to search a cell on the
   inheritance model tree if the cell is not found on current one.
   '''
   paysheet = kw.get('paysheet')
   if paysheet is None:
     from Products.ERP5Type.Document import newTempPaySheetTransaction
     paysheet = newTempPaySheetTransaction(self.getPortalObject(), '',
                                           specialise_value=self)
   model_list = self.findEffectiveSpecialiseValueList(paysheet)
   for specialised_model in model_list:
     cell = XMLMatrix.getCell(specialised_model, *args, **kw)
     if cell is not None:
       return cell
Example #12
0
    def newCell(self, *kw, **kwd):
      result = XMLMatrix.newCell(self, *kw, **kwd)
      result._setPredicateOperator("SUPERSET_OF")
      membership_list = []
      for c in kw:
        if c is not None:
          membership_list += [c]
      result._setPredicateValueList(membership_list)
      base_id = kwd.get('base_id', 'cell')
      if base_id == 'quantity':
        result._setDomainBaseCategoryList(self.getQVariationBaseCategoryList())
      elif base_id == 'variation':
        result._setDomainBaseCategoryList(self.getVVariationBaseCategoryList())

      return result
Example #13
0
 def getCell(self, *args, **kw):
     '''Overload the function getCell to be able to search a cell on the
 inheritance model tree if the cell is not found on current one.
 '''
     paysheet = kw.get('paysheet')
     if paysheet is None:
         from Products.ERP5Type.Document import newTempPaySheetTransaction
         paysheet = newTempPaySheetTransaction(self.getPortalObject(),
                                               '',
                                               specialise_value=self)
     model_list = self.findEffectiveSpecialiseValueList(paysheet)
     for specialised_model in model_list:
         cell = XMLMatrix.getCell(specialised_model, *args, **kw)
         if cell is not None:
             return cell
Example #14
0
 def getCell(self, *args, **kw):
   '''Overload the function getCell to be able to search a cell on the
   inheritance model tree if the cell is not found on current one.
   '''
   paysheet = kw.get('paysheet')
   if paysheet is None:
     paysheet = self.getPortalObject().newContent(
       temp_object=True,
       portal_type='Pay Sheet Transaction',
       id='',
       specialise_value=self)
   model_list = self.findEffectiveSpecialiseValueList(paysheet)
   for specialised_model in model_list:
     cell = XMLMatrix.getCell(specialised_model, *args, **kw)
     if cell is not None:
       return cell
Example #15
0
 def getCell(self, *kw, **kwd):
     """
       This method can be overriden
   """
     kwd.setdefault("base_id", "path")
     return XMLMatrix.getCell(self, *kw, **kwd)
Example #16
0
 def newCell(self, *kw, **kwd):
     """
       This method creates a new cell
   """
     kwd.setdefault("base_id", "path")
     return XMLMatrix.newCell(self, *kw, **kwd)
Example #17
0
 def hasCellContent(self, base_id="path"):
     """
       This method can be overriden
   """
     return XMLMatrix.hasCellContent(self, base_id=base_id)
Example #18
0
 def getCellValueList(self, base_id='movement'):
   """
       This method can be overriden
   """
   return XMLMatrix.getCellValueList(self, base_id=base_id)
 def hasCellContent(self, base_id='path'):
     """
     This method can be overriden
 """
     return XMLMatrix.hasCellContent(self, base_id=base_id)
 def newCell(self, *kw, **kwd):
     """
     This method creates a new cell
 """
     kwd.setdefault('base_id', 'path')
     return XMLMatrix.newCell(self, *kw, **kwd)
 def getCell(self, *kw, **kwd):
     """
     This method can be overriden
 """
     kwd.setdefault('base_id', 'path')
     return XMLMatrix.getCell(self, *kw, **kwd)
 def getCellValueList(self, base_id='path'):
     """
     This method can be overriden
 """
     return XMLMatrix.getCellValueList(self, base_id=base_id)