>From c42fbef333f0128b6b80659996f08af22567b028 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Sat, 23 Apr 2016 05:28:10 +0200
Subject: [PATCH] Renamed token status UNINITIALIZED to AVAILABLE.

The token status UNINITIALIZED has been renamed to AVAILABLE for
clarity.

To simplify the transition, the CLIs and the REST API will continue
to accept UNINITIALIZED but it will be converted internally into
AVAILABLE and a deprecation warning will be generated.

https://fedorahosted.org/pki/ticket/2288
---
 .../src/com/netscape/certsrv/tps/token/TokenStatus.java      |  7 ++++++-
 base/tps-client/doc/CS.cfg.in                                |  4 ++--
 base/tps/shared/conf/CS.cfg.in                               |  4 ++--
 base/tps/shared/conf/token-states.properties                 | 12 ++++++------
 base/tps/shared/webapps/tps/js/token.js                      |  2 +-
 base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java      |  6 +++---
 base/tps/src/org/dogtagpki/server/tps/TPSTokendb.java        |  2 +-
 base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java   |  4 ++--
 .../dogtagpki/server/tps/processor/TPSEnrollProcessor.java   |  6 +++---
 .../src/org/dogtagpki/server/tps/processor/TPSProcessor.java |  6 +++---
 base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java | 12 ++++++------
 11 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java b/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java
