UpgradeReportsTree.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * UpgrageReportsTree.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. *
  14. */
  15. import java.awt.Dimension;
  16. import java.awt.GridLayout;
  17. import java.awt.event.MouseEvent;
  18. import java.io.File;
  19. import java.io.FileOutputStream;
  20. import javax.swing.JFileChooser;
  21. import javax.swing.JMenuItem;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JPanel;
  24. import javax.swing.JScrollPane;
  25. import javax.swing.JTable;
  26. import javax.swing.JTree;
  27. import javax.swing.event.TreeExpansionEvent;
  28. import javax.swing.event.TreeExpansionListener;
  29. import javax.swing.event.TreeSelectionEvent;
  30. import javax.swing.event.TreeSelectionListener;
  31. import javax.swing.filechooser.FileFilter;
  32. import javax.swing.tree.DefaultMutableTreeNode;
  33. import javax.swing.tree.TreePath;
  34. import javax.swing.tree.TreeSelectionModel;
  35. import com.cognos.developer.schemas.bibus._3.AddOptions;
  36. import com.cognos.developer.schemas.bibus._3.AnyTypeProp;
  37. import com.cognos.developer.schemas.bibus._3.AsynchDetailReportObject;
  38. import com.cognos.developer.schemas.bibus._3.AsynchReply;
  39. import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum;
  40. import com.cognos.developer.schemas.bibus._3.AuthoredReport;
  41. import com.cognos.developer.schemas.bibus._3.BaseClass;
  42. import com.cognos.developer.schemas.bibus._3.Locale;
  43. import com.cognos.developer.schemas.bibus._3.MultilingualToken;
  44. import com.cognos.developer.schemas.bibus._3.MultilingualTokenProp;
  45. import com.cognos.developer.schemas.bibus._3.Option;
  46. import com.cognos.developer.schemas.bibus._3.ParameterValue;
  47. import com.cognos.developer.schemas.bibus._3.PropEnum;
  48. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  49. import com.cognos.developer.schemas.bibus._3.Report;
  50. import com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionBoolean;
  51. import com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionEnum;
  52. import com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionSpecificationFormat;
  53. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  54. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  55. import com.cognos.developer.schemas.bibus._3.Sort;
  56. import com.cognos.developer.schemas.bibus._3.SpecificationFormatEnum;
  57. import com.cognos.developer.schemas.bibus._3.UpdateActionEnum;
  58. import com.cognos.developer.schemas.bibus._3.UpdateOptions;
  59. public class UpgradeReportsTree
  60. extends JPanel
  61. implements
  62. TreeSelectionListener,
  63. TreeExpansionListener,
  64. java.awt.event.MouseListener,
  65. java.awt.event.ActionListener
  66. {
  67. private JTree tree;
  68. private static String defaultRootSearchPath = "/";
  69. private CRNConnect connection;
  70. public UpgradeReportsTree(CRNConnect oCrn)
  71. {
  72. super(new GridLayout(1, 0));
  73. connection = oCrn;
  74. //Create the nodes.
  75. DefaultMutableTreeNode top = new DefaultMutableTreeNode();
  76. TreeBrowserNode crnRootNode =
  77. new TreeBrowserNode(defaultRootSearchPath, connection);
  78. crnRootNode.setContainer(top);
  79. createNodes(top);
  80. for (int i = 0; i < top.getChildCount(); i++)
  81. {
  82. createNodes((DefaultMutableTreeNode)top.getChildAt(i));
  83. }
  84. ((TreeBrowserNode)top.getUserObject()).setChildrenPopulated(true);
  85. //Create a tree that allows one selection at a time.
  86. tree = new JTree(top);
  87. tree.getSelectionModel().setSelectionMode(
  88. TreeSelectionModel.SINGLE_TREE_SELECTION);
  89. //Listen for when the selection changes.
  90. tree.addTreeExpansionListener(this);
  91. tree.addTreeSelectionListener(this);
  92. tree.addMouseListener(this);
  93. tree.setCellRenderer(new TreeBrowserCellRenderer());
  94. //Create the scroll pane and add the tree to it.
  95. JScrollPane treeView = new JScrollPane(tree);
  96. Dimension minimumSize = new Dimension(100, 50);
  97. treeView.setMinimumSize(minimumSize);
  98. add(treeView);
  99. //Set the root node as the currently selected node in the tree
  100. tree.setSelectionRow(0);
  101. }
  102. /** Required by MouseListener interface. */
  103. public void mousePressed(MouseEvent mEvent)
  104. {}
  105. public void mouseEntered(MouseEvent mEvent)
  106. {}
  107. public void mouseExited(MouseEvent mEvent)
  108. {}
  109. public void mouseReleased(MouseEvent mEvent)
  110. {}
  111. public void mouseClicked(MouseEvent mEvent)
  112. {
  113. if (javax.swing.SwingUtilities.isRightMouseButton(mEvent))
  114. {
  115. javax.swing.JMenu upgrade = new javax.swing.JMenu("Upgrade");
  116. javax.swing.JMenu extract = new javax.swing.JMenu("Extract");
  117. javax.swing.JMenuItem upgradeItem =
  118. new javax.swing.JMenuItem(UpgradeReports.UPGRADE_SPEC_STRING);
  119. upgradeItem.addActionListener(this);
  120. javax.swing.JMenuItem upgradeCopyItem =
  121. new javax.swing.JMenuItem(UpgradeReports.UPGRADE_COPY_SPEC_STRING);
  122. upgradeCopyItem.addActionListener(this);
  123. javax.swing.JMenuItem extractItem =
  124. new javax.swing.JMenuItem(UpgradeReports.EXTRACT_SPEC_STRING);
  125. extractItem.addActionListener(this);
  126. javax.swing.JMenuItem extractUpgradeItem =
  127. new javax.swing.JMenuItem(UpgradeReports.EXTRACT_UPGRADED_SPEC_STRING);
  128. extractUpgradeItem.addActionListener(this);
  129. javax.swing.JPopupMenu dropDownMenu = new javax.swing.JPopupMenu();
  130. upgrade.add(upgradeItem);
  131. upgrade.add(upgradeCopyItem);
  132. dropDownMenu.add(upgrade);
  133. extract.add(extractItem);
  134. extract.add(extractUpgradeItem);
  135. dropDownMenu.add(extract);
  136. dropDownMenu.show(
  137. mEvent.getComponent(),
  138. mEvent.getX(),
  139. mEvent.getY());
  140. }
  141. if (javax.swing.SwingUtilities.isLeftMouseButton(mEvent))
  142. {
  143. if (mEvent.getClickCount() > 1)
  144. {
  145. if (mEvent.getSource().getClass() == JTable.class)
  146. {
  147. JTable tableForDBLClick = (JTable)mEvent.getSource();
  148. TreeBrowserNode nodeForDBLClick =
  149. (
  150. (TreeBrowserTableModel)tableForDBLClick
  151. .getModel())
  152. .getTbnForRow(
  153. tableForDBLClick.getSelectedRow());
  154. exploreNode(nodeForDBLClick);
  155. }
  156. }
  157. }
  158. }
  159. public void exploreNode(TreeBrowserNode node)
  160. {
  161. tree.setSelectionPath(new TreePath((node.getContainer().getPath())));
  162. }
  163. public void treeCollapsed(TreeExpansionEvent teEvent)
  164. {}
  165. public void treeExpanded(TreeExpansionEvent teEvent)
  166. {
  167. DefaultMutableTreeNode currentExpandedNode =
  168. (DefaultMutableTreeNode)teEvent.getPath().getLastPathComponent();
  169. for (int i = 0; i < currentExpandedNode.getChildCount(); i++)
  170. {
  171. createNodes(
  172. (DefaultMutableTreeNode)currentExpandedNode.getChildAt(i));
  173. }
  174. }
  175. /** Required by TreeSelectionListener interface. */
  176. public void valueChanged(TreeSelectionEvent e)
  177. {
  178. DefaultMutableTreeNode node =
  179. (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
  180. if (node != null)
  181. {
  182. createNodes(node);
  183. //This updates the searchPath textBox in the GUI
  184. if ((this.getParent() != null)
  185. && (this.getParent().getParent().getParent().getParent() != null))
  186. {
  187. (
  188. (UpgradeReports)this
  189. .getParent()
  190. .getParent()
  191. .getParent()
  192. .getParent())
  193. .updateSelectedSearchPath(
  194. ((TreeBrowserNode)node.getUserObject())
  195. .getCMObject()
  196. .getSearchPath()
  197. .getValue());
  198. }
  199. }
  200. }
  201. public void actionPerformed(java.awt.event.ActionEvent action)
  202. {
  203. JMenuItem actionSource = (JMenuItem)action.getSource();
  204. TreeBrowserNode nodeForPopup;
  205. nodeForPopup =
  206. (TreeBrowserNode) ((DefaultMutableTreeNode)tree
  207. .getLastSelectedPathComponent())
  208. .getUserObject();
  209. if (UpgradeReports.UPGRADE_SPEC_STRING == actionSource.getText())
  210. {
  211. showUpgradeDialog(nodeForPopup, connection);
  212. }
  213. else if (UpgradeReports.UPGRADE_COPY_SPEC_STRING == actionSource.getText())
  214. {
  215. showUpgradeCopyDialog(nodeForPopup, connection);
  216. }
  217. else if (UpgradeReports.EXTRACT_SPEC_STRING == actionSource.getText())
  218. {
  219. showExtractDialog(nodeForPopup, connection);
  220. }
  221. else if (UpgradeReports.EXTRACT_UPGRADED_SPEC_STRING == actionSource.getText())
  222. {
  223. showExtractUpgradedDialog(nodeForPopup, connection);
  224. }
  225. }
  226. public TreeBrowserNode getSelectedNode()
  227. {
  228. TreeBrowserNode node;
  229. node =
  230. (TreeBrowserNode) ((DefaultMutableTreeNode)tree
  231. .getLastSelectedPathComponent())
  232. .getUserObject();
  233. return node;
  234. }
  235. public void showUpgradeDialog(TreeBrowserNode node, CRNConnect connection)
  236. {
  237. Option[] queryOpts = new Option[2];
  238. ReportServiceQueryOptionBoolean upgradeSpecFlag = new ReportServiceQueryOptionBoolean();
  239. upgradeSpecFlag.setName(ReportServiceQueryOptionEnum.upgrade);
  240. upgradeSpecFlag.setValue(true);
  241. ReportServiceQueryOptionSpecificationFormat specFormat = new ReportServiceQueryOptionSpecificationFormat();
  242. specFormat.setName(ReportServiceQueryOptionEnum.specificationFormat);
  243. specFormat.setValue(SpecificationFormatEnum.report);
  244. queryOpts[0] = upgradeSpecFlag;
  245. queryOpts[1] = specFormat;
  246. if (node == null)
  247. {
  248. node = getSelectedNode();
  249. }
  250. int ok =
  251. JOptionPane.showConfirmDialog(
  252. null,
  253. "This will replace existing report specification(s) with up-to-date version(s) in the content store. Once performed, this action cannot be undone.");
  254. if (ok == JOptionPane.OK_OPTION)
  255. {
  256. ok =
  257. JOptionPane.showConfirmDialog(
  258. null,
  259. "I really, really mean it. You can't go back. Think about it.");
  260. if (ok == JOptionPane.OK_OPTION)
  261. {
  262. AuthoredReport reportToUpdate = null;
  263. try
  264. {
  265. BaseClass[] reports =
  266. getReportList(node.getCMObject(), connection);
  267. for (int i = 0; i < reports.length; i++)
  268. {
  269. AsynchReply qrResult =
  270. connection.getReportService().query(
  271. new SearchPathSingleObject(reports[i].getSearchPath().getValue()),
  272. new ParameterValue[] {},
  273. queryOpts);
  274. if ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  275. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  276. {
  277. while ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  278. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  279. {
  280. qrResult = connection.getReportService().wait(qrResult.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
  281. }
  282. }
  283. for (int j = 0; j < qrResult.getDetails().length; j++)
  284. {
  285. if ( qrResult.getDetails()[j] instanceof AsynchDetailReportObject)
  286. {
  287. reportToUpdate = ( (AsynchDetailReportObject) qrResult.getDetails()[j]).getReport();
  288. }
  289. }
  290. updateReportsInContentStore(
  291. reportToUpdate,
  292. reports[i].getParent().getValue()[0],
  293. connection);
  294. }
  295. }
  296. catch (java.rmi.RemoteException remoteEx)
  297. {
  298. remoteEx.printStackTrace();
  299. }
  300. }
  301. else
  302. {
  303. JOptionPane.showMessageDialog(null, "Cancelled.");
  304. }
  305. }
  306. else
  307. {
  308. JOptionPane.showMessageDialog(null, "Cancelled.");
  309. }
  310. }
  311. public void showUpgradeCopyDialog(
  312. TreeBrowserNode node,
  313. CRNConnect connection)
  314. {
  315. Option[] queryOpts = new Option[2];
  316. ReportServiceQueryOptionBoolean upgradeSpecFlag = new ReportServiceQueryOptionBoolean();
  317. upgradeSpecFlag.setName(ReportServiceQueryOptionEnum.upgrade);
  318. upgradeSpecFlag.setValue(true);
  319. ReportServiceQueryOptionSpecificationFormat specFormat = new ReportServiceQueryOptionSpecificationFormat();
  320. specFormat.setName(ReportServiceQueryOptionEnum.specificationFormat);
  321. specFormat.setValue(SpecificationFormatEnum.report);
  322. queryOpts[0] = upgradeSpecFlag;
  323. queryOpts[1] = specFormat;
  324. if (node == null)
  325. {
  326. node = getSelectedNode();
  327. }
  328. int ok =
  329. JOptionPane.showConfirmDialog(
  330. null,
  331. "Retrieve up-to-date version of report specification(s) and add to the content store.");
  332. if (ok == JOptionPane.OK_OPTION)
  333. {
  334. try
  335. {
  336. AuthoredReport reportCopy = null;
  337. BaseClass[] reports =
  338. getReportList(node.getCMObject(), connection);
  339. for (int i = 0; i < reports.length; i++)
  340. {
  341. AsynchReply qrResult =
  342. connection.getReportService().query(
  343. new SearchPathSingleObject(reports[i].getSearchPath().getValue()),
  344. new ParameterValue[] {},
  345. queryOpts);
  346. if ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  347. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  348. {
  349. while ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  350. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  351. {
  352. qrResult = connection.getReportService().wait(qrResult.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
  353. }
  354. }
  355. for (int j = 0; j < qrResult.getDetails().length; j++)
  356. {
  357. if ( qrResult.getDetails()[j] instanceof AsynchDetailReportObject)
  358. {
  359. reportCopy = ( (AsynchDetailReportObject) qrResult.getDetails()[j]).getReport();
  360. }
  361. }
  362. copyReportSpecInContentStore(
  363. reportCopy,
  364. reports[i].getParent().getValue()[0],
  365. connection);
  366. }
  367. }
  368. catch (java.rmi.RemoteException remoteEx)
  369. {
  370. remoteEx.printStackTrace();
  371. }
  372. }
  373. else
  374. {
  375. JOptionPane.showMessageDialog(null, "Cancelled.");
  376. }
  377. }
  378. public void showExtractDialog(TreeBrowserNode node, CRNConnect connection)
  379. {
  380. File saveDir = getFileFolder();
  381. if (saveDir == null)
  382. {
  383. return;
  384. }
  385. if (node == null)
  386. {
  387. node = getSelectedNode();
  388. }
  389. Option[] queryOpts = new Option[2];
  390. ReportServiceQueryOptionBoolean upgradeSpecFlag = new ReportServiceQueryOptionBoolean();
  391. upgradeSpecFlag.setName(ReportServiceQueryOptionEnum.upgrade);
  392. upgradeSpecFlag.setValue(false);
  393. ReportServiceQueryOptionSpecificationFormat specFormat = new ReportServiceQueryOptionSpecificationFormat();
  394. specFormat.setName(ReportServiceQueryOptionEnum.specificationFormat);
  395. specFormat.setValue(SpecificationFormatEnum.report);
  396. queryOpts[0] = upgradeSpecFlag;
  397. queryOpts[1] = specFormat;
  398. try
  399. {
  400. AuthoredReport reportToExtract = null;
  401. BaseClass[] reports =
  402. getReportList(node.getCMObject(), connection);
  403. for (int i = 0; i < reports.length; i++)
  404. {
  405. AsynchReply qrResult =
  406. connection.getReportService().query(
  407. new SearchPathSingleObject(reports[i].getSearchPath().getValue()),
  408. new ParameterValue[]{},
  409. queryOpts);
  410. if ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  411. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  412. {
  413. while ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  414. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  415. {
  416. qrResult = connection.getReportService().wait(qrResult.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
  417. }
  418. }
  419. for (int j = 0; j < qrResult.getDetails().length; j++)
  420. {
  421. if ( qrResult.getDetails()[j] instanceof AsynchDetailReportObject)
  422. {
  423. reportToExtract = ( (AsynchDetailReportObject) qrResult.getDetails()[j]).getReport();
  424. }
  425. }
  426. saveReportSpecLocally(reportToExtract, saveDir);
  427. }
  428. }
  429. catch (java.rmi.RemoteException remoteEx)
  430. {
  431. remoteEx.printStackTrace();
  432. }
  433. }
  434. public void showExtractUpgradedDialog(
  435. TreeBrowserNode node,
  436. CRNConnect connection)
  437. {
  438. File saveDir = getFileFolder();
  439. if (saveDir == null)
  440. {
  441. return;
  442. }
  443. if (node == null)
  444. {
  445. node = getSelectedNode();
  446. }
  447. Option[] queryOpts = new Option[2];
  448. ReportServiceQueryOptionBoolean upgradeSpecFlag = new ReportServiceQueryOptionBoolean();
  449. upgradeSpecFlag.setName(ReportServiceQueryOptionEnum.upgrade);
  450. upgradeSpecFlag.setValue(true);
  451. ReportServiceQueryOptionSpecificationFormat specFormat = new ReportServiceQueryOptionSpecificationFormat();
  452. specFormat.setName(ReportServiceQueryOptionEnum.specificationFormat);
  453. specFormat.setValue(SpecificationFormatEnum.report);
  454. queryOpts[0] = upgradeSpecFlag;
  455. queryOpts[1] = specFormat;
  456. try
  457. {
  458. AuthoredReport reportToExtract = null;
  459. BaseClass[] reports =
  460. getReportList(node.getCMObject(), connection);
  461. for (int i = 0; i < reports.length; i++)
  462. {
  463. AsynchReply qrResult =
  464. connection.getReportService().query(
  465. new SearchPathSingleObject(reports[i].getSearchPath().getValue()),
  466. new ParameterValue[]{},
  467. queryOpts);
  468. if ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  469. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  470. {
  471. while ( (qrResult.getStatus() == AsynchReplyStatusEnum.working)
  472. || (qrResult.getStatus() == AsynchReplyStatusEnum.stillWorking) )
  473. {
  474. qrResult = connection.getReportService().wait(qrResult.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
  475. }
  476. }
  477. for (int j = 0; j < qrResult.getDetails().length; j++)
  478. {
  479. if ( qrResult.getDetails()[j] instanceof AsynchDetailReportObject)
  480. {
  481. reportToExtract = ( (AsynchDetailReportObject) qrResult.getDetails()[j]).getReport();
  482. }
  483. }
  484. saveReportSpecLocally(
  485. reportToExtract,
  486. saveDir);
  487. }
  488. }
  489. catch (java.rmi.RemoteException remoteEx)
  490. {
  491. remoteEx.printStackTrace();
  492. }
  493. }
  494. public BaseClass[] getReportList(
  495. BaseClass rootObject,
  496. CRNConnect connection)
  497. {
  498. String searchPathExpression;
  499. if (rootObject instanceof Report)
  500. {
  501. searchPathExpression = rootObject.getSearchPath().getValue();
  502. }
  503. else
  504. {
  505. searchPathExpression =
  506. rootObject.getSearchPath().getValue() + "//report";
  507. }
  508. PropEnum[] props =
  509. new PropEnum[] {
  510. PropEnum.searchPath,
  511. PropEnum.defaultName,
  512. PropEnum.parent };
  513. try
  514. {
  515. return connection.getCMService().query(
  516. new SearchPathMultipleObject(searchPathExpression),
  517. props,
  518. new Sort[] {},
  519. new QueryOptions());
  520. }
  521. catch (java.rmi.RemoteException remoteEx)
  522. {
  523. remoteEx.printStackTrace();
  524. }
  525. return null;
  526. }
  527. public boolean updateReportsInContentStore(
  528. AuthoredReport reportToSave,
  529. BaseClass parent,
  530. CRNConnect connection)
  531. {
  532. reportToSave.setMetadataModelPackage(null);
  533. reportToSave.setDefaultName(null);
  534. reportToSave.setDescription(null);
  535. try
  536. {
  537. connection.getReportService().update(reportToSave, new UpdateOptions());
  538. }
  539. catch (java.rmi.RemoteException remoteEx)
  540. {
  541. return false;
  542. }
  543. return true;
  544. }
  545. public boolean copyReportSpecInContentStore(
  546. AuthoredReport reportToSave,
  547. BaseClass parent,
  548. CRNConnect connection)
  549. {
  550. String reportName = reportToSave.getDefaultName().getValue();
  551. Report newReport = new Report();
  552. AnyTypeProp reportSpecProperty = new AnyTypeProp();
  553. reportSpecProperty.setValue(reportToSave.getSpecification().getValue());
  554. MultilingualToken[] reportNames = new MultilingualToken[1];
  555. reportNames[0] = new MultilingualToken();
  556. reportNames[0].setValue(reportName);
  557. CSHandlers csHandler = new CSHandlers();
  558. Locale[] locales = csHandler.getConfiguration(connection);
  559. if (locales == null)
  560. {
  561. locales[0] = new Locale();
  562. locales[0].setLocale("en");
  563. }
  564. reportNames[0].setLocale(locales[0].getLocale());
  565. reportNames[0].setValue(reportName);
  566. newReport.setName(new MultilingualTokenProp());
  567. newReport.getName().setValue(reportNames);
  568. newReport.setSpecification(reportSpecProperty);
  569. AddOptions addReportOptions = new AddOptions();
  570. addReportOptions.setUpdateAction(UpdateActionEnum.replace);
  571. String parentPath = parent.getSearchPath().getValue();
  572. try
  573. {
  574. BaseClass[] targetDir =
  575. csHandler.createDirectoryInCS(
  576. connection,
  577. parentPath,
  578. "Upgrade");
  579. if (targetDir.length <= 0)
  580. {
  581. return false;
  582. }
  583. String targetPath = targetDir[0].getSearchPath().getValue();
  584. connection.getReportService().add(new SearchPathSingleObject(targetPath), newReport, addReportOptions);
  585. }
  586. catch (java.rmi.RemoteException remoteEx)
  587. {
  588. //return false;
  589. }
  590. return true;
  591. }
  592. public void saveReportSpecLocally(BaseClass reportToSave, File saveDir)
  593. {
  594. String reportFileName = reportToSave.getDefaultName().getValue();
  595. reportFileName = reportFileName.replace('/', '_');
  596. reportFileName = reportFileName + ".xml";
  597. if (!saveDir.isDirectory())
  598. {
  599. return;
  600. }
  601. try
  602. {
  603. File reportFile = new File(saveDir, reportFileName);
  604. FileOutputStream fos = new FileOutputStream(reportFile);
  605. fos.write(
  606. ((AuthoredReport)reportToSave)
  607. .getSpecification()
  608. .getValue()
  609. .getBytes());
  610. fos.flush();
  611. fos.close();
  612. }
  613. catch (java.io.IOException ioEx)
  614. {
  615. System.out.println("Failed to write file: " + reportFileName);
  616. ioEx.printStackTrace();
  617. }
  618. return;
  619. }
  620. private File getFileFolder()
  621. {
  622. final JFileChooser fc =
  623. new JFileChooser(System.getProperty("user.dir"));
  624. fc.setFileFilter(new DIRFileFilter());
  625. fc.setAcceptAllFileFilterUsed(false);
  626. fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  627. int fileSelectedOK = fc.showOpenDialog(null);
  628. if (fileSelectedOK != JFileChooser.APPROVE_OPTION)
  629. {
  630. return null;
  631. }
  632. return fc.getSelectedFile();
  633. }
  634. private void createNodes(DefaultMutableTreeNode top)
  635. {
  636. if (((TreeBrowserNode)top.getUserObject()).getChildrenPopulated())
  637. {
  638. return;
  639. }
  640. DefaultMutableTreeNode subNode = null;
  641. TreeBrowserNode tmpNode = (TreeBrowserNode)top.getUserObject();
  642. for (int i = 0; i < tmpNode.getNumChildren(); i++)
  643. {
  644. TreeBrowserNode child = tmpNode.getChild(i, connection);
  645. subNode = new DefaultMutableTreeNode();
  646. child.setContainer(subNode);
  647. top.add(subNode);
  648. }
  649. ((TreeBrowserNode)top.getUserObject()).setChildrenPopulated(true);
  650. }
  651. private class DIRFileFilter extends FileFilter
  652. {
  653. public boolean accept(File f)
  654. {
  655. if (f.isDirectory())
  656. {
  657. return true;
  658. }
  659. else
  660. {
  661. return false;
  662. }
  663. }
  664. public String getDescription()
  665. {
  666. return "Only Directories";
  667. }
  668. }
  669. }