>From 6d8c81f00102e222fce9d375c006b8a01271f7d9 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Sat, 23 Apr 2016 00:50:08 +0200
Subject: [PATCH] Renamed token status TEMP_LOST to SUSPENDED.

The token status TEMP_LOST has been renamed to SUSPENDED such that
it can be used more general contexts.

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

https://fedorahosted.org/pki/ticket/2286
---
 .../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               | 14 +++++++-------
 base/tps/shared/webapps/tps/js/token.js                    |  2 +-
 base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java    |  4 ++--
 base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java |  2 +-
 .../src/org/dogtagpki/server/tps/rest/TokenService.java    |  4 ++--
 8 files changed, 23 insertions(+), 18 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 18c1d9302c0529279f303c9613d17383004078be..790e092ef53f13312f869a5c45299291c42c8ace 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenStatus.java
@@ -51,7 +51,7 @@ public class TokenStatus {
     public final static TokenStatus UNINITIALIZED       = new TokenStatus("UNINITIALIZED", 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 TEMP_LOST           = new TokenStatus("TEMP_LOST", 3);
+    public final static TokenStatus SUSPENDED           = new TokenStatus("SUSPENDED", 3);
     public final static TokenStatus ACTIVE              = new TokenStatus("ACTIVE", 4);
     public final static TokenStatus TEMP_LOST_PERM_LOST = new TokenStatus("TEMP_LOST_PERM_LOST", 5);
     public final static TokenStatus TERMINATED          = new TokenStatus("TERMINATED", 6);
@@ -128,6 +128,11 @@ public class TokenStatus {
 
     public static TokenStatus valueOf(String name) {
 
+        if ("TEMP_LOST".equals(name)) {
+            System.err.println("WARNING: The token status " + name + " has been deprecated. Please use SUSPENDED instead.");
+            return SUSPENDED;
+        }
+
         TokenStatus status = instancesByName.get(name);
 
         if (status == null) {
diff --git a/base/tps-client/doc/CS.cfg.in b/base/tps-client/doc/CS.cfg.in
index f1a79032abb52660ef189aba3a91f6d4049614a2..457f6ebe4098460194b0b9691772334d7cff1b0f 100644
--- a/base/tps-client/doc/CS.cfg.in
+++ b/base/tps-client/doc/CS.cfg.in
@@ -1485,7 +1485,7 @@ tokendb._067=#   - has transitions between the following states
 tokendb._068=#     UNINITIALIZED = 0,
 tokendb._069=#     DAMAGED = 1,
 tokendb._070=#     PERM_LOST = 2,
-tokendb._071=#     TEMP_LOST = 3,
+tokendb._071=#     SUSPENDED = 3,
 tokendb._072=#     ACTIVE = 4,
 tokendb._073=#     TEMP_LOST_PERM_LOST = 5,
 tokendb._074=#     TERMINATED = 6
@@ -1595,7 +1595,7 @@ tps._009=#   - token operations, like formatting and enrollment have transitions
 tps._010=#     UNINITIALIZED = 0,
 tps._011=#     DAMAGED = 1,
 tps._012=#     PERM_LOST = 2,
-tps._013=#     TEMP_LOST =3 ,
+tps._013=#     SUSPENDED =3 ,
 tps._014=#     ACTIVE = 4,
 tps._015=#     TEMP_LOST_PERM_LOST = 5,
 tps._016=#     TERMINATED = 6
diff --git a/base/tps/shared/conf/CS.cfg.in b/base/tps/shared/conf/CS.cfg.in
index 39e504976762ec0af8824b53d977f0e94516df4e..b5441a0a1eb85e0b3c6e3c93ed27a806976a5bf2 100644
--- a/base/tps/shared/conf/CS.cfg.in
+++ b/base/tps/shared/conf/CS.cfg.in
@@ -1957,7 +1957,7 @@ tokendb._067=#   - has transitions between the following states
 tokendb._068=#     UNINITIALIZED = 0,
 tokendb._069=#     DAMAGED = 1,
 tokendb._070=#     PERM_LOST = 2,
-tokendb._071=#     TEMP_LOST = 3,
+tokendb._071=#     SUSPENDED = 3,
 tokendb._072=#     ACTIVE = 4,
 tokendb._073=#     TEMP_LOST_PERM_LOST = 5,
 tokendb._074=#     TERMINATED = 6
@@ -2026,7 +2026,7 @@ tps._009=#   - token operations, like formatting and enrollment have transitions
 tps._010=#     UNINITIALIZED = 0,
 tps._011=#     DAMAGED = 1,
 tps._012=#     PERM_LOST = 2,
-tps._013=#     TEMP_LOST = 3,
+tps._013=#     SUSPENDED = 3,
 tps._014=#     ACTIVE = 4,
 tps._015=#     TEMP_LOST_PERM_LOST = 5,
 tps._016=#     TERMINATED = 6
diff --git a/base/tps/shared/conf/token-states.properties b/base/tps/shared/conf/token-states.properties
index a64d940c61ebf13dce097805f0a256b1cf991569..3c7e7d6da2786a96d5fe3278b715000a56f96f68 100644
--- a/base/tps/shared/conf/token-states.properties
+++ b/base/tps/shared/conf/token-states.properties
@@ -1,7 +1,7 @@
 # Token states
 UNINITIALIZED       = Uninitialized
 ACTIVE              = Active
-TEMP_LOST           = Temporarily lost
+SUSPENDED           = Temporarily lost/suspended
 PERM_LOST           = Permanently lost
 DAMAGED             = Physically damaged
 TEMP_LOST_PERM_LOST = Temporarily lost then permanently lost
@@ -10,13 +10,13 @@ TERMINATED          = Terminated
 # Token state transitions
 UNINITIALIZED.DAMAGED    = This token has been physically damaged.
 UNINITIALIZED.PERM_LOST  = This token has been permanently lost.
-UNINITIALIZED.TEMP_LOST  = This token has been temporarily lost.
+UNINITIALIZED.SUSPENDED  = This token has been temporarily lost/suspended.
 UNINITIALIZED.TERMINATED = This token has been terminated.
-TEMP_LOST.ACTIVE         = This temporarily lost token has been found.
-TEMP_LOST.PERM_LOST      = This temporarily lost token has become permanently lost.
-TEMP_LOST.TERMINATED     = This temporarily lost token has been terminated.
-TEMP_LOST.UNINITIALIZED  = This temporarily lost token has been found.
+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.
 ACTIVE.DAMAGED           = This token has been physically damaged.
 ACTIVE.PERM_LOST         = This token has been permanently lost.
-ACTIVE.TEMP_LOST         = This token has been temporarily lost.
+ACTIVE.SUSPENDED         = This token has been temporarily lost/suspended.
 ACTIVE.TERMINATED        = This token has been terminated.
diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js
index e09fa5fc6816f812c64e0fed5605707ceec71859..c81e2ccb8b29769e53fc37a38b85f12a9e3797ce 100644
--- a/base/tps/shared/webapps/tps/js/token.js
+++ b/base/tps/shared/webapps/tps/js/token.js
@@ -23,7 +23,7 @@
 var TokenStatus = {
     UNINITIALIZED       : "Uninitialized",
     ACTIVE              : "Active",
-    TEMP_LOST           : "Temporarily lost",
+    SUSPENDED           : "Temporarily lost/suspended",
     PERM_LOST           : "Permanently lost",
     DAMAGED             : "Physically damaged",
     TEMP_LOST_PERM_LOST : "Temporarily lost then 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 008f61333e099049462c02564b99294b110410d5..b0ffb75704eb95a55b78654f75eae6cd4199d90f 100644
--- a/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java
+++ b/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java
@@ -145,7 +145,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 TEMP_LOST, token will be allowed transition to either
+     * If the current state is SUSPENDED, token will be allowed transition to either
      * UNINITIALIZED or ACTIVE depending on whether the token has certificates.
      *
      * @param tokenRecord
@@ -156,7 +156,7 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
         TokenStatus currentState = tokenRecord.getTokenStatus();
         Collection<TokenStatus> nextStates = allowedTransitions.get(currentState);
 
-        if (currentState == TokenStatus.TEMP_LOST) {
+        if (currentState == TokenStatus.SUSPENDED) {
 
             Collection<TokenStatus> ns = new LinkedHashSet<TokenStatus>();
 
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 a1aef5720830bdf9f621a8d54630bcf6c8319bd3..80fd30eb87bd9995ce358f0416dd8dabb5672e55 100644
--- a/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java
+++ b/base/tps/src/org/dogtagpki/server/tps/dbs/TokenRecord.java
@@ -258,7 +258,7 @@ public class TokenRecord extends DBRecord {
                 return TokenStatus.DAMAGED;
 
             } else if ("onHold".equals(reason)) {
-                return TokenStatus.TEMP_LOST;
+                return TokenStatus.SUSPENDED;
             }
 
         } else if ("terminated".equals(status)) {
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 312b09934282d0e508db868ac27a675d817c1238..09989219395278843662c0497cf8698f6308c57d 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
@@ -96,7 +96,7 @@ public class TokenService extends PKIService implements TokenResource {
             tokenRecord.setReason(null);
 
         } else if (tokenState == TokenStatus.ACTIVE) {
-            if (tokenRecord.getTokenStatus() == TokenStatus.TEMP_LOST) {
+            if (tokenRecord.getTokenStatus() == TokenStatus.SUSPENDED) {
                 // unrevoke certs
                 tps.tdb.unRevokeCertsByCUID(tokenRecord.getId(), ipAddress, remoteUser);
             }
@@ -123,7 +123,7 @@ public class TokenService extends PKIService implements TokenResource {
             //revoke certs
             tps.tdb.revokeCertsByCUID(tokenRecord.getId(), "destroyed", ipAddress, remoteUser);
 
-        } else if (tokenState == TokenStatus.TEMP_LOST) {
+        } else if (tokenState == TokenStatus.SUSPENDED) {
             tokenRecord.setStatus("lost");
             newStatus = "lost";
             tokenRecord.setReason("onHold");
-- 
2.5.5

