def delete_all_component_types()

in src/libs/deploy_utils/WorkspaceUtils.py [0:0]


    def delete_all_component_types(self):
        resp = self.iottwinmaker_client.list_component_types(workspaceId=self.workspace_id)
        component_type_summaries = resp['componentTypeSummaries']

        details_map = {} # details of each component type indexed by component_id
        decendants_map = {} # list of ancestors of each component type indexed by component_id
        # for each component initialize the ancestor map
        for i, cts in enumerate(component_type_summaries):
            decendants_map[cts['componentTypeId']] = []

        # for each component lookup the details and populate the ancestor map
        for i, cts in enumerate(component_type_summaries):
            component_type_id = cts['componentTypeId']
            component_type = self.iottwinmaker_client.get_component_type(workspaceId=self.workspace_id, componentTypeId=component_type_id)
            details_map[component_type_id] = component_type
            if 'extendsFrom' in component_type:
                # for each of the base types this type extends... add it to the ancestor map
                for i, base_component_type_id in enumerate(component_type['extendsFrom']):
                    decendants_map[base_component_type_id].append(component_type_id)

        # remove all component type by looping over the map
        while len(decendants_map) > 0:
            # get the next component_id found in the decendants map and delete its chain of decendants
            component_type_id = next(iter(decendants_map.items()))[0]
            self.recursive_delete_component_type(decendants_map=decendants_map, component_type_id=component_type_id)