Bladeren bron

cotnent restructuring

Dr-Swopt 2 maanden geleden
bovenliggende
commit
66446460b9

+ 50 - 156
src/main/java/com/example/EventHandler.java

@@ -4,8 +4,6 @@ import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
 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;
@@ -13,14 +11,19 @@ import javax.imageio.ImageIO;
 import org.json.JSONArray;
 import org.json.JSONObject;
 
+import com.example.types.Fingerprint;
+import com.example.types.FingerprintCompareListItem;
+import com.example.types.PersonFingerprintData;
+import com.example.types.VerificationResult;
+import static com.example.utils.JavaResponse.buildJavaResponse;
+import com.example.utils.TransparencyContents;
+import com.example.utils.Verification;
 import com.machinezoo.sourceafis.FingerprintImage;
-import com.machinezoo.sourceafis.FingerprintMatcher;
 import com.machinezoo.sourceafis.FingerprintTemplate;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class EventHandler {
 
-    private static final double MATCH_THRESHOLD = 40.0;
+    private static FingerprintCompareListItem[] registeredFingerprints = new FingerprintCompareListItem[0];
 
     public static String handleEvent(String rawMessage) {
         try {
@@ -81,6 +84,8 @@ public class EventHandler {
                     return handleVerification(id, imageBase64, fpTemplateList, personInfo, fingerPosition);
                 case "qualityassurance":
                     return handleQualityAssurance(id, imageBase64, fpTemplateList, personInfo, fingerPosition);
+                case "updateRegisteredFingerprints":
+                    return updateRegisteredFingerprints(id, fpTemplateList);
                 default:
                     // Unknown command fallback
                     JSONObject unknown = new JSONObject();
@@ -100,62 +105,40 @@ 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;
+            AtomicInteger edgeScore = new AtomicInteger();
             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()) {
-                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 (image == null) {
+                throw new IllegalArgumentException("Invalid image format.");
             }
 
+            // Calculate edge scores to determine fingerprint quality
+            edgeScore.set(TransparencyContents.calculateEdgeScore(imageBytes));
+
             // If no existing templates are provided, register the new one
-            if (templateArray == null || templateArray.length <= 0) {
+            if (templateArray == null || templateArray.length <= 0 && registeredFingerprints.length <= 0) {
                 // Register this new template
-                String response = buildJavaResponse(id, "Registration", "Success", "No existing templates. Registered as new.", probeTemplate, 100.0, edgeScore, personInfo, fingerPosition);
+                String response = buildJavaResponse(id, "Registration", "Success", "No existing templates. Registered as new.", probeTemplate, 100.0, edgeScore.get(), personInfo, fingerPosition);
                 return response.toString();  // Return the response as a JSON string
             }
 
-            // Compare with existing templates
-            double bestScore = 0;
-            String matchedPerson = null;
-
-            for (FingerprintCompareListItem entry : templateArray) {
-                String personName = entry.getName();
-                FingerprintTemplate candidate = entry.getFingerprint();
-
-                double score = new FingerprintMatcher(probeTemplate).match(candidate);
-                if (score > bestScore) {
-                    bestScore = score;
-                    matchedPerson = personName;
-                }
-            }
-
+            VerificationResult matchedPerson = Verification.verifyFingeprint(probeTemplate, templateArray, registeredFingerprints);
             // Return response based on score
-            if (bestScore >= MATCH_THRESHOLD) {
-                // Match found
-                return buildJavaResponse(id, "Registration", "Registered", "Existing Fingerprint template found for " + matchedPerson + "!", probeTemplate, bestScore, edgeScore, personInfo, fingerPosition).toString();
+            if (matchedPerson != null) { // Match found
+                String response = buildJavaResponse(id, "Registration", "Registered", "Existing Fingerprint template found for " + matchedPerson + "!", probeTemplate, matchedPerson.getScore(), edgeScore.get(), personInfo, fingerPosition);
+                return response;
             } else {
                 // Register new template
-                String response = buildJavaResponse(id, "Registration", "Success", "New fingerprint template constructed.", probeTemplate, 100.0, edgeScore, personInfo, fingerPosition);
+                String response = buildJavaResponse(id, "Registration", "Success", "New fingerprint template constructed.", probeTemplate, 100.0, edgeScore.get(), 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, null, personInfo, fingerPosition);
+            String errorResponse = buildJavaResponse(id, "Registration", "Failed", "Template Construction Failed: " + e.getMessage(), null, 0.0, 0, personInfo, fingerPosition);
             return errorResponse.toString();
         }
     }
@@ -163,7 +146,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;
+            AtomicInteger edgeScore = new AtomicInteger();
             byte[] imageBytes = Base64.getDecoder().decode(imageBase64);
             BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
             if (image == null) {
@@ -173,87 +156,28 @@ 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());
-            }
+            // Calculate edge scores to determine fingerprint quality
+            edgeScore.set(TransparencyContents.calculateEdgeScore(imageBytes));
 
-            double bestScore = 0;
-            int matchedFingerprintPosition = 0; // just put 0 as default value for now
-            String matchedPerson = null;
-            FingerprintTemplate matchedFingerprintTemplate = null;
+            VerificationResult matchedPerson = Verification.verifyFingeprint(probeTemplate, templateArray, registeredFingerprints);
 
-            for (int i = 0; i < templateArray.length; i++) {
-                FingerprintCompareListItem entry = templateArray[i];
-                String personName = entry.getName();
-                int fpPosition = entry.getFingerPosition();
-                FingerprintTemplate candidateTemplate = entry.getFingerprint();
-
-                // Maybe there's no need to check? will see about it later
-                if (candidateTemplate == null) {
-                    continue;
-                }
-
-                double score = new FingerprintMatcher(probeTemplate).match(candidateTemplate);
-
-                if (score > bestScore) {
-                    bestScore = score;
-                    matchedFingerprintPosition = fpPosition;
-                    matchedPerson = personName;
-                    matchedFingerprintTemplate = candidateTemplate;
-                }
-            }
-
-            if (bestScore >= MATCH_THRESHOLD) {
-                // Match found
-                Fingerprint matchedFingerprint = new Fingerprint(matchedPerson, matchedFingerprintPosition, Base64.getEncoder().encodeToString(matchedFingerprintTemplate.toByteArray()));
-                List<Fingerprint> fingerprints = Collections.singletonList(matchedFingerprint);
-                PersonFingerprintData matchedData = new PersonFingerprintData(
-                        personInfo.getId(),
-                        matchedPerson,
-                        personInfo.getOrg(),
-                        personInfo.getCode(),
-                        fingerprints
-                );
-                // JavaResponse response = new JavaResponse(id, "Verification", "Match found.", matchedData, bestScore);
-                String response = buildJavaResponse(id, "Verification", "Registered", "Match found.", matchedFingerprintTemplate, bestScore, null, matchedData, matchedFingerprintPosition);
-                return response.toString();
+            // Return response based on score
+            if (matchedPerson != null) { // Match found
+                return buildJavaResponse(id, "Verification", "Registered", "Existing Fingerprint template found for " + matchedPerson.getName() + "!", probeTemplate, matchedPerson.getScore(), edgeScore.get(), personInfo, fingerPosition).toString().toString();
             } else {
-                // No match
-                PersonFingerprintData noMatchData = new PersonFingerprintData(
-                        personInfo.getId(),
-                        personInfo.getName(),
-                        personInfo.getOrg(),
-                        personInfo.getCode(),
-                        new ArrayList<Fingerprint>()
-                );
-                String response = buildJavaResponse(id, "Verification", "Not Registered", "No Match found.", probeTemplate, bestScore, null, noMatchData, fingerPosition); // defaul value
-                return response.toString();
+                // Register new template
+                return buildJavaResponse(id, "Verification", "Not Registered", "Fingerprint Data Not found.", probeTemplate, 0, 0, personInfo, fingerPosition);
             }
 
         } catch (Exception e) {
-            PersonFingerprintData errorData = new PersonFingerprintData(
-                    personInfo.getId(),
-                    personInfo.getName(),
-                    personInfo.getOrg(),
-                    personInfo.getCode(),
-                    new ArrayList<Fingerprint>()
-            );
-            String errorResponse = buildJavaResponse(id, "Verification", "Failed", "No Match found.", null, 0, null, personInfo, fingerPosition); // defaul value
+            String errorResponse = buildJavaResponse(id, "Verification", "Failed", "Verification operation faulty...", null, 0, 0, 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;
+            AtomicInteger edgeScore = new AtomicInteger();
             // Decode the fingerprint image from base64
             byte[] imageBytes = Base64.getDecoder().decode(imageBase64);
             BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
@@ -264,61 +188,31 @@ 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()) {
-                transparency.accepts("edge-table");
-                transparency.take("edge-table", "application/cbor", imageBytes);
-                edgeScore = transparency.countEdgeNumber();
+            // Calculate edge scores to determine fingerprint quality
+            edgeScore.set(TransparencyContents.calculateEdgeScore(imageBytes));
+            System.out.println("Edge Score " + edgeScore);
 
-                // 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();
+            VerificationResult matchedPerson = Verification.verifyFingeprint(probeTemplate, templateArray, registeredFingerprints);
+
+            // Return response based on score
+            if (matchedPerson != null) { // Match found
+                return buildJavaResponse(id, "QualityAssurance", "Registered", "Registered fingeprint. ", null, 0, edgeScore.get(), personInfo, fingerPosition).toString();
+            } else {
+                return buildJavaResponse(id, "QualityAssurance", "Not Registered", "New Fingerprint detected...", probeTemplate, 100, edgeScore.get(), personInfo, fingerPosition).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);
+            String errorResponse = buildJavaResponse(id, "QualityAssurance", "Failed", "Unable to produce Edge score... " + e.getMessage(), null, 0.0, 0, personInfo, fingerPosition);
             return errorResponse.toString();
         }
     }
 
-    public static String buildJavaResponse(
-            String id,
-            String operation,
-            String status,
-            String message,
-            FingerprintTemplate fingerprintTemplate,
-            double score,
-            Integer edgeScore,
-            PersonFingerprintData personInfo,
-            int fingerPosition) {
-
-        // Convert the FingerprintTemplate to a base64-encoded string (assuming `FingerprintTemplate` has a way to do this)
-        String templateBase64 = (fingerprintTemplate != null) ? Base64.getEncoder().encodeToString(fingerprintTemplate.toByteArray()) : "";
-
-        // Construct the fingerprint data (if there is a fingerprint template)
-        Fingerprint fingerprint = new Fingerprint(personInfo.getName(), fingerPosition, templateBase64);
-
-        // Add the fingerprint to the personInfo
-        personInfo.addFingerprint(fingerprint);
-
-        // Build the 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
+    public static String updateRegisteredFingerprints(String id, FingerprintCompareListItem[] fpTemplateList) {
         try {
-            ObjectMapper mapper = new ObjectMapper();
-            String jsonResponse = mapper.writeValueAsString(javaResponse);
-            return jsonResponse;
+            return "response here for now...";
         } catch (Exception e) {
-            // Handle exception if serialization fails
-            e.printStackTrace();
-            return "{\"error\":\"Failed to serialize response\"}";
+            return "error response here for now...";
         }
     }
 

+ 0 - 21
src/main/java/com/example/FingerprintImage.java

@@ -1,21 +0,0 @@
-package com.example;
-
-import java.awt.image.BufferedImage;
-
-public class FingerprintImage {
-    private byte[] imageBytes;
-
-    // Constructor
-    public FingerprintImage(byte[] imageBytes) {
-        this.imageBytes = imageBytes;
-    }
-
-    // Getter and Setter
-    public byte[] getImageBytes() {
-        return imageBytes;
-    }
-
-    public void setImageBytes(byte[] imageBytes) {
-        this.imageBytes = imageBytes;
-    }
-}

+ 0 - 82
src/main/java/com/example/JavaResponse.java

@@ -1,82 +0,0 @@
-package com.example;
-
-public class JavaResponse {
-
-    private String id;
-    private String operation;
-    private String status;
-    private String message;
-    private PersonFingerprintData data;
-    private Double score;
-    private Integer edgeScore;
-
-    // Constructor
-    public JavaResponse(String id, String operation, String status, String message, PersonFingerprintData data, Double score, Integer edgeScore) {
-        // logic here
-        this.id = id;
-        this.operation = operation;
-        this.status = status;
-        this.message = message;
-        this.data = data;
-        this.score = score;
-        this.edgeScore = edgeScore;
-    }
-
-    // Getters and Setters
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getOperation() {
-        return operation;
-    }
-
-    public void setOperation(String status) {
-        this.status = status;
-    }
-
-    public String getStatus() {
-        return status;
-    }
-
-    public void setStatus(String status) {
-        this.status = status;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public PersonFingerprintData getData() {
-        return data;
-    }
-
-    public void setData(PersonFingerprintData data) {
-        this.data = data;
-    }
-
-    public Double getScore() {
-        return score;
-    }
-
-    public void setData(Double score) {
-        this.score = score;
-    }
-
-    public Integer getEdgeScore() {
-        return edgeScore;
-    }
-
-    public void setEdgeScore(Integer edgeScore) {
-        this.edgeScore = edgeScore;
-    }
-
-}

+ 2 - 0
src/main/java/com/example/Main.java

@@ -1,5 +1,7 @@
 package com.example;
 
+import com.example.utils.MonitorMemory;
+
 public class Main {
 
     public static void main(String[] args) {

+ 1 - 1
src/main/java/com/example/Fingerprint.java → src/main/java/com/example/types/Fingerprint.java

@@ -1,4 +1,4 @@
-package com.example;
+package com.example.types;
 
 public class Fingerprint {
 

+ 1 - 1
src/main/java/com/example/FingerprintCompareListItem.java → src/main/java/com/example/types/FingerprintCompareListItem.java

@@ -1,4 +1,4 @@
-package com.example;
+package com.example.types;
 
 import com.machinezoo.sourceafis.FingerprintTemplate;
 

+ 1 - 1
src/main/java/com/example/PersonFingerprintData.java → src/main/java/com/example/types/PersonFingerprintData.java

@@ -1,4 +1,4 @@
-package com.example;
+package com.example.types;
 
 import java.util.ArrayList;
 import java.util.List;

+ 22 - 0
src/main/java/com/example/types/VerificationResult.java

@@ -0,0 +1,22 @@
+package com.example.types;
+
+import com.machinezoo.sourceafis.FingerprintTemplate;
+
+public class VerificationResult extends FingerprintCompareListItem {
+
+    double bestScore;
+
+    public VerificationResult(String name, int fpPosition, FingerprintTemplate fpTemplate, double bestScore) {
+        super(name, fpPosition, fpTemplate);
+        this.bestScore = bestScore;
+    }
+
+    public void setScore(double bestScore) {
+        bestScore = bestScore;
+    }
+
+    public double getScore() {
+        return bestScore;
+    }
+
+}

+ 125 - 0
src/main/java/com/example/utils/JavaResponse.java

@@ -0,0 +1,125 @@
+package com.example.utils;
+
+import java.util.Base64;
+
+import com.example.types.Fingerprint;
+import com.example.types.PersonFingerprintData;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.machinezoo.sourceafis.FingerprintTemplate;
+
+public class JavaResponse {
+
+    private String id;
+    private String operation;
+    private String status;
+    private String message;
+    private PersonFingerprintData data;
+    private Double score;
+    private Integer edgeScore;
+
+    // Constructor
+    public JavaResponse(String id, String operation, String status, String message, PersonFingerprintData data, Double score, Integer edgeScore) {
+        // logic here
+        this.id = id;
+        this.operation = operation;
+        this.status = status;
+        this.message = message;
+        this.data = data;
+        this.score = score;
+        this.edgeScore = edgeScore;
+    }
+
+    // Getters and Setters
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getOperation() {
+        return operation;
+    }
+
+    public void setOperation(String status) {
+        this.status = status;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public PersonFingerprintData getData() {
+        return data;
+    }
+
+    public void setData(PersonFingerprintData data) {
+        this.data = data;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setData(Double score) {
+        this.score = score;
+    }
+
+    public Integer getEdgeScore() {
+        return edgeScore;
+    }
+
+    public void setEdgeScore(Integer edgeScore) {
+        this.edgeScore = edgeScore;
+    }
+
+    public static String buildJavaResponse(
+            String id,
+            String operation,
+            String status,
+            String message,
+            FingerprintTemplate fingerprintTemplate,
+            double score,
+            int edgeScore,
+            PersonFingerprintData personInfo,
+            int fingerPosition) {
+
+        // Convert the FingerprintTemplate to a base64-encoded string (assuming `FingerprintTemplate` has a way to do this)
+        String templateBase64 = (fingerprintTemplate != null) ? Base64.getEncoder().encodeToString(fingerprintTemplate.toByteArray()) : "";
+
+        // Construct the fingerprint data (if there is a fingerprint template)
+        Fingerprint fingerprint = new Fingerprint(personInfo.getName(), fingerPosition, templateBase64);
+
+        // Add the fingerprint to the personInfo
+        personInfo.addFingerprint(fingerprint);
+
+        // Build the 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 {
+            ObjectMapper mapper = new ObjectMapper();
+            String jsonResponse = mapper.writeValueAsString(javaResponse);
+            return jsonResponse;
+        } catch (Exception e) {
+            // Handle exception if serialization fails
+            e.printStackTrace();
+            return "{\"error\":\"Failed to serialize response\"}";
+        }
+    }
+
+}

+ 1 - 1
src/main/java/com/example/MonitorMemory.java → src/main/java/com/example/utils/MonitorMemory.java

@@ -1,4 +1,4 @@
-package com.example;
+package com.example.utils;
 
 public class MonitorMemory {
 

+ 21 - 16
src/main/java/com/example/TransparencyContents.java → src/main/java/com/example/utils/TransparencyContents.java

@@ -1,43 +1,34 @@
-package com.example;
+package com.example.utils;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 
-import com.fasterxml.jackson.core.JsonToken;
 import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
 import com.fasterxml.jackson.dataformat.cbor.CBORParser;
 import com.machinezoo.sourceafis.FingerprintTransparency;
 
-// to  calcualte the edge of a fingerpint. Must exeed a specific amount to be considered a valid fingerprint data
 public class TransparencyContents extends FingerprintTransparency {
 
-    int edgeNumber = 0;
+    private int edgeNumber = 0;
 
     @Override
     public void take(String key, String mime, byte[] data) {
         try {
-            if ("edge-table".equals(key)) {
+            if (key.equals("edge-table")) {
                 CBORFactory cborFactory = new CBORFactory();
                 ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
                 try (CBORParser cborParser = cborFactory.createParser(inputStream)) {
-                    JsonToken token;
-                    while ((token = cborParser.nextToken()) != null) {
-                        // Only check when token is a field name
-                        if (token == JsonToken.FIELD_NAME) {
-                            String fieldName = cborParser.getText();
-                            if ("length".equals(fieldName)) {
-                                edgeNumber++;
-                            }
+                    while (cborParser.nextToken() != null) {
+                        if (cborParser.getText().equals("length")) {
+                            edgeNumber++;
                         }
                     }
                     countEdgeNumber();
                 } catch (IOException e) {
-                    e.printStackTrace();   // <-- print full exception for debugging
-                    throw new IOException("Counting edge error", e);
+                    throw new IOException("Counting edge error");
                 }
             }
         } catch (NullPointerException | IOException ex) {
-            ex.printStackTrace();
             System.out.println("Error: " + ex);
         }
     }
@@ -50,4 +41,18 @@ public class TransparencyContents extends FingerprintTransparency {
     public Integer countEdgeNumber() {
         return edgeNumber;
     }
+
+    // Static helper method to use this class easily
+    public static Integer calculateEdgeScore(byte[] imageBytes) {
+        Integer edgeScore = null;
+        try (TransparencyContents transparency = new TransparencyContents()) {
+            // FingerprintTemplate probe = new FingerprintTemplate(new FingerprintImage(imageBytes));
+            transparency.accepts("edge-table");
+            transparency.take("edge-table", "application/cbor", imageBytes);
+            edgeScore = transparency.countEdgeNumber();
+        } catch (Exception e) {
+            System.out.println("Error calculating edge score: " + e.getMessage());
+        }
+        return edgeScore;
+    }
 }

+ 56 - 0
src/main/java/com/example/utils/Verification.java

@@ -0,0 +1,56 @@
+package com.example.utils;
+
+import com.example.types.FingerprintCompareListItem;
+import com.example.types.VerificationResult;
+import com.machinezoo.sourceafis.FingerprintMatcher;
+import com.machinezoo.sourceafis.FingerprintTemplate;
+
+public class Verification {
+
+    private static final double MATCH_THRESHOLD = 40.0;
+
+    public static VerificationResult verifyFingeprint(FingerprintTemplate fingerprintData, FingerprintCompareListItem[] givenDataToMatch, FingerprintCompareListItem[] localData) {
+        try {
+            FingerprintCompareListItem[] fingerprintList;
+            double bestScore = 0;
+            VerificationResult matchedPerson = null;
+            // If no given Data to Match then try local data to match
+            if (givenDataToMatch == null || givenDataToMatch.length <= 0) {
+                fingerprintList = localData;
+            } else {
+                fingerprintList = givenDataToMatch;
+            }
+
+            if (fingerprintList.length <= 0) {
+                return null;
+            }
+
+            for (FingerprintCompareListItem entry : fingerprintList) {
+                String personName = entry.getName();
+                int fpPosition = entry.getFingerPosition();
+                FingerprintTemplate candidate = entry.getFingerprint();
+
+                double score = new FingerprintMatcher(fingerprintData).match(candidate);
+                if (score > bestScore) {
+                    bestScore = score;
+                    matchedPerson.setName(personName);
+                    matchedPerson.setFingerPosition(fpPosition);
+                    matchedPerson.setFingerprint(candidate);
+                    matchedPerson.setScore(bestScore);
+                }
+            }
+
+            // Return response based on score
+            if (bestScore >= MATCH_THRESHOLD) {
+                System.out.println("Person Matched: " + matchedPerson.getName() + "Score: " + bestScore);
+                return matchedPerson;
+            } else {
+                return null;
+            }
+
+        } catch (Exception e) {
+            System.out.println("Exception Error" + e);
+            return null;
+        }
+    }
+}

+ 0 - 11
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@@ -1,12 +1 @@
-com\example\FingerprintCompareListItem.class
-com\example\Main.class
-com\example\TransparencyContents.class
 com\example\ClientHandler.class
-com\example\EventHandler.class
-com\example\Fingerprint.class
-com\example\JavaResponse.class
-com\example\MonitorMemory.class
-com\example\FingerprintImage.class
-com\example\TCPServer.class
-com\example\PersonFingerprintData.class
-com\example\TCPClient.class

+ 8 - 7
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@@ -1,12 +1,13 @@
 E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\ClientHandler.java
 E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\EventHandler.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\Fingerprint.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\FingerprintCompareListItem.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\FingerprintImage.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\JavaResponse.java
 E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\Main.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\MonitorMemory.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\PersonFingerprintData.java
 E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\TCPClient.java
 E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\TCPServer.java
-E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\TransparencyContents.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\types\Fingerprint.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\types\FingerprintCompareListItem.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\types\PersonFingerprintData.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\types\VerificationResult.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\utils\JavaResponse.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\utils\MonitorMemory.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\utils\TransparencyContents.java
+E:\Task\Fingerprint\microservices\libs\java\FingerprintDataVerification\src\main\java\com\example\utils\Verification.java