Skip to content
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

Issue 10652 java formatter #10653

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<springfox.version>3.0.0</springfox.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<formatVersion>2.22.1</formatVersion>

<!-- Sonar -->
<sonar.projectKey>cBioPortal_cbioportal</sonar.projectKey>
Expand Down Expand Up @@ -550,6 +551,32 @@
</execution>
</executions>
</plugin>

<!-- Format Code -->
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>${formatVersion}</version>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<verbose>true</verbose>
<filesNamePattern>.*\.java</filesNamePattern>
<skip>false</skip>
<skipSourceDirectory>false</skipSourceDirectory>
<skipTestSourceDirectory>false</skipTestSourceDirectory>
<skipSortingImports>false</skipSortingImports>
<style>google</style>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
30 changes: 12 additions & 18 deletions src/main/java/org/cbioportal/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
package org.cbioportal;

import java.util.concurrent.Executor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.lang.Runtime;
import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {


@Value("${multithread.core_pool_size:#{T(java.lang.Runtime).getRuntime().availableProcessors()}}")
private int corePoolSize;

@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setThreadNamePrefix("ThreadPoolTaskExecutor-");
executor.initialize();
return executor;
}
@Value("${multithread.core_pool_size:#{T(java.lang.Runtime).getRuntime().availableProcessors()}}")
private int corePoolSize;

@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setThreadNamePrefix("ThreadPoolTaskExecutor-");
executor.initialize();
return executor;
}
}
19 changes: 8 additions & 11 deletions src/main/java/org/cbioportal/PortalApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@SpringBootApplication(exclude = {
MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class
})
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@PropertySources({
@PropertySource(ignoreResourceNotFound = true, value = "classpath:application.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:security.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:maven.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:git.properties")
@PropertySource(ignoreResourceNotFound = true, value = "classpath:application.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:security.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:maven.properties"),
@PropertySource(ignoreResourceNotFound = true, value = "classpath:git.properties")
})
public class PortalApplication {
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
}
67 changes: 33 additions & 34 deletions src/main/java/org/cbioportal/WebAppConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cbioportal;

import java.util.List;

import org.cbioportal.web.util.InvolvedCancerStudyExtractorInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -16,28 +15,29 @@
// TODO Consider creating separate DispatcherServlets as in the original web.xml
// See: https://stackoverflow.com/a/30686733/11651683
@Configuration
//@EnableAspectJAutoProxy // TODO no idea what this does; is this logging aspect still useful?
// @EnableAspectJAutoProxy // TODO no idea what this does; is this logging aspect still useful?
public class WebAppConfig implements WebMvcConfigurer {

private static final String SINGLE_PAGE_APP_ROOT = "forward:/";
private static final String SINGLE_PAGE_APP_ROOT = "forward:/";

@Value("${springdoc.swagger-ui.path:/swagger-ui.html}")
private String swaggerRedirectUrl;
@Value("${springdoc.swagger-ui.path:/swagger-ui.html}")
private String swaggerRedirectUrl;

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/webapp/images/");
registry.addResourceHandler("/reactapp/**").addResourceLocations("classpath:/reactapp/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/webapp/images/");
registry.addResourceHandler("/reactapp/**").addResourceLocations("classpath:/reactapp/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/api", swaggerRedirectUrl);
registry.addRedirectViewController("/installations", "https://installationmap.netlify.app/");
registry.addRedirectViewController("/tutorials", "https://docs.cbioportal.org/user-guide/overview/#tutorial-slides");
registry.addRedirectViewController("/oql", "https://docs.cbioportal.org/user-guide/oql/");
registry.addRedirectViewController("/faq", "https://docs.cbioportal.org/user-guide/faq/");
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/api", swaggerRedirectUrl);
registry.addRedirectViewController("/installations", "https://installationmap.netlify.app/");
registry.addRedirectViewController(
"/tutorials", "https://docs.cbioportal.org/user-guide/overview/#tutorial-slides");
registry.addRedirectViewController("/oql", "https://docs.cbioportal.org/user-guide/oql/");
registry.addRedirectViewController("/faq", "https://docs.cbioportal.org/user-guide/faq/");

List<String> endpoints = List.of(
"/results/*",
Expand All @@ -63,23 +63,22 @@ public void addViewControllers(ViewControllerRegistry registry) {
"/news**"
);

endpoints.forEach( route -> registry.addViewController(route).setViewName(SINGLE_PAGE_APP_ROOT));
}

@Bean
public HandlerInterceptor involvedCancerStudyExtractorInterceptor() {
return new InvolvedCancerStudyExtractorInterceptor();
}
endpoints.forEach(route -> registry.addViewController(route).setViewName(SINGLE_PAGE_APP_ROOT));
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(involvedCancerStudyExtractorInterceptor());
}
@Bean
public HandlerInterceptor involvedCancerStudyExtractorInterceptor() {
return new InvolvedCancerStudyExtractorInterceptor();
}

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Adds support for trailing slash Matches
configurer.setUseTrailingSlashMatch(true);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(involvedCancerStudyExtractorInterceptor());
}

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Adds support for trailing slash Matches
configurer.setUseTrailingSlashMatch(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package org.cbioportal.documentation;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -15,35 +8,45 @@
import java.net.URLDecoder;
import java.util.Collections;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

// Retrieve the content of an external page
// Make it auto-scannable
@Controller
public class ExternalPageController {

// service name: getexternalpage.json
// available via GET method
// sourceURL is required
@Transactional
@RequestMapping(value = "/api/getexternalpage.json", method = {RequestMethod.GET})
public @ResponseBody Map<String, String> getExternalPage(@RequestParam(required = true) String sourceURL) throws IOException {
String decodedString, pageText = "";

// decode the sourceURL and open a connection
sourceURL = URLDecoder.decode(sourceURL, "UTF-8");
URL url = new URL(sourceURL);
URLConnection connection = url.openConnection();

// create a reader
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));

// read
while ((decodedString = in.readLine()) != null) {
pageText += decodedString + "\n";
}
in.close();

// turn the pageText into a singletonMap for json and return
return Collections.singletonMap("response", pageText);
// service name: getexternalpage.json
// available via GET method
// sourceURL is required
@Transactional
@RequestMapping(
value = "/api/getexternalpage.json",
method = {RequestMethod.GET})
public @ResponseBody Map<String, String> getExternalPage(
@RequestParam(required = true) String sourceURL) throws IOException {
String decodedString, pageText = "";

// decode the sourceURL and open a connection
sourceURL = URLDecoder.decode(sourceURL, "UTF-8");
URL url = new URL(sourceURL);
URLConnection connection = url.openConnection();

// create a reader
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));

// read
while ((decodedString = in.readLine()) != null) {
pageText += decodedString + "\n";
}
}
in.close();

// turn the pageText into a singletonMap for json and return
return Collections.singletonMap("response", pageText);
}
}
Loading
Loading