on 01-01-2018 11:15 AM
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.
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();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.