# Path: jasper_erpnext_report/utils/file.py
# def get_image_name(iname):
# def get_images_path(compiled_path):
# def get_jasper_path(for_all_sites = False):
# def write_StringIO_to_file(file_path, output):
# def write_file(content, file_path, modes="w+"):
# def check_extension(fname):
# def get_extension(fname):
# def remove_from_doc(dt, dn, field, where_field = "name"):
# def delete_from_doc(dt, dn, field, value, where_field):
# def delete_from_FileData(dt, dn, file_url):
# def remove_directory(path, ignore_errors=True):
# def remove_compiled_report(root_path):
# def get_file(path, modes="r", raise_not_found=False):
# def read_file(path, modes="r", raise_not_found=False):
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# def get_html_reports_images_path(report_path, where="images"):


import jasper_erpnext_report as jr
import copy
	import jasperserverlib.core as jasper
import frappe
import json
import inspect
import jasper_erpnext_report.utils.utils as utils
import JasperBase as Jb
	from jasperserverlib.core.reportingService import ReportingService
	from jasperserverlib.core.ReportExecutionRequest import ReportExecutionRequest
	from jasperserverlib.resource_details import Details
	from jasperserverlib.repo_search import Search
	from jasperserverlib.resource_download import DownloadBinary
	from jasperserverlib.core.exceptions import Unauthorized, NotFound
from frappe import _
from io import BytesIO
from jasper_erpnext_report.utils.file import JasperXmlReport
		from jasper_erpnext_report.core.FrappeTask import FrappeTask
		return serverInfo

	def get_jrxml_from_server(self, uri):
		f = DownloadBinary(self.session, uri)
		f.downloadBinary(file=True)
		return f.getFileContent()

	def import_all_jasper_reports(self, data, force=True):
		if self.is_login:
			reports = self.get_reports_list_from_server(force=force)
			if reports:
				docs = utils.do_doctype_from_jasper(data, reports, force=True)
				utils.import_all_jasper_remote_reports(docs, force)
				return
			frappe.msgprint(_("There is no report to import.\n Check if the path to JasperReports Server folder is correct.\n "
			                  "Click with right mouse button in the folder to see the uri, check below the 'Path:' name."), raise_exception=True)

	@_jasperserver
	def get_reports_list_from_server(self, force=False):
		ret = {}
		s = Search(self.session)
		result = s.search(path=self.doc.get("jasper_report_root_path").strip(), type="reportUnit")
		reports = result.getDescriptor().json_descriptor()
		for report in reports:
			ics = []
			d = Details(self.session, report.get("uri"))
			r_details = d.details(expanded=False)
			r_param = r_details.getDescriptor().json_descriptor()
			uri = r_param[0].get('jrxml').get('jrxmlFileReference').get('uri')
			file_content = self.get_jrxml_from_server(uri)

# Path: jasper_erpnext_report/utils/file.py
# def get_image_name(iname):
# def get_images_path(compiled_path):
# def get_jasper_path(for_all_sites = False):
# def write_StringIO_to_file(file_path, output):
# def write_file(content, file_path, modes="w+"):
# def check_extension(fname):
# def get_extension(fname):
# def remove_from_doc(dt, dn, field, where_field = "name"):
# def delete_from_doc(dt, dn, field, value, where_field):
# def delete_from_FileData(dt, dn, file_url):
# def remove_directory(path, ignore_errors=True):
# def remove_compiled_report(root_path):
# def get_file(path, modes="r", raise_not_found=False):
# def read_file(path, modes="r", raise_not_found=False):
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# def get_html_reports_images_path(report_path, where="images"):


# Path: jasper_erpnext_report/core/JasperServer.py
import jasper_erpnext_report as jr
import copy
	import jasperserverlib.core as jasper
import frappe
import json
import inspect
import jasper_erpnext_report.utils.utils as utils
import JasperBase as Jb
	from jasperserverlib.core.reportingService import ReportingService
	from jasperserverlib.core.ReportExecutionRequest import ReportExecutionRequest
	from jasperserverlib.resource_details import Details
	from jasperserverlib.repo_search import Search
	from jasperserverlib.resource_download import DownloadBinary
	from jasperserverlib.core.exceptions import Unauthorized, NotFound
from frappe import _
from io import BytesIO
from jasper_erpnext_report.utils.file import JasperXmlReport
		from jasper_erpnext_report.core.FrappeTask import FrappeTask

		return serverInfo

	def get_jrxml_from_server(self, uri):
		f = DownloadBinary(self.session, uri)
		f.downloadBinary(file=True)
		return f.getFileContent()

	def import_all_jasper_reports(self, data, force=True):
		if self.is_login:
			reports = self.get_reports_list_from_server(force=force)
			if reports:
				docs = utils.do_doctype_from_jasper(data, reports, force=True)
				utils.import_all_jasper_remote_reports(docs, force)
				return
			frappe.msgprint(_("There is no report to import.\n Check if the path to JasperReports Server folder is correct.\n "
			                  "Click with right mouse button in the folder to see the uri, check below the 'Path:' name."), raise_exception=True)

	@_jasperserver
	def get_reports_list_from_server(self, force=False):
		ret = {}
		s = Search(self.session)
		result = s.search(path=self.doc.get("jasper_report_root_path").strip(), type="reportUnit")
		reports = result.getDescriptor().json_descriptor()
		for report in reports:
			ics = []
			d = Details(self.session, report.get("uri"))
			r_details = d.details(expanded=False)
			r_param = r_details.getDescriptor().json_descriptor()
			uri = r_param[0].get('jrxml').get('jrxmlFileReference').get('uri')
			file_content = self.get_jrxml_from_server(uri)

			xmldoc = JasperXmlReport(BytesIO(file_content))