Skip to content

Commit

Permalink
Merge branch 'main' into renovate/actions-checkout-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli authored Nov 22, 2023
2 parents ab100c3 + e337061 commit 4ccf648
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 181 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
"args": "--spring.profiles.active=local",
"envFile": "${workspaceFolder}/.env",
"vmArgs": " -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=33093 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dspring.jmx.enabled=true -Djava.rmi.server.hostname=localhost -Dspring.application.admin.enabled=true -Dspring.boot.project.name=aws-sqs-project"
},
{
"type": "java",
"name": "Spring Boot-Application<aws-lambda-project>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.learning.awslambda.Application",
"projectName": "aws-lambda-project",
"args": "--spring.profiles.active=local",
"envFile": "${workspaceFolder}/.env"
}
]
}
2 changes: 1 addition & 1 deletion aws-lambda-project/.github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Java 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
Expand Down
12 changes: 6 additions & 6 deletions aws-lambda-project/.localstack/01_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ awslocal lambda wait function-active-v2 --function-name "$FUNCTION_NAME"
echo -e "Lambda function is now active\n"

# Invoke Lambda function or use curl
#awslocal lambda invoke \
# --function-name "$FUNCTION_NAME" \
# --payload '{"body": "{\"name\": \"profile\"}" }' \
# output.txt
#
#echo -e "Lambda function invoked successfully\n"
awslocal lambda invoke \
--function-name "$FUNCTION_NAME" \
--payload '{"body": "{\"name\": \"profile\"}" }' \
output.txt

echo -e "Lambda function invoked successfully\n"

# Use curl to invoke Lambda function and capture the response
response_from_curl=$(curl -X POST \
Expand Down
38 changes: 26 additions & 12 deletions aws-lambda-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<version>3.2.0-RC2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.learning.awslambda</groupId>
Expand All @@ -21,15 +21,14 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>17</java.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>
<spring-cloud-aws.version>3.0.3</spring-cloud-aws.version>
<spring-cloud.version>2023.0.0-RC1</spring-cloud.version>
<springdoc-openapi.version>2.2.0</springdoc-openapi.version>
<wrapper.version>1.0.31.RELEASE</wrapper.version>
<aws.java.sdk.version>2.21.28</aws.java.sdk.version>

<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<spotless.version>2.40.0</spotless.version>
<dependency-check-maven.version>8.4.2</dependency-check-maven.version>
<dependency-check-maven.version>9.0.0</dependency-check-maven.version>
<properties-maven-plugin.version>1.2.1</properties-maven-plugin.version>
<sonar-maven-plugin.version>3.10.0.2594</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
Expand All @@ -43,10 +42,12 @@
</properties>

<dependencies>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -62,7 +63,7 @@

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down Expand Up @@ -121,13 +122,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>${spring-cloud-aws.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
Expand Down Expand Up @@ -376,4 +370,24 @@
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.learning.awslambda.model.request.ActorRequest;
import com.learning.awslambda.model.response.ActorResponse;
import com.learning.awslambda.services.ActorService;
import java.util.List;
import java.util.function.Function;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -11,7 +12,7 @@
public class AWSLambdaConfig {

@Bean
Function<ActorRequest, ActorResponse> findActorByName(ActorService actorService) {
Function<ActorRequest, List<ActorResponse>> findActorByName(ActorService actorService) {
return request -> actorService.findActorByName(request.name());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
package com.learning.awslambda.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.Objects;
import org.hibernate.Hibernate;

@Entity
@Table(name = "actors")
public class Actor {

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

@Column(nullable = false)
private String name;

public Actor(Long id, String name) {
Expand Down Expand Up @@ -46,7 +34,6 @@ public void setName(String name) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Actor actor = (Actor) o;
return id != null && Objects.equals(id, actor.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.learning.awslambda.entities.Actor;
import com.learning.awslambda.model.request.ActorRequest;
import com.learning.awslambda.model.response.ActorResponse;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -17,4 +18,8 @@ public Actor toEntity(ActorRequest actorRequest) {
public ActorResponse toResponse(Actor actor) {
return new ActorResponse(actor.getId(), actor.getName());
}

public List<ActorResponse> toResponseList(List<Actor> actorList) {
return actorList.stream().map(this::toResponse).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
package com.learning.awslambda.repositories;

import com.learning.awslambda.entities.Actor;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

public interface ActorRepository extends JpaRepository<Actor, Long> {
Optional<Actor> findByNameLike(String name);
@Repository
public class ActorRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(ActorRepository.class);

private final JdbcClient jdbcClient;
private final NamedParameterJdbcTemplate jdbcTemplate;

public ActorRepository(JdbcClient jdbcClient, NamedParameterJdbcTemplate jdbcTemplate) {
this.jdbcClient = jdbcClient;
this.jdbcTemplate = jdbcTemplate;
}

@Transactional(readOnly = true)
public List<Actor> findByNameLike(String name) {
String sql = "select id, name from actors where name like :name";
return jdbcClient
.sql(sql)
.param("name", "%" + name + "%")
.query(Actor.class)
.list();
}

@Transactional
public void deleteAll() {
String sql = "delete from actors";
int count = jdbcClient.sql(sql).update();
LOGGER.info("deleted {} rows", count);
}

@Transactional
public List<Actor> saveAll(List<Actor> actorList) {

List<Object[]> batch = actorList.stream()
.map(customer -> new Object[] {customer.getName()})
.toList();

String sql = "INSERT INTO actors(name) values :batch RETURNING id, name";

return jdbcTemplate.query(sql, new MapSqlParameterSource("batch", batch), rs -> {
List<Actor> actors = new ArrayList<>();
while (rs.next()) {
actors.add(new Actor(rs.getLong(1), rs.getString(2)));
}
return actors;
});
}
}
Loading

0 comments on commit 4ccf648

Please sign in to comment.