Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
e16ed51835
|
@ -44,11 +44,6 @@
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -68,16 +63,6 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>olingo-odata2-api</artifactId>
|
|
||||||
<version>${olingo2.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
|
|
||||||
<version>${olingo2.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.olingo</groupId>
|
<groupId>org.apache.olingo</groupId>
|
||||||
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
|
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
|
||||||
|
|
|
@ -12,25 +12,104 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Table(name = "car_maker")
|
||||||
@Table(name="car_maker")
|
|
||||||
public class CarMaker {
|
public class CarMaker {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Column(name="name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany(mappedBy="maker",
|
@OneToMany(mappedBy = "maker", orphanRemoval = true, cascade = CascadeType.ALL)
|
||||||
orphanRemoval = true,
|
|
||||||
cascade=CascadeType.ALL)
|
|
||||||
private List<CarModel> models;
|
private List<CarModel> models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id the id to set
|
||||||
|
*/
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name the name to set
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the models
|
||||||
|
*/
|
||||||
|
public List<CarModel> getModels() {
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param models the models to set
|
||||||
|
*/
|
||||||
|
public void setModels(List<CarModel> models) {
|
||||||
|
this.models = models;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
result = prime * result + ((models == null) ? 0 : models.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
CarMaker other = (CarMaker) obj;
|
||||||
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
|
return false;
|
||||||
|
if (models == null) {
|
||||||
|
if (other.models != null)
|
||||||
|
return false;
|
||||||
|
} else if (!models.equals(other.models))
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.baeldung.examples.olingo2.domain;
|
package org.baeldung.examples.olingo2.domain;
|
||||||
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
|
@ -11,28 +10,150 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Table(name = "car_model")
|
||||||
@Table(name="car_model")
|
|
||||||
public class CarModel {
|
public class CarModel {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Integer year;
|
private Integer year;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String sku;
|
private String sku;
|
||||||
|
|
||||||
@ManyToOne(optional=false, fetch= FetchType.LAZY)
|
@ManyToOne(optional = false, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name="maker_fk")
|
@JoinColumn(name = "maker_fk")
|
||||||
private CarMaker maker;
|
private CarMaker maker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id the id to set
|
||||||
|
*/
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name the name to set
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the year
|
||||||
|
*/
|
||||||
|
public Integer getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param year the year to set
|
||||||
|
*/
|
||||||
|
public void setYear(Integer year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the sku
|
||||||
|
*/
|
||||||
|
public String getSku() {
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sku the sku to set
|
||||||
|
*/
|
||||||
|
public void setSku(String sku) {
|
||||||
|
this.sku = sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the maker
|
||||||
|
*/
|
||||||
|
public CarMaker getMaker() {
|
||||||
|
return maker;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maker the maker to set
|
||||||
|
*/
|
||||||
|
public void setMaker(CarMaker maker) {
|
||||||
|
this.maker = maker;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
result = prime * result + ((maker == null) ? 0 : maker.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((sku == null) ? 0 : sku.hashCode());
|
||||||
|
result = prime * result + ((year == null) ? 0 : year.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
CarModel other = (CarModel) obj;
|
||||||
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
|
return false;
|
||||||
|
if (maker == null) {
|
||||||
|
if (other.maker != null)
|
||||||
|
return false;
|
||||||
|
} else if (!maker.equals(other.maker))
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
if (sku == null) {
|
||||||
|
if (other.sku != null)
|
||||||
|
return false;
|
||||||
|
} else if (!sku.equals(other.sku))
|
||||||
|
return false;
|
||||||
|
if (year == null) {
|
||||||
|
if (other.year != null)
|
||||||
|
return false;
|
||||||
|
} else if (!year.equals(other.year))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
server:
|
server:
|
||||||
port: 8180
|
port: 8080
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
jersey:
|
jersey:
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
HELP.md
|
|
||||||
/target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
/build/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
|
@ -1,95 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
|
||||||
<version>2.1.3.RELEASE</version>
|
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
|
||||||
</parent>
|
|
||||||
<groupId>org.baeldung.examples.olingo4</groupId>
|
|
||||||
<artifactId>olingo4-sample</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>olingo4-sample</name>
|
|
||||||
<description>Sample Olingo 4 Project</description>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<odata.version>4.5.0</odata.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>odata-server-api</artifactId>
|
|
||||||
<version>${odata.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>odata-server-core</artifactId>
|
|
||||||
<version>${odata.version}</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>odata-commons-api</artifactId>
|
|
||||||
<version>${odata.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.olingo</groupId>
|
|
||||||
<artifactId>odata-commons-core</artifactId>
|
|
||||||
<version>${odata.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-beanutils</groupId>
|
|
||||||
<artifactId>commons-beanutils</artifactId>
|
|
||||||
<version>1.9.3</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation for ODataFactory
|
|
||||||
* @author Philippe
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class DefaultODataFactory implements ODataFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OData newInstance() {
|
|
||||||
return OData.newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
|
|
||||||
public interface ODataFactory {
|
|
||||||
|
|
||||||
public OData newInstance();
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import org.apache.olingo.server.api.ODataHttpHandler;
|
|
||||||
|
|
||||||
public interface ODataHttpHandlerFactory {
|
|
||||||
|
|
||||||
ODataHttpHandler newInstance();
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.apache.olingo.server.api.ODataHttpHandler;
|
|
||||||
import org.apache.olingo.server.api.ServiceMetadata;
|
|
||||||
import org.apache.olingo.server.api.processor.Processor;
|
|
||||||
|
|
||||||
import lombok.Builder;
|
|
||||||
|
|
||||||
@Builder
|
|
||||||
public class ODataHttpHandlerFactoryImpl implements ODataHttpHandlerFactory {
|
|
||||||
|
|
||||||
|
|
||||||
private final ODataFactory odataFactory;
|
|
||||||
private final CsdlEdmProvider edmProvider;
|
|
||||||
private final List<Processor> processors;
|
|
||||||
|
|
||||||
public ODataHttpHandlerFactoryImpl(ODataFactory odataFactory,CsdlEdmProvider edmProvider, List<Processor> processors) {
|
|
||||||
this.odataFactory = odataFactory;
|
|
||||||
this.edmProvider = edmProvider;
|
|
||||||
this.processors = processors;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ODataHttpHandler newInstance() {
|
|
||||||
|
|
||||||
OData odata = odataFactory.newInstance();
|
|
||||||
ServiceMetadata metadata = odata.createServiceMetadata(edmProvider, Collections.emptyList());
|
|
||||||
ODataHttpHandler handler = odata.createHandler(metadata);
|
|
||||||
|
|
||||||
// Register all available processors
|
|
||||||
processors.forEach(p -> handler.register(p));
|
|
||||||
|
|
||||||
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
|
|
||||||
import org.apache.olingo.server.api.processor.Processor;
|
|
||||||
import org.baeldung.examples.olingo4.ODataHttpHandlerFactoryImpl.ODataHttpHandlerFactoryImplBuilder;
|
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ODataServiceConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ServletRegistrationBean<HttpServlet> odataServletRegistration(ODataHttpHandlerFactory factory) {
|
|
||||||
ServletRegistrationBean<HttpServlet> srb =
|
|
||||||
new ServletRegistrationBean<>(new ODataServlet(factory), "/odata/*");
|
|
||||||
srb.setLoadOnStartup(1);
|
|
||||||
return srb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ODataHttpHandlerFactory httpHandlerFactory(CsdlEdmProvider edmProvider, ODataFactory odataFactory, List<Processor> processors) {
|
|
||||||
return new ODataHttpHandlerFactoryImplBuilder()
|
|
||||||
.edmProvider(edmProvider)
|
|
||||||
.odataFactory(odataFactory)
|
|
||||||
.processors(processors)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.EntityTransaction;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.apache.olingo.server.api.ODataHttpHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Philippe
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ODataServlet extends HttpServlet {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private final ODataHttpHandlerFactory odataHttpHandlerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
public ODataServlet(ODataHttpHandlerFactory factory) {
|
|
||||||
this.odataHttpHandlerFactory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
||||||
|
|
||||||
ODataHttpHandler handler = odataHttpHandlerFactory.newInstance();
|
|
||||||
handler.process(req, resp);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.domain;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@Table(name="car_maker")
|
|
||||||
public class CarMaker {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name="name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy="maker",
|
|
||||||
orphanRemoval = true,
|
|
||||||
cascade=CascadeType.ALL)
|
|
||||||
private List<CarModel> models;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.domain;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@Table(name="car_model")
|
|
||||||
public class CarModel {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer year;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String sku;
|
|
||||||
|
|
||||||
@ManyToOne(optional=false, fetch= FetchType.EAGER )
|
|
||||||
@JoinColumn(name="maker_fk")
|
|
||||||
private CarMaker maker;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.edm;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class EdmTypeMapper {
|
|
||||||
|
|
||||||
public EdmPrimitiveTypeKind java2edm(Class<?> clazz) {
|
|
||||||
EdmPrimitiveTypeKind result = java2edm.get(clazz);
|
|
||||||
if ( result == null ) {
|
|
||||||
throw new IllegalArgumentException("[E19] Unsupported class mapping: class=" + clazz);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Static map used generate attribute metadada based on Java types
|
|
||||||
static Map<Class<?>,EdmPrimitiveTypeKind> java2edm = Collections
|
|
||||||
.unmodifiableMap(Stream.of(
|
|
||||||
new SimpleEntry<>(Boolean.class,EdmPrimitiveTypeKind.Boolean),
|
|
||||||
new SimpleEntry<>(Byte.class,EdmPrimitiveTypeKind.SByte),
|
|
||||||
new SimpleEntry<>(Date.class,EdmPrimitiveTypeKind.Date),
|
|
||||||
new SimpleEntry<>(Time.class,EdmPrimitiveTypeKind.TimeOfDay),
|
|
||||||
new SimpleEntry<>(Number.class,EdmPrimitiveTypeKind.Decimal),
|
|
||||||
new SimpleEntry<>(Float.class,EdmPrimitiveTypeKind.Single),
|
|
||||||
new SimpleEntry<>(Double.class,EdmPrimitiveTypeKind.Double),
|
|
||||||
new SimpleEntry<>(UUID.class,EdmPrimitiveTypeKind.Guid),
|
|
||||||
new SimpleEntry<>(Short.class,EdmPrimitiveTypeKind.Int16),
|
|
||||||
new SimpleEntry<>(Integer.class,EdmPrimitiveTypeKind.Int32),
|
|
||||||
new SimpleEntry<>(Long.class,EdmPrimitiveTypeKind.Int64),
|
|
||||||
new SimpleEntry<>(String.class,EdmPrimitiveTypeKind.String)
|
|
||||||
|
|
||||||
).collect(Collectors.toMap((e)-> e.getKey(),(e)-> e.getValue())));
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,269 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.edm;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
|
|
||||||
import javax.persistence.metamodel.EntityType;
|
|
||||||
import javax.persistence.metamodel.Metamodel;
|
|
||||||
import javax.persistence.metamodel.PluralAttribute;
|
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataException;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class JpaEdmProvider extends CsdlAbstractEdmProvider {
|
|
||||||
|
|
||||||
EntityManagerFactory emf;
|
|
||||||
|
|
||||||
//
|
|
||||||
private EdmTypeMapper typeMapper;
|
|
||||||
|
|
||||||
// Service Namespace
|
|
||||||
public static final String NAMESPACE = "Baeldung.OData";
|
|
||||||
|
|
||||||
// EDM Container
|
|
||||||
public static final String CONTAINER_NAME = "Cars";
|
|
||||||
public static final FullQualifiedName CONTAINER = new FullQualifiedName(NAMESPACE, CONTAINER_NAME);
|
|
||||||
|
|
||||||
// Caches of OData types by it fully qualified name
|
|
||||||
private Map<FullQualifiedName, CsdlEntityType> cdslName2Type = new HashMap<>();
|
|
||||||
|
|
||||||
public JpaEdmProvider(EntityManagerFactory emf, EdmTypeMapper mapper) {
|
|
||||||
this.emf = emf;
|
|
||||||
this.typeMapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider#getEntitySet(org.apache.olingo.commons.api.edm.FullQualifiedName, java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CsdlEntitySet getEntitySet(FullQualifiedName entityContainer, String entitySetName) throws ODataException {
|
|
||||||
|
|
||||||
if (entityContainer.equals(CONTAINER)) {
|
|
||||||
|
|
||||||
EntityType<?> e = emf.getMetamodel()
|
|
||||||
.getEntities()
|
|
||||||
.stream()
|
|
||||||
.filter((ent) -> (ent.getName() + "s")
|
|
||||||
.equals(entitySetName))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
if (e != null) {
|
|
||||||
CsdlEntitySet entitySet = new CsdlEntitySet();
|
|
||||||
entitySet
|
|
||||||
.setName(entitySetName)
|
|
||||||
.setType(new FullQualifiedName(NAMESPACE, e.getName()));
|
|
||||||
return entitySet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider#getEntityContainerInfo(org.apache.olingo.commons.api.edm.FullQualifiedName)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CsdlEntityContainerInfo getEntityContainerInfo(FullQualifiedName entityContainerName) throws ODataException {
|
|
||||||
|
|
||||||
// This method is invoked when displaying the Service Document at e.g. http://localhost:8080/DemoService/DemoService.svc
|
|
||||||
if (entityContainerName == null || entityContainerName.equals(CONTAINER)) {
|
|
||||||
CsdlEntityContainerInfo entityContainerInfo = new CsdlEntityContainerInfo();
|
|
||||||
entityContainerInfo.setContainerName(CONTAINER);
|
|
||||||
return entityContainerInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider#getSchemas()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<CsdlSchema> getSchemas() throws ODataException {
|
|
||||||
// create Schema
|
|
||||||
CsdlSchema schema = new CsdlSchema();
|
|
||||||
schema.setNamespace(NAMESPACE);
|
|
||||||
|
|
||||||
// add EntityTypes
|
|
||||||
List<CsdlEntityType> entityTypes = emf.getMetamodel()
|
|
||||||
.getEntities()
|
|
||||||
.stream()
|
|
||||||
.map((e) -> {
|
|
||||||
try {
|
|
||||||
return getEntityType(new FullQualifiedName(NAMESPACE, e.getName()));
|
|
||||||
} catch (ODataException oe) {
|
|
||||||
throw new RuntimeException(oe);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
schema.setEntityTypes(entityTypes);
|
|
||||||
|
|
||||||
// add EntityContainer
|
|
||||||
schema.setEntityContainer(getEntityContainer());
|
|
||||||
|
|
||||||
// finally
|
|
||||||
List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
|
|
||||||
schemas.add(schema);
|
|
||||||
|
|
||||||
return schemas;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider#getEntityContainer()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CsdlEntityContainer getEntityContainer() throws ODataException {
|
|
||||||
|
|
||||||
|
|
||||||
// add EntityTypes
|
|
||||||
List<CsdlEntitySet> entitySets = emf.getMetamodel()
|
|
||||||
.getEntities()
|
|
||||||
.stream()
|
|
||||||
.map((e) -> {
|
|
||||||
try {
|
|
||||||
// Here we use a simple mapping strategy to map entity types to entity set names:
|
|
||||||
return getEntitySet(CONTAINER, e.getName() + "s");
|
|
||||||
} catch (ODataException oe) {
|
|
||||||
throw new RuntimeException(oe);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
// create EntityContainer
|
|
||||||
CsdlEntityContainer entityContainer = new CsdlEntityContainer();
|
|
||||||
entityContainer.setName(CONTAINER_NAME);
|
|
||||||
entityContainer.setEntitySets(entitySets);
|
|
||||||
|
|
||||||
return entityContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) throws ODataException {
|
|
||||||
|
|
||||||
CsdlEntityType result = cdslName2Type.get(entityTypeName);
|
|
||||||
if ( result != null ) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Metamodel mm = emf.getMetamodel();
|
|
||||||
result = mm.getEntities()
|
|
||||||
.stream()
|
|
||||||
.filter(et -> entityTypeName.equals(new FullQualifiedName(NAMESPACE, et.getName())))
|
|
||||||
.map(et -> buildODataType(et))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
// save for future use
|
|
||||||
cdslName2Type.put(entityTypeName, result);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a JPA type to its OData counterpart.
|
|
||||||
* @param et
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected CsdlEntityType buildODataType(EntityType<?> et) {
|
|
||||||
|
|
||||||
CsdlEntityType result = new CsdlEntityType();
|
|
||||||
result.setName(et.getName());
|
|
||||||
|
|
||||||
// Process simple properties
|
|
||||||
List<CsdlProperty> properties = et.getDeclaredSingularAttributes()
|
|
||||||
.stream()
|
|
||||||
.filter(attr -> attr.getPersistentAttributeType() == PersistentAttributeType.BASIC)
|
|
||||||
.map(attr -> buildBasicAttribute(et, attr))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
result.setProperties(properties);
|
|
||||||
|
|
||||||
// Process Ids
|
|
||||||
List<CsdlPropertyRef> ids = et.getDeclaredSingularAttributes()
|
|
||||||
.stream()
|
|
||||||
.filter(attr -> attr.getPersistentAttributeType() == PersistentAttributeType.BASIC && attr.isId())
|
|
||||||
.map(attr -> buildRefAttribute(et, attr))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
result.setKey(ids);
|
|
||||||
|
|
||||||
// Process 1:N navs
|
|
||||||
List<CsdlNavigationProperty> navs = et.getDeclaredPluralAttributes()
|
|
||||||
.stream()
|
|
||||||
.map(attr -> buildNavAttribute(et, attr))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
result.setNavigationProperties(navs);
|
|
||||||
|
|
||||||
// Process N:1 navs
|
|
||||||
List<CsdlNavigationProperty> navs2 = et.getDeclaredSingularAttributes()
|
|
||||||
.stream()
|
|
||||||
.filter(attr -> attr.getPersistentAttributeType() == PersistentAttributeType.MANY_TO_ONE)
|
|
||||||
.map(attr -> buildNavAttribute(et, attr))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
result.getNavigationProperties().addAll(navs2);
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CsdlProperty buildBasicAttribute(EntityType<?> et, SingularAttribute<?, ?> attr) {
|
|
||||||
|
|
||||||
CsdlProperty p = new CsdlProperty().setName(attr.getName())
|
|
||||||
.setType(typeMapper.java2edm(attr.getJavaType())
|
|
||||||
.getFullQualifiedName())
|
|
||||||
.setNullable(et.getDeclaredSingularAttribute(attr.getName())
|
|
||||||
.isOptional());
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CsdlPropertyRef buildRefAttribute(EntityType<?> et, SingularAttribute<?, ?> attr) {
|
|
||||||
|
|
||||||
CsdlPropertyRef p = new CsdlPropertyRef().setName(attr.getName());
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build NavProperty for 1:N or M:N associations
|
|
||||||
private CsdlNavigationProperty buildNavAttribute(EntityType<?> et, PluralAttribute<?, ?, ?> attr) {
|
|
||||||
|
|
||||||
CsdlNavigationProperty p = new CsdlNavigationProperty().setName(attr.getName())
|
|
||||||
.setType(new FullQualifiedName(NAMESPACE, attr.getBindableJavaType().getSimpleName()))
|
|
||||||
.setCollection(true)
|
|
||||||
.setNullable(false);
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build NavProperty for N:1 associations
|
|
||||||
private CsdlNavigationProperty buildNavAttribute(EntityType<?> et, SingularAttribute<?, ?> attr) {
|
|
||||||
|
|
||||||
CsdlNavigationProperty p = new CsdlNavigationProperty().setName(attr.getName())
|
|
||||||
.setType(new FullQualifiedName(NAMESPACE, attr.getBindableJavaType().getSimpleName()))
|
|
||||||
.setCollection(false)
|
|
||||||
.setNullable(attr.isOptional());
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,161 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.processor;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.metamodel.EntityType;
|
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
|
||||||
|
|
||||||
import org.apache.commons.beanutils.PropertyUtils;
|
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
|
||||||
import org.apache.olingo.commons.api.data.EntityCollection;
|
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
|
||||||
import org.apache.olingo.commons.api.data.ValueType;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
|
||||||
import org.apache.olingo.server.api.ODataLibraryException;
|
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
|
||||||
import org.apache.olingo.server.api.ServiceMetadata;
|
|
||||||
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
|
|
||||||
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
|
||||||
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
|
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
|
||||||
import org.apache.olingo.server.api.serializer.SerializerResult;
|
|
||||||
import org.apache.olingo.server.api.uri.UriInfo;
|
|
||||||
import org.apache.olingo.server.api.uri.UriParameter;
|
|
||||||
import org.apache.olingo.server.api.uri.UriResource;
|
|
||||||
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
|
||||||
import org.baeldung.examples.olingo4.repository.RepositoryRegistry;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class JpaEntityCollectionProcessor implements CountEntityCollectionProcessor {
|
|
||||||
|
|
||||||
private OData odata;
|
|
||||||
private ServiceMetadata serviceMetadata;
|
|
||||||
private EntityManagerFactory emf;
|
|
||||||
private RepositoryRegistry repositoryRegistry;
|
|
||||||
private JpaEntityMapper entityMapper;
|
|
||||||
|
|
||||||
public JpaEntityCollectionProcessor(EntityManagerFactory emf, RepositoryRegistry repositoryRegistry, JpaEntityMapper entityMapper) {
|
|
||||||
this.emf = emf;
|
|
||||||
this.repositoryRegistry = repositoryRegistry;
|
|
||||||
this.entityMapper = entityMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(OData odata, ServiceMetadata serviceMetadata) {
|
|
||||||
this.odata = odata;
|
|
||||||
this.serviceMetadata = serviceMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
|
|
||||||
// 1st we have retrieve the requested EntitySet from the uriInfo object (representation of the parsed service URI)
|
|
||||||
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
|
|
||||||
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); // in our example, the first segment is the EntitySet
|
|
||||||
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
|
|
||||||
|
|
||||||
// 2nd: fetch the data from backend for this requested EntitySetName
|
|
||||||
// it has to be delivered as EntitySet object
|
|
||||||
EntityCollection entitySet = getData(edmEntitySet, uriInfo);
|
|
||||||
|
|
||||||
// 3rd: create a serializer based on the requested format (json)
|
|
||||||
ODataSerializer serializer = odata.createSerializer(responseFormat);
|
|
||||||
|
|
||||||
// 4th: Now serialize the content: transform from the EntitySet object to InputStream
|
|
||||||
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
|
|
||||||
ContextURL contextUrl = ContextURL.with()
|
|
||||||
.entitySet(edmEntitySet)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
|
||||||
EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
|
|
||||||
.id(id)
|
|
||||||
.contextURL(contextUrl)
|
|
||||||
.build();
|
|
||||||
SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
|
|
||||||
InputStream serializedContent = serializerResult.getContent();
|
|
||||||
|
|
||||||
// Finally: configure the response object: set the body, headers and status code
|
|
||||||
response.setContent(serializedContent);
|
|
||||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void countEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
|
|
||||||
// 1st we have retrieve the requested EntitySet from the uriInfo object (representation of the parsed service URI)
|
|
||||||
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
|
|
||||||
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); // in our example, the first segment is the EntitySet
|
|
||||||
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
|
|
||||||
|
|
||||||
// 2nd: fetch the data from backend for this requested EntitySetName
|
|
||||||
Long count = getCount(edmEntitySet, uriInfo);
|
|
||||||
|
|
||||||
// Finally: configure the response object: set the body, headers and status code
|
|
||||||
response.setContent(new ByteArrayInputStream(count.toString().getBytes()));
|
|
||||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE, "text/plain");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to retrieve all entities of an entity set from an the backend database
|
|
||||||
* @param edmEntitySet
|
|
||||||
* @param uriInfo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected EntityCollection getData(EdmEntitySet edmEntitySet, UriInfo uriInfo) {
|
|
||||||
|
|
||||||
EdmEntityType type = edmEntitySet.getEntityType();
|
|
||||||
JpaRepository<?, ?> repo = (JpaRepository<?, ?>)repositoryRegistry.getRepositoryForEntity(type);
|
|
||||||
EntityCollection result = new EntityCollection();
|
|
||||||
|
|
||||||
repo.findAll()
|
|
||||||
.stream()
|
|
||||||
.forEach((it) -> result.getEntities()
|
|
||||||
.add(entityMapper.map2entity(edmEntitySet, it)));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get the total size of an entity set
|
|
||||||
* @param edmEntitySet
|
|
||||||
* @param uriInfo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected Long getCount(EdmEntitySet edmEntitySet, UriInfo uriInfo) {
|
|
||||||
|
|
||||||
EdmEntityType type = edmEntitySet.getEntityType();
|
|
||||||
JpaRepository<?, ?> repo = (JpaRepository<?, ?>)repositoryRegistry.getRepositoryForEntity(type);
|
|
||||||
EntityCollection result = new EntityCollection();
|
|
||||||
|
|
||||||
return repo.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.baeldung.examples.olingo4.processor;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.metamodel.EntityType;
|
|
||||||
|
|
||||||
import org.apache.commons.beanutils.PropertyUtils;
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
|
||||||
import org.apache.olingo.commons.api.data.ValueType;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Helper class that converts a JPA entity into an OData entity using
|
|
||||||
* available metadata from the JPA's EntityManagerFactory.</p>
|
|
||||||
*
|
|
||||||
* @author Philippe
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class JpaEntityMapper {
|
|
||||||
|
|
||||||
private EntityManagerFactory emf;
|
|
||||||
|
|
||||||
public JpaEntityMapper(EntityManagerFactory emf) {
|
|
||||||
this.emf = emf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Entity map2entity(EdmEntitySet edmEntitySet, Object entry) {
|
|
||||||
|
|
||||||
EntityType<?> et = emf.getMetamodel()
|
|
||||||
.entity(entry.getClass());
|
|
||||||
|
|
||||||
|
|
||||||
Entity e = new Entity();
|
|
||||||
try {
|
|
||||||
et.getDeclaredSingularAttributes().stream()
|
|
||||||
.forEach( (attr) -> {
|
|
||||||
if ( !attr.isAssociation()) {
|
|
||||||
Object v = getPropertyValue(entry,attr.getName());
|
|
||||||
Property p = new Property(null, attr.getName(),ValueType.PRIMITIVE,v);
|
|
||||||
e.addProperty(p);
|
|
||||||
|
|
||||||
if ( attr.isId()) {
|
|
||||||
e.setId(createId(edmEntitySet.getName(),v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new ODataRuntimeException("[E141] Unable to create OData entity", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Object getPropertyValue(Object entry, String name) {
|
|
||||||
try {
|
|
||||||
return PropertyUtils.getProperty(entry,name);
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
|
||||||
throw new ODataRuntimeException("[E141] Unable to read property from entity, property=" + name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPropertyValue(Object entry, String name,Object value) {
|
|
||||||
try {
|
|
||||||
PropertyUtils.setProperty(entry,name,value);
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
|
||||||
throw new ODataRuntimeException("[E141] Unable to read property from entity, property=" + name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private URI createId(String entitySetName, Object id) {
|
|
||||||
try {
|
|
||||||
return new URI(entitySetName + "(" + String.valueOf(id) + ")");
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new ODataRuntimeException("[E177] Unable to create URI", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,304 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.baeldung.examples.olingo4.processor;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
|
||||||
import org.apache.olingo.server.api.ODataLibraryException;
|
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
|
||||||
import org.apache.olingo.server.api.ServiceMetadata;
|
|
||||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
|
||||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
|
||||||
import org.apache.olingo.server.api.serializer.SerializerResult;
|
|
||||||
import org.apache.olingo.server.api.uri.UriInfo;
|
|
||||||
import org.apache.olingo.server.api.uri.UriParameter;
|
|
||||||
import org.apache.olingo.server.api.uri.UriResource;
|
|
||||||
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
|
||||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
|
||||||
import org.baeldung.examples.olingo4.repository.EdmEntityRepository;
|
|
||||||
import org.baeldung.examples.olingo4.repository.RepositoryRegistry;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JpaEntityProcessor adapter.
|
|
||||||
* <p>This implementation is heavily based on the Tutorial available
|
|
||||||
* at Olingo's site. It is meant to be an starting point for an actual implementation.</p>
|
|
||||||
* <p>Please note that many features from a full-fledged are missing
|
|
||||||
* @author Philippe
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class JpaEntityProcessor implements EntityProcessor {
|
|
||||||
|
|
||||||
private EntityManagerFactory emf;
|
|
||||||
private OData odata;
|
|
||||||
private ServiceMetadata serviceMetadata;
|
|
||||||
private RepositoryRegistry registry;
|
|
||||||
private JpaEntityMapper entityMapper;
|
|
||||||
|
|
||||||
public JpaEntityProcessor(EntityManagerFactory emf, RepositoryRegistry registry, JpaEntityMapper entityMapper) {
|
|
||||||
this.emf = emf;
|
|
||||||
this.registry = registry;
|
|
||||||
this.entityMapper = entityMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.server.api.processor.Processor#init(org.apache.olingo.server.api.OData, org.apache.olingo.server.api.ServiceMetadata)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init(OData odata, ServiceMetadata serviceMetadata) {
|
|
||||||
this.odata = odata;
|
|
||||||
this.serviceMetadata = serviceMetadata;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.server.api.processor.EntityProcessor#readEntity(org.apache.olingo.server.api.ODataRequest, org.apache.olingo.server.api.ODataResponse, org.apache.olingo.server.api.uri.UriInfo, org.apache.olingo.commons.api.format.ContentType)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
|
|
||||||
// First, we have to figure out which entity is requested
|
|
||||||
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
|
|
||||||
InputStream entityStream;
|
|
||||||
|
|
||||||
UriResourceEntitySet rootResourceEntitySet = (UriResourceEntitySet) resourceParts.get(0);
|
|
||||||
EdmEntitySet rootEntitySet = rootResourceEntitySet.getEntitySet();
|
|
||||||
List<UriParameter> rootPredicates = rootResourceEntitySet.getKeyPredicates();
|
|
||||||
|
|
||||||
if ( resourceParts.size() == 1 ) {
|
|
||||||
entityStream = readRootEntity(rootEntitySet,rootPredicates,responseFormat);
|
|
||||||
}
|
|
||||||
else if ( resourceParts.size() == 2 ) {
|
|
||||||
UriResource part = resourceParts.get(1);
|
|
||||||
if ( !(part instanceof UriResourceNavigation)) {
|
|
||||||
throw new ODataRuntimeException("[E103] part type not supported: class=" + part.getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
UriResourceNavigation navSegment = (UriResourceNavigation)part;
|
|
||||||
entityStream = readRelatedEntity(request, rootEntitySet,rootPredicates,navSegment.getProperty(),navSegment.getKeyPredicates(),responseFormat);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// For now, we'll only allow navigation just to directly linked navs
|
|
||||||
throw new ODataApplicationException("[E109] Multi-level navigation not supported", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//4. configure the response object
|
|
||||||
response.setContent(entityStream);
|
|
||||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Lookup the EntitySet associated with an EntityType
|
|
||||||
// In our example, we assume we have only one entityset for each entity type
|
|
||||||
private EdmEntitySet entitySetFromType(EdmEntityType type) {
|
|
||||||
return serviceMetadata
|
|
||||||
.getEdm()
|
|
||||||
.getEntityContainer()
|
|
||||||
.getEntitySets()
|
|
||||||
.stream()
|
|
||||||
.filter((s) -> s.getEntityType().getName().equals(type.getName()))
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new ODataRuntimeException("[E144] No entity set found for type " + type.getFullQualifiedName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// private boolean isOne2ManyProperty(EdmEntityType entityType, EdmNavigationProperty property) {
|
|
||||||
// return entityType.getProperty(property.getName()) != null && property.isCollection();
|
|
||||||
//}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
private InputStream readRootEntity(EdmEntitySet entitySet, List<UriParameter> keyPredicates,ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
EdmEntityType type = entitySet.getEntityType();
|
|
||||||
JpaRepository repo = registry.getRepositoryForEntity(type);
|
|
||||||
|
|
||||||
// Get key value
|
|
||||||
Long keyValue = getEntityKey(keyPredicates);
|
|
||||||
Optional<Object> entry = repo.findById(keyValue);
|
|
||||||
if ( !entry.isPresent()) {
|
|
||||||
throw new ODataApplicationException(
|
|
||||||
"[E116] NO entity found for the given key",
|
|
||||||
HttpStatusCode.NOT_FOUND.getStatusCode(),
|
|
||||||
Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity e = entityMapper.map2entity(entitySet, entry.get());
|
|
||||||
return serializeEntity(entitySet,e,responseFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream serializeEntity(EdmEntitySet entitySet, Entity entity,ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
ContextURL contextUrl = ContextURL.with().entitySet(entitySet).build();
|
|
||||||
// expand and select currently not supported
|
|
||||||
EntitySerializerOptions options = EntitySerializerOptions
|
|
||||||
.with()
|
|
||||||
.contextURL(contextUrl)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
ODataSerializer serializer = odata.createSerializer(responseFormat);
|
|
||||||
|
|
||||||
SerializerResult serializerResult = serializer.entity(serviceMetadata, entitySet.getEntityType(), entity, options);
|
|
||||||
return serializerResult.getContent();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SuppressWarnings("unchecked")
|
|
||||||
// protected InputStream readRelatedEntities(EdmEntitySet rootEntitySet, List<UriParameter> rootPredicates, EdmNavigationProperty property, ContentType responseFormat) throws ODataApplicationException {
|
|
||||||
//
|
|
||||||
// Object jpaEntity = readJPAEntity(rootEntitySet, rootPredicates);
|
|
||||||
// try {
|
|
||||||
// Collection<Object> set = (Collection<Object>)PropertyUtils.getProperty(jpaEntity, property.getName());
|
|
||||||
// EdmEntitySet entitySet = entitySetFromType(property.getType());
|
|
||||||
// ContextURL contextUrl = ContextURL
|
|
||||||
// .with()
|
|
||||||
// .entitySet(entitySet)
|
|
||||||
// .build();
|
|
||||||
//
|
|
||||||
// EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions
|
|
||||||
// .with()
|
|
||||||
// .contextURL(contextUrl)
|
|
||||||
// .build();
|
|
||||||
//
|
|
||||||
// EntityCollection result = new EntityCollection();
|
|
||||||
//
|
|
||||||
// set.stream()
|
|
||||||
// .map((o) -> this.entityMapper.map2entity(entitySet, o))
|
|
||||||
// .forEach((e) -> result.getEntities().add(e));
|
|
||||||
//
|
|
||||||
// ODataSerializer serializer = odata.createSerializer(responseFormat);
|
|
||||||
// SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, property.getType(), result, options);
|
|
||||||
// return serializerResult.getContent();
|
|
||||||
// }
|
|
||||||
// catch(Exception ex) {
|
|
||||||
// throw new ODataRuntimeException("[E181] Error accessing database", ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
private InputStream readRelatedEntity(ODataRequest request, EdmEntitySet entitySet, List<UriParameter> rootPredicates, EdmNavigationProperty property, List<UriParameter> parentPredicates, ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
|
|
||||||
|
|
||||||
JpaRepository<Object,Object> repo = (JpaRepository<Object,Object>)registry.getRepositoryForEntity(entitySet.getEntityType());
|
|
||||||
EdmEntityRepository<Object> relatedRepo = (EdmEntityRepository<Object>)registry.getRepositoryForEntity(property.getType());
|
|
||||||
|
|
||||||
// We assume here that we have a bi-directional 1:N relationship, so we'll
|
|
||||||
// always have a property in the child entity that points to the parent
|
|
||||||
Class<?> rootClass = ((EdmEntityRepository)repo).getEntityClass();
|
|
||||||
Class<?> relatedClass = ((EdmEntityRepository)relatedRepo).getEntityClass();
|
|
||||||
|
|
||||||
SingularAttribute fk = emf.getMetamodel()
|
|
||||||
.entity(rootClass)
|
|
||||||
.getSingularAttributes()
|
|
||||||
.stream()
|
|
||||||
.filter((attr) -> {
|
|
||||||
boolean b = attr.isAssociation() && attr.getJavaType().isAssignableFrom(relatedClass);
|
|
||||||
return b;
|
|
||||||
})
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
if ( fk == null ) {
|
|
||||||
throw new ODataRuntimeException("[E230] No singular attribute of child class '" + relatedClass.getName() + "' found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
Long pkValue = getEntityKey(rootPredicates);
|
|
||||||
EntityManager em = this.emf.createEntityManager();
|
|
||||||
try {
|
|
||||||
// Read data from DB
|
|
||||||
Object root = em.find(rootClass, pkValue);
|
|
||||||
Object related = this.entityMapper.getPropertyValue(root, fk.getName());
|
|
||||||
|
|
||||||
EdmEntitySet relatedEntitySet = entitySetFromType(property.getType());
|
|
||||||
Entity e = entityMapper.map2entity(relatedEntitySet, related);
|
|
||||||
return serializeEntity(relatedEntitySet,e,responseFormat);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @SuppressWarnings("unchecked")
|
|
||||||
// private Object readJPAEntity(EdmEntitySet edmEntitySet, List<UriParameter> keyPredicates) throws ODataApplicationException {
|
|
||||||
// EdmEntityType type = edmEntitySet.getEntityType();
|
|
||||||
// JpaRepository<Object,Object> repo = (JpaRepository<Object,Object>)registry.getRepositoryForEntity(type);
|
|
||||||
//
|
|
||||||
// // Get key value
|
|
||||||
// Object keyValue = getEntityKey(type,keyPredicates);
|
|
||||||
// Object entry = repo
|
|
||||||
// .findById(keyValue)
|
|
||||||
// .orElseThrow(
|
|
||||||
// () -> new ODataApplicationException("[E116] NO entity found for the given key",
|
|
||||||
// HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH));
|
|
||||||
//
|
|
||||||
// return entry;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private Long getEntityKey(List<UriParameter> keyPredicates) {
|
|
||||||
|
|
||||||
if ( keyPredicates.size() > 1 ) {
|
|
||||||
throw new ODataRuntimeException("[E131] Composite keys are not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
// For now, we'll assume we only have numeric keys.
|
|
||||||
UriParameter keyParam = keyPredicates.get(0);
|
|
||||||
try {
|
|
||||||
return Long.parseLong(keyParam.getText());
|
|
||||||
}
|
|
||||||
catch(NumberFormatException nfe) {
|
|
||||||
throw new ODataRuntimeException("[E140] Invalid key value. Only numeric keys are supported by this service");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.server.api.processor.EntityProcessor#createEntity(org.apache.olingo.server.api.ODataRequest, org.apache.olingo.server.api.ODataResponse, org.apache.olingo.server.api.uri.UriInfo, org.apache.olingo.commons.api.format.ContentType, org.apache.olingo.commons.api.format.ContentType)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.server.api.processor.EntityProcessor#updateEntity(org.apache.olingo.server.api.ODataRequest, org.apache.olingo.server.api.ODataResponse, org.apache.olingo.server.api.uri.UriInfo, org.apache.olingo.commons.api.format.ContentType, org.apache.olingo.commons.api.format.ContentType)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.olingo.server.api.processor.EntityProcessor#deleteEntity(org.apache.olingo.server.api.ODataRequest, org.apache.olingo.server.api.ODataResponse, org.apache.olingo.server.api.uri.UriInfo)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void deleteEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.repository;
|
|
||||||
|
|
||||||
import org.baeldung.examples.olingo4.domain.CarMaker;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface CarMakerRepository extends EdmEntityRepository<CarMaker>, JpaRepository<CarMaker, Long>, JpaSpecificationExecutor<CarMaker> {
|
|
||||||
|
|
||||||
public default String getEdmEntityName() { return CarMaker.class.getSimpleName();}
|
|
||||||
@Override
|
|
||||||
default Class<CarMaker> getEntityClass() {
|
|
||||||
return CarMaker.class;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.baeldung.examples.olingo4.domain.CarModel;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface CarModelRepository extends EdmEntityRepository<CarModel>, JpaRepository<CarModel, Long>, JpaSpecificationExecutor<CarModel> {
|
|
||||||
|
|
||||||
public List<CarModel> findByMakerId(Long makerId);
|
|
||||||
|
|
||||||
public default String getEdmEntityName() { return CarModel.class.getSimpleName();}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default Class<CarModel> getEntityClass() {
|
|
||||||
return CarModel.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.baeldung.examples.olingo4.repository;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Philippe
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface EdmEntityRepository<E> {
|
|
||||||
|
|
||||||
public String getEdmEntityName();
|
|
||||||
public Class<E> getEntityClass();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4.repository;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class RepositoryRegistry {
|
|
||||||
|
|
||||||
private Map<String,JpaRepository<?,?>> repositoriesByClassName = new HashMap<>();
|
|
||||||
|
|
||||||
public RepositoryRegistry(List<EdmEntityRepository<?>> allRepositories) {
|
|
||||||
|
|
||||||
allRepositories.stream()
|
|
||||||
.forEach((r) ->
|
|
||||||
repositoriesByClassName.put(r.getEdmEntityName(),(JpaRepository<?,?>)r));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public JpaRepository<?,?> getRepositoryForEntity(EdmEntityType entityType) {
|
|
||||||
JpaRepository<?,?> repo = repositoriesByClassName.get(entityType.getName());
|
|
||||||
return repo;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
server:
|
|
||||||
port: 8080
|
|
||||||
|
|
||||||
spring:
|
|
||||||
jpa:
|
|
||||||
show-sql: true
|
|
||||||
open-in-view: true
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: update
|
|
|
@ -1,12 +0,0 @@
|
||||||
insert into car_maker(id,name) values (1,'Special Motors');
|
|
||||||
insert into car_maker(id,name) values (2,'BWM');
|
|
||||||
insert into car_maker(id,name) values (3,'Dolores');
|
|
||||||
|
|
||||||
insert into car_model(id,maker_fk,name,sku,year) values(1,1,'Muze','SM001',2018);
|
|
||||||
insert into car_model(id,maker_fk,name,sku,year) values(2,1,'Empada','SM002',2008);
|
|
||||||
|
|
||||||
insert into car_model(id,maker_fk,name,sku,year) values(4,2,'BWM-100','BWM100',2008);
|
|
||||||
insert into car_model(id,maker_fk,name,sku,year) values(5,2,'BWM-200','BWM200',2009);
|
|
||||||
insert into car_model(id,maker_fk,name,sku,year) values(6,2,'BWM-300','BWM300',2008);
|
|
||||||
|
|
||||||
alter sequence hibernate_sequence restart with 100;
|
|
|
@ -1,16 +0,0 @@
|
||||||
package org.baeldung.examples.olingo4;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class Olingo4SampleApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
/target
|
||||||
|
/classes
|
||||||
|
/checkouts
|
||||||
|
profiles.clj
|
||||||
|
pom.xml
|
||||||
|
pom.xml.asc
|
||||||
|
*.jar
|
||||||
|
*.class
|
||||||
|
/.lein-*
|
||||||
|
/.nrepl-port
|
||||||
|
.hgignore
|
||||||
|
.hg/
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Clojure Ring Examples
|
||||||
|
|
||||||
|
This project acts as a set of examples for the Clojure Ring library.
|
||||||
|
|
||||||
|
## Runing the examples
|
||||||
|
|
||||||
|
The examples can all be run from the Leiningen REPL.
|
||||||
|
|
||||||
|
Firstly, start the REPL with `lein repl`. Then the examples can be executed with:
|
||||||
|
|
||||||
|
* `(run simple-handler)` - A simple handler that just echos a constant string to the client
|
||||||
|
* `(run check-ip-handler)` - A handler that echos the clients IP Address back to them
|
||||||
|
* `(run echo-handler)` - A handler that echos the value of the "input" parameter back
|
||||||
|
* `(run request-count-handler)` - A handler with a session that tracks how many times this session has requested this handler
|
||||||
|
|
||||||
|
In all cases, the handlers can be accessed on http://localhost:3000.
|
||||||
|
|
||||||
|
## Relevant Articles
|
||||||
|
- [Writing Clojure Webapps with Ring](https://www.baeldung.com/clojure-ring)
|
|
@ -0,0 +1,8 @@
|
||||||
|
(defproject baeldung-ring "0.1.0-SNAPSHOT"
|
||||||
|
:dependencies [[org.clojure/clojure "1.10.0"]
|
||||||
|
[ring/ring-core "1.7.1"]
|
||||||
|
[ring/ring-jetty-adapter "1.7.1"]
|
||||||
|
[ring/ring-devel "1.7.1"]]
|
||||||
|
:plugins [[lein-ring "0.12.5"]]
|
||||||
|
:ring {:handler ring.core/simple-handler}
|
||||||
|
:repl-options {:init-ns ring.core})
|
|
@ -0,0 +1,48 @@
|
||||||
|
(ns ring.core
|
||||||
|
(:use ring.adapter.jetty
|
||||||
|
[ring.middleware.content-type]
|
||||||
|
[ring.middleware.cookies]
|
||||||
|
[ring.middleware.params]
|
||||||
|
[ring.middleware.session]
|
||||||
|
[ring.middleware.session.cookie]
|
||||||
|
[ring.util.response]))
|
||||||
|
|
||||||
|
;; Handler that just echos back the string "Hello World"
|
||||||
|
(defn simple-handler [request]
|
||||||
|
{:status 200
|
||||||
|
:headers {"Content-Type" "text/plain"}
|
||||||
|
:body "Hello World"})
|
||||||
|
|
||||||
|
;; Handler that echos back the clients IP Address
|
||||||
|
;; This demonstrates building responses properly, and extracting values from the request
|
||||||
|
(defn check-ip-handler [request]
|
||||||
|
(content-type
|
||||||
|
(response (:remote-addr request))
|
||||||
|
"text/plain"))
|
||||||
|
|
||||||
|
;; Handler that echos back the incoming parameter "input"
|
||||||
|
;; This demonstrates middleware chaining and accessing parameters
|
||||||
|
(def echo-handler
|
||||||
|
(-> (fn [{params :params}]
|
||||||
|
(content-type
|
||||||
|
(response (get params "input"))
|
||||||
|
"text/plain"))
|
||||||
|
(wrap-params {:encoding "UTF-8"})
|
||||||
|
))
|
||||||
|
|
||||||
|
;; Handler that keeps track of how many times each session has accessed the service
|
||||||
|
;; This demonstrates cookies and sessions
|
||||||
|
(def request-count-handler
|
||||||
|
(-> (fn [{session :session}]
|
||||||
|
(let [count (:count session 0)
|
||||||
|
session (assoc session :count (inc count))]
|
||||||
|
(-> (response (str "You accessed this page " count " times."))
|
||||||
|
(assoc :session session))))
|
||||||
|
wrap-cookies
|
||||||
|
(wrap-session {:cookie-attrs {:max-age 3600}})
|
||||||
|
))
|
||||||
|
|
||||||
|
;; Run the provided handler on port 3000
|
||||||
|
(defn run
|
||||||
|
[h]
|
||||||
|
(run-jetty h {:port 3000}))
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.error;
|
||||||
|
|
||||||
|
public class ErrorGenerator {
|
||||||
|
public void throwException() throws Exception {
|
||||||
|
throw new Exception("checked");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void throwRuntimeException() {
|
||||||
|
throw new RuntimeException("unchecked");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void throwError() {
|
||||||
|
throw new Error("unchecked");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.baeldung.error;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ErrorGeneratorUnitTest {
|
||||||
|
|
||||||
|
private ErrorGenerator errorGenerator;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
errorGenerator = new ErrorGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckedException_thenIsCaughtByCatchException() {
|
||||||
|
try {
|
||||||
|
errorGenerator.throwException();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// caught! -> test pass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUncheckedException_thenIsCaughtByCatchException() {
|
||||||
|
try {
|
||||||
|
errorGenerator.throwRuntimeException();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// caught! -> test pass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = Error.class)
|
||||||
|
public void whenError_thenIsNotCaughtByCatchException() {
|
||||||
|
try {
|
||||||
|
errorGenerator.throwError();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail(); // errors are not caught by catch exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenError_thenIsCaughtByCatchError() {
|
||||||
|
try {
|
||||||
|
errorGenerator.throwError();
|
||||||
|
} catch (Error e) {
|
||||||
|
// caught! -> test pass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-11</artifactId>
|
<artifactId>core-java-11</artifactId>
|
||||||
|
@ -12,7 +14,7 @@
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>../../</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -21,6 +23,12 @@
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${guava.version}</version>
|
<version>${guava.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -41,6 +49,7 @@
|
||||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||||
<guava.version>27.1-jre</guava.version>
|
<guava.version>27.1-jre</guava.version>
|
||||||
|
<assertj.version>3.11.1</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.baeldung.predicate.not;
|
||||||
|
|
||||||
|
public class Person {
|
||||||
|
private static final int ADULT_AGE = 18;
|
||||||
|
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
public Person(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdult() {
|
||||||
|
return age >= ADULT_AGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotAdult() {
|
||||||
|
return !isAdult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import junit.framework.TestSuite;
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class AppTest
|
public class AppUnitTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,7 @@ public class AppTest
|
||||||
*
|
*
|
||||||
* @param testName name of the test case
|
* @param testName name of the test case
|
||||||
*/
|
*/
|
||||||
public AppTest( String testName )
|
public AppUnitTest(String testName )
|
||||||
{
|
{
|
||||||
super( testName );
|
super( testName );
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class AppTest
|
||||||
*/
|
*/
|
||||||
public static Test suite()
|
public static Test suite()
|
||||||
{
|
{
|
||||||
return new TestSuite( AppTest.class );
|
return new TestSuite( AppUnitTest.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -32,7 +32,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class HttpClientTest {
|
public class HttpClientUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException {
|
|
@ -19,7 +19,7 @@ import java.time.Duration;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HttpRequestTest {
|
public class HttpRequestUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
|
@ -14,7 +14,7 @@ import java.net.http.HttpResponse;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HttpResponseTest {
|
public class HttpResponseUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException {
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.baeldung.predicate.not;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.function.Predicate.not;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class PersonUnitTest {
|
||||||
|
private List<Person> people;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void preparePeople() {
|
||||||
|
people = Arrays.asList(
|
||||||
|
new Person(1),
|
||||||
|
new Person(18),
|
||||||
|
new Person(2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenPeople_whenFilterIsAdult_thenOneResult() {
|
||||||
|
List<Person> adults = people.stream()
|
||||||
|
.filter(Person::isAdult)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertThat(adults).size().isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenPeople_whenFilterIsAdultNegated_thenTwoResults() {
|
||||||
|
List<Person> nonAdults = people.stream()
|
||||||
|
.filter(person -> !person.isAdult())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertThat(nonAdults).size().isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenPeople_whenFilterIsNotAdult_thenTwoResults() {
|
||||||
|
List<Person> nonAdults = people.stream()
|
||||||
|
.filter(Person::isNotAdult)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertThat(nonAdults).size().isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenPeople_whenFilterNotIsAdult_thenTwoResults() {
|
||||||
|
List<Person> nonAdults = people.stream()
|
||||||
|
.filter(not(Person::isAdult))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertThat(nonAdults).size().isEqualTo(2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
package com.baeldung.delay;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class Delay {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws InterruptedException {
|
||||||
|
|
||||||
|
threadSleep(4, 1);
|
||||||
|
|
||||||
|
timeunitSleep(4, 1);
|
||||||
|
|
||||||
|
delayedServiceTask(5);
|
||||||
|
|
||||||
|
fixedRateServiceTask(5);
|
||||||
|
|
||||||
|
System.out.println("Done.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void threadSleep(Integer iterations, Integer secondsToSleep) {
|
||||||
|
|
||||||
|
for (Integer i = 0; i < iterations; i++) {
|
||||||
|
|
||||||
|
System.out.println("This is loop iteration number " + i.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(secondsToSleep * 1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void timeunitSleep(Integer iterations, Integer secondsToSleep) {
|
||||||
|
|
||||||
|
for (Integer i = 0; i < iterations; i++) {
|
||||||
|
|
||||||
|
System.out.println("This is loop iteration number " + i.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(secondsToSleep);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void delayedServiceTask(Integer delayInSeconds) {
|
||||||
|
|
||||||
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
|
executorService.schedule(Delay::someTask1, delayInSeconds, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fixedRateServiceTask(Integer delayInSeconds) {
|
||||||
|
|
||||||
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
|
ScheduledFuture<?> sf = executorService.scheduleAtFixedRate(Delay::someTask2, 0, delayInSeconds,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(20);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
sf.cancel(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void someTask1() {
|
||||||
|
System.out.println("Task 1 completed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void someTask2() {
|
||||||
|
System.out.println("Task 2 completed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
public class Slf4jLogger implements System.Logger {
|
public class Slf4jLogger implements System.Logger {
|
||||||
|
|
||||||
|
@ -74,26 +75,27 @@ public class Slf4jLogger implements System.Logger {
|
||||||
if (!isLoggable(level)) {
|
if (!isLoggable(level)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String message = MessageFormat.format(format, params);
|
||||||
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case TRACE:
|
case TRACE:
|
||||||
logger.trace(format, params);
|
logger.trace(message);
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
logger.debug(format, params);
|
logger.debug(message);
|
||||||
break;
|
break;
|
||||||
case INFO:
|
case INFO:
|
||||||
logger.info(format, params);
|
logger.info(message);
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
logger.warn(format, params);
|
logger.warn(message);
|
||||||
break;
|
break;
|
||||||
case ERROR:
|
case ERROR:
|
||||||
logger.error(format, params);
|
logger.error(message);
|
||||||
break;
|
break;
|
||||||
case ALL:
|
case ALL:
|
||||||
default:
|
default:
|
||||||
logger.info(format, params);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class NumberFormatExceptionUnitTest {
|
||||||
|
|
||||||
@Test(expected = NumberFormatException.class)
|
@Test(expected = NumberFormatException.class)
|
||||||
public void givenParseIntMethod_whenUnderscoreInInput_thenFail() {
|
public void givenParseIntMethod_whenUnderscoreInInput_thenFail() {
|
||||||
int bIntPrim = Integer.parseInt("6_000");
|
int bIntPrim = Integer.parseInt("_6000");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NumberFormatException.class)
|
@Test(expected = NumberFormatException.class)
|
||||||
|
@ -51,7 +51,7 @@ public class NumberFormatExceptionUnitTest {
|
||||||
|
|
||||||
@Test(expected = NumberFormatException.class)
|
@Test(expected = NumberFormatException.class)
|
||||||
public void givenDecodeMethod_whenAlphabetInInput_thenFail() {
|
public void givenDecodeMethod_whenAlphabetInInput_thenFail() {
|
||||||
Long decodeInteger = Long.decode("64403L");
|
Long decodedLong = Long.decode("64403L");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---INTEGER PASS CASES--- */
|
/* ---INTEGER PASS CASES--- */
|
||||||
|
@ -72,7 +72,7 @@ public class NumberFormatExceptionUnitTest {
|
||||||
int aIntPrim = Integer.parseInt("6000 ".trim());
|
int aIntPrim = Integer.parseInt("6000 ".trim());
|
||||||
assertEquals(6000, aIntPrim);
|
assertEquals(6000, aIntPrim);
|
||||||
|
|
||||||
int bIntPrim = Integer.parseInt("6_000".replaceAll("_", ""));
|
int bIntPrim = Integer.parseInt("_6000".replaceAll("_", ""));
|
||||||
assertEquals(6000, bIntPrim);
|
assertEquals(6000, bIntPrim);
|
||||||
|
|
||||||
int cIntPrim = Integer.parseInt("-6000");
|
int cIntPrim = Integer.parseInt("-6000");
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>consumermodule</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.decoupling-pattern1</groupId>
|
||||||
|
<artifactId>decoupling-pattern1</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.servicemodule</groupId>
|
||||||
|
<artifactId>servicemodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.baeldung.consumermodule;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.external.TextService;
|
||||||
|
import com.baeldung.servicemodule.external.TextServiceFactory;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
TextService textService = TextServiceFactory.getTextService("lowercase");
|
||||||
|
System.out.println(textService.processText("Hello from Baeldung!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module com.baeldung.consumermodule {
|
||||||
|
requires com.baeldung.servicemodule;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung.decoupling-pattern1</groupId>
|
||||||
|
<artifactId>decoupling-pattern1</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>servicemodule</module>
|
||||||
|
<module>consumermodule</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>11</source>
|
||||||
|
<target>11</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</project>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.baeldung.servicemodule</groupId>
|
||||||
|
<artifactId>servicemodule</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.decoupling-pattern1</groupId>
|
||||||
|
<artifactId>decoupling-pattern1</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.baeldung.servicemodule.external;
|
||||||
|
|
||||||
|
public interface TextService {
|
||||||
|
|
||||||
|
String processText(String text);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.baeldung.servicemodule.external;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.internal.LowercaseTextService;
|
||||||
|
import com.baeldung.servicemodule.internal.UppercaseTextService;
|
||||||
|
|
||||||
|
public class TextServiceFactory {
|
||||||
|
|
||||||
|
private TextServiceFactory() {}
|
||||||
|
|
||||||
|
public static TextService getTextService(String name) {
|
||||||
|
return name.equalsIgnoreCase("lowercase") ? new LowercaseTextService(): new UppercaseTextService();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.servicemodule.internal;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.external.TextService;
|
||||||
|
|
||||||
|
public class LowercaseTextService implements TextService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String processText(String text) {
|
||||||
|
return text.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.servicemodule.internal;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.external.TextService;
|
||||||
|
|
||||||
|
public class UppercaseTextService implements TextService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String processText(String text) {
|
||||||
|
return text.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module com.baeldung.servicemodule {
|
||||||
|
exports com.baeldung.servicemodule.external;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>com.baeldung.decoupling-pattern2</artifactId>
|
||||||
|
<groupId>decoupling-pattern2</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.baeldung.consumermodule</groupId>
|
||||||
|
<artifactId>consumermodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.servicemodule</groupId>
|
||||||
|
<artifactId>servicemodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.providermodule</groupId>
|
||||||
|
<artifactId>providermodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.consumermodule;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.TextService;
|
||||||
|
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ServiceLoader<TextService> services = ServiceLoader.load(TextService.class);
|
||||||
|
for (final TextService service: services) {
|
||||||
|
System.out.println("The service " + service.getClass().getSimpleName() + " says: " + service.parseText("Hello from Baeldung!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
module com.baeldung.consumermodule {
|
||||||
|
requires com.baeldung.servicemodule;
|
||||||
|
uses com.baeldung.servicemodule.TextService;
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.baeldung.decoupling-pattern2</groupId>
|
||||||
|
<artifactId>decoupling-pattern2</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>servicemodule</module>
|
||||||
|
<module>providermodule</module>
|
||||||
|
<module>consumermodule</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>11</source>
|
||||||
|
<target>11</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung.providermodule</groupId>
|
||||||
|
<artifactId>providermodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>com.baeldung.decoupling-pattern2</artifactId>
|
||||||
|
<groupId>decoupling-pattern2</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.servicemodule</groupId>
|
||||||
|
<artifactId>servicemodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.baeldung.providermodule;
|
||||||
|
|
||||||
|
import com.baeldung.servicemodule.TextService;
|
||||||
|
|
||||||
|
public class LowercaseTextService implements TextService {
|
||||||
|
@Override
|
||||||
|
public String parseText(String text) {
|
||||||
|
return text.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
module com.baeldung.providermodule {
|
||||||
|
requires com.baeldung.servicemodule;
|
||||||
|
provides com.baeldung.servicemodule.TextService with com.baeldung.providermodule.LowercaseTextService;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<artifactId>>com.baeldung.decoupling-pattern2</artifactId>
|
||||||
|
<groupId>decoupling-pattern2</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>com.baeldung.servicemodule</groupId>
|
||||||
|
<artifactId>servicemodule</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.baeldung.servicemodule;
|
||||||
|
|
||||||
|
public interface TextService {
|
||||||
|
|
||||||
|
String parseText(String text);
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module com.baeldung.servicemodule {
|
||||||
|
exports com.baeldung.servicemodule;
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
### Relevant Articles
|
||||||
|
|
||||||
|
- [Why Do Local Variables Used in Lambdas Have to Be Final or Effectively Final?](https://www.baeldung.com/java-lambda-effectively-final-local-variables)
|
|
@ -0,0 +1,5 @@
|
||||||
|
0.*
|
||||||
|
|
||||||
|
# Files generated by integration tests
|
||||||
|
# *.txt
|
||||||
|
/temp
|
|
@ -0,0 +1,16 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>core-java-nio</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<name>core-java-nio</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-java</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-java</relativePath>
|
||||||
|
</parent>
|
||||||
|
</project>
|
|
@ -0,0 +1,165 @@
|
||||||
|
package com.baeldung.filechannel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.MappedByteBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.channels.FileLock;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FileChannelUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFile_whenReadWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException {
|
||||||
|
|
||||||
|
try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
|
||||||
|
FileChannel channel = reader.getChannel();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
|
||||||
|
int bufferSize = 1024;
|
||||||
|
if (bufferSize > channel.size()) {
|
||||||
|
bufferSize = (int) channel.size();
|
||||||
|
}
|
||||||
|
ByteBuffer buff = ByteBuffer.allocate(bufferSize);
|
||||||
|
|
||||||
|
while (channel.read(buff) > 0) {
|
||||||
|
out.write(buff.array(), 0, buff.position());
|
||||||
|
buff.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
assertEquals("Hello world", fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFile_whenReadWithFileChannelUsingFileInputStream_thenCorrect() throws IOException {
|
||||||
|
|
||||||
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
FileInputStream fin = new FileInputStream("src/test/resources/test_read.in");
|
||||||
|
FileChannel channel = fin.getChannel()) {
|
||||||
|
|
||||||
|
int bufferSize = 1024;
|
||||||
|
if (bufferSize > channel.size()) {
|
||||||
|
bufferSize = (int) channel.size();
|
||||||
|
}
|
||||||
|
ByteBuffer buff = ByteBuffer.allocate(bufferSize);
|
||||||
|
|
||||||
|
while (channel.read(buff) > 0) {
|
||||||
|
out.write(buff.array(), 0, buff.position());
|
||||||
|
buff.clear();
|
||||||
|
}
|
||||||
|
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
assertEquals("Hello world", fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFile_whenReadAFileSectionIntoMemoryWithFileChannel_thenCorrect() throws IOException {
|
||||||
|
|
||||||
|
try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
|
||||||
|
FileChannel channel = reader.getChannel();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
|
||||||
|
MappedByteBuffer buff = channel.map(FileChannel.MapMode.READ_ONLY, 6, 5);
|
||||||
|
|
||||||
|
if (buff.hasRemaining()) {
|
||||||
|
byte[] data = new byte[buff.remaining()];
|
||||||
|
buff.get(data);
|
||||||
|
assertEquals("world", new String(data, StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWriteWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException {
|
||||||
|
String file = "src/test/resources/test_write_using_filechannel.txt";
|
||||||
|
try (RandomAccessFile writer = new RandomAccessFile(file, "rw");
|
||||||
|
FileChannel channel = writer.getChannel()) {
|
||||||
|
ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
channel.write(buff);
|
||||||
|
|
||||||
|
// now we verify whether the file was written correctly
|
||||||
|
RandomAccessFile reader = new RandomAccessFile(file, "r");
|
||||||
|
assertEquals("Hello world", reader.readLine());
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFile_whenWriteAFileUsingLockAFileSectionWithFileChannel_thenCorrect() throws IOException {
|
||||||
|
try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "rw");
|
||||||
|
FileChannel channel = reader.getChannel();
|
||||||
|
FileLock fileLock = channel.tryLock(6, 5, Boolean.FALSE);) {
|
||||||
|
|
||||||
|
assertNotNull(fileLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFile_whenReadWithFileChannelGetPosition_thenCorrect() throws IOException {
|
||||||
|
|
||||||
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
|
||||||
|
FileChannel channel = reader.getChannel()) {
|
||||||
|
|
||||||
|
int bufferSize = 1024;
|
||||||
|
if (bufferSize > channel.size()) {
|
||||||
|
bufferSize = (int) channel.size();
|
||||||
|
}
|
||||||
|
ByteBuffer buff = ByteBuffer.allocate(bufferSize);
|
||||||
|
|
||||||
|
while (channel.read(buff) > 0) {
|
||||||
|
out.write(buff.array(), 0, buff.position());
|
||||||
|
buff.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// the original file is 11 bytes long, so that's where the position pointer should be
|
||||||
|
assertEquals(11, channel.position());
|
||||||
|
|
||||||
|
channel.position(4);
|
||||||
|
assertEquals(4, channel.position());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetFileSize_thenCorrect() throws IOException {
|
||||||
|
|
||||||
|
try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
|
||||||
|
FileChannel channel = reader.getChannel()) {
|
||||||
|
|
||||||
|
// the original file is 11 bytes long, so that's where the position pointer should be
|
||||||
|
assertEquals(11, channel.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenTruncateFile_thenCorrect() throws IOException {
|
||||||
|
String input = "this is a test input";
|
||||||
|
|
||||||
|
FileOutputStream fout = new FileOutputStream("src/test/resources/test_truncate.txt");
|
||||||
|
FileChannel channel = fout.getChannel();
|
||||||
|
|
||||||
|
ByteBuffer buff = ByteBuffer.wrap(input.getBytes());
|
||||||
|
channel.write(buff);
|
||||||
|
buff.flip();
|
||||||
|
|
||||||
|
channel = channel.truncate(5);
|
||||||
|
assertEquals(5, channel.size());
|
||||||
|
|
||||||
|
fout.close();
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
*.class
|
||||||
|
|
||||||
|
#folders#
|
||||||
|
/target
|
||||||
|
/neoDb*
|
||||||
|
/data
|
||||||
|
/src/main/webapp/WEB-INF/classes
|
||||||
|
*/META-INF/*
|
||||||
|
|
||||||
|
# Packaged files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
|
@ -0,0 +1 @@
|
||||||
|
Hello world
|
|
@ -0,0 +1 @@
|
||||||
|
this
|
|
@ -0,0 +1 @@
|
||||||
|
Hello world
|
|
@ -5,6 +5,8 @@ import java.util.*
|
||||||
interface Document {
|
interface Document {
|
||||||
|
|
||||||
@JvmDefault
|
@JvmDefault
|
||||||
|
fun getTypeDefault() = "document"
|
||||||
|
|
||||||
fun getType() = "document"
|
fun getType() = "document"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +25,3 @@ class TextDocument : Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
class XmlDocument(d : Document) : Document by d
|
class XmlDocument(d : Document) : Document by d
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val myDocument = TextDocument()
|
|
||||||
val myTextDocument = XmlDocument(myDocument)
|
|
||||||
println("${myDocument.getType()} ${myTextDocument.getType()}")
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.range
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class DocumentTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testDefaultMethod() {
|
||||||
|
|
||||||
|
val myDocument = TextDocument()
|
||||||
|
val myTextDocument = XmlDocument(myDocument)
|
||||||
|
|
||||||
|
assertEquals("text", myDocument.getType())
|
||||||
|
assertEquals("text", myTextDocument.getType())
|
||||||
|
assertEquals("document", myTextDocument.getTypeDefault())
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ import org.junit.Test;
|
||||||
/**
|
/**
|
||||||
* BAEL-2832: Different ways to check if a Substring could be found in a String.
|
* BAEL-2832: Different ways to check if a Substring could be found in a String.
|
||||||
*/
|
*/
|
||||||
public class SubstringSearch {
|
public class SubstringSearchUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchSubstringWithIndexOf() {
|
public void searchSubstringWithIndexOf() {
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.baeldung.jersey.server;
|
||||||
|
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
|
public class ItemParam {
|
||||||
|
|
||||||
|
@HeaderParam("headerParam")
|
||||||
|
private String shopKey;
|
||||||
|
|
||||||
|
@PathParam("pathParam")
|
||||||
|
private String itemId;
|
||||||
|
|
||||||
|
@FormParam("formParam")
|
||||||
|
private String price;
|
||||||
|
|
||||||
|
public String getShopKey() {
|
||||||
|
return shopKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopKey(String shopKey) {
|
||||||
|
this.shopKey = shopKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemId(String itemId) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(String price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ItemParam{shopKey='" + shopKey + ", itemId='" + itemId + ", price='" + price + '}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.baeldung.jersey.server;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
|
||||||
|
@Path("items")
|
||||||
|
public class Items {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/cookie")
|
||||||
|
public String readCookieParam(@CookieParam("cookieParamToRead") String cookieParamToRead) {
|
||||||
|
return "Cookie parameter value is [" + cookieParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/header")
|
||||||
|
public String readHeaderParam(@HeaderParam("headerParamToRead") String headerParamToRead) {
|
||||||
|
return "Header parameter value is [" + headerParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/path/{pathParamToRead}")
|
||||||
|
public String readPathParam(@PathParam("pathParamToRead") String pathParamToRead) {
|
||||||
|
return "Path parameter value is [" + pathParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/query")
|
||||||
|
public String readQueryParam(@QueryParam("queryParamToRead") String queryParamToRead) {
|
||||||
|
return "Query parameter value is [" + queryParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/form")
|
||||||
|
public String readFormParam(@FormParam("formParamToRead") String formParamToRead) {
|
||||||
|
return "Form parameter value is [" + formParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/matrix")
|
||||||
|
public String readMatrixParam(@MatrixParam("matrixParamToRead") String matrixParamToRead) {
|
||||||
|
return "Matrix parameter value is [" + matrixParamToRead + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/bean/{pathParam}")
|
||||||
|
public String readBeanParam(@BeanParam ItemParam itemParam) {
|
||||||
|
return itemParam.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,12 +7,13 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.glassfish.grizzly.http.server.HttpServer;
|
import org.glassfish.grizzly.http.server.HttpServer;
|
||||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||||
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
import com.baeldung.jersey.server.config.ViewApplicationConfig;
|
import com.baeldung.jersey.server.config.ViewApplicationConfig;
|
||||||
|
|
||||||
public class EmbeddedHttpServer {
|
public class EmbeddedHttpServer {
|
||||||
|
|
||||||
private static final URI BASE_URI = URI.create("http://localhost:8082/");
|
public static final URI BASE_URI = URI.create("http://localhost:8082/");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
|
@ -32,4 +33,9 @@ public class EmbeddedHttpServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HttpServer startServer() {
|
||||||
|
final ResourceConfig rc = new ResourceConfig().packages("com.baeldung.jersey.server");
|
||||||
|
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI.toString()), rc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.baeldung.jersey.server;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
|
||||||
|
import org.glassfish.grizzly.http.server.HttpServer;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.jersey.server.http.EmbeddedHttpServer;
|
||||||
|
|
||||||
|
public class ItemsUnitTest {
|
||||||
|
|
||||||
|
private HttpServer server;
|
||||||
|
private WebTarget target;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
server = EmbeddedHttpServer.startServer();
|
||||||
|
target = ClientBuilder.newClient().target(EmbeddedHttpServer.BASE_URI.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenCookieParameter_whenGet_thenReturnsExpectedText() {
|
||||||
|
String paramValue = "1";
|
||||||
|
String responseText = target.path("items/cookie").request().cookie("cookieParamToRead", paramValue).get(String.class);
|
||||||
|
assertEquals("Cookie parameter value is [" + paramValue + "]", responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenHeaderParameter_whenGet_thenReturnsExpectedText() {
|
||||||
|
String paramValue = "2";
|
||||||
|
String responseText = target.path("items/header").request().header("headerParamToRead", paramValue).get(String.class);
|
||||||
|
assertEquals("Header parameter value is [" + paramValue + "]", responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPathParameter_whenGet_thenReturnsExpectedText() {
|
||||||
|
String paramValue = "3";
|
||||||
|
String responseText = target.path("items/path/" + paramValue).request().get(String.class);
|
||||||
|
assertEquals("Path parameter value is [" + paramValue + "]", responseText);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +1,100 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.car.app</groupId>
|
|
||||||
<artifactId>car-app</artifactId>
|
|
||||||
<name>car-app</name>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>jhipster-microservice</artifactId>
|
<artifactId>jhipster-microservice</artifactId>
|
||||||
<groupId>com.baeldung.jhipster</groupId>
|
<groupId>com.baeldung.jhipster</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
<groupId>com.car.app</groupId>
|
||||||
|
<artifactId>car-app</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>car-app</name>
|
||||||
|
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>${maven.version}</maven>
|
<maven>${maven.version}</maven>
|
||||||
</prerequisites>
|
</prerequisites>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
||||||
|
<assertj.version>3.6.2</assertj.version>
|
||||||
|
<awaitility.version>2.0.0</awaitility.version>
|
||||||
|
<commons-io.version>2.5</commons-io.version>
|
||||||
|
<commons-lang.version>3.5</commons-lang.version>
|
||||||
|
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
||||||
|
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
||||||
|
<hibernate.version>5.2.8.Final</hibernate.version>
|
||||||
|
<hikaricp.version>2.6.0</hikaricp.version>
|
||||||
|
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<javassist.version>3.21.0-GA</javassist.version>
|
||||||
|
<jcache.version>1.0.0</jcache.version>
|
||||||
|
<jhipster.server.version>1.1.0</jhipster.server.version>
|
||||||
|
<jjwt.version>0.7.0</jjwt.version>
|
||||||
|
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
||||||
|
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
||||||
|
<liquibase.version>3.6.2</liquibase.version>
|
||||||
|
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
||||||
|
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
||||||
|
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
||||||
|
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
||||||
|
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
||||||
|
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
||||||
|
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||||
|
<maven.version>3.0.0</maven.version>
|
||||||
|
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||||
|
<node.version>v6.10.0</node.version>
|
||||||
|
<!-- These remain empty unless the corresponding profile is active -->
|
||||||
|
<profile.no-liquibase />
|
||||||
|
<profile.swagger />
|
||||||
|
<!-- Sonar properties -->
|
||||||
|
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||||
|
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||||
|
<run.addResources>false</run.addResources>
|
||||||
|
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
||||||
|
<scala.version>2.12.1</scala.version>
|
||||||
|
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
||||||
|
|
||||||
|
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
||||||
|
|
||||||
|
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
||||||
|
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
||||||
|
recommended by http://fontawesome.io/examples/ -->
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
||||||
|
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
||||||
|
should be self-explanatory -->
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
||||||
|
|
||||||
|
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
||||||
|
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
||||||
|
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
||||||
|
|
||||||
|
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
||||||
|
<!-- For Sonar < 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
||||||
|
<!-- For Sonar >= 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
||||||
|
|
||||||
|
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
||||||
|
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
||||||
|
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
||||||
|
|
||||||
|
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
||||||
|
<!-- Spring properties -->
|
||||||
|
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
||||||
|
<springfox.version>2.6.1</springfox.version>
|
||||||
|
<undertow.version>1.4.10.Final</undertow.version>
|
||||||
|
<validation-api.version>1.1.0.Final</validation-api.version>
|
||||||
|
<yarn.version>v0.21.3</yarn.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -819,83 +898,4 @@
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
|
||||||
<assertj.version>3.6.2</assertj.version>
|
|
||||||
<awaitility.version>2.0.0</awaitility.version>
|
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-lang.version>3.5</commons-lang.version>
|
|
||||||
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
|
||||||
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
|
||||||
<hibernate.version>5.2.8.Final</hibernate.version>
|
|
||||||
<hikaricp.version>2.6.0</hikaricp.version>
|
|
||||||
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<javassist.version>3.21.0-GA</javassist.version>
|
|
||||||
<jcache.version>1.0.0</jcache.version>
|
|
||||||
<jhipster.server.version>1.1.0</jhipster.server.version>
|
|
||||||
<jjwt.version>0.7.0</jjwt.version>
|
|
||||||
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
|
||||||
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
|
||||||
<liquibase.version>3.6.2</liquibase.version>
|
|
||||||
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
|
||||||
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
|
||||||
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
|
||||||
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
|
||||||
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
|
||||||
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
|
||||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
|
||||||
<maven.version>3.0.0</maven.version>
|
|
||||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
|
||||||
<node.version>v6.10.0</node.version>
|
|
||||||
<!-- These remain empty unless the corresponding profile is active -->
|
|
||||||
<profile.no-liquibase />
|
|
||||||
<profile.swagger />
|
|
||||||
<!-- Sonar properties -->
|
|
||||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
|
||||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
|
||||||
<run.addResources>false</run.addResources>
|
|
||||||
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
|
||||||
<scala.version>2.12.1</scala.version>
|
|
||||||
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
|
||||||
|
|
||||||
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
|
||||||
|
|
||||||
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
|
||||||
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
|
||||||
recommended by http://fontawesome.io/examples/ -->
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
|
||||||
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
|
||||||
should be self-explanatory -->
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
|
||||||
|
|
||||||
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
|
||||||
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
|
||||||
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
|
||||||
|
|
||||||
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
|
||||||
<!-- For Sonar < 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
|
||||||
<!-- For Sonar >= 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
|
||||||
|
|
||||||
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
|
||||||
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
|
||||||
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
|
||||||
|
|
||||||
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
|
||||||
<!-- Spring properties -->
|
|
||||||
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
|
||||||
<springfox.version>2.6.1</springfox.version>
|
|
||||||
<undertow.version>1.4.10.Final</undertow.version>
|
|
||||||
<validation-api.version>1.1.0.Final</validation-api.version>
|
|
||||||
<yarn.version>v0.21.3</yarn.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,21 +1,99 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.dealer.app</groupId>
|
|
||||||
<artifactId>dealer-app</artifactId>
|
|
||||||
<name>dealer-app</name>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>jhipster-microservice</artifactId>
|
<artifactId>jhipster-microservice</artifactId>
|
||||||
<groupId>com.baeldung.jhipster</groupId>
|
<groupId>com.baeldung.jhipster</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
<groupId>com.dealer.app</groupId>
|
||||||
|
<artifactId>dealer-app</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>dealer-app</name>
|
||||||
|
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>${maven.version}</maven>
|
<maven>${maven.version}</maven>
|
||||||
</prerequisites>
|
</prerequisites>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
||||||
|
<assertj.version>3.6.2</assertj.version>
|
||||||
|
<awaitility.version>2.0.0</awaitility.version>
|
||||||
|
<commons-io.version>2.5</commons-io.version>
|
||||||
|
<commons-lang.version>3.5</commons-lang.version>
|
||||||
|
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
||||||
|
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
||||||
|
<hibernate.version>5.2.8.Final</hibernate.version>
|
||||||
|
<hikaricp.version>2.6.0</hikaricp.version>
|
||||||
|
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
||||||
|
<javassist.version>3.21.0-GA</javassist.version>
|
||||||
|
<jcache.version>1.0.0</jcache.version>
|
||||||
|
<jhipster.server.version>1.1.0</jhipster.server.version>
|
||||||
|
<jjwt.version>0.7.0</jjwt.version>
|
||||||
|
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
||||||
|
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
||||||
|
<liquibase.version>3.6.2</liquibase.version>
|
||||||
|
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
||||||
|
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
||||||
|
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
||||||
|
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
||||||
|
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
||||||
|
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
||||||
|
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||||
|
<maven.version>3.0.0</maven.version>
|
||||||
|
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||||
|
<node.version>v6.10.0</node.version>
|
||||||
|
<!-- These remain empty unless the corresponding profile is active -->
|
||||||
|
<profile.no-liquibase />
|
||||||
|
<profile.swagger />
|
||||||
|
<!-- Sonar properties -->
|
||||||
|
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||||
|
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||||
|
<run.addResources>false</run.addResources>
|
||||||
|
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
||||||
|
<scala.version>2.12.1</scala.version>
|
||||||
|
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
||||||
|
|
||||||
|
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
||||||
|
|
||||||
|
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
||||||
|
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
||||||
|
recommended by http://fontawesome.io/examples/ -->
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
||||||
|
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
||||||
|
should be self-explanatory -->
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
||||||
|
|
||||||
|
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
||||||
|
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
||||||
|
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
||||||
|
|
||||||
|
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
||||||
|
<!-- For Sonar < 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
||||||
|
<!-- For Sonar >= 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
||||||
|
|
||||||
|
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
||||||
|
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
||||||
|
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
||||||
|
|
||||||
|
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
||||||
|
<!-- Spring properties -->
|
||||||
|
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
||||||
|
<springfox.version>2.6.1</springfox.version>
|
||||||
|
<undertow.version>1.4.10.Final</undertow.version>
|
||||||
|
<validation-api.version>1.1.0.Final</validation-api.version>
|
||||||
|
<yarn.version>v0.21.3</yarn.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -813,83 +891,5 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
|
||||||
<assertj.version>3.6.2</assertj.version>
|
|
||||||
<awaitility.version>2.0.0</awaitility.version>
|
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-lang.version>3.5</commons-lang.version>
|
|
||||||
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
|
||||||
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
|
||||||
<hibernate.version>5.2.8.Final</hibernate.version>
|
|
||||||
<hikaricp.version>2.6.0</hikaricp.version>
|
|
||||||
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
|
||||||
<javassist.version>3.21.0-GA</javassist.version>
|
|
||||||
<jcache.version>1.0.0</jcache.version>
|
|
||||||
<jhipster.server.version>1.1.0</jhipster.server.version>
|
|
||||||
<jjwt.version>0.7.0</jjwt.version>
|
|
||||||
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
|
||||||
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
|
||||||
<liquibase.version>3.6.2</liquibase.version>
|
|
||||||
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
|
||||||
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
|
||||||
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
|
||||||
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
|
||||||
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
|
||||||
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
|
||||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
|
||||||
<maven.version>3.0.0</maven.version>
|
|
||||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
|
||||||
<node.version>v6.10.0</node.version>
|
|
||||||
<!-- These remain empty unless the corresponding profile is active -->
|
|
||||||
<profile.no-liquibase />
|
|
||||||
<profile.swagger />
|
|
||||||
<!-- Sonar properties -->
|
|
||||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
|
||||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
|
||||||
<run.addResources>false</run.addResources>
|
|
||||||
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
|
||||||
<scala.version>2.12.1</scala.version>
|
|
||||||
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
|
||||||
|
|
||||||
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
|
||||||
|
|
||||||
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
|
||||||
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
|
||||||
recommended by http://fontawesome.io/examples/ -->
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
|
||||||
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
|
||||||
should be self-explanatory -->
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
|
||||||
|
|
||||||
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
|
||||||
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
|
||||||
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
|
||||||
|
|
||||||
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
|
||||||
<!-- For Sonar < 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
|
||||||
<!-- For Sonar >= 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
|
||||||
|
|
||||||
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
|
||||||
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
|
||||||
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
|
||||||
|
|
||||||
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
|
||||||
<!-- Spring properties -->
|
|
||||||
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
|
||||||
<springfox.version>2.6.1</springfox.version>
|
|
||||||
<undertow.version>1.4.10.Final</undertow.version>
|
|
||||||
<validation-api.version>1.1.0.Final</validation-api.version>
|
|
||||||
<yarn.version>v0.21.3</yarn.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,21 +1,103 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.gateway</groupId>
|
|
||||||
<artifactId>gateway-app</artifactId>
|
|
||||||
<name>gateway-app</name>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>jhipster-microservice</artifactId>
|
<artifactId>jhipster-microservice</artifactId>
|
||||||
<groupId>com.baeldung.jhipster</groupId>
|
<groupId>com.baeldung.jhipster</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
<groupId>com.gateway</groupId>
|
||||||
|
<artifactId>gateway-app</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<name>gateway-app</name>
|
||||||
|
|
||||||
<prerequisites>
|
<prerequisites>
|
||||||
<maven>${maven.version}</maven>
|
<maven>${maven.version}</maven>
|
||||||
</prerequisites>
|
</prerequisites>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
||||||
|
<assertj.version>3.6.2</assertj.version>
|
||||||
|
<awaitility.version>2.0.0</awaitility.version>
|
||||||
|
<cassandra-driver.version>3.6.0</cassandra-driver.version>
|
||||||
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
|
<commons-io.version>2.5</commons-io.version>
|
||||||
|
<commons-lang.version>3.5</commons-lang.version>
|
||||||
|
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
||||||
|
<frontend-maven-plugin.version>1.3</frontend-maven-plugin.version>
|
||||||
|
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
||||||
|
<hibernate.version>5.2.8.Final</hibernate.version>
|
||||||
|
<hikaricp.version>2.6.0</hikaricp.version>
|
||||||
|
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
||||||
|
<javassist.version>3.21.0-GA</javassist.version>
|
||||||
|
<jcache.version>1.0.0</jcache.version>
|
||||||
|
<jhipster.server.version>1.1.0</jhipster.server.version>
|
||||||
|
<jjwt.version>0.7.0</jjwt.version>
|
||||||
|
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
||||||
|
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
||||||
|
<liquibase.version>3.6.2</liquibase.version>
|
||||||
|
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
||||||
|
<lz4.version>1.3.0</lz4.version>
|
||||||
|
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
||||||
|
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
||||||
|
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
||||||
|
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
||||||
|
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
||||||
|
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||||
|
<maven.version>3.0.0</maven.version>
|
||||||
|
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||||
|
<node.version>v6.10.0</node.version>
|
||||||
|
<!-- These remain empty unless the corresponding profile is active -->
|
||||||
|
<profile.no-liquibase />
|
||||||
|
<profile.swagger />
|
||||||
|
<!-- Sonar properties -->
|
||||||
|
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||||
|
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||||
|
<run.addResources>false</run.addResources>
|
||||||
|
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
||||||
|
<scala.version>2.12.1</scala.version>
|
||||||
|
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
||||||
|
|
||||||
|
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
||||||
|
|
||||||
|
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
||||||
|
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
||||||
|
recommended by http://fontawesome.io/examples/ -->
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
||||||
|
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
||||||
|
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
||||||
|
should be self-explanatory -->
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
||||||
|
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
||||||
|
|
||||||
|
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
||||||
|
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
||||||
|
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
||||||
|
|
||||||
|
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
||||||
|
<!-- For Sonar < 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
||||||
|
<!-- For Sonar >= 6.2 -->
|
||||||
|
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
||||||
|
|
||||||
|
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
||||||
|
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
||||||
|
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
||||||
|
|
||||||
|
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
||||||
|
<!-- Spring properties -->
|
||||||
|
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
||||||
|
<springfox.version>2.6.1</springfox.version>
|
||||||
|
<undertow.version>1.4.10.Final</undertow.version>
|
||||||
|
<validation-api.version>1.1.0.Final</validation-api.version>
|
||||||
|
<yarn.version>v0.21.3</yarn.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -925,87 +1007,5 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
|
|
||||||
<assertj.version>3.6.2</assertj.version>
|
|
||||||
<awaitility.version>2.0.0</awaitility.version>
|
|
||||||
<cassandra-driver.version>3.6.0</cassandra-driver.version>
|
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<commons-lang.version>3.5</commons-lang.version>
|
|
||||||
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
|
|
||||||
<frontend-maven-plugin.version>1.3</frontend-maven-plugin.version>
|
|
||||||
<hazelcast-hibernate52.version>1.2</hazelcast-hibernate52.version>
|
|
||||||
<hibernate.version>5.2.8.Final</hibernate.version>
|
|
||||||
<hikaricp.version>2.6.0</hikaricp.version>
|
|
||||||
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
|
|
||||||
<javassist.version>3.21.0-GA</javassist.version>
|
|
||||||
<jcache.version>1.0.0</jcache.version>
|
|
||||||
<jhipster.server.version>1.1.0</jhipster.server.version>
|
|
||||||
<jjwt.version>0.7.0</jjwt.version>
|
|
||||||
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
|
|
||||||
<liquibase-slf4j.version>2.0.0</liquibase-slf4j.version>
|
|
||||||
<liquibase.version>3.6.2</liquibase.version>
|
|
||||||
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
|
|
||||||
<lz4.version>1.3.0</lz4.version>
|
|
||||||
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
|
|
||||||
<mapstruct.version>1.1.0.Final</mapstruct.version>
|
|
||||||
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
|
||||||
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
|
|
||||||
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
|
|
||||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
|
||||||
<maven.version>3.0.0</maven.version>
|
|
||||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
|
||||||
<node.version>v6.10.0</node.version>
|
|
||||||
<!-- These remain empty unless the corresponding profile is active -->
|
|
||||||
<profile.no-liquibase />
|
|
||||||
<profile.swagger />
|
|
||||||
<!-- Sonar properties -->
|
|
||||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
|
||||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
|
||||||
<run.addResources>false</run.addResources>
|
|
||||||
<scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
|
|
||||||
<scala.version>2.12.1</scala.version>
|
|
||||||
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
|
|
||||||
|
|
||||||
<sonar.exclusions>src/main/webapp/content/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*</sonar.exclusions>
|
|
||||||
|
|
||||||
<sonar.issue.ignore.multicriteria>S3437,UndocumentedApi,BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria>
|
|
||||||
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=Web%3ABoldAndItalicTagsCheck is ignored. Even if we agree that using the "i" tag is an awful practice, this is what is
|
|
||||||
recommended by http://fontawesome.io/examples/ -->
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>src/main/webapp/app/**/*.*</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>Web:BoldAndItalicTagsCheck</sonar.issue.ignore.multicriteria.BoldAndItalicTagsCheck.ruleKey>
|
|
||||||
<!-- Rule https://sonarqube.com/coding_rules#rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient -->
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.S3437.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.S3437.ruleKey>squid:S3437</sonar.issue.ignore.multicriteria.S3437.ruleKey>
|
|
||||||
<!-- Rule http://sonarqube.com/coding_rules#rule_key=squid%3AUndocumentedApi is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names
|
|
||||||
should be self-explanatory -->
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>src/main/java/**/*</sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey>
|
|
||||||
<sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>squid:UndocumentedApi</sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey>
|
|
||||||
|
|
||||||
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
|
|
||||||
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
|
||||||
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
|
|
||||||
|
|
||||||
<sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
|
|
||||||
<!-- For Sonar < 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>
|
|
||||||
<!-- For Sonar >= 6.2 -->
|
|
||||||
<sonar.javascript.lcov.reportPaths>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPaths>
|
|
||||||
|
|
||||||
<sonar.sources>${project.basedir}/src/main/</sonar.sources>
|
|
||||||
<sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
|
|
||||||
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
|
|
||||||
|
|
||||||
<sortpom-maven-plugin.version>2.5.0</sortpom-maven-plugin.version>
|
|
||||||
<!-- Spring properties -->
|
|
||||||
<spring-cloud.version>Camden.SR5</spring-cloud.version>
|
|
||||||
<springfox.version>2.6.1</springfox.version>
|
|
||||||
<undertow.version>1.4.10.Final</undertow.version>
|
|
||||||
<validation-api.version>1.1.0.Final</validation-api.version>
|
|
||||||
<yarn.version>v0.21.3</yarn.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
### Relevant Articles
|
||||||
|
|
||||||
|
- [Guide to FastUtil](https://www.baeldung.com/fastutil)
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Product {
|
||||||
|
@Id
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String category;
|
||||||
|
private BigDecimal unitPrice;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
public BigDecimal getUnitPrice() {
|
||||||
|
return unitPrice;
|
||||||
|
}
|
||||||
|
public void setUnitPrice(BigDecimal unitPrice) {
|
||||||
|
this.unitPrice = unitPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import javax.persistence.Persistence;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.Tuple;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
public class ProductRepository {
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
public ProductRepository() {
|
||||||
|
EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-projections");
|
||||||
|
entityManager = factory.createEntityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Object> findAllNamesUsingJPQL() {
|
||||||
|
Query query = entityManager.createQuery("select name from Product");
|
||||||
|
List<Object> resultList = query.getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Object> findAllIdsUsingJPQL() {
|
||||||
|
Query query = entityManager.createQuery("select id from Product");
|
||||||
|
List<Object> resultList = query.getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findAllNamesUsingCriteriaBuilder() {
|
||||||
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<String> query = builder.createQuery(String.class);
|
||||||
|
Root<Product> product = query.from(Product.class);
|
||||||
|
query.select(product.get("name"));
|
||||||
|
List<String> resultList = entityManager.createQuery(query).getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Object[]> findAllIdAndNamesUsingJPQL() {
|
||||||
|
Query query = entityManager.createQuery("select id, name from Product");
|
||||||
|
List<Object[]> resultList = query.getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object[]> findAllIdAndNamesUsingCriteriaBuilderArray() {
|
||||||
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
|
||||||
|
Root<Product> product = query.from(Product.class);
|
||||||
|
query.select(builder.array(product.get("id"), product.get("name")));
|
||||||
|
List<Object[]> resultList = entityManager.createQuery(query).getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object[]> findAllIdNameUnitPriceUsingCriteriaQueryMultiselect() {
|
||||||
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
|
||||||
|
Root<Product> product = query.from(Product.class);
|
||||||
|
query.multiselect(product.get("id"), product.get("name"), product.get("unitPrice"));
|
||||||
|
List<Object[]> resultList = entityManager.createQuery(query).getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Tuple> findAllIdAndNamesUsingCriteriaBuilderTuple() {
|
||||||
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Tuple> query = builder.createQuery(Tuple.class);
|
||||||
|
Root<Product> product = query.from(Product.class);
|
||||||
|
query.select(builder.tuple(product.get("id"), product.get("name")));
|
||||||
|
List<Tuple> resultList = entityManager.createQuery(query).getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object[]> findCountByCategoryUsingJPQL() {
|
||||||
|
Query query = entityManager.createQuery("select p.category, count(p) from Product p group by p.category");
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object[]> findCountByCategoryUsingCriteriaBuilder() {
|
||||||
|
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
|
||||||
|
Root<Product> product = query.from(Product.class);
|
||||||
|
query.multiselect(product.get("category"), builder.count(product));
|
||||||
|
query.groupBy(product.get("category"));
|
||||||
|
List<Object[]> resultList = entityManager.createQuery(query).getResultList();
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -147,7 +147,7 @@
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
<persistence-unit name="jpa-entity-definition">
|
<persistence-unit name="jpa-entity-definition">
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
<class>com.baeldung.jpa.entity.Student</class>
|
<class>com.baeldung.jpa.entity.Student</class>
|
||||||
|
@ -163,4 +163,21 @@
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
<persistence-unit name="jpa-projections">
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
<class>com.baeldung.jpa.projections.Product</class>
|
||||||
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
|
<properties>
|
||||||
|
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||||
|
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test"/>
|
||||||
|
<property name="javax.persistence.jdbc.user" value="sa"/>
|
||||||
|
<property name="javax.persistence.jdbc.password" value=""/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
|
||||||
|
<property name="show_sql" value="true"/>
|
||||||
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
|
||||||
|
<property name="javax.persistence.sql-load-script-source" value="products_jpa.sql"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
|
@ -0,0 +1,4 @@
|
||||||
|
insert into product(id, name, description, category) values (1,'Product Name 1','This is Product 1', 'category1');
|
||||||
|
insert into product(id, name, description, category) values (2,'Product Name 2','This is Product 2', 'category1');
|
||||||
|
insert into product(id, name, description, category) values (3,'Product Name 3','This is Product 3', 'category2');
|
||||||
|
insert into product(id, name, description, category) values (4,'Product Name 4','This is Product 4', 'category3');
|
|
@ -0,0 +1,133 @@
|
||||||
|
package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.criterion.Order;
|
||||||
|
import org.hibernate.criterion.Projections;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HibernateProjectionsIntegrationTest {
|
||||||
|
private static Session session;
|
||||||
|
private static SessionFactory sessionFactory;
|
||||||
|
private Transaction transaction;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void init() {
|
||||||
|
Configuration configuration = getConfiguration();
|
||||||
|
configuration.addAnnotatedClass(Product.class);
|
||||||
|
sessionFactory = configuration.buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
session = sessionFactory.getCurrentSession();
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() {
|
||||||
|
if(transaction.isActive()) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Configuration getConfiguration() {
|
||||||
|
Configuration cfg = new Configuration();
|
||||||
|
cfg.setProperty(AvailableSettings.DIALECT,
|
||||||
|
"org.hibernate.dialect.H2Dialect");
|
||||||
|
cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "none");
|
||||||
|
cfg.setProperty(AvailableSettings.DRIVER, "org.h2.Driver");
|
||||||
|
cfg.setProperty(AvailableSettings.URL,
|
||||||
|
"jdbc:h2:mem:myexceptiondb2;DB_CLOSE_DELAY=-1;;INIT=RUNSCRIPT FROM 'src/test/resources/products.sql'");
|
||||||
|
cfg.setProperty(AvailableSettings.USER, "sa");
|
||||||
|
cfg.setProperty(AvailableSettings.PASS, "");
|
||||||
|
cfg.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "thread");
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenIdAndNameProjectionUsingCriteria_thenListOfObjectArrayReturned() {
|
||||||
|
Criteria criteria = session.createCriteria(Product.class);
|
||||||
|
criteria = criteria.setProjection(Projections.projectionList()
|
||||||
|
.add(Projections.id())
|
||||||
|
.add(Projections.property("name")));
|
||||||
|
List<Object[]> resultList = criteria.list();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals(1L, resultList.get(0)[0]);
|
||||||
|
assertEquals("Product Name 1", resultList.get(0)[1]);
|
||||||
|
assertEquals(2L, resultList.get(1)[0]);
|
||||||
|
assertEquals("Product Name 2", resultList.get(1)[1]);
|
||||||
|
assertEquals(3L, resultList.get(2)[0]);
|
||||||
|
assertEquals("Product Name 3", resultList.get(2)[1]);
|
||||||
|
assertEquals(4L, resultList.get(3)[0]);
|
||||||
|
assertEquals("Product Name 4", resultList.get(3)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenNameProjectionUsingCriteria_thenListOfStringReturned() {
|
||||||
|
Criteria criteria = session.createCriteria(Product.class);
|
||||||
|
criteria = criteria.setProjection(Projections.property("name"));
|
||||||
|
List resultList = criteria.list();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals("Product Name 1", resultList.get(0));
|
||||||
|
assertEquals("Product Name 2", resultList.get(1));
|
||||||
|
assertEquals("Product Name 3", resultList.get(2));
|
||||||
|
assertEquals("Product Name 4", resultList.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenCountByCategoryUsingCriteria_thenOK() {
|
||||||
|
Criteria criteria = session.createCriteria(Product.class);
|
||||||
|
criteria = criteria.setProjection(Projections.projectionList()
|
||||||
|
.add(Projections.groupProperty("category"))
|
||||||
|
.add(Projections.rowCount()));
|
||||||
|
List<Object[]> resultList = criteria.list();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(3, resultList.size());
|
||||||
|
assertEquals("category1", resultList.get(0)[0]);
|
||||||
|
assertEquals(2L, resultList.get(0)[1]);
|
||||||
|
assertEquals("category2", resultList.get(1)[0]);
|
||||||
|
assertEquals(1L, resultList.get(1)[1]);
|
||||||
|
assertEquals("category3", resultList.get(2)[0]);
|
||||||
|
assertEquals(1L, resultList.get(2)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenCountByCategoryWithAliasUsingCriteria_thenOK() {
|
||||||
|
Criteria criteria = session.createCriteria(Product.class);
|
||||||
|
criteria = criteria.setProjection(Projections.projectionList()
|
||||||
|
.add(Projections.groupProperty("category"))
|
||||||
|
.add(Projections.alias(Projections.rowCount(), "count")));
|
||||||
|
criteria.addOrder(Order.asc("count"));
|
||||||
|
List<Object[]> resultList = criteria.list();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(3, resultList.size());
|
||||||
|
assertEquals("category2", resultList.get(0)[0]);
|
||||||
|
assertEquals(1L, resultList.get(0)[1]);
|
||||||
|
assertEquals("category3", resultList.get(1)[0]);
|
||||||
|
assertEquals(1L, resultList.get(1)[1]);
|
||||||
|
assertEquals("category1", resultList.get(2)[0]);
|
||||||
|
assertEquals(2L, resultList.get(2)[1]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
public class ProductRepositoryIntegrationTest {
|
||||||
|
private static ProductRepository productRepository;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void once() throws IOException {
|
||||||
|
productRepository = new ProductRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenIdAndNameProjectionUsingJPQL_thenListOfObjectArrayReturned() {
|
||||||
|
List<Object[]> resultList = productRepository.findAllIdAndNamesUsingJPQL();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals(1L, resultList.get(0)[0]);
|
||||||
|
assertEquals("Product Name 1", resultList.get(0)[1]);
|
||||||
|
assertEquals(2L, resultList.get(1)[0]);
|
||||||
|
assertEquals("Product Name 2", resultList.get(1)[1]);
|
||||||
|
assertEquals(3L, resultList.get(2)[0]);
|
||||||
|
assertEquals("Product Name 3", resultList.get(2)[1]);
|
||||||
|
assertEquals(4L, resultList.get(3)[0]);
|
||||||
|
assertEquals("Product Name 4", resultList.get(3)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenIdAndNameProjectionUsingCriteriaBuilder_thenListOfObjectArrayReturned() {
|
||||||
|
List<Object[]> resultList = productRepository.findAllIdAndNamesUsingCriteriaBuilderArray();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals(1L, resultList.get(0)[0]);
|
||||||
|
assertEquals("Product Name 1", resultList.get(0)[1]);
|
||||||
|
assertEquals(2L, resultList.get(1)[0]);
|
||||||
|
assertEquals("Product Name 2", resultList.get(1)[1]);
|
||||||
|
assertEquals(3L, resultList.get(2)[0]);
|
||||||
|
assertEquals("Product Name 3", resultList.get(2)[1]);
|
||||||
|
assertEquals(4L, resultList.get(3)[0]);
|
||||||
|
assertEquals("Product Name 4", resultList.get(3)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenNameProjectionUsingJPQL_thenListOfStringReturned() {
|
||||||
|
List resultList = productRepository.findAllNamesUsingJPQL();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals("Product Name 1", resultList.get(0));
|
||||||
|
assertEquals("Product Name 2", resultList.get(1));
|
||||||
|
assertEquals("Product Name 3", resultList.get(2));
|
||||||
|
assertEquals("Product Name 4", resultList.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenNameProjectionUsingCriteriaBuilder_thenListOfStringReturned() {
|
||||||
|
List<String> resultList = productRepository.findAllNamesUsingCriteriaBuilder();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(4, resultList.size());
|
||||||
|
assertEquals("Product Name 1", resultList.get(0));
|
||||||
|
assertEquals("Product Name 2", resultList.get(1));
|
||||||
|
assertEquals("Product Name 3", resultList.get(2));
|
||||||
|
assertEquals("Product Name 4", resultList.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenCountByCategoryUsingJPQL_thenOK() {
|
||||||
|
List<Object[]> resultList = productRepository.findCountByCategoryUsingJPQL();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(3, resultList.size());
|
||||||
|
assertEquals("category1", resultList.get(0)[0]);
|
||||||
|
assertEquals(2L, resultList.get(0)[1]);
|
||||||
|
assertEquals("category2", resultList.get(1)[0]);
|
||||||
|
assertEquals(1L, resultList.get(1)[1]);
|
||||||
|
assertEquals("category3", resultList.get(2)[0]);
|
||||||
|
assertEquals(1L, resultList.get(2)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductData_whenCountByCategoryUsingCriteriaBuider_thenOK() {
|
||||||
|
List<Object[]> resultList = productRepository.findCountByCategoryUsingCriteriaBuilder();
|
||||||
|
|
||||||
|
assertNotNull(resultList);
|
||||||
|
assertEquals(3, resultList.size());
|
||||||
|
assertEquals("category1", resultList.get(0)[0]);
|
||||||
|
assertEquals(2L, resultList.get(0)[1]);
|
||||||
|
assertEquals("category2", resultList.get(1)[0]);
|
||||||
|
assertEquals(1L, resultList.get(1)[1]);
|
||||||
|
assertEquals("category3", resultList.get(2)[0]);
|
||||||
|
assertEquals(1L, resultList.get(2)[1]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
create table Product (id bigint not null, category varchar(255), description varchar(255), name varchar(255), unitPrice decimal(19,2), primary key (id));
|
||||||
|
insert into product(id, name, description, category) values (1,'Product Name 1','This is Product 1', 'category1');
|
||||||
|
insert into product(id, name, description, category) values (2,'Product Name 2','This is Product 2', 'category1');
|
||||||
|
insert into product(id, name, description, category) values (3,'Product Name 3','This is Product 3', 'category2');
|
||||||
|
insert into product(id, name, description, category) values (4,'Product Name 4','This is Product 4', 'category3');
|
|
@ -43,22 +43,22 @@ public class DeleteFromRepositoryUnitTest {
|
||||||
public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() {
|
public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() {
|
||||||
repository.deleteById(book1.getId());
|
repository.deleteById(book1.getId());
|
||||||
|
|
||||||
assertThat(repository.count() == 1).isTrue();
|
assertThat(repository.count()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() {
|
public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() {
|
||||||
repository.deleteAll();
|
repository.deleteAll();
|
||||||
|
|
||||||
assertThat(repository.count() == 0).isTrue();
|
assertThat(repository.count()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() {
|
public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() {
|
||||||
repository.deleteByTitle("The Hobbit");
|
long deletedRecords = repository.deleteByTitle("The Hobbit");
|
||||||
|
|
||||||
assertThat(repository.count() == 1).isTrue();
|
assertThat(deletedRecords).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,7 +66,7 @@ public class DeleteFromRepositoryUnitTest {
|
||||||
public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() {
|
public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() {
|
||||||
repository.deleteBooks("The Hobbit");
|
repository.deleteBooks("The Hobbit");
|
||||||
|
|
||||||
assertThat(repository.count() == 1).isTrue();
|
assertThat(repository.count()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,15 +46,15 @@ public class DeleteInRelationshipsUnitTest {
|
||||||
public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() {
|
public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() {
|
||||||
categoryRepository.deleteAll();
|
categoryRepository.deleteAll();
|
||||||
|
|
||||||
assertThat(bookRepository.count() == 0).isTrue();
|
assertThat(bookRepository.count()).isEqualTo(0);
|
||||||
assertThat(categoryRepository.count() == 0).isTrue();
|
assertThat(categoryRepository.count()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() {
|
public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() {
|
||||||
bookRepository.deleteAll();
|
bookRepository.deleteAll();
|
||||||
|
|
||||||
assertThat(bookRepository.count() == 0).isTrue();
|
assertThat(bookRepository.count()).isEqualTo(0);
|
||||||
assertThat(categoryRepository.count() == 2).isTrue();
|
assertThat(categoryRepository.count()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,6 @@ public class MultipleDbApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MultipleDbApplication.class, args);
|
SpringApplication.run(MultipleDbApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.baeldung.multipledb;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, the persistence-multiple-db.properties file is read for
|
||||||
|
* non auto configuration in PersistenceProductConfiguration.
|
||||||
|
* <p>
|
||||||
|
* If we need to use persistence-multiple-db-boot.properties and auto configuration
|
||||||
|
* then uncomment the below @Configuration class and comment out PersistenceProductConfiguration.
|
||||||
|
*/
|
||||||
|
//@Configuration
|
||||||
|
@PropertySource({"classpath:persistence-multiple-db-boot.properties"})
|
||||||
|
@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager")
|
||||||
|
@Profile("!tc")
|
||||||
|
public class PersistenceProductAutoConfiguration {
|
||||||
|
@Autowired
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
|
public PersistenceProductAutoConfiguration() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LocalContainerEntityManagerFactoryBean productEntityManager() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
em.setDataSource(productDataSource());
|
||||||
|
em.setPackagesToScan("com.baeldung.multipledb.model.product");
|
||||||
|
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
em.setJpaVendorAdapter(vendorAdapter);
|
||||||
|
final HashMap<String, Object> properties = new HashMap<String, Object>();
|
||||||
|
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
|
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
|
em.setJpaPropertyMap(properties);
|
||||||
|
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix="spring.second-datasource")
|
||||||
|
public DataSource productDataSource() {
|
||||||
|
return DataSourceBuilder.create().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager productTransactionManager() {
|
||||||
|
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||||
|
transactionManager.setEntityManagerFactory(productEntityManager().getObject());
|
||||||
|
return transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.baeldung.multipledb;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, the persistence-multiple-db.properties file is read for
|
||||||
|
* non auto configuration in PersistenceUserConfiguration.
|
||||||
|
* <p>
|
||||||
|
* If we need to use persistence-multiple-db-boot.properties and auto configuration
|
||||||
|
* then uncomment the below @Configuration class and comment out PersistenceUserConfiguration.
|
||||||
|
*/
|
||||||
|
//@Configuration
|
||||||
|
@PropertySource({"classpath:persistence-multiple-db-boot.properties"})
|
||||||
|
@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager")
|
||||||
|
@Profile("!tc")
|
||||||
|
public class PersistenceUserAutoConfiguration {
|
||||||
|
@Autowired
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
|
public PersistenceUserAutoConfiguration() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean
|
||||||
|
public LocalContainerEntityManagerFactoryBean userEntityManager() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
em.setDataSource(userDataSource());
|
||||||
|
em.setPackagesToScan("com.baeldung.multipledb.model.user");
|
||||||
|
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
em.setJpaVendorAdapter(vendorAdapter);
|
||||||
|
final HashMap<String, Object> properties = new HashMap<String, Object>();
|
||||||
|
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
|
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
|
em.setJpaPropertyMap(properties);
|
||||||
|
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
@ConfigurationProperties(prefix="spring.datasource")
|
||||||
|
public DataSource userDataSource() {
|
||||||
|
return DataSourceBuilder.create().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager userTransactionManager() {
|
||||||
|
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||||
|
transactionManager.setEntityManagerFactory(userEntityManager().getObject());
|
||||||
|
return transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
|
hibernate.cache.use_second_level_cache=false
|
||||||
|
hibernate.cache.use_query_cache=false
|
||||||
|
|
||||||
|
spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
|
||||||
|
spring.datasource.username=sa
|
||||||
|
spring.datasource.password=sa
|
||||||
|
|
||||||
|
spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
|
||||||
|
spring.second-datasource.username=sa
|
||||||
|
spring.second-datasource.password=sa
|
|
@ -12,7 +12,6 @@ import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
7
pom.xml
7
pom.xml
|
@ -11,7 +11,6 @@
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>lombok-custom</module>
|
|
||||||
<module>quarkus</module>
|
<module>quarkus</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
@ -392,6 +391,7 @@
|
||||||
<module>core-java-modules/core-java-concurrency-basic</module>
|
<module>core-java-modules/core-java-concurrency-basic</module>
|
||||||
<module>core-java-modules/core-java-concurrency-collections</module>
|
<module>core-java-modules/core-java-concurrency-collections</module>
|
||||||
<module>core-java-modules/core-java-io</module>
|
<module>core-java-modules/core-java-io</module>
|
||||||
|
<module>core-java-modules/core-java-nio</module>
|
||||||
<module>core-java-modules/core-java-security</module>
|
<module>core-java-modules/core-java-security</module>
|
||||||
<module>core-java-modules/core-java-lang-syntax</module>
|
<module>core-java-modules/core-java-lang-syntax</module>
|
||||||
<module>core-java-modules/core-java-lang</module>
|
<module>core-java-modules/core-java-lang</module>
|
||||||
|
@ -1074,6 +1074,7 @@
|
||||||
<module>core-java-modules/core-java-concurrency-basic</module>
|
<module>core-java-modules/core-java-concurrency-basic</module>
|
||||||
<module>core-java-modules/core-java-concurrency-collections</module>
|
<module>core-java-modules/core-java-concurrency-collections</module>
|
||||||
<module>core-java-modules/core-java-io</module>
|
<module>core-java-modules/core-java-io</module>
|
||||||
|
<module>core-java-modules/core-java-nio</module>
|
||||||
<module>core-java-modules/core-java-security</module>
|
<module>core-java-modules/core-java-security</module>
|
||||||
<module>core-java-modules/core-java-lang-syntax</module>
|
<module>core-java-modules/core-java-lang-syntax</module>
|
||||||
<module>core-java-modules/core-java-lang</module>
|
<module>core-java-modules/core-java-lang</module>
|
||||||
|
@ -1526,7 +1527,7 @@
|
||||||
<logback.version>1.1.7</logback.version>
|
<logback.version>1.1.7</logback.version>
|
||||||
|
|
||||||
<!-- plugins -->
|
<!-- plugins -->
|
||||||
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
@ -1537,7 +1538,7 @@
|
||||||
<jmh-generator.version>1.19</jmh-generator.version>
|
<jmh-generator.version>1.19</jmh-generator.version>
|
||||||
<hamcrest-all.version>1.3</hamcrest-all.version>
|
<hamcrest-all.version>1.3</hamcrest-all.version>
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
|
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
<commons-io.version>2.5</commons-io.version>
|
||||||
<commons-cli.version>1.4</commons-cli.version>
|
<commons-cli.version>1.4</commons-cli.version>
|
||||||
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
||||||
|
|
|
@ -28,12 +28,22 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<spring-boot.version>2.2.0.M3</spring-boot.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-rsocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -46,8 +56,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>io.projectreactor</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>reactor-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -60,4 +70,35 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.baeldung.spring.rsocket.client;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ClientApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new SpringApplicationBuilder()
|
||||||
|
.main(ClientApplication.class)
|
||||||
|
.sources(ClientApplication.class)
|
||||||
|
.profiles("client")
|
||||||
|
.run(args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.baeldung.spring.rsocket.client;
|
||||||
|
|
||||||
|
import io.rsocket.RSocket;
|
||||||
|
import io.rsocket.RSocketFactory;
|
||||||
|
import io.rsocket.frame.decoder.PayloadDecoder;
|
||||||
|
import io.rsocket.transport.netty.client.TcpClientTransport;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.messaging.rsocket.RSocketRequester;
|
||||||
|
import org.springframework.messaging.rsocket.RSocketStrategies;
|
||||||
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ClientConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RSocket rSocket() {
|
||||||
|
return RSocketFactory.connect()
|
||||||
|
.mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE)
|
||||||
|
.frameDecoder(PayloadDecoder.ZERO_COPY)
|
||||||
|
.transport(TcpClientTransport.create(7000))
|
||||||
|
.start()
|
||||||
|
.block();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
|
||||||
|
return RSocketRequester.wrap(rSocket(), MimeTypeUtils.APPLICATION_JSON, rSocketStrategies);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue