Package de.iritgo.aktera.i18n

Examples of de.iritgo.aktera.i18n.I18N


   * @param req The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    I18N i18n = (I18N) req.getSpringBean(I18N.ID);

    ModelResponse res = req.createResponse();

    String file = req.getParameterAsString("file");
    String bulkImport = req.getParameterAsString("bulkImport");
    String destination = req.getParameterAsString("destination");
    String handler = req.getParameterAsString("handler");
    String backModel = req.getParameterAsString("backModel");
    String importModel = req.getParameterAsString("importModel");

    res.setAttribute("forward", "aktera.import.analyse-report");

    Output report = res.createOutput("report");

    res.add(report);

    String lastLine = null;

    try
    {
      StringBuffer reportBuf = new StringBuffer();
      File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");
      BufferedReader in = new BufferedReader(new FileReader(reportFile));
      String line = null;

      while ((line = in.readLine()) != null)
      {
        reportBuf.append(line + "\n");
        lastLine = line;
      }

      report.setContent(reportBuf.toString());
    }
    catch (IOException x)
    {
    }

    if (i18n.msg(req, "Aktera", "reportFileResult", "OK").equals(lastLine))
    {
      Command cmdImport = res.createCommand(importModel);

      cmdImport.setName("cmdImport");
      cmdImport.setParameter("file", file);
      cmdImport.setParameter("bulkImport", bulkImport);
      cmdImport.setParameter("destination", destination);
      cmdImport.setParameter("mode", "import");
      cmdImport.setParameter("backModel", backModel);
      cmdImport.setParameter("handler", handler);
      res.add(cmdImport);

      Command cmdBack = res.createCommand(backModel);

      cmdBack.setName("cmdBack");
      res.add(cmdBack);
    }
    else if (i18n.msg(req, "Aktera", "reportFileResult", "ERROR").equals(lastLine))
    {
      Command cmdBack = res.createCommand(backModel);

      cmdBack.setName("cmdBack");
      res.add(cmdBack);
View Full Code Here


   * @param req The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    I18N i18n = (I18N) req.getSpringBean(I18N.ID);

    ModelResponse res = req.createResponse();

    String backModel = req.getParameterAsString("backModel");

    res.setAttribute("forward", "aktera.import.import-report");

    Output report = res.createOutput("report");

    res.add(report);

    String lastLine = null;

    try
    {
      StringBuffer reportBuf = new StringBuffer();
      File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");
      BufferedReader in = new BufferedReader(new FileReader(reportFile));
      String line = null;

      while ((line = in.readLine()) != null)
      {
        reportBuf.append(line + "\n");
        lastLine = line;
      }

      report.setContent(reportBuf.toString());
    }
    catch (IOException x)
    {
    }

    if (i18n.msg(req, "Aktera", "reportFileResult", "OK").equals(lastLine))
    {
      Command cmdBack = res.createCommand(backModel);

      cmdBack.setName("cmdBack");
      res.add(cmdBack);
    }
    else if (i18n.msg(req, "Aktera", "reportFileResult", "ERROR").equals(lastLine))
    {
      Command cmdBack = res.createCommand(backModel);

      cmdBack.setName("cmdBack");
      res.add(cmdBack);
View Full Code Here

   *         file.
   */
  protected boolean analyze(final ModelRequest req, ModelResponse res, final String fileName, final String handlerId,
          final boolean bulkImport, String xslt, 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 ("Y".equals(req.getParameter("force")))
    {
      lockFile.delete();
    }

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

    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;

            try
            {
              File file = new File(fileName);
              Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
                      "file://" + file.getAbsolutePath());

              if (doc.getChildNodes().getLength() > 0)
              {
                XPath xPath = XPathFactory.newInstance().newXPath();
                Node importElem = (Node) xPath.evaluate("import", doc, XPathConstants.NODE);

                if (importElem != null)
                {
                  reporter.println(i18n.msg(req, "Aktera", "startingImportAnalysis"));
                  ok = im.analyzeImport(req, doc, importElem, reporter, i18n, handlerId, bulkImport, properties);
                }
                else
                {
                  reporter.println(i18n
                          .msg(req, "AkteraImporter", "importErrorNoImportRootNodeFound"));
                }
              }
              else
              {
                reporter.println(i18n.msg(req, "AkteraImporter", "importErrorNoImportRootNodeFound"));
              }
            }
            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()));
            }

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

            reporter.close();
            lockFile.delete();
          }
        }.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
      {
        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();
        lockFile.delete();
      }
      catch (IOException xx)
      {
View Full Code Here

   *         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)
      {
      }
