Skip to content

Commit 31a959c

Browse files
committed
updated logic
1 parent 77082d6 commit 31a959c

File tree

3 files changed

+77
-51
lines changed

3 files changed

+77
-51
lines changed

javav2/example_code/entityresolution/src/main/java/com/example/entity/scenario/EntityResScenario.java

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class EntityResScenario {
2828
private static String workflowName = "workflow-"+ UUID.randomUUID();
2929

3030
public static void main(String[] args) throws InterruptedException {
31-
3231
String jsonSchemaMappingName = "jsonschema-" + UUID.randomUUID();
3332
String jsonSchemaMappingArn = null;
3433
String csvSchemaMappingName = "csv-" + UUID.randomUUID();
@@ -126,13 +125,14 @@ Amazon Web Services (AWS) that helps organizations extract, link, and
126125
and uses machine learning to link related entities, enabling a
127126
consolidated, accurate view for improved data quality and decision-making.
128127
129-
In this example, the schema mapping lines up with the fields in the JSON objects. That is,
128+
In this example, the schema mapping lines up with the fields in the JSON ans CSV objects. That is,
130129
it contains these fields: id, name, and email.
131130
""");
132131
waitForInputToContinue(scanner);
133132
try {
134133
CreateSchemaMappingResponse response = actions.createSchemaMappingAsync(jsonSchemaMappingName).join();
135134
jsonSchemaMappingArn = response.schemaArn();
135+
logger.info("The JSON schema mapping ARN is "+jsonSchemaMappingArn);
136136
} catch (CompletionException ce) {
137137
Throwable cause = ce.getCause();
138138
logger.info("Failed to create JSON schema mapping: " + (cause != null ? cause.getMessage() : ce.getMessage()));
@@ -141,12 +141,11 @@ Amazon Web Services (AWS) that helps organizations extract, link, and
141141
try {
142142
CreateSchemaMappingResponse response = actions.createSchemaMappingAsync(csvSchemaMappingName).join();
143143
csvSchemaMappingArn = response.schemaArn();
144+
logger.info("The CSV schema mapping ARN is "+csvSchemaMappingArn);
144145
} catch (CompletionException ce) {
145146
Throwable cause = ce.getCause();
146147
logger.info("Failed to create CSV schema mapping: " + (cause != null ? cause.getMessage() : ce.getMessage()));
147148
}
148-
149-
150149
waitForInputToContinue(scanner);
151150
logger.info(DASHES);
152151

@@ -231,19 +230,19 @@ Amazon Web Services (AWS) that helps organizations extract, link, and
231230
logger.info(DASHES);
232231

233232
logger.info(DASHES);
234-
logger.info("8. Delete the AWS Entity Resolution Workflow.");
233+
logger.info("8. View the results of the AWS Entity Resolution Workflow.");
235234
logger.info("""
236-
You cannot delete a workflow that is in a running state.
237-
Would you like to wait for the workflow that we started in step 3 to complete.
235+
You cannot view the result of the workflow that is in a running state.
236+
In order to view the results, you need to wait for the workflow that we started in step 3 to complete.
238237
239-
If you choose not to wait, you will need to delete the workflow manually
240-
in the AWS Management Console.
238+
If you choose not to wait, you cannot view the results or delete the workflow. You would have to
239+
perform both tasks manually in the AWS Management Console.
241240
242241
This can take up to 30 mins (y/n).
243242
""");
244-
String delAns = scanner.nextLine().trim();
245-
if (delAns.equalsIgnoreCase("y")) {
246-
logger.info("You selected to delete Entity Resolution Workflow.");
243+
String viewAns = scanner.nextLine().trim();
244+
if (viewAns.equalsIgnoreCase("y")) {
245+
logger.info("You selected to view the Entity Resolution Workflow results.");
247246
waitForInputToContinue(scanner);
248247
countdownWithWorkflowCheck(actions, 1800, jobId, workflowName);
249248
JobMetrics metrics = actions.getJobInfo(workflowName, jobId).join();
@@ -272,30 +271,38 @@ Amazon Web Services (AWS) that helps organizations extract, link, and
272271
the confidence level is lower for the differing email addresses.
273272
274273
""");
275-
try {
276-
actions.deleteMatchingWorkflowAsync(workflowName).join();
277-
logger.info("Workflow deleted successfully!");
278-
} catch (CompletionException ce) {
279-
Throwable cause = ce.getCause();
280-
logger.info("Failed to delete workflow: " + (cause != null ? cause.getMessage() : ce.getMessage()));
281-
}
282-
}
283-
waitForInputToContinue(scanner);
284-
logger.info(DASHES);
285274

