Exemple #1
0
    def add_requirement(self, requirement, asset_name=None, environment_name=None):
        try:
            self.db_proxy.nameCheck(requirement.theName, "requirement")
        except ARMException as ex:
            self.close()
            raise ARMHTTPError(ex)

        new_id = self.db_proxy.newId()
        requirement.theId = new_id

        if asset_name is not None:
            try:
                self.db_proxy.addRequirement(requirement, assetName=asset_name, isAsset=True)
            except Exception as ex:
                self.close()
                handle_exception(ex)
        elif environment_name is not None:
            try:
                self.db_proxy.addRequirement(requirement, assetName=environment_name, isAsset=False)
            except Exception as ex:
                self.close()
                handle_exception(ex)
        else:
            self.close()
            raise MissingParameterHTTPError(param_names=["requirement", "environment"])

        return new_id
Exemple #2
0
  def add_requirement(self, requirement, asset_name=None, environment_name=None):
    try:
      self.db_proxy.nameCheck(requirement.theName, 'requirement')
    except ARMException as ex:
      self.close()
      raise ARMHTTPError(ex)

    new_id = self.db_proxy.newId()
    requirement.theId = new_id

    if asset_name is not None:
      try:
        self.db_proxy.addRequirement(requirement, assetName=asset_name, isAsset=True)
      except Exception as ex:
        self.close()
        handle_exception(ex)
    elif environment_name is not None:
      try:
        self.db_proxy.addRequirement(requirement, assetName=environment_name, isAsset=False)
      except Exception as ex:
        self.close()
        handle_exception(ex)
    else:
      self.close()
      raise MissingParameterHTTPError(param_names=['requirement', 'environment'])

    return new_id
  def add_requirement(self, requirement, pathValues = []):

    try:
      self.db_proxy.nameCheck(requirement.theName, 'requirement')
    except ARMException as ex:
      self.close()
      raise ARMHTTPError(ex)

    new_id = self.db_proxy.newId()
    requirement.theId = new_id
    requirement.theVersion = 1

    isAsset = False
    if requirement.domainType() == 'asset':
      isAsset = True 

    try:
      self.db_proxy.addRequirement(requirement, assetName=requirement.domain(), isAsset=isAsset)
    except ARMException as ex:
      self.close()
      handle_exception(ex)
Exemple #4
0
def json_deserialize(string, class_name=None):
    """
  Deserializes the JSON object to the appropriate class instance.
  :param string: The JSON string
  :type string: str
  :param class_name: The name of the target class
  :type class_name: str
  :return: Returns a dictionary or a class instance depending on the target class chosen
  :rtype: list|dict|Asset|Goal|Requirement|Risk
  """
    if isinstance(string, dict) or isinstance(string, list):
        string = json_serialize(string)

    if isinstance(string, list):
        list_result = []
        for item_string in string:
            item_string = json_serialize(item_string)
            for key in conv_terms:
                item_string = item_string.replace(conv_terms[key], key)
            list_result.append(json_deserialize(item_string))

    if isinstance(string, string_types):
        for key in conv_terms:
            string = string.replace(conv_terms[key], key)

    try:
        obj = deserialize(string)
        if isinstance(obj, Environment):
            tensions = {}
            for key, value in list(obj.theTensions.items()):
                key = str(key)
                attrs = key.strip('(').strip(')').split(',')
                if len(attrs) == 2:
                    idx1 = int(attrs[0].strip(' '))
                    idx2 = int(attrs[1].strip(' '))
                    tuple_key = (idx1, idx2)
                    tensions[tuple_key] = value

            obj = Environment(
                id=obj.theId,
                name=obj.theName,
                sc=obj.theShortCode,
                description=obj.theDescription,
                environments=obj.theEnvironments,
                duplProperty=obj.theDuplicateProperty,
                overridingEnvironment=obj.theOverridingEnvironment,
                envTensions=tensions)

        if isinstance(obj, dict):
            if class_name == 'asset':
                from cairis.daemon.CairisHTTPError import MalformedJSONHTTPError
                raise MalformedJSONHTTPError()
            elif class_name == 'goal':
                obj = deserialize_goal(dict)
            elif class_name == 'requirement':
                obj = deserialize_requirement(dict)

        return obj
    except Exception as ex:
        from cairis.daemon.CairisHTTPError import handle_exception
        handle_exception(ex)
Exemple #5
0
def json_deserialize(string, class_name=None):
  """
  Deserializes the JSON object to the appropriate class instance.
  :param string: The JSON string
  :type string: str
  :param class_name: The name of the target class
  :type class_name: str
  :return: Returns a dictionary or a class instance depending on the target class chosen
  :rtype: list|dict|Asset|Goal|Requirement|Risk
  """
  if isinstance(string, dict) or isinstance(string, list):
    string = json_serialize(string)

  if isinstance(string, list):
    list_result = []
    for item_string in string:
      item_string = json_serialize(item_string)
      for key in conv_terms:
        item_string = item_string.replace(conv_terms[key], key)
      list_result.append(json_deserialize(item_string))

  if isinstance(string, string_types):
    for key in conv_terms:
      string = string.replace(conv_terms[key], key)

  try:
    obj = deserialize(string)
    if isinstance(obj, Environment):
      tensions = {}
      for key, value in list(obj.theTensions.items()):
        key = str(key)
        attrs = key.strip('(').strip(')').split(',')
        if len(attrs) == 2:
          idx1 = int(attrs[0].strip(' '))
          idx2 = int(attrs[1].strip(' '))
          tuple_key = (idx1, idx2)
          tensions[tuple_key] = value

      obj = Environment(
              id=obj.theId,
              name=obj.theName,
              sc=obj.theShortCode,
              description=obj.theDescription,
              environments=obj.theEnvironments,
              duplProperty=obj.theDuplicateProperty,
              overridingEnvironment=obj.theOverridingEnvironment,
              envTensions=tensions
            )

    if isinstance(obj, dict):
      if class_name == 'asset':
        from cairis.daemon.CairisHTTPError import MalformedJSONHTTPError
        raise MalformedJSONHTTPError()
      elif class_name == 'goal':
        obj = deserialize_goal(dict)
      elif class_name == 'requirement':
        obj = deserialize_requirement(dict)

    return obj
  except Exception as ex:
    from cairis.daemon.CairisHTTPError import handle_exception
    handle_exception(ex)