Example #1
0
    def defaultEnvBody(self):
        defaultEnv = Environment(-1, 'Default', 'DEFAULT',
                                 'Default environment', [], '', '', [])

        for idx1 in range(0, 4):
            for idx2 in range(4, 8):
                tension = EnvironmentTensionModel(idx1, idx2, 0, 'None')
                defaultEnv.theTensions.append(tension)

        return jsonpickle.encode({'session_id': 'test', 'object': defaultEnv})
Example #2
0
 def prepare_comp_environment(self):
     new_environment = Environment(
         id=-1,
         name='Complete',
         sc='ALL',
         description='This is a test description',
         environments=['Psychosis', 'Stroke', 'Core Technology'],
         duplProperty='Maximise',
         overridingEnvironment='',
         envTensions=[])
     return new_environment
Example #3
0
    def prepare_new_environment(self):
        new_environment = Environment(id=-1,
                                      name='Test environment',
                                      sc='TEST',
                                      description='This is a test description',
                                      environments=[],
                                      duplProperty='',
                                      overridingEnvironment='',
                                      envTensions=[])

        for idx1 in range(0, 4):
            for idx2 in range(4, 8):
                tension = EnvironmentTensionModel(base_attr_id=idx1,
                                                  attr_id=idx2,
                                                  value=0,
                                                  rationale='None')
                new_environment.theTensions.append(tension)

        return new_environment
Example #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)