Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ unicorn_approvals/ApprovalsService/target/**
unicorn_contracts/ContractsService/target/**
unicorn_web/ApprovalService/target/**
unicorn_web/SearchService/target/**
unicorn_web/PublicationManagerService/target/**
unicorn_web/Common/target/**
**/.aws-sam/
.DS_Store**
Expand Down
42 changes: 24 additions & 18 deletions unicorn_approvals/ApprovalsService/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<aws.java.sdk.version>2.27.21</aws.java.sdk.version>
<aws.java.powertool.version>1.18.0</aws.java.powertool.version>
<aws-lambda-java-events.version>3.13.0</aws-lambda-java-events.version>
<mockito-core.version>5.13.0</mockito-core.version>
<aws.java.sdk.version>2.32.29</aws.java.sdk.version>
<aws.java.powertool.version>1.20.2</aws.java.powertool.version>
<aws-lambda-java-events.version>3.16.1</aws-lambda-java-events.version>
<mockito-core.version>5.18.0</mockito-core.version>
<junit.version>4.13.2</junit.version>
<aws-lambda-java-tests.version>1.1.1</aws-lambda-java-tests.version>
<aws-lambda-java-core.version>1.2.3</aws-lambda-java-core.version>
<netty-nio-client.version>2.27.21</netty-nio-client.version>
<aws-lambda-java-tests.version>1.1.2</aws-lambda-java-tests.version>
<aws-lambda-java-core.version>1.3.0</aws-lambda-java-core.version>
<netty-nio-client.version>2.32.29</netty-nio-client.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -81,29 +81,29 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
<version>2.18.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.2</version>
<version>2.18.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
<version>2.18.4</version>
</dependency>

<!-- Log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.20.0</version>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -132,7 +132,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.5.3</version>
<configuration>
<environmentVariables>
<LAMBDA_TASK_ROOT>handler</LAMBDA_TASK_ROOT>
Expand All @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<configuration>
</configuration>
<executions>
Expand All @@ -157,11 +157,10 @@
<plugin>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.13.1</version>
<version>1.14.1</version>
<configuration>
<source>17</source>
<target>17</target>
<complianceLevel>17</complianceLevel>
<release>17</release>
<aspectLibraries>
<aspectLibrary>
<groupId>software.amazon.lambda</groupId>
Expand All @@ -184,11 +183,18 @@
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.24</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.14.0</version>
<configuration>
<source>17</source>
<target>17</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,70 +27,60 @@
*/
public class ContractStatusChangedHandlerFunction {

Logger logger = LogManager.getLogger();

final String TABLE_NAME = System.getenv("CONTRACT_STATUS_TABLE");

ObjectMapper objectMapper = new ObjectMapper();

DynamoDbClient dynamodbClient = DynamoDbClient.builder()
.build();

/**
*
* @param inputStream
* @param outputStream
* @param context
* @return
* @throws IOException
*
*/
@Tracing
@Metrics(captureColdStart = true)
@Logging(logEvent = true)
public void handleRequest(InputStream inputStream, OutputStream outputStream,
Context context) throws IOException {

// deseralised and save contract status change in dynamodb table

Event event = Marshaller.unmarshal(inputStream,
Event.class);
// save to database
ContractStatusChanged contractStatusChanged = event.getDetail();
saveContractStatus(contractStatusChanged.getPropertyId(), contractStatusChanged.getContractStatus(),
contractStatusChanged.getContractId(),
contractStatusChanged.getContractLastModifiedOn());

OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
writer.write(objectMapper.writeValueAsString(event.getDetail()));
writer.close();
}

@Tracing
void saveContractStatus(String propertyId,
String contractStatus, String contractId, Long contractLastModifiedOn) {
Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
AttributeValue keyvalue = AttributeValue.fromS(propertyId);
key.put("property_id", keyvalue);

Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":t", AttributeValue.fromS(contractStatus));
expressionAttributeValues.put(":c", AttributeValue.fromS(contractId));
expressionAttributeValues.put(":m", AttributeValue
.fromN(String.valueOf(contractLastModifiedOn)));

UpdateItemRequest updateItemRequest = UpdateItemRequest.builder()
.key(key)
.tableName(TABLE_NAME)
.updateExpression(
"set contract_status=:t, contract_last_modified_on=:m, contract_id=:c")
.expressionAttributeValues(expressionAttributeValues)
.build();

dynamodbClient.updateItem(updateItemRequest);
}

public void setDynamodbClient(DynamoDbClient dynamodbClient) {
this.dynamodbClient = dynamodbClient;
private static final Logger logger = LogManager.getLogger();
private static final String TABLE_NAME = System.getenv("CONTRACT_STATUS_TABLE");
private static final ObjectMapper objectMapper = new ObjectMapper();

private DynamoDbClient dynamodbClient = DynamoDbClient.builder().build();

/**
* Handles contract status change events from EventBridge
*
* @param inputStream the input stream containing the event
* @param outputStream the output stream for the response
* @param context the Lambda context
* @throws IOException if there's an error processing the event
*/
@Tracing
@Metrics(captureColdStart = true)
@Logging(logEvent = true)
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
Event event = Marshaller.unmarshal(inputStream, Event.class);
ContractStatusChanged contractStatusChanged = event.getDetail();

saveContractStatus(
contractStatusChanged.getPropertyId(),
contractStatusChanged.getContractStatus(),
contractStatusChanged.getContractId(),
contractStatusChanged.getContractLastModifiedOn()
);

try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
writer.write(objectMapper.writeValueAsString(event.getDetail()));
}
}

@Tracing
void saveContractStatus(String propertyId, String contractStatus, String contractId, Long contractLastModifiedOn) {
Map<String, AttributeValue> key = Map.of("property_id", AttributeValue.fromS(propertyId));

Map<String, AttributeValue> expressionAttributeValues = Map.of(
":t", AttributeValue.fromS(contractStatus),
":c", AttributeValue.fromS(contractId),
":m", AttributeValue.fromN(String.valueOf(contractLastModifiedOn))
);

UpdateItemRequest updateItemRequest = UpdateItemRequest.builder()
.key(key)
.tableName(TABLE_NAME)
.updateExpression("set contract_status=:t, contract_last_modified_on=:m, contract_id=:c")
.expressionAttributeValues(expressionAttributeValues)
.build();

dynamodbClient.updateItem(updateItemRequest);
}

public void setDynamodbClient(DynamoDbClient dynamodbClient) {
this.dynamodbClient = dynamodbClient;
}
}
Loading
Loading