try {
if ((idObj == null) || idObj.trim().equals(""))
return;
IBIObjectDAO biobjDAO = DAOFactory.getBIObjectDAO();
BIObject biobj = biobjDAO.loadBIObjectForDetail(new Integer(idObj));
IDataSourceDAO dataSourceDao = DAOFactory.getDataSourceDAO();
IDataSetDAO dataSetDao = DAOFactory.getDataSetDAO();
// Data source, if present
Integer objataSourceId = biobj.getDataSourceId();
if (objataSourceId != null) {
IDataSource ds = dataSourceDao.loadDataSourceByID(objataSourceId);
exporter.insertDataSource(ds, session);
}
// Data set if present
Integer objDataSetId = biobj.getDataSetId();
if (objDataSetId != null) {
GuiGenericDataSet genericDs = dataSetDao.loadDataSetById(objDataSetId);
if(genericDs!=null){
exporter.insertDataSet(genericDs, session);
}
}
// Engine if present, and data source if engine uses data source
Engine engine = biobj.getEngine();
if (engine.getUseDataSource() && engine.getDataSourceId() != null) {
Integer engineDataSourceId = engine.getDataSourceId();
IDataSource ds = dataSourceDao.loadDataSourceByID(engineDataSourceId);
exporter.insertDataSource(ds, session);
}
exporter.insertEngine(engine, session);
exporter.insertBIObject(biobj, session, false); // do not insert dataset
logger.debug("Export metadata associated to the object");
IObjMetacontentDAO objMetacontentDAO = DAOFactory.getObjMetacontentDAO();
// get metacontents associated to object
List metacontents = objMetacontentDAO.loadObjOrSubObjMetacontents(biobj.getId(), null);
for (Iterator iterator = metacontents.iterator(); iterator.hasNext();) {
ObjMetacontent metacontent = (ObjMetacontent) iterator.next();
exporter.insertObjMetacontent(metacontent, session);
}
// if the document is a chart, export the relevant dataset that is referenced by the template
boolean isChart = false;
if (biobj.getBiObjectTypeCode().equalsIgnoreCase("DASH")
&& engine.getClassName() != null && engine.getClassName().equals("it.eng.spagobi.engines.chart.SpagoBIChartInternalEngine")) {
isChart = true;
}
if (isChart) {
ObjTemplate template = biobj.getActiveTemplate();
if (template != null) {
try {
byte[] tempFileCont = template.getContent();
String tempFileStr = new String(tempFileCont);
SourceBean tempFileSB = SourceBean.fromXMLString(tempFileStr);
SourceBean datasetnameSB = (SourceBean) tempFileSB.getFilteredSourceBeanAttribute("CONF.PARAMETER", "name", "confdataset");
if (datasetnameSB != null) {
String datasetLabel = (String) datasetnameSB.getAttribute("value");
IDataSetDAO datasetDao = DAOFactory.getDataSetDAO();
IDataSet dataset = datasetDao.loadActiveDataSetByLabel(datasetLabel);
GuiGenericDataSet guiGenericDataSet = datasetDao.loadDataSetByLabel(datasetLabel);
if (dataset == null) {
logger.warn("Error while exporting dashboard with id " + idObj + " and label " + biobj.getLabel() + " : " +
"the template refers to a dataset with label " + datasetLabel + " that does not exist!");
} else {
exporter.insertDataSet(guiGenericDataSet, session);
}
}
} catch (Exception e) {
logger.error("Error while exporting dashboard with id " + idObj + " and label " + biobj.getLabel() + " : " +
"could not find dataset reference in its template.");
}
}
}
// use Types Manager to handle specific export types, by now only KPI and CONSOLE.. TODO with all types
ITypesExportManager typeManager = TypesExportManagerFactory.createTypesExportManager(biobj, engine, exporter, this);
// if null means it is not defined
if (typeManager != null)
typeManager.manageExport(biobj, session);
//maps kpi export
// boolean isKpi = false;
// if (biobj.getBiObjectTypeCode().equalsIgnoreCase("KPI")
// && engine.getClassName() != null && engine.getClassName().equals("it.eng.spagobi.engines.kpi.SpagoBIKpiInternalEngine")) {
// isKpi = true;
// }
// if (isKpi) {
// List objsToInsert=new ArrayList();
// ObjTemplate template = biobj.getActiveTemplate();
// if (template != null) {
// try {
// byte[] tempFileCont = template.getContent();
// String tempFileStr = new String(tempFileCont);
// SourceBean tempFileSB = SourceBean.fromXMLString(tempFileStr);
//
//
// String modelInstanceLabel = (String) tempFileSB.getAttribute("model_node_instance");
//
// // biObjectToInsert keeps track of objects that have to be inserted beacuse related to Kpi
//
// if (modelInstanceLabel != null) {
// IModelInstanceDAO modelInstanceDao = DAOFactory.getModelInstanceDAO();
// ModelInstance modelInstance = modelInstanceDao.loadModelInstanceWithoutChildrenByLabel(modelInstanceLabel);
// if (modelInstance == null) {
// logger.warn("Error while exporting kpi with id " + idObj + " and label " + biobj.getLabel() + " : " +
// "the template refers to a Model Instance with label " + modelInstanceLabel + " that does not exist!");
// } else {
// objsToInsert=exporter.insertAllFromModelInstance(modelInstance, session);
// //exporter.insertModelInstance(modelInstance, session);
// }
// }
// } catch (Exception e) {
// logger.error("Error while exporting kpi with id " + idObj + " and label " + biobj.getLabel());
// throw new EMFUserError(EMFErrorSeverity.ERROR, "8010", "component_impexp_messages");
//
// }
// }
//
// for (Iterator iterator = objsToInsert.iterator(); iterator.hasNext();) {
// Integer id = (Integer) iterator.next();
// BIObject obj=(BIObject)biobjDAO.loadBIObjectById(id);
// if(obj!=null){
// exportSingleObj(obj.getId().toString());
// }
// else{
// logger.error("Could not find object with id"+id);
// }
// }
//
// }
// maps catalogue export
boolean isMap = false;
if (biobj.getBiObjectTypeCode().equalsIgnoreCase("MAP")) isMap = true;
if (isMap) {
exporter.insertMapCatalogue(session);
}
if (exportSubObjects) {
ISubObjectDAO subDao = DAOFactory.getSubObjectDAO();
List subObjectLis = subDao.getSubObjects(biobj.getId());
if (subObjectLis != null && !subObjectLis.isEmpty())
exporter.insertAllSubObject(biobj, subObjectLis, session);
}
if (exportSnapshots) {
ISnapshotDAO subDao = DAOFactory.getSnapshotDAO();
List snapshotLis = subDao.getSnapshots(biobj.getId());
if (snapshotLis != null && !snapshotLis.isEmpty())
exporter.insertAllSnapshot(biobj, snapshotLis, session);
}
// insert functionalities and association with object
List functs = biobj.getFunctionalities();
Iterator iterFunct = functs.iterator();
while (iterFunct.hasNext()) {
Integer functId = (Integer) iterFunct.next();
ILowFunctionalityDAO lowFunctDAO = DAOFactory.getLowFunctionalityDAO();
LowFunctionality funct = lowFunctDAO.loadLowFunctionalityByID(functId, false);
if (funct.getCodType().equals(SpagoBIConstants.USER_FUNCTIONALITY_TYPE_CODE)) {
logger.debug("User folder [" + funct.getPath() + "] will be not exported.");
// if the folder is a personal folder, it is not exported
continue;
}
exporter.insertFunctionality(funct, session);
exporter.insertObjFunct(biobj, funct, session);
}
// export parameters
List biparams = biobjDAO.getBIObjectParameters(biobj);
exportBIParamsBIObj(biparams, biobj);
// export parameters dependecies
exporter.insertBiParamDepend(biparams, session);
// export subReport relation
ISubreportDAO subRepDao = DAOFactory.getSubreportDAO();
List subList = subRepDao.loadSubreportsByMasterRptId(biobj.getId());
Iterator itersub = subList.iterator();
while (itersub.hasNext()) {
Subreport subRep = (Subreport) itersub.next();
exporter.insertSubReportAssociation(subRep, session);
exportSingleObj(subRep.getSub_rpt_id().toString());