Advertisement
mstranieri

Command

Feb 19th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. package com.softfobia.margiani.obi.catalog;
  2.  
  3. import java.io.File;
  4. import java.util.Locale;
  5.  
  6. import org.apache.log4j.Logger;
  7. import org.hibernate.SessionFactory;
  8. import org.riotfamily.riot.list.command.CommandContext;
  9. import org.riotfamily.riot.list.command.CommandResult;
  10. import org.riotfamily.riot.list.command.core.AbstractCommand;
  11. import org.riotfamily.riot.list.command.result.RefreshSiblingsResult;
  12.  
  13. import com.softfobia.margiani.obi.catalog.CatalogFoldersList.FilderListElement;
  14.  
  15.     public class XmlToXlsCommand extends AbstractCommand {
  16.  
  17.         private final Logger logger = Logger.getLogger(this.getClass());
  18.        
  19.         public static final String ACTION_PARSE = "XmlToXls";
  20.  
  21.         private SessionFactory sessionFactory;
  22.         private SubCategoriesAutoCreator subCategoriesAutoCreator;
  23.  
  24.        
  25.         public String getAction() {
  26.             return ACTION_PARSE;
  27.         }
  28.        
  29.         public boolean isEnabled(CommandContext context) {
  30.             FilderListElement file = (FilderListElement) context.getBean();
  31.             return file==null || file.getStatus()==null || !file.getStatus().startsWith("error") || !file.getStatus().startsWith("started");
  32.         }
  33.        
  34.         public String getConfirmationMessage(CommandContext context) {
  35.             FilderListElement file = (FilderListElement) context.getBean();
  36.             return context.getMessageResolver().getMessage("confirm.parse",
  37.                     new Object[] {file.getName()},
  38.                     "Do you really want to parse '"
  39.                      + file.getName() + "'?");
  40.         }
  41.        
  42.         public CommandResult execute(CommandContext context) {
  43.  
  44.             final FilderListElement elememt = (FilderListElement) context.getBean();
  45.             final File sourceFolder =  elememt.getFile();
  46.            
  47.             new Thread(new Runnable() {
  48.                
  49.                 public void run() {
  50.                    
  51.                     try {
  52.                        
  53.                         elememt.setStatus("started");
  54.                        
  55.                         Locale locale = Locale.ITALIAN;
  56.                        
  57.                         RiotProductPersister productPersister = new RiotProductPersister(XmlToXlsCommand.this.getSessionFactory());
  58.                         productPersister.setSubCategoriesAutoCreator(XmlToXlsCommand.this.getSubCategoriesAutoCreator());
  59.                        
  60.                         //Chiamare controller
  61.                        
  62.                        
  63.                        
  64.                         elememt.setStatus("done");
  65.                        
  66.                     } catch (Exception e) {
  67.                        
  68.                         logger.error(sourceFolder.getAbsolutePath(), e);
  69.                         elememt.setStatus("error: "+ e.getMessage());
  70.  
  71.                     }
  72.  
  73.                 }
  74.                
  75.             }).start();
  76.            
  77.             return new RefreshSiblingsResult(); // MessageResult("import started");
  78.        
  79.         }
  80.  
  81.         public SessionFactory getSessionFactory() {
  82.             return sessionFactory;
  83.         }
  84.  
  85.         public void setSessionFactory(SessionFactory sessionFactory) {
  86.             this.sessionFactory = sessionFactory;
  87.         }
  88.  
  89.         public SubCategoriesAutoCreator getSubCategoriesAutoCreator() {
  90.             return subCategoriesAutoCreator;
  91.         }
  92.  
  93.         public void setSubCategoriesAutoCreator(
  94.                 SubCategoriesAutoCreator subCategoriesAutoCreator) {
  95.             this.subCategoriesAutoCreator = subCategoriesAutoCreator;
  96.         }
  97.        
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement