Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0ad9a2e
Delete src/test/java/com/amazonaws/samples/appconfig/movies/MockTest.…
pdineshbalaaji Jan 24, 2025
dc9ab5a
Delete src/test/java/com/amazonaws/samples/appconfig/movies/MovieTest…
pdineshbalaaji Jan 24, 2025
07437f6
Delete src/test/java/com/amazonaws/samples/appconfig/movies/MoviesCon…
pdineshbalaaji Jan 24, 2025
703870a
Update Encoder.java
pdineshbalaaji Jan 24, 2025
05d9fbc
Merge pull request #1 from pdineshbalaaji/change-branch
pdineshbalaaji Jan 24, 2025
be8a6e2
Add files via upload
pdineshbalaaji Jan 24, 2025
2cf0aad
Update Encoder.java
pdineshbalaaji Jan 24, 2025
88c7296
Merge pull request #2 from pdineshbalaaji/main
pdineshbalaaji Jan 24, 2025
4242af4
Merge pull request #3 from pdineshbalaaji/change-branch
pdineshbalaaji Jan 24, 2025
2eafc19
test
pdineshbalaaji Jan 27, 2025
ea5feb0
Merge pull request #4 from pdineshbalaaji/main
pdineshbalaaji Jan 27, 2025
923b274
sub module movie-servoce-util added
pdineshbalaaji Jan 29, 2025
5508543
movie service util upgraded to java 17
pdineshbalaaji Jan 29, 2025
3e82bd5
post transformatoin changes
pdineshbalaaji Jan 29, 2025
82b12dd
required dependencies
pdineshbalaaji Jan 30, 2025
e46a19e
dependencies
pdineshbalaaji Jan 30, 2025
04fffd0
Update custom-transformation-post-qct.yaml
pdineshbalaaji Feb 21, 2025
6420f5f
Update custom-transformation-pre-qct.yaml
pdineshbalaaji Feb 21, 2025
b59bdc8
Update custom-transformation-post-qct.yaml
pdineshbalaaji Feb 21, 2025
b3e25fc
Update custom-transformation-pre-qct.yaml
pdineshbalaaji Feb 21, 2025
dd75f34
Update ConfigurationCache.java
pdineshbalaaji Feb 21, 2025
cedf3f0
Update ConfigurationCacheItem.java
pdineshbalaaji Feb 21, 2025
1eea373
change pre-transformation to remove un-used imports
pdineshbalaaji Feb 22, 2025
71e67db
Add files via upload
pdineshbalaaji Feb 28, 2025
314d945
Merge pull request #5 from pdineshbalaaji/main
pdineshbalaaji Feb 28, 2025
f8627a5
test files
pdineshbalaaji Apr 2, 2025
b2e0889
Merge pull request #7 from pdineshbalaaji/main
pdineshbalaaji Apr 2, 2025
1f97996
Merge pull request #8 from pdineshbalaaji/change-branch
pdineshbalaaji Apr 2, 2025
6b19844
update readme
pdineshbalaaji Apr 2, 2025
b91984f
Merge pull request #9 from pdineshbalaaji/change-branch
pdineshbalaaji Apr 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
.classpath
.project
.settings/
/movie-service-utils/jars/

# Packaged files #
*.jar
#*.jar
*.war
*.ear
*.iml

38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ Refer to Getting Started guide and 3 ways how Amazon Q Developer agent for code

## **Installation Instructions**

## Dependencies Setup

Before building the application, you need to install the movie-service-utils dependency in your local Maven repository. This utility library is available in two versions to support different Java versions:

### For Java 1.8 Version
```bash
mvn install:install-file \
-Dfile=./built-library/0_1_0/movie-service-utils-1.0-SNAPSHOT.jar \
-DgroupId=com.amazon.sample \
-DartifactId=movie-service-utils \
-Dversion=1.0-SNAPSHOT \
-Dpackaging=jar
```

## **Local**

1. Compile the application in Local IDE
2. Open a new terminal and type `java -jar .\target\movie-service-0.1.0.jar`
3. Follow the STEP 1 in AWS section below to set up AppConfig Configuration in your default AWS account profile
4. Open a browser and go to http://localhost:8080/movies/getMovies
5. You should be able to see list of paid movies
2. Follow the STEP 1 in AWS section below to set up AppConfig Configuration in your default AWS account profile
3. Open a browser and go to http://localhost:8080/movies/getMovies
4. You should be able to see list of paid movies

## **AWS**

Expand Down Expand Up @@ -116,13 +129,22 @@ This application has a Caching layer built in to cache the responses from AWS Ap

## **Installation Instructions**

### For Java 1.8 Version
```bash
mvn install:install-file \
-Dfile=./built-library/0_1_0/movie-service-utils-1.0-SNAPSHOT.jar \
-DgroupId=com.amazon.sample \
-DartifactId=movie-service-utils \
-Dversion=1.0-SNAPSHOT \
-Dpackaging=jar
```

## **Local**

1. Compile the application in Local IDE
2. Open a new terminal and type `java -jar .\target\movie-service-0.1.0.jar`
3. Follow the STEP 1 in AWS section below to set up AppConfig Configuration in your default AWS account profile
4. Open a browser and go to http://localhost:8080/movies/getMovies
5. You should be able to see list of 5 Paid movies
2. Follow the STEP 1 in AWS section below to set up AppConfig Configuration in your default AWS account profile
3. Open a browser and go to http://localhost:8080/movies/getMovies
4. You should be able to see list of paid movies

## **AWS**

Expand Down
35 changes: 35 additions & 0 deletions custom-transformation-post-qct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
id: sysout-to-logger
language: java
rule:
pattern: System.out.println($MATCH)
fix: logger.info($MATCH)

--- # this is YAML doc separator to have multiple rules in one file

id: update-movie-service-util-java17
language: html
rule:
pattern: |-
<dependency>
<groupId>org.amazonaws.samples</groupId>
<artifactId>movie-service-utils</artifactId>
<version>$VERSION</version>
</dependency>
constraints:
VERSION:
regex: "^0\\.1\\.0"
fix: |-
<dependency>
<groupId>org.amazonaws.samples</groupId>
<artifactId>movie-service-utils</artifactId>
<version>0.2.0</version>
</dependency>

--- # this is YAML doc separator to have multiple rules in one file
id: update-movie-service-util-method
language: java
rule:
pattern: |-
MovieUtils.isValidMovieName($MOVIE_NAME)
fix: |-
MovieUtils.isValidMovie($MOVIE_NAME, movieId)
43 changes: 43 additions & 0 deletions custom-transformation-pre-qct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
id: no-unused-vars
language: java
rule:
kind: local_variable_declaration
all:
- has:
has:
kind: identifier
pattern: $IDENT
- not:
precedes:
stopBy: end
has:
stopBy: end
any:
- { kind: identifier, pattern: $IDENT }
- { has: {kind: identifier, pattern: $IDENT, stopBy: end}}
fix: ''

--- # this is YAML doc separator to have multiple rules in one file

id: no-unused-imports
language: java
rule:
kind: import_declaration
all:
- not:
has:
kind: asterisk
- has:
has:
kind: identifier
pattern: $IDENT
- not:
precedes:
stopBy: end
has:
stopBy: end
any:
- { kind: identifier, pattern: $IDENT }
- { kind: type_identifier, pattern: $IDENT }
- { has: {kind: type_identifier, pattern: $IDENT, stopBy: end}}
fix: ''
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions movie-service-utils/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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>org.amazonaws.samples</groupId>
<artifactId>movie-service-utils</artifactId>
<version>0.2.0</version>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<dependencies>
<!-- Add any dependencies needed for the utils module -->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.amazonaws.samples.appconfig.utils;

public class MovieUtils {

/**
* Validates if a movie name meets the required criteria
* @param movieName The name of the movie to validate
* @return true if the movie name is valid, false otherwise
*/
public static boolean isValidMovie(String movieName, int movieId) {
if (movieName == null || movieName.trim().isEmpty()) {
return false;
}

if(movieId <= 0){
return false;
}
// Movie name should be between 1 and 200 characters
return movieName.trim().length() > 0 && movieName.trim().length() <= 200;
}
}
Binary file not shown.
3 changes: 3 additions & 0 deletions movie-service-utils/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=movie-service-utils
groupId=org.springframework
version=0.2.0
12 changes: 12 additions & 0 deletions orchestrator_qct_cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: orchestrator_qct_cli
description: My collection of custom transformations to run before and after a transformation.

pre_qct_actions:
ast-grep:
rules:
- custom-transformation-pre-qct.yaml

post_qct_actions:
ast-grep:
rules:
- custom-transformation-post-qct.yaml
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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>org.springframework</groupId>
<groupId>org.amazonaws.samples</groupId>
<artifactId>movie-service</artifactId>
<version>0.1.0</version>

Expand All @@ -25,6 +25,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.amazonaws.samples</groupId>
<artifactId>movie-service-utils</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions qct_tags.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
qct_cli,true
qct_cli_language,java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class ConfigurationCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.time.Clock;
import java.time.Duration;
import java.util.Objects;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class ConfigurationCacheItem<T> {
private final Duration ttl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.amazonaws.samples.appconfig.movies;

import com.amazonaws.samples.appconfig.utils.MovieUtils;

import java.time.Duration;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -109,6 +111,10 @@ public String movie() {

@RequestMapping(value = "/movies/{movie}/edit", method = POST)
public String processUpdateMovie(@Valid Movie movie, BindingResult result, @PathVariable("movieId") int movieId) {
if (!MovieUtils.isValidMovieName(movie.getMovieName())) {
result.rejectValue("name", "error.name", "Invalid movie name");
return "editMovieForm";
}
final AppConfigUtility appConfigUtility = new AppConfigUtility(getOrDefault(this::getClient, this::getDefaultClient),
getOrDefault(this::getConfigurationCache, ConfigurationCache::new),
getOrDefault(this::getCacheItemTtl, () -> cacheItemTtl),
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/amazonaws/samples/appconfig/utils/Encoder.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
// depreciation example - sun.misc.BASE64Encoder;
package com.amazonaws.samples.appconfig.utils;
import sun.misc.BASE64Encoder;
//import sun.misc.BASE64Encoder;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Logger;


public class Encoder {

Date defaultDate = new Date(1999, 0, 1);
Logger logger = Logger.getLogger(Encoder.class.getName());

private String unUsedVariable;

Date defaultDate;

{
String unused = "ast-grep unused string example";
Calendar calendar = new GregorianCalendar(1999, Calendar.JANUARY, 1);
defaultDate = calendar.getTime();
System.out.println("test ast-grep "+defaultDate);
}

byte[] bytes = new byte[57];
String enc1 = new sun.misc.BASE64Encoder().encode(bytes);
// String enc1 = new sun.misc.BASE64Encoder().encode(bytes);



}
}