index 790e092ef53f13312f869a5c45299291c42c8ace..db80b87d33f59c680fd96aa004b47ecc991176f5 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java
@@ -48,7 +48,7 @@ public class TokenStatus {
     static Map<String, TokenStatus> instancesByName = new HashMap<String, TokenStatus>();
     static Map<Integer, TokenStatus> instancesByValue = new HashMap<Integer, TokenStatus>();
 
-    public final static TokenStatus UNINITIALIZED       = new TokenStatus("UNINITIALIZED", 0);
+    public final static TokenStatus AVAILABLE           = new TokenStatus("AVAILABLE", 0);
     public final static TokenStatus DAMAGED             = new TokenStatus("DAMAGED", 1);
     public final static TokenStatus PERM_LOST           = new TokenStatus("PERM_LOST", 2);
     public final static TokenStatus SUSPENDED           = new TokenStatus("SUSPENDED", 3);
@@ -128,6 +128,11 @@ public class TokenStatus {
 
     public static TokenStatus valueOf(String name) {
 
+        if ("UNINITIALIZED".equals(name)) {
+            System.err.println("WARNING: The token status " + name + " has been deprecated. Please use AVAILABLE instead.");
+            return AVAILABLE;
+        }
+
         if ("TEMP_LOST".equals(name)) {
             System.err.println("WARNING: The token status " + name + " has been deprecated. Please use SUSPENDED instead.");
             return SUSPENDED;
diff --git a/base/tps-client/doc/CS.cfg.in b/base/tps-client/doc/CS.cfg.in
index 457f6ebe4098460194b0b9691772334d7cff1b0f..2d1929ef68403543f629de1d496a8f346a482e4c 100644
--- a/base/tps-client/doc/CS.cfg.in
+++ b/base/tps-client/doc/CS.cfg.in
@@ -1482,7 +1482,7 @@ tokendb._064=#     is set to YES. Otherwise, re-enrollment is not
 tokendb._065=#     allowed.
 tokendb._066=# tokendb.allowedTransitions:
 tokendb._067=#   - has transitions between the following states
-tokendb._068=#     UNINITIALIZED = 0,
+tokendb._068=#     AVAILABLE = 0,
 tokendb._069=#     DAMAGED = 1,
 tokendb._070=#     PERM_LOST = 2,
 tokendb._071=#     SUSPENDED = 3,
@@ -1592,7 +1592,7 @@ tps._005=# tps.cert.subsystem.nickname=xxx
 tps._007=# tps.cert.audit_signing.nickname=xxx
 tps._008=# operations.allowedTransitions:
 tps._009=#   - token operations, like formatting and enrollment have transitions between the following states
-tps._010=#     UNINITIALIZED = 0,
+tps._010=#     AVAILABLE = 0,
 tps._011=#     DAMAGED = 1,
 tps._012=#     PERM_LOST = 2,
 tps._013=#     SUSPENDED =3 ,
diff --git a/base/tps/shared/conf/CS.cfg.in b/base/tps/shared/conf/CS.cfg.in
index b5441a0a1eb85e0b3c6e3c93ed27a806976a5bf2..0bcaf59e6c44ed19c4ecf693220a7a5ac25f9c80 100644
--- a/base/tps/shared/conf/CS.cfg.in
+++ b/base/tps/shared/conf/CS.cfg.in
@@ -1954,7 +1954,7 @@ tokendb._064=#     is set to YES. Otherwise, re-enrollment is not
 tokendb._065=#     allowed.
 tokendb._066=# tokendb.allowedTransitions:
 tokendb._067=#   - has transitions between the following states
-tokendb._068=#     UNINITIALIZED = 0,
+tokendb._068=#     AVAILABLE = 0,
 tokendb._069=#     DAMAGED = 1,
 tokendb._070=#     PERM_LOST = 2,
 tokendb._071=#     SUSPENDED = 3,
@@ -2023,7 +2023,7 @@ tps._005=# tps.cert.subsystem.nickname=xxx
 tps._007=# tps.cert.audit_signing.nickname=xxx
 tps._008=# operations.allowedTransitions:
 tps._009=#   - token operations, like formatting and enrollment have transitions between the following states
-tps._010=#     UNINITIALIZED = 0,
+tps._010=#     AVAILABLE = 0,
 tps._011=#     DAMAGED = 1,
 tps._012=#     PERM_LOST = 2,
 tps._013=#     SUSPENDED = 3,
diff --git a/base/tps/shared/conf/token-states.properties b/base/tps/shared/conf/token-states.properties
index 3c7e7d6da2786a96d5fe3278b715000a56f96f68..534aabf4d01b7b848f59ae3c9c18cc06e36e4f7a 100644
--- a/base/tps/shared/conf/token-states.properties
+++ b/base/tps/shared/conf/token-states.properties
@@ -1,5 +1,5 @@
 # Token states
-UNINITIALIZED       = Uninitialized
+AVAILABLE           = Uninitialized/available
 ACTIVE              = Active
 SUSPENDED           = Temporarily lost/suspended
 PERM_LOST           = Permanently lost
@@ -8,14 +8,14 @@ TEMP_LOST_PERM_LOST = Temporarily lost then permanently lost
 TERMINATED          = Terminated
 
 # Token state transitions
-UNINITIALIZED.DAMAGED    = This token has been physically damaged.
-UNINITIALIZED.PERM_LOST  = This token has been permanently lost.
-UNINITIALIZED.SUSPENDED  = This token has been temporarily lost/suspended.
-UNINITIALIZED.TERMINATED = This token has been terminated.
+AVAILABLE.DAMAGED        = This token has been physically damaged.
+AVAILABLE.PERM_LOST      = This token has been permanently lost.
+AVAILABLE.SUSPENDED      = This token has been temporarily lost/suspended.
+AVAILABLE.TERMINATED     = This token has been terminated.
 SUSPENDED.ACTIVE         = This temporarily lost/suspended token has been found.
 SUSPENDED.PERM_LOST      = This temporarily lost/suspended token has become permanently lost.
 SUSPENDED.TERMINATED     = This temporarily lost/suspended token has been terminated.
-SUSPENDED.UNINITIALIZED  = This temporarily lost/suspended token has been found.
+SUSPENDED.AVAILABLE      = This temporarily lost/suspended token has been found.
 ACTIVE.DAMAGED           = This token has been physically damaged.
 ACTIVE.PERM_LOST         = This token has been permanently lost.
 ACTIVE.SUSPENDED         = This token has been temporarily lost/suspended.
diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js
index c81e2ccb8b29769e53fc37a38b85f12a9e3797ce..bc89641041687561da89ffd9c2805bde646951d8 100644
--- a/base/tps/shared/webapps/tps/js/token.js
+++ b/base/tps/shared/webapps/tps/js/token.js
@@ -21,7 +21,7 @@
 
 // TODO: load labels from server
 var TokenStatus = {
-    UNINITIALIZED       : "Uninitialized",
+    AVAILABLE           : "Uninitialized/available",
     ACTIVE              : "Active",
     SUSPENDED           : "Temporarily lost/suspended",
     PERM_LOST           : "Permanently lost",
diff --git a/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java b/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java
index b0ffb75704eb95a55b78654f75eae6cd4199d90f..ae9a82d70671fb697b7ef2b660f6c499f203c7df 100644
--- a/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java
+++ b/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java
@@ -146,7 +146,7 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
      * Return the allowed next states for a given token based on TPS configuration.
      *
      * If the current state is SUSPENDED, token will be allowed transition to either
-     * UNINITIALIZED or ACTIVE depending on whether the token has certificates.
+     * AVAILABLE or ACTIVE depending on whether the token has certificates.
      *
      * @param tokenRecord
      * @return A non-null collection of allowed next token states.
@@ -163,9 +163,9 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
             // check token certificates
             Collection<TPSCertRecord> certRecords = tdb.tdbGetCertRecordsByCUID(tokenRecord.getId());
 
-            // if token has no certificates, allow token to become uninitialized again
+            // if token has no certificates, allow token to become available again
             if (certRecords.isEmpty()) {
-                ns.add(TokenStatus.UNINITIALIZED);
+                ns.add(TokenStatus.AVAILABLE);
 
             } else { // otherwise, allow token to become active again
                 ns.add(TokenStatus.ACTIVE);
diff --git a/base/tps/src/org/dogtagpki/server/tps/TPSTokendb.java b/base/tps/src/org/dogtagpki/server/tps/TPSTokendb.java
index e69ce9359dd56a2f8796eb0b7d3227dd34b270b8..180c90ba2d329f6e7102c6dda854dad67c54baaf 100644
--- a/base/tps/src/org/dogtagpki/server/tps/TPSTokendb.java
+++ b/base/tps/src/org/dogtagpki/server/tps/TPSTokendb.java
@@ -186,7 +186,7 @@ public class TPSTokendb {
         } catch (Exception e) {
             CMS.debug("TPSTokendb.tdbUpdateTokenEntry: token entry not found; Adding");
             // add and exit
-            tdbAddTokenEntry(tokenRecord, "uninitialized");
+            tdbAddTokenEntry(tokenRecord, "available");
             return;
         }
         // token found; modify
diff --git a/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java b/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java
index 80fd30eb87bd9995ce358f0416dd8dabb5672e55..75e75ef77799ec1be1e24bca4e84fb276a4aeb9f 100644
--- a/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java
+++ b/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java
@@ -242,8 +242,8 @@ public class TokenRecord extends DBRecord {
     public TokenStatus getTokenStatus() {
         String status = getStatus();
 
-        if ("uninitialized".equals(status)) {
-            return TokenStatus.UNINITIALIZED;
+        if ("available".equals(status)) {
+            return TokenStatus.AVAILABLE;
 
         } else if ("active".equals(status)) {
             return TokenStatus.ACTIVE;
diff --git a/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java b/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
index 19df79f531c8e655bec1e6b9eec1b7e110c267fb..092e8396e66f9890b8b605c00538780c20611b85 100644
--- a/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
+++ b/base/tps/src/org/dogtagpki/server/tps/processor/TPSEnrollProcessor.java
@@ -319,7 +319,7 @@ public class TPSEnrollProcessor extends TPSProcessor {
             }
         } else {
             CMS.debug(method + " token does not exist");
-            tokenRecord.setStatus("uninitialized");
+            tokenRecord.setStatus("available");
 
             checkAllowUnknownToken(TPSEngine.OP_FORMAT_PREFIX);
         }
@@ -368,7 +368,7 @@ public class TPSEnrollProcessor extends TPSProcessor {
 
         if (!isTokenPresent) {
             try {
-                tps.tdb.tdbAddTokenEntry(tokenRecord, "uninitialized");
+                tps.tdb.tdbAddTokenEntry(tokenRecord, "available");
             } catch (Exception e) {
                 String failMsg = "add token failure";
                 logMsg = failMsg + ":" + e.toString();
@@ -1031,7 +1031,7 @@ public class TPSEnrollProcessor extends TPSProcessor {
                 //same token
                 logMsg = "found current token entry";
                 CMS.debug(method + ":" + logMsg);
-                if (tokenRecord.getStatus().equals("uninitialized")) {
+                if (tokenRecord.getStatus().equals("available")) {
                     // this is the current token
                     if (tokenRecords.size() == 1) {
                         // the current token is the only token owned by the user
diff --git a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
index 01cde7608dafe5504064cef0372546955b44e931..ddf3c5e35111e41a8be25d96270f1113e7fced41 100644
--- a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
+++ b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
@@ -2055,8 +2055,8 @@ public class TPSProcessor {
 
         if (isTokenPresent) {
             CMS.debug("TPSProcessor.format: token exists");
-            TokenStatus newState = TokenStatus.UNINITIALIZED;
-            // Check for transition to 0/UNINITIALIZED status.
+            TokenStatus newState = TokenStatus.AVAILABLE;
+            // Check for transition to 0/AVAILABLE status.
 
             if (!tps.engine.isOperationTransitionAllowed(tokenRecord.getTokenStatus(), newState)) {
                 String info = " illegal transition attempted: " + tokenRecord.getTokenStatus() +
@@ -2151,7 +2151,7 @@ public class TPSProcessor {
         }
 
         // Update Token DB
-        tokenRecord.setStatus("uninitialized");
+        tokenRecord.setStatus("available");
         try {
             tps.tdb.tdbUpdateTokenEntry(tokenRecord);
         } catch (Exception e) {
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
index 09989219395278843662c0497cf8698f6308c57d..40cf428c18ecbed6c424665cd4a64d8562e9e204 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
@@ -90,9 +90,9 @@ public class TokenService extends PKIService implements TokenResource {
 
         auditModParams.put("UserID", tokenRecord.getUserID());
 
-        if (tokenState == TokenStatus.UNINITIALIZED) {
-            tokenRecord.setStatus("uninitialized");
-            newStatus = "uninitialized";
+        if (tokenState == TokenStatus.AVAILABLE) {
+            tokenRecord.setStatus("available");
+            newStatus = "available";
             tokenRecord.setReason(null);
 
         } else if (tokenState == TokenStatus.ACTIVE) {
@@ -369,9 +369,9 @@ public class TokenService extends PKIService implements TokenResource {
                 auditModParams.put("Policy", policy);
             }
 
-            // new tokens are uninitialized when created
-            tokenRecord.setStatus("uninitialized");
-            auditModParams.put("Status", "uninitialized");
+            // new tokens are available when created
+            tokenRecord.setStatus("available");
+            auditModParams.put("Status", "available");
 
             database.addRecord(tokenID, tokenRecord);
             subsystem.tdb.tdbActivity(ActivityDatabase.OP_ADD, tokenRecord,
-- 
2.5.5