286-
logger.info(DASHES);
287-
logger.info("""
275+
logger.info("Do you want to delete the resources, including workflow?");
276+
String delAns = scanner.nextLine().trim();
277+
if (delAns.equalsIgnoreCase("y")) {
278+
try {
279+
actions.deleteMatchingWorkflowAsync(workflowName).join();
280+
logger.info("Workflow deleted successfully!");
281+
} catch (CompletionException ce) {
282+
Throwable cause = ce.getCause();
283+
logger.info("Failed to delete workflow: " + (cause != null ? cause.getMessage() : ce.getMessage()));
284+
}
285+
waitForInputToContinue(scanner);
286+
logger.info(DASHES);
287+
logger.info("""
288288
Now we delete the CloudFormation stack, which deletes
289289
the resources that were created at the beginning
290290
""");
291+
waitForInputToContinue(scanner);
292+
logger.info(DASHES);
293+
try {
294+
deleteResources();
295+
} catch (CompletionException ce) {
296+
Throwable cause = ce.getCause();
297+
logger.error("Failed to delete Glue Table: {}", cause != null ? cause.getMessage() : ce.getMessage());
298+
}
299+
300+
} else {
301+
logger.info("You can delete the Workflow later in the AWS Management console.");
302+
}
303+
}
291304
waitForInputToContinue(scanner);
292305
logger.info(DASHES);
293-
try {
294-
deleteResources();
295-
} catch (CompletionException ce) {
296-
Throwable cause = ce.getCause();
297-
logger.error("Failed to delete Glue Table: {}", cause != null ? cause.getMessage() : ce.getMessage());
298-
}
299306

300307
logger.info(DASHES);
301308
logger.info("This concludes the AWS Entity Resolution scenario.");
@@ -336,13 +343,13 @@ public static void countdownWithWorkflowCheck(EntityResActions actions, int tota
336343
// Check workflow status every 60 seconds
337344
if (secondsElapsed % 60 == 0 || remainingTime <= 0) {
338345
if (actions.checkWorkflowStatusCompleteAsync(jobId, workflowName).join()) {
339-
logger.info(""); // Move to the next line after countdown
346+
logger.info(""); // Move to the next line after countdown.
340347
logger.info("Countdown complete: Workflow is in SUCCEEDED state!");
341348
break;
342349
}
343350
}
344351

345-
// If countdown reaches zero, reset it for continuous countdown
352+
// If countdown reaches zero, reset it for continuous countdown.
346353
if (remainingTime <= 0) {
347354
secondsElapsed = 0;
348355
}
@@ -352,7 +359,6 @@ private static void deleteResources(){
352359
CloudFormationHelper.emptyS3Bucket(glueBucketName);
353360
CloudFormationHelper.destroyCloudFormationStack(STACK_NAME);
354361
logger.info("Resources deleted successfully!");
355-
356362
}
357363
}
358364
// snippet-end:[entityres.java2_scenario.main]

javav2/example_code/entityresolution/src/test/java/EntityResTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ public static void setUp() {
7575
}
7676
]
7777
""";
78-
if (!actions.doesObjectExist(dataS3bucket)) {
79-
actions.uploadInputData(dataS3bucket, json);
80-
} else {
81-
System.out.println("The JSON exists in " + dataS3bucket);
82-
}
78+
79+
String csv = """
80+
id,name,email,phone
81+
1,Alice B. Johnson,[email protected],746-876-9846
82+
2,Bob Smith Jr.,[email protected],987-654-3210
83+
3,Charlie Black,[email protected],345-567-1234
84+
7,Jane E. Doe,[email protected],111-222-3333
85+
""";
86+
87+
actions.uploadInputData(dataS3bucket, json, csv);
8388
}
8489

