cancel
Showing results for 
Search instead for 
Did you mean: 

how to export Content into a specific location by running export script?

Former Member
0 Kudos

I have a requirement like by running the export script, i need to export content into specific location. By default content is downloading into temp folder.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Satish - one option is to create a cronjob and instantiate ImpExExportCronJobModel directly - you can then get a reference to the export output and copy it to wherever you wish.

Example code

     public PerformResult perform(NWMultiExportJobModel job)
         {
             ImpExExportCronJobModel cronJobModel = (ImpExExportCronJobModel) modelService.create(ImpExExportCronJobModel.class);
             
             
             cronJobModel.setCode("my-export-");
             cronJobModel.setJob(cronJobService.getJob("ImpEx-Export"));
                     
             cronJobModel.setJobMedia(job.getJobMedia());
     
             cronJobModel.setDataExportMediaCode(......);
             cronJobModel.setMediasExportMediaCode(......);
             
             modelService.save(cronJobModel);
             cronJobService.performCronJob(cronJobModel, true);
             
             // Custom copy method
             copyExportedMediaToExportDir(cronJobModel, this.getExportDirectory() + job.getJobSpecificExportDir());
     
     .....
     ....
     private void copyExportedMediaToExportDir(final ImpExExportCronJobModel result, String exportDir)
         {        
             if (StringUtils.isNotBlank(exportDir)){
                 final File dir = new File(exportDir);
                 try{
                     if (!dir.exists() && !dir.mkdirs()){
                             LOG.error("Directory " + exportDir + " does not exist. Unable to create it.");
                     }
                     else if (dir.isDirectory() && dir.canWrite()){
                         Path dirPath = Paths.get(dir.getAbsolutePath()) ;    
                         copyExportedMediaFile(dirPath, result.getDataExportTarget());
                     }
                     else{
                         LOG.error("Unable to write to " + exportDir + " or it is not a directory");
                     }
                 }
                 catch (final IOException ioe){
                     LOG.error("Unable to copy generated script files to " + exportDir, ioe);
                 }
             }
         }
     
 
 .....
 ......
 
     private void copyExportedMediaFile(final Path targetDir, final ImpExExportMediaModel impexModel) throws IOException{
             Files.copy(Paths.get(findRealMediaPath(impexModel)), targetDir.resolve(impexModel.getRealFileName()));
         }
 
 
 .....
 .....
 private String findRealMediaPath(final ImpExExportMediaModel impexModel)
     {
         final StringBuilder sb = new StringBuilder(64);
         
         sb.append(configurationService.getConfiguration().getProperty("HYBRIS_DATA_DIR")).append(File.separatorChar);
         sb.append("media").append(File.separatorChar);
         sb.append("sys_").append(impexModel.getFolder().getTenantId());
         sb.append(File.separatorChar).append(impexModel.getLocation());
         return sb.toString();
     }
Former Member
0 Kudos

Hi Satish - how did you progress ?