Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions .mvn/wrapper/MavenWrapperDownloader.java

This file was deleted.

95 changes: 95 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import java.util.Properties

object MavenWrapperDownloader {
private val WRAPPER_VERSION: String? = "0.5.4"

/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private val DEFAULT_DOWNLOAD_URL: String? = ("https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + " .jar")

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private val MAVEN_WRAPPER_PROPERTIES_PATH: String? = ".mvn/wrapper/maven-wrapper.properties"

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private val MAVEN_WRAPPER_JAR_PATH: String? = ".mvn/wrapper/maven-wrapper.jar"

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private val PROPERTY_NAME_WRAPPER_URL: String? = "wrapperUrl"
fun main(args: Array<String?>?) {
System.out.println("- Downloader started")
val baseDirectory = File(args.get(0))
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath())

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
val mavenWrapperPropertyFile = File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH)
var url = DEFAULT_DOWNLOAD_URL
if (mavenWrapperPropertyFile.exists()) {
var mavenWrapperPropertyFileInputStream: FileInputStream? = null
try {
mavenWrapperPropertyFileInputStream = FileInputStream(mavenWrapperPropertyFile)
val mavenWrapperProperties = Properties()
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream)
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url)
} catch (e: IOException) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'")
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close()
}
} catch (e: IOException) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: $url")
val outputFile = File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH)
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'")
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath())
try {
downloadFileFromURL(url, outputFile)
System.out.println("Done")
System.exit(0)
} catch (e: Throwable) {
System.out.println("- Error downloading")
e.printStackTrace()
System.exit(1)
}
}

@Throws(Exception::class)
private fun downloadFileFromURL(urlString: String?, destination: File?) {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
val username: String = System.getenv("MVNW_USERNAME")
val password: CharArray = System.getenv("MVNW_PASSWORD").toCharArray()
Authenticator.setDefault(object : Authenticator() {
@Override
protected fun getPasswordAuthentication(): PasswordAuthentication? {
return PasswordAuthentication(username, password)
}
})
}
val website = URL(urlString)
val rbc: ReadableByteChannel
rbc = Channels.newChannel(website.openStream())
val fos = FileOutputStream(destination)
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE)
fos.close()
rbc.close()
}
}
101 changes: 97 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,121 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<kotlin.version>1.8.10</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.7.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.14.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.11.0</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>br.com.blz.testjava.domain.usecase.*</param>
</targetClasses>
<avoidCallsTo>kotlin.jvm.internal</avoidCallsTo>
</configuration>
</plugin>
</plugins>
</build>

</project>
12 changes: 0 additions & 12 deletions src/main/java/br/com/blz/testjava/TestJavaApplication.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/java/br/com/blz/testjava/TestJavaApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package br.com.blz.testjava

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication(scanBasePackageClasses = [TestJavaApplication::class])
open class TestJavaApplication
fun main(args: Array<String>) {
runApplication<TestJavaApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package br.com.blz.testjava.application.handler

import br.com.blz.testjava.domain.exception.AlreadyExistsException
import br.com.blz.testjava.domain.exception.NotFoundException
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler

@ControllerAdvice
class GlobalExceptionHandler {

@ExceptionHandler(value = [(AlreadyExistsException::class)])
fun handleAlreadyExistsException(ex: Exception) = ResponseEntity.status(HttpStatus.CONFLICT).body(ex.message)

@ExceptionHandler(value = [(NotFoundException::class)])
fun handleNotFoundException(ex: Exception) = ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package br.com.blz.testjava.application.service

import br.com.blz.testjava.application.web.controller.request.CreateProductRequest
import br.com.blz.testjava.application.web.controller.request.ProductResponse
import br.com.blz.testjava.domain.usecase.CreateProductUseCase
import org.springframework.stereotype.Service

@Service
class CreateProductService(
private val createProductUseCase: CreateProductUseCase
) {

fun createProduct(createProductRequest: CreateProductRequest): ProductResponse {
return createProductUseCase.execute(createProductRequest.toDomain())
}
}
Loading