8590
@Test
@@ -99,7 +104,8 @@ public void testCreateMapping() {
99104
@Order(2)
100105
public void testCreateMappingWorkflow() {
101106
assertDoesNotThrow(() -> {
102-
workflowArn = actions.createMatchingWorkflowAsync(roleARN, workflowName, outputBucket, inputGlueTableArn, schemaName).join();
107+
//workflowArn = actions.actions.createMatchingWorkflowAsync(roleARN, workflowName, glueBucketName, jsonGlueTableArn
108+
// , jsonSchemaMappingName, csvGlueTableArn, csvSchemaMappingName).join();
103109
assertNotNull(workflowArn);
104110
});
105111
logger.info("Test 2 passed");

scenarios/basics/entity_resolution/README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
1+
# AWS Entity Resolution Java Program
2+
13
## Overview
2-
This AWS Entity Resolution basic scenario demonstrates how to interact with the AWS Entity Resolution service using an AWS SDK. The scenario covers various operations such as creating a schema mapping, creating a matching workflow, starting a matching job, and so on.
4+
This AWS Entity Resolution basic scenario demonstrates how to interact with the AWS Entity Resolution service using an AWS SDK. This Java application demonstrates how to use AWS Entity Resolution to integrate and deduplicate data from multiple sources using machine learning-based matching. The program walks through setting up AWS resources, uploading structured data, defining schema mappings, creating a matching workflow, and running a matching job.
35

4-
## Key Operations
56

6-
1. **Create an AWS Entity Resolution schema mapping**:
7-
- This step creates an AWS Entity Resolution schema mapping by invoking the `createSchemaMapping` method.
7+
**Note:** See the [specification document](SPECIFICATION.md) for a complete list of operations.
88

9-
2. **Create an AWS Entity Resolution workflow**:
10-
- This step creates an AWS Entity Resolution matching workflow by invoking the `createMatchingWorkflow` method.
9+
## Features
1110

12-
3. **Start a matching aorkflow**:
13-
- This step starts the AWS Entity Resolution matching workflow by invoking the `startMatchingJob` method.
11+
1. Uses AWS CloudFormation to create necessary resources:
1412

15-
4. **Get workflow job details**:
16-
- This step gets workflow job details by invoking the `getMatchingJob` method.
13+
- AWS Glue Data Catalog table
1714

15+
- AWS IAM role
1816

19-
**Note:** See the [specification document](SPECIFICATION.md) for a complete list of operations.
17+
- AWS S3 bucket
18+
19+
- AWS Entity Resolution Schema
20+
21+
2. Uploads sample JSON and CSV data to S3
22+
23+
3. Creates schema mappings for JSON and CSV datasets
24+
25+
4. Creates and starts an Entity Resolution matching workflow
26+
27+
5. Retrieves job details and schema mappings
28+
29+
6. Lists available schema mappings
30+
31+
7. Tags AWS resources for better organization
32+
33+
8. Views the results of the workflow
2034

2135
## Resources
2236

2337
This Basics scenario requires an IAM role that has permissions to work with the AWS Entity Resolution service,
24-
an AWS Glue database, and two S3 buckets. A CDK script is provided to create these resources.
38+
an AWS Glue database, and an S3 bucket. A CDK script is provided to create these resources.
2539
See the resources [Readme](../../../resources/cdk/entityresolution_resources/README.md) file.
2640

2741
## Implementations

0 commit comments

Comments
 (0)