Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 25, 2023
1 parent d8869a4 commit e1f15a2
Show file tree
Hide file tree
Showing 90 changed files with 3,235 additions and 1,631 deletions.
10 changes: 4 additions & 6 deletions src/main/java/com/lpvs/LicensePreValidationSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/

package com.lpvs;

import org.springframework.beans.factory.annotation.Value;
Expand All @@ -20,8 +19,7 @@

import com.lpvs.util.LPVSExitHandler;


@SpringBootApplication(scanBasePackages = { "com.lpvs" })
@SpringBootApplication(scanBasePackages = {"com.lpvs"})
@EnableAutoConfiguration
@EnableAsync
public class LicensePreValidationSystem {
Expand All @@ -36,7 +34,8 @@ public LicensePreValidationSystem(@Value("${lpvs.cores:8}") int corePoolSize) {

public static void main(String[] args) {
try {
ApplicationContext applicationContext = SpringApplication.run(LicensePreValidationSystem.class, args);
ApplicationContext applicationContext =
SpringApplication.run(LicensePreValidationSystem.class, args);
exitHandler = applicationContext.getBean(LPVSExitHandler.class);
} catch (IllegalArgumentException e) {
System.err.println("An IllegalArgumentException occurred: " + e.getMessage());
Expand All @@ -45,7 +44,7 @@ public static void main(String[] args) {
}

@Bean("threadPoolTaskExecutor")
public TaskExecutor getAsyncExecutor(){
public TaskExecutor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setThreadNamePrefix("LPVS-ASYNC::");
Expand All @@ -60,4 +59,3 @@ public static void exit(int exitCode) {
}
}
}

31 changes: 20 additions & 11 deletions src/main/java/com/lpvs/controller/GitHubWebhooksController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/

package com.lpvs.controller;

import com.lpvs.entity.LPVSQueue;
Expand Down Expand Up @@ -34,7 +33,8 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

@RestController @Slf4j
@RestController
@Slf4j
public class GitHubWebhooksController {

private String GITHUB_SECRET;
Expand All @@ -47,19 +47,21 @@ public class GitHubWebhooksController {
*/
@PostConstruct
public void setProps() {
this.GITHUB_SECRET = Optional.ofNullable(this.GITHUB_SECRET).filter(s -> !s.isEmpty())
.orElse(Optional.ofNullable(System.getenv("LPVS_GITHUB_SECRET")).orElse(""));
this.GITHUB_SECRET =
Optional.ofNullable(this.GITHUB_SECRET)
.filter(s -> !s.isEmpty())
.orElse(
Optional.ofNullable(System.getenv("LPVS_GITHUB_SECRET"))
.orElse(""));
if (this.GITHUB_SECRET.isEmpty()) {
log.error("LPVS_GITHUB_SECRET(github.secret) is not set.");
exitHandler.exit(-1);
}
}

@Autowired
private LPVSQueueService queueService;
@Autowired private LPVSQueueService queueService;

@Autowired
private LPVSQueueRepository queueRepository;
@Autowired private LPVSQueueRepository queueRepository;

private LPVSGitHubService gitHubService;

Expand All @@ -70,7 +72,12 @@ public void setProps() {
private static final String ERROR = "Error";
private static final String ALGORITHM = "HmacSHA256";

public GitHubWebhooksController(LPVSQueueService queueService, LPVSGitHubService gitHubService, LPVSQueueRepository queueRepository, @Value("${github.secret:}") String GITHUB_SECRET, LPVSExitHandler exitHandler) {
public GitHubWebhooksController(
LPVSQueueService queueService,
LPVSGitHubService gitHubService,
LPVSQueueRepository queueRepository,
@Value("${github.secret:}") String GITHUB_SECRET,
LPVSExitHandler exitHandler) {
this.queueService = queueService;
this.gitHubService = gitHubService;
this.queueRepository = queueRepository;
Expand All @@ -87,7 +94,9 @@ public GitHubWebhooksController(LPVSQueueService queueService, LPVSGitHubService
* @throws Exception if an error occurs during processing.
*/
@RequestMapping(value = "/webhooks", method = RequestMethod.POST)
public ResponseEntity<LPVSResponseWrapper> gitHubWebhooks(@RequestHeader(SIGNATURE) String signature, @RequestBody String payload) throws Exception {
public ResponseEntity<LPVSResponseWrapper> gitHubWebhooks(
@RequestHeader(SIGNATURE) String signature, @RequestBody String payload)
throws Exception {
log.debug("New GitHub webhook request received");

// if signature is empty return 401
Expand Down Expand Up @@ -127,7 +136,7 @@ public ResponseEntity<LPVSResponseWrapper> gitHubWebhooks(@RequestHeader(SIGNATU
* @throws Exception if an error occurs during signature verification.
*/
public boolean wrongSecret(String signature, String payload) throws Exception {
String lpvsSecret = signature.split("=",2)[1];
String lpvsSecret = signature.split("=", 2)[1];

SecretKeySpec key = new SecretKeySpec(GITHUB_SECRET.getBytes("utf-8"), ALGORITHM);
Mac mac = Mac.getInstance(ALGORITHM);
Expand Down
118 changes: 80 additions & 38 deletions src/main/java/com/lpvs/controller/LPVSWebController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/

package com.lpvs.controller;

import com.lpvs.entity.*;
Expand Down Expand Up @@ -51,9 +50,13 @@ public class LPVSWebController implements ErrorController {

private LPVSStatisticsService lpvsStatisticsService;

public LPVSWebController(LPVSMemberRepository memberRepository, LPVSDetectedLicenseRepository detectedLicenseRepository,
LPVSPullRequestRepository lpvsPullRequestRepository, LPVSLicenseRepository licenseRepository,
LPVSLoginCheckService lpvsLoginCheckService, LPVSStatisticsService lpvsStatisticsService) {
public LPVSWebController(
LPVSMemberRepository memberRepository,
LPVSDetectedLicenseRepository detectedLicenseRepository,
LPVSPullRequestRepository lpvsPullRequestRepository,
LPVSLicenseRepository licenseRepository,
LPVSLoginCheckService lpvsLoginCheckService,
LPVSStatisticsService lpvsStatisticsService) {
this.memberRepository = memberRepository;
this.detectedLicenseRepository = detectedLicenseRepository;
this.lpvsPullRequestRepository = lpvsPullRequestRepository;
Expand All @@ -75,18 +78,21 @@ public LPVSMember personalInfoSettings(Authentication authentication) {
@GetMapping("/user/login")
@ResponseBody
public LPVSLoginMember loginMember(Authentication authentication) {
Map<String, Object> oauthLoginMemberMap = lpvsLoginCheckService.getOauthLoginMemberMap(authentication);
Map<String, Object> oauthLoginMemberMap =
lpvsLoginCheckService.getOauthLoginMemberMap(authentication);
boolean isLoggedIn = oauthLoginMemberMap == null || oauthLoginMemberMap.isEmpty();
if (!isLoggedIn) {
LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication);
LPVSMember findMember =
lpvsLoginCheckService.getMemberFromMemberMap(authentication);
return new LPVSLoginMember(!isLoggedIn, findMember);
} else {
return new LPVSLoginMember(!isLoggedIn, null);
}
}

@PostMapping("/user/update")
public ResponseEntity<LPVSMember> postSettingTest(@RequestBody Map<String, String> map, Authentication authentication) {
public ResponseEntity<LPVSMember> postSettingTest(
@RequestBody Map<String, String> map, Authentication authentication) {
lpvsLoginCheckService.loginVerification(authentication);
LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication);
try {
Expand All @@ -101,12 +107,15 @@ public ResponseEntity<LPVSMember> postSettingTest(@RequestBody Map<String, Strin

@ResponseBody
@GetMapping("/history/{type}/{name}")
public HistoryEntity newHistoryPageByUser(@PathVariable("type") String type,
@PathVariable("name") String name,
@PageableDefault(size = 5, sort = "date",
direction = Sort.Direction.DESC) Pageable pageable, Authentication authentication) {

HistoryPageEntity historyPageEntity = lpvsLoginCheckService.pathCheck(type, name, pageable, authentication);
public HistoryEntity newHistoryPageByUser(
@PathVariable("type") String type,
@PathVariable("name") String name,
@PageableDefault(size = 5, sort = "date", direction = Sort.Direction.DESC)
Pageable pageable,
Authentication authentication) {

HistoryPageEntity historyPageEntity =
lpvsLoginCheckService.pathCheck(type, name, pageable, authentication);
Page<LPVSPullRequest> prPage = historyPageEntity.getPrPage();
Long count = historyPageEntity.getCount();

Expand All @@ -115,15 +124,24 @@ public HistoryEntity newHistoryPageByUser(@PathVariable("type") String type,

for (LPVSPullRequest pr : lpvsPullRequests) {
String[] pullNumberTemp = pr.getPullRequestUrl().split("/");
LocalDateTime localDateTime = new Timestamp(pr.getDate().getTime()).toLocalDateTime();
LocalDateTime localDateTime =
new Timestamp(pr.getDate().getTime()).toLocalDateTime();
String formattingDateTime = lpvsLoginCheckService.dateTimeFormatting(localDateTime);

Boolean hasIssue = detectedLicenseRepository.existsIssue(pr);

lpvsHistories.add(new LPVSHistory(formattingDateTime, pr.getRepositoryName(), pr.getId(),
pr.getPullRequestUrl(), pr.getStatus(), pr.getSender(),
pullNumberTemp[pullNumberTemp.length - 2] + "/" +
pullNumberTemp[pullNumberTemp.length - 1], hasIssue));
lpvsHistories.add(
new LPVSHistory(
formattingDateTime,
pr.getRepositoryName(),
pr.getId(),
pr.getPullRequestUrl(),
pr.getStatus(),
pr.getSender(),
pullNumberTemp[pullNumberTemp.length - 2]
+ "/"
+ pullNumberTemp[pullNumberTemp.length - 1],
hasIssue));
}

HistoryEntity historyEntity = new HistoryEntity(lpvsHistories, count);
Expand All @@ -132,14 +150,18 @@ public HistoryEntity newHistoryPageByUser(@PathVariable("type") String type,

@ResponseBody
@GetMapping("/result/{prId}")
public LPVSResult resultPage(@PathVariable("prId") Long prId, @PageableDefault(size = 5, sort = "id",
direction = Sort.Direction.ASC) Pageable pageable, Authentication authentication) {
public LPVSResult resultPage(
@PathVariable("prId") Long prId,
@PageableDefault(size = 5, sort = "id", direction = Sort.Direction.ASC)
Pageable pageable,
Authentication authentication) {

lpvsLoginCheckService.loginVerification(authentication);
//LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication);
// LPVSMember findMember = lpvsLoginCheckService.getMemberFromMemberMap(authentication);

LPVSPullRequest pr = lpvsPullRequestRepository.findById(prId).get();
List<LPVSLicense> distinctByLicense = detectedLicenseRepository.findDistinctByLicense(pr);
List<LPVSLicense> distinctByLicense =
detectedLicenseRepository.findDistinctByLicense(pr);
List<String> detectedLicenses = new ArrayList<>();
Map<String, Integer> licenseCountMap = new HashMap<>();

Expand All @@ -151,10 +173,16 @@ public LPVSResult resultPage(@PathVariable("prId") Long prId, @PageableDefault(s
detectedLicenses.add(lpvsLicense.getSpdxId());
}

LPVSResultInfo lpvsResultInfo = new LPVSResultInfo(pr.getId(), pr.getDate(), pr.getRepositoryName(),
pr.getStatus(), detectedLicenses);
LPVSResultInfo lpvsResultInfo =
new LPVSResultInfo(
pr.getId(),
pr.getDate(),
pr.getRepositoryName(),
pr.getStatus(),
detectedLicenses);

Page<LPVSDetectedLicense> dlPage = detectedLicenseRepository.findByPullRequest(pr, pageable);
Page<LPVSDetectedLicense> dlPage =
detectedLicenseRepository.findByPullRequest(pr, pageable);
List<LPVSDetectedLicense> dlList = detectedLicenseRepository.findByPullRequest(pr);
List<LPVSResultFile> lpvsResultFileList = new ArrayList<>();
Boolean hasIssue = detectedLicenseRepository.existsIssue(pr);
Expand All @@ -169,41 +197,55 @@ public LPVSResult resultPage(@PathVariable("prId") Long prId, @PageableDefault(s
licenseSpdxId = dl.getLicense().getSpdxId();
status = dl.getLicense().getAccess();
}
lpvsResultFileList.add(new LPVSResultFile(dl.getId(), dl.getFilePath(),
dl.getComponentFileUrl(), dl.getLines(), dl.getMatch(),
status, licenseSpdxId));
lpvsResultFileList.add(
new LPVSResultFile(
dl.getId(),
dl.getFilePath(),
dl.getComponentFileUrl(),
dl.getLines(),
dl.getMatch(),
status,
licenseSpdxId));
}

for (LPVSDetectedLicense dl : dlList) {
if (dl.getLicense() != null) {
licenseSpdxId = dl.getLicense().getSpdxId();
licenseCountMap.put(licenseSpdxId,
licenseCountMap.get(licenseSpdxId) + 1);
licenseCountMap.put(licenseSpdxId, licenseCountMap.get(licenseSpdxId) + 1);
}
}

Long count = detectedLicenseRepository.CountByDetectedLicenseWherePullRequestId(pr);
String[] tempPullNumber = pr.getPullRequestUrl().split("/");
LPVSResult lpvsResult = new LPVSResult(lpvsResultFileList, lpvsResultInfo, count, licenseCountMap,
tempPullNumber[tempPullNumber.length-2] + '/' +
tempPullNumber[tempPullNumber.length-1], hasIssue);
LPVSResult lpvsResult =
new LPVSResult(
lpvsResultFileList,
lpvsResultInfo,
count,
licenseCountMap,
tempPullNumber[tempPullNumber.length - 2]
+ '/'
+ tempPullNumber[tempPullNumber.length - 1],
hasIssue);
return lpvsResult;
}

@ResponseBody
@GetMapping("dashboard/{type}/{name}")
public Dashboard dashboardPage(@PathVariable("type") String type,
@PathVariable("name") String name,
Authentication authentication) {
public Dashboard dashboardPage(
@PathVariable("type") String type,
@PathVariable("name") String name,
Authentication authentication) {

Dashboard dashboardEntity = lpvsStatisticsService.getDashboardEntity(type, name, authentication);
Dashboard dashboardEntity =
lpvsStatisticsService.getDashboardEntity(type, name, authentication);

return dashboardEntity;
}
}

@GetMapping("/error")
public String redirect(){
public String redirect() {
return "index.html";
}
}
7 changes: 3 additions & 4 deletions src/main/java/com/lpvs/entity/LPVSDetectedLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/

package com.lpvs.entity;

import lombok.Getter;
Expand All @@ -15,7 +14,8 @@

@Entity
@Table(name = "detected_license", schema = "lpvs")
@Getter @Setter
@Getter
@Setter
public class LPVSDetectedLicense implements Serializable {

@Id
Expand All @@ -39,7 +39,7 @@ public class LPVSDetectedLicense implements Serializable {
@JoinColumn(name = "repository_license_id", referencedColumnName = "id")
private LPVSLicense repositoryLicense = null;

@Column(name = "file_path", columnDefinition = "LONGTEXT")
@Column(name = "file_path", columnDefinition = "LONGTEXT")
private String filePath = null;

@Column(name = "match_type")
Expand Down Expand Up @@ -74,5 +74,4 @@ public class LPVSDetectedLicense implements Serializable {

@Column(name = "issue")
private Boolean issue = false;

}
6 changes: 3 additions & 3 deletions src/main/java/com/lpvs/entity/LPVSDiffFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/

package com.lpvs.entity;

import lombok.Getter;
Expand All @@ -13,13 +12,14 @@
import java.util.LinkedList;
import java.util.List;

@Getter @Setter
@Getter
@Setter
public class LPVSDiffFile {
private String oldFileName;
private String newFileName;
private List<String> changedLines;

public void appendPatchedLine(String line){
public void appendPatchedLine(String line) {
if (this.changedLines == null) this.changedLines = new LinkedList<>();
this.changedLines.add(line);
}
Expand Down
Loading

0 comments on commit e1f15a2

Please sign in to comment.