-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MODEXPS-273] Improve logging for job launching process #610
base: master
Are you sure you want to change the base?
Changes from all commits
0587dd9
563994c
965be52
538c074
30f0fe9
79dcdbe
caace7b
8d8611e
04c1790
5bd434f
9093da5
195f41a
63c4919
d4f64d2
c5eb9fe
75a6e66
6fa8951
06df10d
24ca809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.jobs; | ||
|
||
import static org.folio.dew.domain.dto.JobParameterNames.ACQ_EXPORT_FILE; | ||
import static org.folio.dew.domain.dto.JobParameterNames.EDIFACT_FILE_NAME; | ||
import static org.folio.dew.domain.dto.JobParameterNames.EDIFACT_ORDERS_EXPORT; | ||
import static org.folio.dew.domain.dto.JobParameterNames.UPLOADED_FILE_PATH; | ||
import static org.folio.dew.domain.dto.VendorEdiOrdersExportConfig.IntegrationTypeEnum.ORDERING; | ||
import static org.folio.dew.domain.dto.VendorEdiOrdersExportConfig.TransmissionMethodEnum.FTP; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.FilenameUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.dew.batch.ExecutionContextUtils; | ||
import org.folio.dew.batch.acquisitions.edifact.services.FTPStorageService; | ||
import org.folio.dew.domain.dto.VendorEdiOrdersExportConfig; | ||
import org.folio.dew.repository.RemoteFilesStorage; | ||
import org.springframework.batch.core.StepContribution; | ||
import org.springframework.batch.core.configuration.annotation.StepScope; | ||
import org.springframework.batch.core.scope.context.ChunkContext; | ||
import org.springframework.batch.core.step.tasklet.Tasklet; | ||
import org.springframework.batch.repeat.RepeatStatus; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
@@ -28,30 +30,32 @@ | |
@StepScope | ||
@Log4j2 | ||
public class SaveToFileStorageTasklet implements Tasklet { | ||
private final ObjectMapper ediObjectMapper; | ||
private final FTPStorageService ftpStorageService; | ||
|
||
private final RemoteFilesStorage remoteFilesStorage; | ||
|
||
private static final String SFTP_PROTOCOL = "sftp://"; | ||
@Value("#{jobParameters['edifactFileName']}") | ||
private String edifactFileName; | ||
|
||
private final ObjectMapper ediObjectMapper; | ||
private final FTPStorageService ftpStorageService; | ||
|
||
@Override | ||
@SneakyThrows | ||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { | ||
var stepExecution = chunkContext.getStepContext().getStepExecution(); | ||
var jobParameters = chunkContext.getStepContext().getJobParameters(); | ||
var ediExportConfig = ediObjectMapper.readValue((String)jobParameters.get(EDIFACT_ORDERS_EXPORT), VendorEdiOrdersExportConfig.class); | ||
var uploadedFilePath = (String) ExecutionContextUtils.getExecutionVariable(stepExecution, UPLOADED_FILE_PATH); | ||
var ediExportConfig = ediObjectMapper.readValue((String) jobParameters.get(EDIFACT_ORDERS_EXPORT), VendorEdiOrdersExportConfig.class); | ||
if (ediExportConfig.getIntegrationType() != ORDERING && ediExportConfig.getTransmissionMethod() != FTP) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit hard to read with inverse conditions. Also having integration type here will lead us to modify source code of tasklet during adding new integration type. If we could not do such inverse configuration on some higher config level - we can leave as it. |
||
log.info("execute:: Transmission method is not FTP, skipping the step"); | ||
return RepeatStatus.FINISHED; | ||
} | ||
|
||
String host = ediExportConfig.getEdiFtp().getServerAddress().replace(SFTP_PROTOCOL, ""); | ||
// skip ftp upload if address not specified | ||
if (StringUtils.isEmpty(host)) { | ||
return RepeatStatus.FINISHED; | ||
} | ||
byte[] fileContent = remoteFilesStorage.readAllBytes(uploadedFilePath); | ||
ftpStorageService.uploadToFtp(ediExportConfig, fileContent, FilenameUtils.getName(uploadedFilePath)); | ||
|
||
var stepExecution = chunkContext.getStepContext().getStepExecution(); | ||
var fileName = (String) ExecutionContextUtils.getExecutionVariable(stepExecution, EDIFACT_FILE_NAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename to ACQ_EXPORT_FILE_NAME? In this case we will have the same convention as for ACQ_EXPORT_FILE |
||
var edifactOrderAsString = (String) ExecutionContextUtils.getExecutionVariable(stepExecution, ACQ_EXPORT_FILE); | ||
ftpStorageService.uploadToFtp(ediExportConfig, edifactOrderAsString.getBytes(StandardCharsets.UTF_8), fileName); | ||
|
||
return RepeatStatus.FINISHED; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit harder to understand the sequence now, need to find where steps are declared in this case, but can leave if you prefer to leave