|
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
@@ -45,17 +46,27 @@ public class EventHandler {
|
|
|
|
|
|
FingerprintCompareListItem[] fpTemplateList = new FingerprintCompareListItem[templateArray.length()];
|
|
|
for (int i = 0; i < templateArray.length(); i++) {
|
|
|
- System.out.println(templateArray);
|
|
|
JSONObject obj = templateArray.getJSONObject(i);
|
|
|
String name = obj.optString("name");
|
|
|
int fpPosition = obj.optInt("fpPosition");
|
|
|
String fpTemplateString = obj.optString("fpTemplate");
|
|
|
|
|
|
// Decoding it back to fingeprintTemplate so that afis can compare
|
|
|
- byte[] templateBytes = Base64.getDecoder().decode(fpTemplateString);
|
|
|
- FingerprintTemplate fpTemplate = new FingerprintTemplate(templateBytes);
|
|
|
+ // byte[] templateBytes = Base64.getDecoder().decode(fpTemplateString);
|
|
|
+ // FingerprintTemplate fpTemplate = new FingerprintTemplate(templateBytes);
|
|
|
+ try {
|
|
|
+ byte[] templateBytes = Base64.getDecoder().decode(fpTemplateString);
|
|
|
+ System.out.println("Decoded bytes length: " + templateBytes.length);
|
|
|
+
|
|
|
+ FingerprintTemplate fpTemplate = new FingerprintTemplate(templateBytes);
|
|
|
+ System.out.println("Successfully created FingerprintTemplate!");
|
|
|
+ fpTemplateList[i] = new FingerprintCompareListItem(name, fpPosition, fpTemplate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("Error decoding or constructing FingerprintTemplate: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- fpTemplateList[i] = new FingerprintCompareListItem(name, fpPosition, fpTemplate);
|
|
|
+ // fpTemplateList[i] = new FingerprintCompareListItem(name, fpPosition, fpTemplate);
|
|
|
};
|
|
|
|
|
|
if (imageBase64 == null || imageBase64.isEmpty()) {
|
|
@@ -68,6 +79,8 @@ public class EventHandler {
|
|
|
return handleRegistration(id, imageBase64, fpTemplateList, personInfo, fingerPosition);
|
|
|
case "verification":
|
|
|
return handleVerification(id, imageBase64, fpTemplateList, personInfo, fingerPosition);
|
|
|
+ case "qualityassurance":
|
|
|
+ return handleQualityAssurance(id, imageBase64, fpTemplateList, personInfo, fingerPosition);
|
|
|
default:
|
|
|
// Unknown command fallback
|
|
|
JSONObject unknown = new JSONObject();
|
|
@@ -79,7 +92,7 @@ public class EventHandler {
|
|
|
} catch (Exception e) {
|
|
|
// Generic error response
|
|
|
JSONObject error = new JSONObject();
|
|
|
- error.put("error", "Failed to process message: " + e.getMessage());
|
|
|
+ error.put("message", "Failed to process message: " + e.getMessage());
|
|
|
return error.toString();
|
|
|
}
|
|
|
}
|
|
@@ -87,6 +100,7 @@ public class EventHandler {
|
|
|
public static String handleRegistration(String id, String imageBase64, FingerprintCompareListItem[] templateArray, PersonFingerprintData personInfo, int fingerPosition) {
|
|
|
try {
|
|
|
// Decode the fingerprint image from base64
|
|
|
+ Integer edgeScore = null;
|
|
|
byte[] imageBytes = Base64.getDecoder().decode(imageBase64);
|
|
|
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
|
|
|
if (image == null) {
|
|
@@ -96,10 +110,21 @@ public class EventHandler {
|
|
|
// Create a FingerprintTemplate from the imageBytes
|
|
|
FingerprintTemplate probeTemplate = new FingerprintTemplate(new FingerprintImage(imageBytes));
|
|
|
|
|
|
+ // Logic for transparency goes here
|
|
|
+ // ... <Edge Number Must be 250 to be considered success>
|
|
|
+ try (TransparencyContents transparency = new TransparencyContents()) {
|
|
|
+ FingerprintTemplate probe = new FingerprintTemplate(imageBytes);
|
|
|
+ transparency.accepts("edge-table");
|
|
|
+ transparency.take("edge-table", "application/cbor", imageBytes);
|
|
|
+ edgeScore = transparency.countEdgeNumber();
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("Error: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
// If no existing templates are provided, register the new one
|
|
|
if (templateArray == null || templateArray.length <= 0) {
|
|
|
// Register this new template
|
|
|
- String response = buildJavaResponse(id, "Registration", "Success", "No existing templates. Registered as new.", probeTemplate, 100.0, personInfo, fingerPosition);
|
|
|
+ String response = buildJavaResponse(id, "Registration", "Success", "No existing templates. Registered as new.", probeTemplate, 100.0, edgeScore, personInfo, fingerPosition);
|
|
|
return response.toString(); // Return the response as a JSON string
|
|
|
}
|
|
|
|
|
@@ -121,16 +146,16 @@ public class EventHandler {
|
|
|
// Return response based on score
|
|
|
if (bestScore >= MATCH_THRESHOLD) {
|
|
|
// Match found
|
|
|
- return buildJavaResponse(id, "Registration", "Registered", "Existing Fingerprint template found for " + matchedPerson + "!", probeTemplate, bestScore, personInfo, fingerPosition).toString();
|
|
|
+ return buildJavaResponse(id, "Registration", "Registered", "Existing Fingerprint template found for " + matchedPerson + "!", probeTemplate, bestScore, edgeScore, personInfo, fingerPosition).toString();
|
|
|
} else {
|
|
|
// Register new template
|
|
|
- String response = buildJavaResponse(id, "Registration", "Success", "New fingerprint template constructed.", probeTemplate, 100.0, personInfo, fingerPosition);
|
|
|
+ String response = buildJavaResponse(id, "Registration", "Success", "New fingerprint template constructed.", probeTemplate, 100.0, edgeScore, personInfo, fingerPosition);
|
|
|
return response.toString();
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
// Handle errors during registration
|
|
|
- String errorResponse = buildJavaResponse(id, "Registration", "Failed", "Template Construction Failed: " + e.getMessage(), null, 0.0, personInfo, fingerPosition);
|
|
|
+ String errorResponse = buildJavaResponse(id, "Registration", "Failed", "Template Construction Failed: " + e.getMessage(), null, 0.0, null, personInfo, fingerPosition);
|
|
|
return errorResponse.toString();
|
|
|
}
|
|
|
}
|
|
@@ -138,6 +163,7 @@ public class EventHandler {
|
|
|
public static String handleVerification(String id, String imageBase64, FingerprintCompareListItem[] templateArray, PersonFingerprintData personInfo, int fingerPosition) {
|
|
|
try {
|
|
|
// Decode the fingerprint image from base64
|
|
|
+ Integer edgeScore = null;
|
|
|
byte[] imageBytes = Base64.getDecoder().decode(imageBase64);
|
|
|
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
|
|
|
if (image == null) {
|
|
@@ -147,6 +173,17 @@ public class EventHandler {
|
|
|
// Create a FingerprintTemplate from the imageBytes
|
|
|
FingerprintTemplate probeTemplate = new FingerprintTemplate(new FingerprintImage(imageBytes));
|
|
|
|
|
|
+ // Logic for transparency goes here
|
|
|
+ // ... <Edge Number Must be 250 to be considered success>
|
|
|
+ try (TransparencyContents transparency = new TransparencyContents()) {
|
|
|
+ FingerprintTemplate probe = new FingerprintTemplate(imageBytes);
|
|
|
+ transparency.accepts("edge-table");
|
|
|
+ transparency.take("edge-table", "application/cbor", imageBytes);
|
|
|
+ edgeScore = transparency.countEdgeNumber();
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("Error: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
double bestScore = 0;
|
|
|
int matchedFingerprintPosition = 0; // just put 0 as default value for now
|
|
|
String matchedPerson = null;
|
|
@@ -185,7 +222,7 @@ public class EventHandler {
|
|
|
fingerprints
|
|
|
);
|
|
|
// JavaResponse response = new JavaResponse(id, "Verification", "Match found.", matchedData, bestScore);
|
|
|
- String response = buildJavaResponse(id, "Verification", "Registered", "Match found.", matchedFingerprintTemplate, bestScore, matchedData, matchedFingerprintPosition);
|
|
|
+ String response = buildJavaResponse(id, "Verification", "Registered", "Match found.", matchedFingerprintTemplate, bestScore, null, matchedData, matchedFingerprintPosition);
|
|
|
return response.toString();
|
|
|
} else {
|
|
|
// No match
|
|
@@ -196,8 +233,7 @@ public class EventHandler {
|
|
|
personInfo.getCode(),
|
|
|
new ArrayList<Fingerprint>()
|
|
|
);
|
|
|
- // JavaResponse response = new JavaResponse(id, "Verification", "No match found.", noMatchData, bestScore);
|
|
|
- String response = buildJavaResponse(id, "Verification", "Not Registered", "No Match found.", matchedFingerprintTemplate, bestScore, noMatchData, fingerPosition); // defaul value
|
|
|
+ String response = buildJavaResponse(id, "Verification", "Not Registered", "No Match found.", probeTemplate, bestScore, null, noMatchData, fingerPosition); // defaul value
|
|
|
return response.toString();
|
|
|
}
|
|
|
|
|
@@ -209,7 +245,43 @@ public class EventHandler {
|
|
|
personInfo.getCode(),
|
|
|
new ArrayList<Fingerprint>()
|
|
|
);
|
|
|
- String errorResponse = buildJavaResponse(id, "Verification", "Failed", "No Match found.", null, 0, personInfo, fingerPosition); // defaul value
|
|
|
+ String errorResponse = buildJavaResponse(id, "Verification", "Failed", "No Match found.", null, 0, null, personInfo, fingerPosition); // defaul value
|
|
|
+ return errorResponse.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String handleQualityAssurance(String id, String imageBase64, FingerprintCompareListItem[] templateArray, PersonFingerprintData personInfo, int fingerPosition) {
|
|
|
+ try {
|
|
|
+ Integer edgeScore = null;
|
|
|
+ double bestScore = 0;
|
|
|
+ // Decode the fingerprint image from base64
|
|
|
+ byte[] imageBytes = Base64.getDecoder().decode(imageBase64);
|
|
|
+ BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
|
|
|
+ if (image == null) {
|
|
|
+ throw new IllegalArgumentException("Invalid image format.");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create a FingerprintTemplate from the imageBytes
|
|
|
+ FingerprintTemplate probeTemplate = new FingerprintTemplate(new FingerprintImage(imageBytes));
|
|
|
+
|
|
|
+ // Logic for transparency goes here
|
|
|
+ // ... <Edge Number Must be 250 to be considered success>
|
|
|
+ try (TransparencyContents transparency = new TransparencyContents()) {
|
|
|
+ transparency.accepts("edge-table");
|
|
|
+ transparency.take("edge-table", "application/cbor", imageBytes);
|
|
|
+ edgeScore = transparency.countEdgeNumber();
|
|
|
+
|
|
|
+ // Addition features to verify against existing fingerprint data
|
|
|
+ String response = buildJavaResponse(id, "QualityAssurance", "Success", "Edge score result: " + bestScore, probeTemplate, bestScore, edgeScore, personInfo, fingerPosition); // defaul value
|
|
|
+ return response.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("Error: " + e.getMessage());
|
|
|
+ String response = buildJavaResponse(id, "QualityAssurance", "Failed", "Edge score result: " + bestScore, probeTemplate, bestScore, edgeScore, personInfo, fingerPosition); // defaul value
|
|
|
+ return response.toString();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // Handle errors during checking
|
|
|
+ String errorResponse = buildJavaResponse(id, "QualityAssurance", "Failed", "Unable to produce Edge score... " + e.getMessage(), null, 0.0, null, personInfo, fingerPosition);
|
|
|
return errorResponse.toString();
|
|
|
}
|
|
|
}
|
|
@@ -221,6 +293,7 @@ public class EventHandler {
|
|
|
String message,
|
|
|
FingerprintTemplate fingerprintTemplate,
|
|
|
double score,
|
|
|
+ Integer edgeScore,
|
|
|
PersonFingerprintData personInfo,
|
|
|
int fingerPosition) {
|
|
|
|
|
@@ -234,8 +307,8 @@ public class EventHandler {
|
|
|
personInfo.addFingerprint(fingerprint);
|
|
|
|
|
|
// Build the JavaResponse
|
|
|
- JavaResponse javaResponse = new JavaResponse(id, operation, status, message, personInfo, score);
|
|
|
- System.out.println("Java Response: " + javaResponse);
|
|
|
+ JavaResponse javaResponse = new JavaResponse(id, operation, status, message, personInfo, score, edgeScore);
|
|
|
+ // System.out.println("Java Response: " + javaResponse.toString());
|
|
|
|
|
|
// Serialize JavaResponse to JSON string using Jackson
|
|
|
try {
|