public String exportData(String reference, Search search, OutputStream data, boolean destructive, Map<String, Object> params) { LOG.info("exportData(): reference="+reference+", destructive="+destructive); if(M_dhs.entityExists(reference)) { //String destSiteId = M_dhs.getLocationIdFromRef(reference); String exportInfo = IMPORTEXPORT_DEFAULT_ENCODING + "|" + IMPORTEXPORT_CURRENT_VERSION; List<ReportDef> list = M_rm.getReportDefinitions(M_dhs.getCurrentLocationId(), false, true); if(list != null && !list.isEmpty()) { try{ String xml = DigesterUtil.convertReportDefsToXml(list); data.write(xml.getBytes(IMPORTEXPORT_DEFAULT_ENCODING)); if(destructive) { for(ReportDef rd : list) { M_rm.removeReportDefinition(rd); } } return exportInfo; }catch(Exception e){ LOG.error("Unable to export SiteStats reports", e); } } } return null; }
public String[] importData(String reference, InputStream data, String encodingKey, Map<String, Object> params) { LOG.info("importData(): reference="+reference+", encodingKey="+encodingKey+", params="+params); String[] imported = new String[0]; if(M_dhs.entityExists(reference)) { //String srcSiteId = M_dhs.getLocationIdFromRef(reference); String[] importInfo = encodingKey.split("\\|"); try{ byte[] bytes = new byte[data.available()]; data.read(bytes); List<ReportDef> list = DigesterUtil.convertXmlToReportDefs(new String(bytes, importInfo[0])); String thisSiteId = M_dhs.getCurrentLocationId(); for(ReportDef rf : list) { rf.setId(0); rf.setSiteId(thisSiteId); rf.getReportParams().setSiteId(thisSiteId); M_rm.saveReportDefinition(rf); } }catch(Exception e){ LOG.error("Unable to import SiteStats reports", e); } } return imported; }