Ejemplo n.º 1
0
 /** @see de.iritgo.aktera.dashboard.DashboardGroup#getTitle() */
 public String getTitle() {
   return i18n.msg(locale, getBundle(), title);
 }
Ejemplo n.º 2
0
  /**
   * Import a given XML import file. This method generates output elements describing the contents
   * of the import file.
   *
   * @param req The model request.
   * @param res The model response.
   * @param fileName The XML import file.
   * @param handlerId The id of the handler to execute (can be null to execute all handlers).
   * @param xslt XSLT script used to convert to xml.
   * @param destination TODO
   * @return False if the import wasn't started because of an existing lock file.
   */
  protected boolean perform(
      final ModelRequest req,
      ModelResponse res,
      final String fileName,
      final String handlerId,
      String xslt,
      final boolean bulkImport,
      final Properties properties)
      throws ModelException {
    final I18N i18n = (I18N) req.getSpringBean(I18N.ID);
    final ImportManager im = (ImportManager) req.getSpringBean(ImportManager.ID);

    FileTools.newAkteraFile("/var/tmp/iritgo").mkdirs();

    final File lockFile = FileTools.newAkteraFile("/var/tmp/iritgo/import.lck");

    if (lockFile.exists()) {
      return true;
    }

    try {
      lockFile.createNewFile();

      File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");

      reportFile.delete();
      reportFile.createNewFile();

      final PrintWriter reporter = new PrintWriter(new FileOutputStream(reportFile), true);

      convertToXml(req, fileName, xslt);

      if (im.validateXmlFile(new File(fileName))) {
        new Thread() {
          public void run() {
            boolean ok = true;
            File file = null;

            try {
              file = new File(fileName);

              Document doc =
                  DocumentBuilderFactory.newInstance()
                      .newDocumentBuilder()
                      .parse("file://" + file.getAbsolutePath());

              XPath xPath = XPathFactory.newInstance().newXPath();

              Node importElem = (Node) xPath.evaluate("import", doc, XPathConstants.NODE);

              reporter.println(i18n.msg(req, "Aktera", "startingImport"));

              ok =
                  im.performImport(
                      req, doc, importElem, reporter, i18n, handlerId, bulkImport, properties);
            } catch (ParserConfigurationException x) {
              reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
            } catch (SAXException x) {
              reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
            } catch (IOException x) {
              reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
            } catch (XPathExpressionException x) {
              reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
            } catch (ModelException x) {
              reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
            } finally {
              lockFile.delete();
              file.delete();
            }

            reporter.println(i18n.msg(req, "Aktera", "finishedImport"));
            reporter.println();
            reporter.println(i18n.msg(req, "Aktera", "reportFileResult", (ok ? "OK" : "ERROR")));

            reporter.close();
          }
        }.start();
      } else {
        reporter.println(i18n.msg(req, "Aktera", "importFileDoesntContainImportElement"));
        reporter.println();
        reporter.println(i18n.msg(req, "Aktera", "reportFileResult", "ERROR"));
        reporter.close();
        lockFile.delete();
      }
    } catch (Exception x) {
      try {
        lockFile.delete();

        File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");
        PrintWriter out = new PrintWriter(reportFile);

        out.println(i18n.msg(req, "Aktera", "importError", x.toString()));
        out.println();
        out.println(i18n.msg(req, "Aktera", "reportFileResult", "ERROR"));
        out.close();
      } catch (IOException xx) {
      }
    }

    return true;
  }