* Example: one could attach the age of the enrollee and the city they were enrolled, in order to find out the average age of beneficiaries for each city.
*/
-@SuppressWarnings({"WeakerAccess", "unused"})
-public class Metadata {
-
- public class InvalidMetadataException extends Exception {
- /**
- * Constructs a new exception with the specified detail message.
- *
- * @param message the detail message. The detail message is saved for later retrieval by the getMessage() method.
- */
- InvalidMetadataException(String message) {
- super(message);
- }
- }
+data class Metadata(
+ private var json: JSONObject = JSONObject(),
+) {
- final private JSONObject json;
+ /**
+ * Thrown when provided meta-data cannot be marshalled or unmarshalled from the intent extras.
+ */
+ class InvalidMetadataException(message: String) : RuntimeException(message)
/**
* Constructs a new Metadata object with key/value mappings from a JSON object string.
@@ -39,29 +27,22 @@ public class InvalidMetadataException extends Exception {
* @throws InvalidMetadataException if the passed string is not a valid JSON object string,
* or it contains nested arrays or key/value mappings.
*/
- public Metadata(@NonNull String jsonString) throws InvalidMetadataException {
+ constructor(jsonString: String) : this() {
// Parse the JSON-encoded string
try {
- json = new JSONObject(jsonString);
- } catch (JSONException e) {
- throw new InvalidMetadataException("The metadata string is not a valid JSON object string.");
+ json = JSONObject(jsonString)
+ } catch (e: JSONException) {
+ throw InvalidMetadataException("The metadata string is not a valid JSON object string.")
}
// Make sure the metadata string does not contain nested arrays or key-value mappings
- Iterator
- * Two call-outs are currently available:
- *
- */
-@SuppressWarnings({"unused", "WeakerAccess"})
-public class SimHelper {
-
- final private String projectId;
- final private String userId;
-
- /**
- * Constructs a new helper for making call-outs to Simprints ID with the specified project id and user id.
- *
- * @param projectId identifies the project that is making the call-out. Will be checked if it matches the scanned project id upon signing-in.
- * @param userId identifies which user is making a request to Simprints ID. Can be any arbitrary String.
- */
- public SimHelper(@NonNull String projectId, @NonNull String userId) {
- this.projectId = projectId;
- this.userId = userId;
- }
-
- /**
- * Builds a new {@link Intent} to make a registration call-out to Simprints ID.
- * This intent will start an activity that returns a {@link Registration} object.
- *
- * @param moduleId identifies which module to register into.
- * @return a new registration {@link Intent}.
- */
- @NonNull
- public Intent register(@NonNull String moduleId) {
- return new Intent(Constants.SIMPRINTS_REGISTER_INTENT)
- .putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId)
- .putExtra(Constants.SIMPRINTS_USER_ID, userId)
- .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId);
- }
-
- /**
- * Builds a new {@link Intent} to make a registration call-out to Simprints ID
- * with additional arbitrary {@link Metadata}.
- * This intent will start an activity that returns a {@link Registration} object.
- *
- * @param moduleId identifies which module to register into.
- * @param metadata optional metadata to attach to the registration.
- * @return a new registration {@link Intent}.
- */
- @NonNull
- public Intent register(@NonNull String moduleId, @NonNull Metadata metadata) {
- return register(moduleId)
- .putExtra(Constants.SIMPRINTS_METADATA, metadata.toString());
- }
-
- /**
- * (COMING SOON) Builds a new {@link Intent} to make an update call-out to Simprints ID.
- *
- * @param moduleId identifies which module to update.
- * @param updateId identifies which beneficiary to update.
- * @return a new update {@link Intent}.
- */
- @NonNull
- public Intent update(@NonNull String moduleId, @NonNull String updateId) {
- return new Intent(Constants.SIMPRINTS_UPDATE_INTENT)
- .putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId)
- .putExtra(Constants.SIMPRINTS_USER_ID, userId)
- .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
- .putExtra(Constants.SIMPRINTS_UPDATE_GUID, updateId);
- }
-
- /**
- * (COMING SOON) Builds a new {@link Intent} to make an update call-out to Simprints ID
- * with additional arbitrary {@link Metadata}.
- *
- * @param moduleId identifies which module to update.
- * @param updateId identifies which beneficiary to update.
- * @param metadata optional metadata to attach to the update.
- * @return a new update {@link Intent}.
- */
- @NonNull
- public Intent update(@NonNull String moduleId, @NonNull String updateId, @NonNull Metadata metadata) {
- return update(moduleId, updateId)
- .putExtra(Constants.SIMPRINTS_METADATA, metadata.toString());
- }
-
- /**
- * Builds a new {@link Intent} to make an identification call-out to Simprints ID.
- * This intent will start an activity that returns an ArrayList of {@link Identification} objects.
- *
- * @param moduleId identifies which module to search in.
- * @return a new identification {@link Intent}.
- */
- @NonNull
- public Intent identify(@NonNull String moduleId) {
- Intent intent = new Intent(Constants.SIMPRINTS_IDENTIFY_INTENT);
- intent.putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId);
- intent.putExtra(Constants.SIMPRINTS_USER_ID, userId);
- intent.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId);
- return intent;
- }
-
- /**
- * Builds a new {@link Intent} to make an identification call-out to Simprints ID with
- * additional arbitrary {@link Metadata}.
- * This intent will start an activity that returns an ArrayList of {@link Identification} objects.
- *
- * @param moduleId identifies which module to search in.
- * @param metadata optional metadata to attach to the identification.
- * @return a new identification {@link Intent}.
- */
- @NonNull
- public Intent identify(@NonNull String moduleId, @NonNull Metadata metadata) {
- return identify(moduleId)
- .putExtra(Constants.SIMPRINTS_METADATA, metadata.toString());
- }
-
- /**
- * Sends which GUID was confirmed in a session back to SimprintsId.
- *
- * @param sessionId identifies the identification session.
- * @param selectedGuid the GUID that was confirmed in the host app.
- * @return a new confirm indentity {@link Intent}.
- */
- public Intent confirmIdentity(@NonNull String sessionId, @Nullable String selectedGuid) {
- Intent intent = new Intent(Constants.SIMPRINTS_SELECT_GUID_INTENT);
- intent.putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId);
- intent.putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId);
- intent.putExtra(Constants.SIMPRINTS_SELECTED_GUID, selectedGuid);
- return intent;
- }
-
- /**
- * Builds a new {@link Intent} to register the templates captured during
- * the last Simprints ID session, if that was an identification.
- * Used to register a new record after an identification that hasn't produced
- * valid results without capturing the templates again.
- *
- * @param moduleId identifies which module to register into.
- * @param sessionId identifies the identification session.
- * @return a new registration for last biometrics {@link Intent}.
- */
- public Intent registerLastBiometrics(@NonNull String moduleId, @NonNull String sessionId) {
- return new Intent(Constants.SIMPRINTS_REGISTER_LAST_BIOMETRICS_INTENT)
- .putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId)
- .putExtra(Constants.SIMPRINTS_USER_ID, userId)
- .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
- .putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId);
- }
-
- /**
- * Builds a new {@link Intent} to register the templates captured during
- * the last Simprints ID session, if that was an identification.
- * Used to register a new record after an identification that hasn't produced
- * valid results without capturing the templates again.
- *
- * @param moduleId identifies which module to register into.
- * @param metadata metadata to attach to the registration.
- * @param sessionId identifies the identification session.
- * @return a new registration for last biometrics {@link Intent}.
- */
- public Intent registerLastBiometrics(@NonNull String moduleId, @NonNull String sessionId, @NonNull Metadata metadata) {
- return registerLastBiometrics(moduleId, sessionId)
- .putExtra(Constants.SIMPRINTS_METADATA, metadata.toString());
- }
-
- /**
- * Builds a new {@link Intent} to make a verification call-out to Simprints ID.
- * This intent will start an activity that returns a {@link Verification} object.
- *
- * @param moduleId identifies which module contains the registered beneficiary to verify.
- * @param verifyId identifies which registered beneficiary to verify.
- * @return a new verification {@link Intent}.
- */
- @NonNull
- public Intent verify(@NonNull String moduleId, @NonNull String verifyId) {
- Intent intent = new Intent(Constants.SIMPRINTS_VERIFY_INTENT);
- intent.putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId);
- intent.putExtra(Constants.SIMPRINTS_USER_ID, userId);
- intent.putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId);
- intent.putExtra(Constants.SIMPRINTS_VERIFY_GUID, verifyId);
- return intent;
- }
-
- /**
- * Builds a new {@link Intent} to make a verification call-out to Simprints ID with
- * additional arbitrary {@link Metadata}.
- * This intent will start an activity that returns a {@link Verification} object.
- *
- * @param moduleId identifies which module contains the registered beneficiary to verify.
- * @param verifyId identifies which registered beneficiary to verify.
- * @param metadata optional metadata to attach to the verification.
- * @return a new verification {@link Intent}.
- */
- @NonNull
- public Intent verify(@NonNull String moduleId, @NonNull String verifyId, @NonNull Metadata metadata) {
- return verify(moduleId, verifyId)
- .putExtra(Constants.SIMPRINTS_METADATA, metadata.toString());
- }
-}
diff --git a/src/main/java/com/simprints/libsimprints/SimHelper.kt b/src/main/java/com/simprints/libsimprints/SimHelper.kt
new file mode 100644
index 0000000..a51a740
--- /dev/null
+++ b/src/main/java/com/simprints/libsimprints/SimHelper.kt
@@ -0,0 +1,119 @@
+package com.simprints.libsimprints;
+
+import android.content.Intent
+
+/**
+ * A helper class facilitating the construction of an {@link Intent} to call Simprints ID.
+ *
+ * Two call-outs are currently available:
+ *
+ *
+ * @param projectId identifies the project that is making the call-out. Will be checked if it matches the scanned project id upon signing-in.
+ * @param userId identifies which user is making a request to Simprints ID. Can be any arbitrary String.
+ */
+@SuppressWarnings("unused", "WeakerAccess")
+data class SimHelper(
+ private val projectId: String,
+ private val userId: String
+) {
+
+ /**
+ * Builds a new {@link Intent} to make a registration call-out to Simprints ID.
+ * This intent will start an activity that returns a {@link Registration} object.
+ *
+ * @param moduleId identifies which module to register into.
+ * @param metadata optional metadata to attach to the registration if provided.
+ * @return a new registration {@link Intent}.
+ */
+ @JvmOverloads
+ fun register(
+ moduleId: String,
+ metadata: Metadata? = null,
+ ) = createBaseIntent(Constants.SIMPRINTS_REGISTER_INTENT)
+ .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
+ .appendOptionalMetadata(metadata)
+
+ /**
+ * Builds a new {@link Intent} to make an identification call-out to Simprints ID.
+ * This intent will start an activity that returns an ArrayList of {@link Identification} objects.
+ *
+ * @param moduleId identifies which module to search in.
+ * @param metadata optional metadata to attach to the identification if provided.
+ * @return a new identification {@link Intent}.
+ */
+ @JvmOverloads
+ fun identify(
+ moduleId: String,
+ metadata: Metadata? = null,
+ ) = createBaseIntent(Constants.SIMPRINTS_IDENTIFY_INTENT)
+ .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
+ .appendOptionalMetadata(metadata)
+
+ /**
+ * Builds a new {@link Intent} to make a verification call-out to Simprints ID.
+ * This intent will start an activity that returns a {@link Verification} object.
+ *
+ * @param moduleId identifies which module contains the registered beneficiary to verify.
+ * @param verifyId identifies which registered beneficiary to verify.
+ * @param metadata optional metadata to attach to the verification if provided.
+ * @return a new verification {@link Intent}.
+ */
+ @JvmOverloads
+ fun verify(
+ moduleId: String,
+ verifyId: String,
+ metadata: Metadata? = null,
+ ) = createBaseIntent(Constants.SIMPRINTS_VERIFY_INTENT)
+ .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
+ .putExtra(Constants.SIMPRINTS_VERIFY_GUID, verifyId)
+ .appendOptionalMetadata(metadata)
+
+ /**
+ * Sends which GUID was confirmed in a session back to SimprintsId.
+ *
+ * @param sessionId identifies the identification session.
+ * @param selectedGuid the GUID that was confirmed in the host app.
+ * @return a new confirm indentity {@link Intent}.
+ */
+ fun confirmIdentity(
+ sessionId: String,
+ selectedGuid: String,
+ ) = createBaseIntent(Constants.SIMPRINTS_SELECT_GUID_INTENT)
+ .putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId)
+ .putExtra(Constants.SIMPRINTS_SELECTED_GUID, selectedGuid)
+
+ /**
+ * Builds a new {@link Intent} to register the templates captured during
+ * the last Simprints ID session, if that was an identification.
+ * Used to register a new record after an identification that hasn't produced
+ * valid results without capturing the templates again.
+ *
+ * @param moduleId identifies which module to register into.
+ * @param sessionId identifies the identification session.
+ * @param metadata metadata to attach to the registration if provided.
+ * @return a new registration for last biometrics {@link Intent}.
+ */
+ @JvmOverloads
+ fun registerLastBiometrics(
+ moduleId: String,
+ sessionId: String,
+ metadata: Metadata? = null,
+ ) = createBaseIntent(Constants.SIMPRINTS_REGISTER_LAST_BIOMETRICS_INTENT)
+ .putExtra(Constants.SIMPRINTS_MODULE_ID, moduleId)
+ .putExtra(Constants.SIMPRINTS_SESSION_ID, sessionId)
+ .appendOptionalMetadata(metadata)
+
+ private fun createBaseIntent(action: String) = Intent(action)
+ .putExtra(Constants.SIMPRINTS_PROJECT_ID, projectId)
+ .putExtra(Constants.SIMPRINTS_USER_ID, userId)
+
+ private fun Intent.appendOptionalMetadata(metadata: Metadata?) =
+ if (metadata == null) this
+ else putExtra(Constants.SIMPRINTS_METADATA, metadata.toString())
+}
diff --git a/src/main/java/com/simprints/libsimprints/Tier.java b/src/main/java/com/simprints/libsimprints/Tier.kt
similarity index 83%
rename from src/main/java/com/simprints/libsimprints/Tier.java
rename to src/main/java/com/simprints/libsimprints/Tier.kt
index 6aa03bc..ba6f0e2 100644
--- a/src/main/java/com/simprints/libsimprints/Tier.java
+++ b/src/main/java/com/simprints/libsimprints/Tier.kt
@@ -1,6 +1,6 @@
package com.simprints.libsimprints;
-public enum Tier {
+enum class Tier {
TIER_1,
TIER_2,
TIER_3,
diff --git a/src/main/java/com/simprints/libsimprints/Verification.java b/src/main/java/com/simprints/libsimprints/Verification.java
deleted file mode 100644
index d5a188e..0000000
--- a/src/main/java/com/simprints/libsimprints/Verification.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package com.simprints.libsimprints;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import androidx.annotation.NonNull;
-
-@SuppressWarnings({"unused", "WeakerAccess"})
-public class Verification implements Parcelable {
-
- private int confidence;
- private Tier tier;
- private String guid;
-
-
- /**
- * Empty Constructor
- */
- public Verification() {
-
- }
-
- /**
- * This constructor creates a new verification
- *
- * @param confidence An int containing the (matching) confidence
- * @param tier The tier score derived from the confidence
- * @param guid Global unique id of the verified person
- */
- public Verification(int confidence, @NonNull Tier tier, @NonNull String guid) {
- this.confidence = confidence;
- this.tier = tier;
- this.guid = guid;
- }
-
- protected Verification(Parcel in) {
- confidence = in.readInt();
- tier = Tier.values()[in.readInt()];
- guid = in.readString();
- }
-
- public static final Creator
- *
+ *