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

Replace tkit extensions #12

Open
wants to merge 4 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<!--rest client-->
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -122,13 +137,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-logging-json</artifactId>
</dependency>
<!--tkit-->
<dependency>
<groupId>org.tkit.quarkus</groupId>
<artifactId>tkit-quarkus-test</artifactId>
<version>1.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -187,34 +195,25 @@
</executions>
</plugin>
<plugin>
<groupId>org.tkit.maven</groupId>
<artifactId>tkit-mp-restclient-plugin</artifactId>
<version>0.11.0</version>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>codegen</goal>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/product-service-openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/</output>
<apiPackage>com.devonfw.quarkus.general.restclient.product</apiPackage>
<modelPackage>com.devonfw.quarkus.general.restclient.product.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<annotations>
<annotation>org.eclipse.microprofile.rest.client.inject.RegisterRestClient(configKey="product-service-key")</annotation>
<annotation>javax.enterprise.context.ApplicationScoped</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<generatorName>jaxrs-spec</generatorName>
<apiPackage>com.devonfw.quarkus.ordermanagement.restclient.product</apiPackage>
<modelPackage>com.devonfw.quarkus.ordermanagement.restclient.product.models</modelPackage>
<configOptions>
<sourceFolder>restclient</sourceFolder>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
<useTags>true</useTags>
<interfaceOnly>true</interfaceOnly>
<generatePom>false</generatePom>
</configOptions>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,74 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;

/**
* Abstract base class for all persistence entities with an {@link #getId() id} and a
* Abstract base class for all {@link PersistenceEntity persistence entities} with an {@link #getId() id} and a
* {@link #getModificationCounter() modificationCounter} (version) field. All persistence entities of this application
* should inherit from this class. It is using JPA annotations at the getters what has several advantages but also
* implies that you have to annotate transient getter methods with the {@link Transient} annotation.
* should inherit from this class.
*/
@MappedSuperclass
public abstract class ApplicationPersistenceEntity {

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private Integer modificationCounter;
@Version
private Integer modificationCounter;

public ApplicationPersistenceEntity() {
/**
* The constructor.
*/
public ApplicationPersistenceEntity() {

super();
}
super();
}

public Long getId() {
public Long getId() {

return this.id;
}
return this.id;
}

public void setId(Long id) {
public void setId(Long id) {

this.id = id;
}
this.id = id;
}

@Version
public Integer getModificationCounter() {
public Integer getModificationCounter() {

return this.modificationCounter;
}
return this.modificationCounter;
}

public void setModificationCounter(Integer version) {
public void setModificationCounter(Integer version) {

this.modificationCounter = version;
}
this.modificationCounter = version;
}

@Override
public String toString() {
@Override
public String toString() {

StringBuilder buffer = new StringBuilder();
toString(buffer);
return buffer.toString();
}
StringBuilder buffer = new StringBuilder();
toString(buffer);
return buffer.toString();
}

/**
* Method to extend {@link #toString()} logic.
*
* @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string
* representation.
*/
protected void toString(StringBuilder buffer) {

/**
* Method to extend {@link #toString()} logic.
*
* @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string
* representation.
*/
protected void toString(StringBuilder buffer) {

buffer.append(getClass().getSimpleName());
if (this.id != null) {
buffer.append("[id=");
buffer.append(this.id);
buffer.append("]");
}
buffer.append(getClass().getSimpleName());
if (this.id != null) {
buffer.append("[id=");
buffer.append(this.id);
buffer.append("]");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
package com.devonfw.quarkus.ordermanagement.domain.model;

import com.devonfw.quarkus.general.domain.model.ApplicationPersistenceEntity;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.time.Instant;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.time.Instant;

import com.devonfw.quarkus.general.domain.model.ApplicationPersistenceEntity;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "ITEM")
public class ItemEntity extends ApplicationPersistenceEntity {

private String title;
private String title;

private BigDecimal price;
private BigDecimal price;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "productorder", referencedColumnName = "id")
private OrderEntity productorder;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "productorder", referencedColumnName = "id")
private OrderEntity productorder;

private Instant creationDate;
private Instant creationDate;

private Long productId;
private Long productId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.Transactional;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import com.devonfw.quarkus.general.restclient.product.ProductsRestClient;
import com.devonfw.quarkus.general.restclient.product.models.ProductDto;
import com.devonfw.quarkus.ordermanagement.domain.model.ItemEntity;
import com.devonfw.quarkus.ordermanagement.domain.model.OrderEntity;
import com.devonfw.quarkus.ordermanagement.domain.model.OrderStatus;
import com.devonfw.quarkus.ordermanagement.domain.repo.ItemRepository;
import com.devonfw.quarkus.ordermanagement.domain.repo.OrderRepository;
import com.devonfw.quarkus.ordermanagement.rest.v1.model.NewOrderDto;
import com.devonfw.quarkus.ordermanagement.restclient.product.ProductRestClient;
import com.devonfw.quarkus.ordermanagement.restclient.product.models.ProductDto;

@Named
@Transactional
Expand All @@ -36,7 +35,7 @@ public class UcManageOrder {

@Inject
@RestClient
ProductsRestClient productsRestClient;
ProductRestClient productsRestClient;

public void saveOrder(NewOrderDto dto) {

Expand All @@ -48,13 +47,12 @@ public void saveOrder(NewOrderDto dto) {
List<ItemEntity> listItems = new ArrayList<>();
BigDecimal totalPrice = new BigDecimal(0.0);
for (Long id : dto.getOrderedProductIds()) {
Response response = this.productsRestClient.getProductById(String.valueOf(id));
ProductDto productDto = response.readEntity(ProductDto.class);
ProductDto productDto = this.productsRestClient.productV1IdGet(String.valueOf(id));
ItemEntity itemEntity = new ItemEntity();
itemEntity.setTitle(productDto.title);
itemEntity.setProductId(productDto.id);
itemEntity.setTitle(productDto.getTitle());
itemEntity.setProductId(productDto.getId());
itemEntity.setCreationDate(Instant.now());
itemEntity.setPrice(productDto.price);
itemEntity.setPrice(productDto.getPrice());
totalPrice = totalPrice.add(itemEntity.getPrice());
listItems.add(itemEntity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.devonfw.quarkus.ordermanagement.restclient.product;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.Path;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import com.devonfw.quarkus.ordermanagement.restclient.product.DefaultApi;

@Path("/product/v1")
@RegisterRestClient(configKey = "product-service-key")
@ApplicationScoped
public interface ProductRestClient extends DefaultApi {

}
7 changes: 4 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ quarkus.datasource.password=demo
%dev.quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n

# TEST profile
%test.quarkus.datasource.password=demo
%test.quarkus.datasource.jdbc.driver=org.testcontainers.jdbc.ContainerDatabaseDriver
%test.quarkus.datasource.jdbc.url=jdbc:tc:postgresql:11.5://demo_db
%test.quarkus.datasource.username=demo
%test.quarkus.datasource.password=demo
%test.quarkus.hibernate-orm.database.generation=drop-and-create
%test.quarkus.hibernate-orm.log.sql=true


ryuk.container.image=testcontainersofficial/ryuk
Loading