JoaoJandre commented on a change in pull request #6048:
URL: https://github.com/apache/cloudstack/pull/6048#discussion_r815981665



##########
File path: api/src/main/java/com/cloud/user/Account.java
##########
@@ -16,35 +16,55 @@
 // under the License.
 package com.cloud.user;
 
-import java.util.Date;
-
 import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.api.Identity;
 import org.apache.cloudstack.api.InternalIdentity;
 
-public interface Account extends ControlledEntity, InternalIdentity, Identity {
+import java.util.Date;
+import java.util.HashMap;
 
+public interface Account extends ControlledEntity, InternalIdentity, Identity {
 
-    public enum State {
-        disabled, enabled, locked
+    /**
+     *  Account states.
+     * */
+    enum State {
+        DISABLED, ENABLED, LOCKED;
+
+        /**
+         * The toString method was overridden to maintain consistency in the 
DB, as the GenericDaoBase uses toString in the enum value to make the sql 
statements
+         * and previously the enum was in lowercase.
+         * */
+        @Override
+        public String toString(){
+            return super.toString().toLowerCase();
+        }
     }
 
-    public static final short ACCOUNT_TYPE_NORMAL = 0;
-    public static final short ACCOUNT_TYPE_ADMIN = 1;
-    public static final short ACCOUNT_TYPE_DOMAIN_ADMIN = 2;
-    public static final short ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN = 3;
-    public static final short ACCOUNT_TYPE_READ_ONLY_ADMIN = 4;
-    public static final short ACCOUNT_TYPE_PROJECT = 5;
+    /**
+     * Account types.
+     * */
+    enum Type {
+        NORMAL, ADMIN, DOMAIN_ADMIN, RESOURCE_DOMAIN_ADMIN, READ_ONLY_ADMIN, 
PROJECT;

Review comment:
       I opted to hardcode them to ordinals because the `prepareAttribute` 
method in the `GenericDaoBase` uses the `ordinal()` method to convert enums to 
integers when they are annotated as `EnumType.ORDINAL`; this ensures 
compatibility to the current DB schema. Moreover, in the AccountTypeTest there 
is a unit test to ensure that the order is maintained.
   I hope to extend this refactoring in the future so that both the API and the 
DB schema use the string value of the enums instead of the integer value, thus 
making the application more intuitive.
   To answer your question, since the `Account.Type` uses `EnumType.ORDINAL`, 
we don't need a upgrade path to change anything in the DB. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to