diff --git a/main.py b/main.py
index b03a75c..8ac112f 100644
--- a/main.py
+++ b/main.py
@@ -37,6 +37,8 @@
# Step 2: Register bundle
result = igc.register_bundle(repo)
+result.content
+
# Step 3: Download Power BI db2_reports
#pbi.download_all_reports(repo)
@@ -45,73 +47,103 @@
# Step 5: Generate a pandas dataframe for hosts, folders, reports and schemas
-
-
#host
host = [{"name":os.getenv("SERVER"),
"short_description":os.getenv("DATABASE"),
"long_description":"",
- "phase":"DEV"
+ "$phase":"DEV",
+ "internal_id":igc.internal_id
}]
hosts = pd.DataFrame(host)
+hosts.drop('internal_id',inplace=True,axis=1)## TODO: fix this shit later
#folders
folders = pbi.get_folder_list()
+#create and populate a internal_id field, which is used to perform containment relationships
+for idx,row in folders.iterrows():
+ folders.at[idx,"internal_id"] = igc.internal_id
+
+
+#getting internal_id from parent assets
+#create a dataframe with folders that are parent
+folders2 = folders[folders.itemid.isin(folders.parentid)]
+
+#join child and father dataframes, to have both internal ids on a row
+folders = folders.set_index('parentid').join(folders2.set_index('itemid'),rsuffix='_parent')
+folders.parentid.fillna('',inplace=True)
+
#reports
reports = pbi.get_report_list()
-from lxml import etree
+#create and populate a internal_id field, which is used to perform containment relationships
+for idx,row in reports.iterrows():
+ reports.at[idx,"internal_id"] = igc.internal_id
+#join child and father dataframes, to have both internal ids on a row
+reports = reports.set_index('parentid').join(folders.set_index('itemid'),rsuffix='_folder')
+folders.parentid.fillna('',inplace=True)
+
+from lxml import etree
#create doc
doc = etree.Element("doc",{"xmlns":"http://www.ibm.com/iis/flow-doc"})
#create assets
assets = etree.SubElement(doc,"assets")
-#create asset
-asset = etree.SubElement(assets,"asset",{"class":"$PowerBI-PbiServer","repr":"Servidor Produção","ID":igc.internal_id})
-
-for row in hosts.iterrows():
- for column in row[1].keys():
- asset.append(etree.Element("attribute",{"name":column,"value":row[1][column]}))
-
-request = igc.insert_all_assets(etree.tostring(doc))
-
-request.headers
-#
-#
-#
-#
-#
-# # serie = row1[1]
-# #
-# # for column in serie.keys():
-# # print(column,serie[column])
-# #
-# #
-# #
-# #
-# #
-# #
-# #
-#
-#
-#
-#
-# #function applying methods:
-# reports['db2'] = np.vectorize(pqp.has_db2_sources)(reports['itemid'])
-# #reports['db2'] = reports['db2'].map(pqp.has_db2_sources)
-#
-# db2_reports = reports[reports.db2].reset_index()
-#
-# db2_reports['itemid'][0]
-#
-# meta = pqp.get_metadata(db2_reports['itemid'][0])
-#
-# meta
-#
-# query = meta[0].get('query')
-#
-# query_meta = pqp.get_query_from_tables.findall(query)
-#
-# query_meta
+#create host
+asset = etree.SubElement(assets,"asset",{"class":"$PowerBI-PbiServer","repr":os.getenv("SERVER"),"ID":host[0]['internal_id']})
+#create host attributes
+for idx,series in hosts.iterrows():
+ for column in series.keys():
+ asset.append(etree.Element("attribute",{"name":column,"value":series[column]}))
+
+#create folder assets
+for idx,row in folders.iterrows():
+ asset = etree.SubElement(assets,"asset",{"class":"$PowerBI-PbiFolder","repr":row['name'],"ID":row.internal_id})
+ #create folder attributes
+ asset.append(etree.Element("attribute",{"name":"name","value":row['name']}))
+ #create containment reference
+ if len(row.parentid) == 0:
+ asset.append(etree.Element("reference",{"name":"$PbiServer","assetIDs":host[0]['internal_id']}))
+ else:
+ asset.append(etree.Element("reference",{"name":"$PbiFolder","assetIDs":row.internal_id_parent}))
+
+#create report assets
+for idx,row in reports.iterrows():
+ asset = etree.SubElement(assets,"asset",{"class":"$PowerBI-PbiReport","repr":row['name'],"ID":row.internal_id})
+ #create folder attributes
+ asset.append(etree.Element("attribute",{"name":"name","value":row['name']}))
+ #create containment reference
+ asset.append(etree.Element("reference",{"name":"$PbiFolder","assetIDs":row.internal_id_folder}))
+
+
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+ #
+
+
+#create importAction
+
+importAction = etree.SubElement(doc,"importAction",{"partialAssetIDs":"a1"})
+
+
+
+with open('output/generated.xml','wb') as f:
+ f.write(etree.tostring(doc,pretty_print=True))
+
+xml = etree.tostring(doc, pretty_print=True).decode('UTF-8')
+
+request = igc.insert_all_assets(xml)
+
+request.content