Skip to content

Commit

Permalink
Merge pull request #42 from dricazenck/checkstyle_format_fix
Browse files Browse the repository at this point in the history
refactor: Apply Google Format
  • Loading branch information
dricazenck authored Jul 2, 2024
2 parents 66bcf43 + a6460f7 commit 76364f2
Show file tree
Hide file tree
Showing 60 changed files with 1,455 additions and 889 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build/*
# IntelliJ customizations
!.idea/checkstyle-idea.xml
!.idea/saveactions_settings.xml
!.idea/codeStyles/codeStyleConfig.xml
!.idea/codeStyles/*
!.idea/codeStyleSettings.xml
!.idea/externalDependencies.xml
!.idea/codeStyles
!.idea/google-java-format.xml
6 changes: 6 additions & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 42 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* [Setup](#setup)
* [JAVA 21 with SDKMAN](#java-21-with-sdkman)
* [Setup IntelliJ](#setup-intellij)
* [Lombok](#lombok)
* [Enable Save Actions](#enable-save-actions)
* [Enable Checkstyle Warnings](#enable-checkstyle-warnings)
* [Google Format](#google-format)
* [IntelliJ JRE Config](#intellij-jre-config)
* [Run Locally](#run-locally)
* [Open API Documentation](#open-api-documentation)

Expand All @@ -17,8 +22,6 @@

This project uses Java 21, you can run in 21.0.2 or 21.0.3. If you have installed a different
version on your machine and don't want to remove it, you can use **SDKMAN** development tool.
It will allow you to switch based on the Java version you want to use.
Here is the [link](https://sdkman.io).

* Install SDKMAN

Expand Down Expand Up @@ -55,7 +58,8 @@ Set the default Java version for your system:
sdk default java 21.0.2-open
```

To verify if the java version is correct use:
* To verify if the java version is correct use:

```shell
java -version
```
Expand All @@ -64,93 +68,74 @@ java -version

#### Lombok

Install lombok plugin and enable Annotation Processing, as the image below:
Install lombok plugin and enable Annotation Processing, as the image below:

![image](docs/images/annotation-procession.png)

#### Enable Save Actions

![image](docs/images/save-actions.png)
![image](docs/images/save-actions.png)

#### Enable Checkstyle Warnings

Install checkstyle plugin and the configuration will be enabled

## Run Locally
#### Google Format

* Build and run tests
A google-java-format IntelliJ plugin is available from the plugin repository. To install it, go to
your IDE's settings and select the Plugins category. Click the Marketplace tab, search for the
google-java-format plugin, and click the Install button.

```shell
./gradlew clean build
```
The plugin will be disabled by default. To enable it in the current project, go to
File→Settings...→google-java-format Settings (or IntelliJ IDEA→Preferences...→Other
Settings→google-java-format Settings on macOS) and check the Enable google-java-format checkbox. (A
notification will be presented when you first open a project offering to do this for you.)

* Create Jar
To enable it by default in new projects, use File→Other Settings→Default Settings....

```shell
./gradlew clean bootJar
```
When enabled, it will replace the normal Reformat Code and Optimize Imports actions.

* Start Spring Boot Application:
![image](docs/images/google-format.png)

```shell
./gradlew bootRun
```

* Access application on http://localhost:8080/api/cms/v1/team
##### IntelliJ JRE Config

<<<<<<< HEAD
## Open API Documentation
The google-java-format plugin uses some internal classes that aren't available without extra
configuration. To use the plugin, go to Help→Edit Custom VM Options... and paste in these lines:

* Access swagger at http://localhost:8080/swagger-ui/index.html
=======
## JAVA 21

This project uses Java 21, you can run in 21.0.2 or 21.0.3. If you have installed a different version on your machine
and don't want to remove it, you can use **SDKMAN** development tool.
It will allow you to switch based on the Java version you want to use.
Here is the [link](https://sdkman.io).

* Install SDKMAN

Open your terminal and run the following command:

```shell
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
```

* Check the list of available Java versions:

```shell
sdk list java
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
```

* Install the desired Java version
Once you've done that, restart the IDE.

```shell
sdk install java 21.0.2-open
```
## Run Locally

* Use the specific java version in the current session on your terminal
* Build and run tests

```shell
sdk use java 21.0.2-open
./gradlew clean build
```

## Set the default Java version for your system:

* To set the newly installed Java version as the default:
* Create Jar

```shell
sdk default java 21.0.2-open
./gradlew clean bootJar
```

* To verify if the java version is correct use:
* Start Spring Boot Application:

```shell
java -version
./gradlew bootRun
```

## Api documentation
* Access application on http://localhost:8080/api/cms/v1/team

## Open API Documentation

* [Access swagger api](http://localhost:8080/swagger-ui/index.html) and corresponding [openAPI docs here](http://localhost:8080/api-docs)
* [Access swagger api](http://localhost:8080/swagger-ui/index.html) and
corresponding [openAPI docs here](http://localhost:8080/api-docs)
Binary file added docs/images/google-format.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/main/java/com/wcc/platform/PlatformApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

/** Spring application service. */
@SpringBootApplication
@Import(ObjectMapperConfig.class)
public class PlatformApplication {

public static void main(String[] args) {
SpringApplication.run(PlatformApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(PlatformApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;

/** Global controller to handle all exceptions for the API. */
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(ContentNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ResponseEntity<?> handleNotFoundException(
ContentNotFoundException ex, WebRequest request) {
var errorDetails =
new ErrorDetails(NOT_FOUND.value(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, NOT_FOUND);
}
/** Receive ContentNotFoundException and return {@link HttpStatus#NOT_FOUND}. */
@ExceptionHandler(ContentNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ResponseEntity<?> handleNotFoundException(
ContentNotFoundException ex, WebRequest request) {
var errorDetails =
new ErrorDetails(NOT_FOUND.value(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, NOT_FOUND);
}

@ExceptionHandler(PlatformInternalException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity<?> handleInternalError(PlatformInternalException ex, WebRequest request) {
var errorDetails =
new ErrorDetails(
INTERNAL_SERVER_ERROR.value(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, INTERNAL_SERVER_ERROR);
}
/** Receive PlatformInternalException and return {@link HttpStatus#INTERNAL_SERVER_ERROR}. */
@ExceptionHandler(PlatformInternalException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity<?> handleInternalError(PlatformInternalException ex, WebRequest request) {
var errorDetails =
new ErrorDetails(
INTERNAL_SERVER_ERROR.value(), ex.getMessage(), request.getDescription(false));
return new ResponseEntity<>(errorDetails, INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.wcc.platform.deserializers.ImageTypeDeserializer;
import com.wcc.platform.deserializers.MemberTypeDeserializer;
import com.wcc.platform.deserializers.SocialNetworkTypeDeserializer;
Expand All @@ -12,24 +13,28 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/** ObjectMapperConfig. */
@Configuration
public class ObjectMapperConfig {

@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
/** Create ObjectMapper bean and include custom serializer. */
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();

objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

registerCustomDeserializers(objectMapper);
return objectMapper;
}
registerCustomDeserializers(objectMapper);
return objectMapper;
}

private void registerCustomDeserializers(ObjectMapper objectMapper) {
objectMapper.registerModule(
private void registerCustomDeserializers(ObjectMapper objectMapper) {
objectMapper
.registerModule(new JavaTimeModule())
.registerModule(
new SimpleModule()
.addDeserializer(MemberType.class, new MemberTypeDeserializer())
.addDeserializer(ImageType.class, new ImageTypeDeserializer())
.addDeserializer(SocialNetworkType.class, new SocialNetworkTypeDeserializer()));
}
}
}
}
Loading

0 comments on commit 76364f2

Please sign in to comment.