Skip to content

Commit

Permalink
kind to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
SurajBDeore committed Oct 1, 2024
1 parent 53be914 commit fc844a7
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lobster/tools/codebeamer/codebeamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@

class References(Enum):
REFS = "refs"
KIND = "kind"
SCHEMA = "schema"


SUPPORTED_REFERENCES = [References.REFS.value, References.KIND.value]
SUPPORTED_REFERENCES = [References.REFS.value, References.SCHEMA.value]


def add_refs_refrences(req, flat_values_list):
Expand Down Expand Up @@ -178,10 +178,10 @@ def to_lobster(cb_config, cb_item):
assert isinstance(cb_config, dict)
assert isinstance(cb_item, dict) and "id" in cb_item

SCHEMA_MAP = {'implementation', 'requirement', 'activity'}
SCHEMA = cb_config.get("kind", "requirement").lower()
if SCHEMA not in SCHEMA_MAP:
raise LOBSTER_Error(f"Unsupported SCHEMA '{SCHEMA}' provided in configuration.")
schema_map = {'implementation', 'requirement', 'activity'}
schema = cb_config.get("schema", "requirement").lower()
if schema not in schema_map:
raise LOBSTER_Error(f"Unsupported SCHEMA '{schema}' provided in configuration.")

# This looks like it's business logic, maybe we should make this
# configurable?
Expand Down Expand Up @@ -209,7 +209,7 @@ def to_lobster(cb_config, cb_item):
# Create common parameters for all kinds
common_params = {
'tag': Tracing_Tag(
namespace="req" if SCHEMA == 'requirement' else "imp" if SCHEMA == 'implementation' else "act",
namespace="req" if schema == 'requirement' else "imp" if schema == 'implementation' else "act",
tag=str(cb_item["id"]),
version=cb_item["version"]
),
Expand All @@ -224,7 +224,7 @@ def to_lobster(cb_config, cb_item):
}
# Construct the appropriate object based on 'kind'

if SCHEMA == 'requirement':
if schema == 'requirement':
req = Requirement(
**common_params,
framework="codebeamer",
Expand All @@ -233,7 +233,7 @@ def to_lobster(cb_config, cb_item):
name= item_name
)

elif SCHEMA == 'implementation':
elif schema == 'implementation':
req = Implementation(
**common_params,
language="python",
Expand Down Expand Up @@ -304,10 +304,10 @@ def parse_cb_config(file_name):
with open(file_name, "r", encoding='utf-8') as file:
data = json.loads(file.read())

SCHEMA = data.get("kind", "Requirement").lower()
SCHEMA_MAP = {'implementation', 'requirement', 'activity'}
if SCHEMA not in SCHEMA_MAP:
raise LOBSTER_Error(f"Unsupported SCHEMA '{SCHEMA}' provided in configuration.")
schema = data.get("schema", "Requirement").lower()
schema_map = {'implementation', 'requirement', 'activity'}
if schema not in schema_map:
raise LOBSTER_Error(f"Unsupported SCHEMA '{schema}' provided in configuration.")

provided_config_keys = set(data.keys())
supported_references = set(SUPPORTED_REFERENCES)
Expand All @@ -321,7 +321,7 @@ def parse_cb_config(file_name):
for key, value in data.items():
json_config[key] = ensure_array_of_strings(value)

json_config["kind"] = SCHEMA
json_config["schema"] = schema

return json_config

Expand Down Expand Up @@ -373,7 +373,7 @@ def main():
mh = Message_Handler()

cb_config = {
'kind' : options.schema,
'schema' : options.schema,
"root" : options.cb_root,
"base" : "%s/cb/api/v3" % options.cb_root,
"user" : options.cb_user,
Expand All @@ -386,7 +386,7 @@ def main():
if options.config:
if os.path.isfile(options.config):
cb_config["references"] = parse_cb_config(options.config)
cb_config["kind"] = cb_config["references"]['kind']
cb_config["schema"] = cb_config["references"]['schema']
else:
ap.error("cannot open config file '%s'" % options.config)

Expand Down Expand Up @@ -455,16 +455,16 @@ def main():
except LOBSTER_Error:
return 1

kind_map = {
schema_map = {
"requirement": Requirement,
"implementation": Implementation,
"activity": Activity
}

kind_O = kind_map.get(cb_config["kind"].lower(), Requirement)
schema_obj = schema_map.get(cb_config["schema"].lower(), Requirement)
output = sys.stdout if options.out is None else open(options.out, "w", encoding="UTF-8")
with output as fd:
lobster_write(fd, kind_O, "lobster_codebeamer", items)
lobster_write(fd, schema_obj, "lobster_codebeamer", items)
if options.out:
print(f"Written {len(items)} requirements to {options.out}")

Expand Down

0 comments on commit fc844a7

Please sign in to comment.