Package com.jada.ie

Examples of com.jada.ie.ItemSimpleTransformation


        throws Throwable {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();

    ImportActionForm form = (ImportActionForm) actionForm;
      createAdditionalInfo(request, form);
        ItemSimpleTransformation transformation = null;
        if (form.getImportType().equals(Constants.IE_EXPORT_TYPE_CSV)) {
          transformation = new ItemSimpleCsvTransformation(Long.valueOf(form.getIeProfileHeaderId()), getAdminBean(request).getSite());
        }
        else {
          transformation = new ItemSimpleXmlTransformation();
        }
      
    ActionMessages errors = validate(form, request);
    if (errors.size() != 0) {
      saveMessages(request, errors);
      return actionMapping.findForward("error");
    }
   
    try {
      InputStream inputStream = null;
      if (form.getImportLocation().equals(Constants.IE_EXPORT_LOCATION_LOCAL)) {
        inputStream = form.getLocalFile().getInputStream();
      }
      else {
        inputStream = new FileInputStream(new File(form.getHostFileName()));
      }
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Constants.SYSTEM_ENCODING));
      int lineNumber = 0;
      if (form.isSkipFirstLine()) {
        reader.readLine();
        lineNumber++;
      }
      while (true) {
        String input = reader.readLine();
        lineNumber++;
        if (input == null) {
          break;
        }
        System.out.println(input);
        if (Format.isNullOrEmpty(input)) {
          break;
        }
       
        try {
          String messages[] = transformation.validate(input);
          if (messages.length > 0) {
            String output = formatHtmlMessage(lineNumber, input, messages);
            form.setMessageText(output);
            return actionMapping.findForward("error");
          }
         
          ItemSimple itemSimple = transformation.fromImport(input);
          messages = itemSimple.validate();
          if (messages.length > 0) {
            String output = formatHtmlMessage(lineNumber, input, messages);
            form.setMessageText(output);
            return actionMapping.findForward("error");
View Full Code Here


        throws Throwable {
      ExportActionForm form = (ExportActionForm) actionForm;
      form.setGenerate(false);
        Site site = getAdminBean(request).getSite();
        createAdditionalInfo(form, site);
        ItemSimpleTransformation transformation = null;
        if (form.getExportType().equals(Constants.IE_EXPORT_TYPE_CSV)) {
          transformation = new ItemSimpleCsvTransformation(Long.valueOf(form.getIeProfileHeaderId()), site, form.getExportLocation());
        }
        else {
          transformation = new ItemSimpleXmlTransformation();
        }
       
    ActionMessages errors = validate(form, request);
    if (errors.size() != 0) {
      saveMessages(request, errors);
      return actionMapping.findForward("error");
    }
   
    try {
        EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();

        String sql = "from SiteProfileClass siteProfileClass where siteProfileClass.site.siteId = :siteId";
      Query query = em.createQuery(sql);
      query.setParameter("siteId", site.getSiteId());
      SiteProfileClass siteProfileClasses[] = new SiteProfileClass[query.getResultList().size()];
      query.getResultList().toArray(siteProfileClasses);
     
      sql = "from SiteCurrencyClass siteCurrencyClass where siteCurrencyClass.site.siteId = :siteId";
      query = em.createQuery(sql);
      query.setParameter("siteId", site.getSiteId());
      SiteCurrencyClass siteCurrencyClasses[] = new SiteCurrencyClass[query.getResultList().size()];
      query.getResultList().toArray(siteCurrencyClasses);
     
      OutputStream outputStream = null;
      if (form.getExportLocation().equals(Constants.IE_EXPORT_LOCATION_LOCAL)) {
        if (form.getExportType().equals(Constants.IE_EXPORT_TYPE_CSV)) {
          response.setContentType("text/csv");
          response.setHeader("Content-disposition", "attachment; filename=\"" +"jadaexport" + "_" + Format.getSortDate(new Date()) + ".csv" +"\"");
        }
        else {
          response.setContentType("text/plain");
          response.setHeader("Content-disposition", "attachment; filename=\"" +"jadaexport" + "_" + Format.getSortDate(new Date()) + ".txt" +"\"");
        }
        response.setHeader("Content-Transfer-Encoding", "binary");
        outputStream = response.getOutputStream();
      }
      else {
        outputStream = new FileOutputStream(new File(form.getHostFileName()));
      }
 
      String header = transformation.getHeader();
      if (header != null) {
        outputStream.write(header.getBytes());
      }
     
      ItemApi itemApi = new ItemApi(site);
     
      sql = "from Item item where item.site.siteId = :siteId";
      query = em.createQuery(sql);
      query.setParameter("siteId", site.getSiteId());
      Iterator<?> iterator = query.getResultList().iterator();
      boolean error = false;
      while (iterator.hasNext()) {
        Item item = (Item) iterator.next();
        for (SiteProfileClass siteProfileClass : siteProfileClasses) {
          for (SiteCurrencyClass siteCurrencyClass : siteCurrencyClasses) {
            String result = "";
            try {
              com.jada.xml.ie.Item i = itemApi.export(item);
              ItemSimple itemSimpleXml = new ItemSimple(i,
                                    siteProfileClass.getSiteProfileClassId(),
                                    siteProfileClass.getSiteProfileClassName(),
                                    siteCurrencyClass.getSiteCurrencyClassId(),
                                    siteCurrencyClass.getSiteCurrencyClassName());
              result = transformation.toExport(itemSimpleXml);
            }
            catch (Exception e) {
              result = "Unable to export item with sku code " + item.getItemSkuCd() + System.getProperty("line.separator");
              result += Utility.getStackTrace(e);
              error = true;
              outputStream.write(result.getBytes(Constants.SYSTEM_ENCODING));
              break;
            }
            outputStream.write(result.getBytes(Constants.SYSTEM_ENCODING));
          }
          if (error) {
            break;
          }
        }
        if (error) {
          break;
        }
      }
     
      String footer = transformation.getFooter();
      if (footer != null) {
        outputStream.write(footer.getBytes());
      }
     
      if (form.getExportLocation().equals(Constants.IE_EXPORT_LOCATION_SERVER)) {
View Full Code Here

TOP

Related Classes of com.jada.ie.ItemSimpleTransformation

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.