import json
import pandas as pd
from sqlalchemy.sql import table, column
from igf_data.igfdb.baseadaptor import BaseAdaptor
from igf_data.igfdb.igfTables import File 

class FileAdaptor(BaseAdaptor):
  '''
  An adaptor class for File tables
  '''
  def get_file_columns(self):
    '''
    A method for fetching the columns for table file
    '''
    file_column=[column.key for column in File.__table__.columns]
    return user_column

  
  def store_file_data(self, data):
    '''
    Load data to file table
    '''
    if not isinstance(data, pd.DataFrame):
      data=pd.DataFrame(data)     

    try:
      self.store_records(table=File, data=data, mode='bulk' )
      self.commit_session()
    except:
      self.rollback_session()
      raise


  def fetch_file_records_file_path(self, file_path):
    '''
    A method for fetching data for file table
    required params:
    file_path: an absolute file path
    '''
    try:
      file_obj=self.fetch_records_by_column(table=File, column_name=File.file_path, column_id=file_path, output_mode='one')
      return file_obj
    except:
      raise

@@ -250,193 +250,1953 @@
 def 
-get_file_columns(self):%0A    '''%0A    A method for fetching the columns for table file%0A    '''%0A    file_column=%5Bcolumn.key for column in File.__table__.columns%5D%0A    return user_column%0A%0A  
+store_file_and_attribute_data(self, data):%0A    '''%0A    A method for dividing and storing data to file and attribute table%0A    '''%0A    (file_data, file_attr_data)=self.divide_data_to_table_and_attribute(data=data)%0A    try:%0A      self.store_file_data(data=file_data) %0A      self.store_run_attributes(data=file_attr_data) %0A      self.commit_session()%0A    except:%0A      self.rollback_session()%0A      raise%0A%0A%0A  def divide_data_to_table_and_attribute(self, data, required_column='file_path', attribute_name_column='attribute_name', attribute_value_column='attribute_value'):%0A    '''%0A    A method for separating data for File and File_attribute tables%0A    required params:%0A    required_column: column name to add to the attribute data%0A    attribute_name_column: label for attribute name column%0A    attribute_value_column: label for attribute value column%0A    It returns two pandas dataframes, one for File and another for File_attribute table%0A    '''%0A    if not isinstance(data, pd.DataFrame):%0A      data=pd.DataFrame(data)%0A %0A    file_columns=self.get_table_columns(table_name=File, excluded_columns=%5B'file_id'%5D)                             # get required columns for file table%0A    (file_df, file_attr_df)=super(FileAdaptor, self).divide_data_to_table_and_attribute( %5C%0A                                                                     data=data, %5C%0A    %09                                                             required_column=required_column, %5C%0A    %09                                                             table_columns=file_columns,  %5C%0A                                                                     attribute_name_column=attribute_name_column, %5C%0A                                                                     attribute_value_column=attribute_value_column%0A                                                                    )                                               # divide dataframe%0A    return (file_df, file_attr_df)%0A%0A
 %0A  d
@@ -2501,24 +2501,293 @@
     raise%0A%0A%0A
+  def store_file_attributes(self, data, file_id=''):%0A    '''%0A    A method for storing data to File_attribute table%0A    '''%0A    try:%0A      self.store_attributes(attribute_table=File_attribute, linked_column='file_id', db_id=file_id, data=data)%0A    except:%0A      raise%0A%0A%0A
   def fetch_
@@ -3106,28 +3106,30 @@
 obj%0A    except:%0A      raise%0A
+%0A%0A

divide data to file and attribute tables