PermissionTypeData.java

  1. package com.syntifi.near.api.model.accesskey.permission;

  2. import com.syntifi.near.api.exception.NoSuchTypeException;

  3. import lombok.Getter;

  4. /**
  5.  * @author Alexandre Carvalho
  6.  * @author Andre Bertolace
  7.  * @since 0.0.1
  8.  */
  9. @Getter
  10. public enum PermissionTypeData {
  11.     FULL_ACCESS("FullAccess", NoDataPermission.class),
  12.     FUNCTION_CALL("FunctionCall", FunctionCallPermission.class);

  13.     private final String name;
  14.     private final Class<?> clazz;

  15.     private PermissionTypeData(String name, Class<?> clazz) {
  16.         this.name = name;
  17.         this.clazz = clazz;
  18.     }

  19.     /**
  20.      * Retrieve Transform implementation class from Transform name
  21.      *
  22.      * @param name the name of the permission type
  23.      * @return the class of given permission type
  24.      * @throws NoSuchTypeException no such type found
  25.      */
  26.     public static Class<?> getClassByName(String name) throws NoSuchTypeException {
  27.         for (PermissionTypeData t : values()) {
  28.             if (t.name.equals(name)) {
  29.                 return t.getClazz();
  30.             }
  31.         }
  32.         throw new NoSuchTypeException(String.format("Permission Type %s invalid/not found.", name));
  33.     }
  34. }