View Full Code Here

  @Override
  public void validatePersistents(List<Configuration> persistentConfig, ModelRequest request, ModelResponse response,
          FormularDescriptor formular, PersistentDescriptor persistents, boolean create,
          ValidationResult result) throws ModelException, PersistenceException
  {
    I18N i18n = (I18N) SpringTools.getBean(I18N.ID);
    javax.validation.ValidatorFactory factory = javax.validation.Validation.buildDefaultValidatorFactory();
    javax.validation.Validator validator = factory.getValidator();
    try
    {
      if (persistentConfig.size() > 0)
      {
        for (Iterator i = persistentConfig.iterator(); i.hasNext();)
        {
          Configuration aPersistentConfig = (Configuration) i.next();
          String id = aPersistentConfig.getAttribute("id");
          if (! persistents.hasPersistent(id))
          {
            Object bean = persistents.get(aPersistentConfig.getAttribute("id"));
            Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean);
            for (javax.validation.ConstraintViolation violation : constraintViolations)
            {
              String fieldName = violation.getPropertyPath().toString();
              FieldDescriptor field = formular.getField(id + "." + fieldName);
              if (field != null)
              {
                result.addError(id + "_" + fieldName.replace('.', '_'), i18n.msg(request, field
                        .getBundle(), field.getLabel() != null ? field.getLabel() : fieldName)
                        + " " + violation.getMessage());
              }
              else
              {
View Full Code Here

  {
    try
    {
      boolean bulkImport = (Boolean) properties.get("bulkImport");

      I18N i18n = (I18N) request.getSpringBean(I18N.ID);

      AddressManager addressManager = (AddressManager) SpringTools.getBean(AddressManager.ID);
      String addressStoreId = properties
              .getProperty("destination", properties.getProperty("addressStoreId", addressManager
                      .getDefaultAddressStore().getName()));
      AddressStore addressStore = null;

      addressStore = addressManager.getAddressStoreByName(addressStoreId);

      if (! addressStore.getEditable())
      {
        reporter.println(i18n.msg(request, "AkteraAddress", "addressImportHandlerStoreNotWriteable"));

        return;
      }

      Integer ownerId = UserTools.getCurrentUserId(request);

      if (addressStore.isGlobalStore())
      {
        ownerId = null;
      }

      String company = StringTools.trim(addressData.get("company"));
      String lastName = StringTools.trim(addressData.get("lastName"));
      String firstName = StringTools.trim(addressData.get("firstName"));
      String contactNumber = StringTools.trim(addressData.get("contactNumber"));

      if (StringTools.isTrimEmpty(company) && StringTools.isTrimEmpty(lastName))
      {
        reporter.println(i18n.msg(request, "AkteraAddress", "noLastNameOrCompanyTagFound"));

        return;
      }

      String displayName = "";

      if (! StringTools.isTrimEmpty(lastName))
      {
        displayName = displayName + lastName;
      }

      if (! StringTools.isTrimEmpty(firstName))
      {
        if (! StringTools.isTrimEmpty(lastName))
        {
          displayName = displayName + ", ";
        }

        displayName = displayName + firstName + " ";
      }

      if (! StringTools.isTrimEmpty(company))
      {
        if (! StringTools.isTrimEmpty(displayName))
        {
          displayName = displayName + " ";
        }

        displayName = displayName + company;
      }

      Option<Address> address = new Empty();
      if (! bulkImport)
      {
        if (! StringTools.isTrimEmpty(contactNumber))
        {
          address = addressStore.findAddressByOwnerAndContactNumber(ownerId, contactNumber);

          if (address.full())
          {
            reporter.println(i18n.msg(request, "AkteraAddress", "updateAddressEntry", displayName));
          }
        }
        else
        {
          address = addressStore.findAddressByOnwerAndFirstNameOrLastNameOrCompany(ownerId, firstName, lastName,
              company);

          if (address.full())
          {
            reporter.println(i18n.msg(request, "AkteraAddress", "updateAddressEntry", displayName));
          }
          else
          {
            reporter.println(i18n.msg(request, "AkteraAddress", "newAddressEntry", displayName));
          }
        }
      }

      if (address.empty())
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.i18n.I18N

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.