-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/maven/cucumber.version-7.0.0
- Loading branch information
Showing
84 changed files
with
15,538 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/dpgrandslam/stockdataservice/adapter/api/JobController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.dpgrandslam.stockdataservice.adapter.api; | ||
|
||
import com.dpgrandslam.stockdataservice.domain.model.JobRunRequest; | ||
import com.dpgrandslam.stockdataservice.domain.model.JobRunResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.core.*; | ||
import org.springframework.batch.core.explore.JobExplorer; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; | ||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; | ||
import org.springframework.batch.core.repository.JobRestartException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Controller | ||
@RequestMapping("/job") | ||
public class JobController { | ||
|
||
@Autowired | ||
private JobLauncher jobLauncher; | ||
|
||
@Autowired | ||
private List<Job> batchJobs; | ||
|
||
@Autowired | ||
private JobExplorer jobExplorer; | ||
|
||
@PostMapping("/run") | ||
public ResponseEntity<JobRunResponse> runOptionCSVLoadJob(@RequestBody JobRunRequest runRequest) throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { | ||
Map<String, JobParameter> jobParameterMap = runRequest.getJobParams().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, x -> new JobParameter(x.getValue()))); | ||
Optional<Job> jobToRun = batchJobs.stream().filter(job -> job.getName().equals(runRequest.getJobName())).findFirst(); | ||
if (jobToRun.isEmpty()) { | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
log.info("Batch job {} started through API call.", runRequest.getJobName()); | ||
JobExecution jobExecution = jobLauncher.run(jobToRun.get(), new JobParameters(jobParameterMap)); | ||
JobRunResponse jobRunResponse = new JobRunResponse(); | ||
jobRunResponse.setJobId(jobExecution.getJobId()); | ||
jobRunResponse.setJobExecutionId(jobExecution.getId()); | ||
jobRunResponse.setJobStatus(jobExecution.getStatus().name()); | ||
return ResponseEntity.ok(jobRunResponse); | ||
} | ||
|
||
@GetMapping("/status") | ||
public ResponseEntity<JobRunResponse> getJobStatus(@RequestParam Long executionId) { | ||
JobRunResponse jobRunResponse = new JobRunResponse(); | ||
JobExecution jobExecution = jobExplorer.getJobExecution(executionId); | ||
jobRunResponse.setJobStatus(jobExecution.getStatus().name()); | ||
String message = jobExecution.getAllFailureExceptions().stream().findFirst().map(Throwable::getMessage).orElse(null); | ||
jobRunResponse.setMessage(message); | ||
jobRunResponse.setJobId(jobExecution.getJobId()); | ||
jobRunResponse.setJobExecutionId(jobExecution.getId()); | ||
return ResponseEntity.ok(jobRunResponse); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/dpgrandslam/stockdataservice/adapter/apiclient/CNNFearGreedClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.dpgrandslam.stockdataservice.adapter.apiclient; | ||
|
||
import com.dpgrandslam.stockdataservice.domain.model.CNNFearGreedResponse; | ||
import feign.Headers; | ||
import feign.Param; | ||
import feign.RequestLine; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Headers({"Accept: application/json", "if-none-match: W/2005698896447632232"}) | ||
public interface CNNFearGreedClient { | ||
|
||
@RequestLine("GET /index/fearandgreed/graphdata/{date}") | ||
CNNFearGreedResponse getFearGreedData(@Param("date") String date); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...in/java/com/dpgrandslam/stockdataservice/adapter/repository/FearGreedIndexRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.dpgrandslam.stockdataservice.adapter.repository; | ||
|
||
import com.dpgrandslam.stockdataservice.domain.model.FearGreedIndex; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface FearGreedIndexRepository extends JpaRepository<FearGreedIndex, Long> { | ||
|
||
Optional<FearGreedIndex> findFearGreedIndexByTradeDate(LocalDate tradeDate); | ||
|
||
List<FearGreedIndex> findFearGreedIndexByTradeDateBetween(LocalDate startDate, LocalDate endDate); | ||
|
||
List<FearGreedIndex> findFearGreedIndicesByTradeDateGreaterThanEqual(LocalDate tradeDate); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/dpgrandslam/stockdataservice/domain/config/APISecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dpgrandslam.stockdataservice.domain.config; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* A simple security configuration for the api without having to use spring security | ||
*/ | ||
@Configuration | ||
public class APISecurityConfig implements WebMvcConfigurer { | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "api.security") | ||
public APISecurityConfigurationProperties apiSecurityConfigurationProperties() { | ||
return new APISecurityConfigurationProperties(); | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
WebMvcConfigurer.super.addInterceptors(registry); | ||
registry.addInterceptor(new HandlerInterceptor() { | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
APISecurityConfigurationProperties securityConfigurationProperties = apiSecurityConfigurationProperties(); | ||
if (securityConfigurationProperties.getEnabled() | ||
&& (StringUtils.isBlank(securityConfigurationProperties.getPassword()) | ||
|| !securityConfigurationProperties.getPassword().equals(request.getHeader("stock-data-password")))) { | ||
response.setStatus(401); | ||
return false; | ||
} | ||
return HandlerInterceptor.super.preHandle(request, response, handler); | ||
} | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...va/com/dpgrandslam/stockdataservice/domain/config/APISecurityConfigurationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dpgrandslam.stockdataservice.domain.config; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class APISecurityConfigurationProperties { | ||
|
||
private Boolean enabled = false; | ||
private String password = ""; | ||
|
||
} |
Oops, something went wrong.