diff --git a/index.html b/index.html index 9430b5c7c..0737839c9 100644 --- a/index.html +++ b/index.html @@ -11,15 +11,15 @@

Box Java SDK

- + - Download v4.10.0 + Download v4.11.0 - + Clone it on GitHub @@ -32,17 +32,17 @@

Box Java SDK

JAR
-
compile 'com.box:box-java-sdk:4.10.0'
+
compile 'com.box:box-java-sdk:4.11.0'
-
@@ -67,25 +67,25 @@

Documentation

- + Javadocs - + Authentication - + Files - + Folders @@ -97,13 +97,13 @@

Documentation

- + Collaborations - + Events @@ -115,20 +115,20 @@

Documentation

- + Users - + Groups - - + + Tasks diff --git a/javadoc/allclasses-frame.html b/javadoc/allclasses-frame.html index 3f32e9121..7e10545b1 100644 --- a/javadoc/allclasses-frame.html +++ b/javadoc/allclasses-frame.html @@ -186,6 +186,7 @@

All Classes

  • MetadataTemplate.FieldOperation
  • MetadataTemplate.Operation
  • MetadataTemplate.Option
  • +
  • MetadataTemplate.StaticConfig
  • PagingParameters
  • Parsers
  • PartialCollection
  • diff --git a/javadoc/allclasses-noframe.html b/javadoc/allclasses-noframe.html index 74bcfdf22..3e5441a4c 100644 --- a/javadoc/allclasses-noframe.html +++ b/javadoc/allclasses-noframe.html @@ -186,6 +186,7 @@

    All Classes

  • MetadataTemplate.FieldOperation
  • MetadataTemplate.Operation
  • MetadataTemplate.Option
  • +
  • MetadataTemplate.StaticConfig
  • PagingParameters
  • Parsers
  • PartialCollection
  • diff --git a/javadoc/com/box/sdk/BoxAPIConnection.ResourceLinkType.html b/javadoc/com/box/sdk/BoxAPIConnection.ResourceLinkType.html index b6c03112a..9d9e7335a 100644 --- a/javadoc/com/box/sdk/BoxAPIConnection.ResourceLinkType.html +++ b/javadoc/com/box/sdk/BoxAPIConnection.ResourceLinkType.html @@ -60,7 +60,7 @@

    Enum BoxAPIConn

    -
    protected static enum BoxAPIConnection.ResourceLinkType
    +
    protected static enum BoxAPIConnection.ResourceLinkType
     extends Enum<BoxAPIConnection.ResourceLinkType>
    Used to categorize the types of resource links.
    @@ -160,7 +160,7 @@

    Enum Constant Detail

    @@ -170,7 +170,7 @@

    Unknown

    @@ -180,7 +180,7 @@

    APIEndpoint

    • SharedLink

      -
      public static final BoxAPIConnection.ResourceLinkType SharedLink
      +
      public static final BoxAPIConnection.ResourceLinkType SharedLink
      Resource URLs that point to a resource that has been shared such as https://example.box.com/s/qwertyuiop1234567890asdfghjk or https://example.app.box.com/notes/0987654321?s=zxcvbnm1234567890asdfghjk.
      diff --git a/javadoc/com/box/sdk/BoxAPIConnection.html b/javadoc/com/box/sdk/BoxAPIConnection.html index 71a9db270..8db430d84 100644 --- a/javadoc/com/box/sdk/BoxAPIConnection.html +++ b/javadoc/com/box/sdk/BoxAPIConnection.html @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":9,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10,"i45":9,"i46":10,"i47":10,"i48":10,"i49":10,"i50":10,"i51":10,"i52":10,"i53":10,"i54":10,"i55":10,"i56":10,"i57":10,"i58":10,"i59":10,"i60":10,"i61":10,"i62":42,"i63":42,"i64":10,"i65":10,"i66":10,"i67":10,"i68":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":9,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10,"i42":10,"i43":10,"i44":10,"i45":10,"i46":9,"i47":10,"i48":10,"i49":10,"i50":10,"i51":10,"i52":10,"i53":10,"i54":10,"i55":10,"i56":10,"i57":10,"i58":10,"i59":10,"i60":10,"i61":10,"i62":10,"i63":42,"i64":42,"i65":10,"i66":10,"i67":10,"i68":10,"i69":10}; var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"],32:["t6","Deprecated Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -51,7 +51,7 @@

      Class BoxAPIConnection



      -
      public class BoxAPIConnection
      +
      public class BoxAPIConnection
       extends Object
      Represents an authenticated connection to the Box API. @@ -223,32 +223,37 @@

      Method Summary

      +protected Call +createNewCall(OkHttpClient httpClient, + Request request)  + + protected BoxAPIRequest createTokenRequest(URL url)  - + protected BoxAPIConnection.ResourceLinkType determineResourceLinkType(String resourceLink)
      Determines the type of resource, given a link to a Box resource.
      - + void enableNotifications()
      Re-enable email notifications from API actions if they have been suppressed.
      - + protected void extractTokens(JsonObject jsonObject)  - + String getAccessToken()
      Gets an access token that can be used to authenticate an API request.
      - + static URL getAuthorizationURL(String clientID, URI redirectUri, @@ -257,7 +262,7 @@

      Method Summary

      Returns the default authorization URL which is used to perform the authorization_code based OAuth2 flow.
      - + URL getAuthorizationURL(URI redirectUri, String state, @@ -265,197 +270,197 @@

      Method Summary

      Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow.
      - + boolean getAutoRefresh()
      Gets whether or not automatic refreshing of this connection's access token is enabled.
      - + String getBaseAppUrl()
      Gets the base App url.
      - + String getBaseUploadURL()
      Gets the base upload URL that's used when performing file uploads to Box.
      - + String getBaseURL()
      Gets the base URL that's used when sending requests to the Box API.
      - + String getClientID()
      Gets the client ID.
      - + String getClientSecret()
      Gets the client secret.
      - + int getConnectTimeout()
      Gets the connect timeout for this connection in milliseconds.
      - + long getExpires()
      Gets the amount of time for which this connection's access token is valid.
      - + protected HostnameVerifier getHostnameVerifier()  - + protected String getKeyValueOrDefault(JsonObject json, String key, String defaultValue)  - + long getLastRefresh()
      Gets the last time that the access token was refreshed.
      - + ScopedToken getLowerScopedToken(List<String> scopes, String resource)
      Get a lower-scoped token restricted to a resource for the list of scopes that are passed.
      - + int getMaxRetryAttempts()
      Gets the maximum number of times an API request will be retried after an error response is received.
      - + Proxy getProxy()
      Gets the proxy value to use for API calls to Box.
      - + String getProxyPassword()
      Gets the password to use for a proxy that requires basic auth.
      - + String getProxyUsername()
      Gets the username to use for a proxy that requires basic auth.
      - + int getReadTimeout()
      Gets the read timeout for this connection in milliseconds.
      - + protected ReadWriteLock getRefreshLock()
      Gets the refresh lock to be used when refreshing an access token.
      - + String getRefreshToken()
      Gets a refresh token that can be used to refresh an access token.
      - + RequestInterceptor getRequestInterceptor()
      Gets the RequestInterceptor associated with this API connection.
      - + String getRevokeURL()
      Returns the URL used for token revocation.
      - + String getTokenURL()
      Gets the token URL that's used to request access tokens.
      - + protected X509TrustManager getTrustManager()  - + String getUserAgent()
      Gets the user agent that's used when sending requests to the Box API.
      - + protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder)
      Can be used to modify OkHttp.Builder used to create connection.
      - + boolean needsRefresh()
      Determines if this connection's access token has expired and needs to be refreshed.
      - + protected void notifyError(BoxAPIException error)
      Notifies an error event to all the listeners.
      - + protected void notifyRefresh()
      Notifies a refresh event to all the listeners.
      - + void refresh()
      Refresh's this connection's access token using its refresh token.
      - + void removeCustomHeader(String header)
      Removes a custom header, so it will no longer be sent on requests through this API connection.
      - + void removeListener(BoxAPIConnectionListener listener)
      Remove a listener listening to Box API connection events.
      - + void restore(String state)
      Restores a saved connection state into this BoxAPIConnection.
      - + static BoxAPIConnection restore(String clientID, String clientSecret, @@ -463,106 +468,106 @@

      Method Summary

      Restores a BoxAPIConnection from a saved state.
      - + void revokeToken()
      Revokes the tokens associated with this API connection.
      - + String save()
      Saves the state of this connection to a string so that it can be persisted and restored at a later time.
      - + void setAccessToken(String accessToken)
      Sets the access token to use when authenticating API requests.
      - + void setAutoRefresh(boolean autoRefresh)
      Enables or disables automatic refreshing of this connection's access token.
      - + void setBaseAppUrl(String baseAppURL)
      Sets the base App url.
      - + void setBaseAuthorizationURL(String baseAuthorizationURL)
      Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow.
      - + void setBaseUploadURL(String baseUploadURL)
      Sets the base upload URL to be used when performing file uploads to Box.
      - + void setBaseURL(String baseURL)
      Sets the base URL to be used when sending requests to the Box API.
      - + void setConnectTimeout(int connectTimeout)
      Sets the connect timeout for this connection.
      - + void setCustomHeader(String header, String value)
      Sets a custom header to be sent on all requests through this API connection.
      - + void setExpires(long milliseconds)
      Sets the amount of time for which this connection's access token is valid before it must be refreshed.
      - + void setLastRefresh(long lastRefresh)
      Sets the last time that the access token was refreshed.
      - + void setMaxRetryAttempts(int attempts)
      Sets the maximum number of times an API request will be retried after an error response is received.
      - + void setProxy(Proxy proxy)
      Sets the proxy to use for API calls to Box.
      - + void setProxyAuthenticator(Authenticator authenticator)
      Sets a proxy authenticator that will be used when proxy requires authentication.
      - + void setProxyBasicAuthentication(String proxyUsername, String proxyPassword)
      Sets the proxy user and password used in basic authentication
      - + void setProxyPassword(String proxyPassword)
      Deprecated.  @@ -570,7 +575,7 @@

      Method Summary

      - + void setProxyUsername(String proxyUsername)
      Deprecated.  @@ -578,31 +583,31 @@

      Method Summary

      - + void setReadTimeout(int readTimeout)
      Sets the read timeout for this connection.
      - + void setRefreshToken(String refreshToken)
      Sets the refresh token to use when refreshing an access token.
      - + void setRequestInterceptor(RequestInterceptor interceptor)
      Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API.
      - + void setUserAgent(String userAgent)
      Sets the user agent to be used when sending requests to the Box API.
      - + void suppressNotifications()
      Suppresses email notifications from API actions.
      @@ -636,7 +641,7 @@

      Field Detail

      • DEFAULT_TRUST_MANAGER

        -
        public static final X509TrustManager DEFAULT_TRUST_MANAGER
        +
        public static final X509TrustManager DEFAULT_TRUST_MANAGER
        Used as a marker to setup connection to use default HostnameVerifier Example:
        
          BoxApiConnection api = new BoxApiConnection(...);
        @@ -651,7 +656,7 @@ 

        DEFAULT_TRUST_MANAGER

        • DEFAULT_HOSTNAME_VERIFIER

          -
          public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER
          +
          public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER
          Used as a marker to setup connection to use default HostnameVerifier Example:
          
            BoxApiConnection api = new BoxApiConnection(...);
          @@ -666,7 +671,7 @@ 

          DEFAULT_HOSTNAME_VERIFIER

          • DEFAULT_MAX_RETRIES

            -
            public static final int DEFAULT_MAX_RETRIES
            +
            public static final int DEFAULT_MAX_RETRIES
            The default maximum number of times an API request will be retried after an error response is received.
            @@ -681,7 +686,7 @@

            DEFAULT_MAX_RETRIES

            • DEFAULT_BASE_AUTHORIZATION_URL

              -
              protected static final String DEFAULT_BASE_AUTHORIZATION_URL
              +
              protected static final String DEFAULT_BASE_AUTHORIZATION_URL
              Default authorization URL
              See Also:
              @@ -703,7 +708,7 @@

              Constructor Detail

              • BoxAPIConnection

                -
                public BoxAPIConnection(String accessToken)
                +
                public BoxAPIConnection(String accessToken)
                Constructs a new BoxAPIConnection that authenticates with a developer or access token.
                Parameters:
                @@ -717,7 +722,7 @@

                BoxAPIConnection

                • BoxAPIConnection

                  -
                  public BoxAPIConnection(String clientID,
                  +
                  public BoxAPIConnection(String clientID,
                                           String clientSecret,
                                           String accessToken,
                                           String refreshToken)
                  @@ -737,7 +742,7 @@

                  BoxAPIConnection

                  • BoxAPIConnection

                    -
                    public BoxAPIConnection(String clientID,
                    +
                    public BoxAPIConnection(String clientID,
                                             String clientSecret,
                                             String authCode)
                    Constructs a new BoxAPIConnection with an auth code that was obtained from the first half of OAuth.
                    @@ -755,7 +760,7 @@

                    BoxAPIConnection

                    • BoxAPIConnection

                      -
                      public BoxAPIConnection(String clientID,
                      +
                      public BoxAPIConnection(String clientID,
                                               String clientSecret)
                      Constructs a new BoxAPIConnection.
                      @@ -771,7 +776,7 @@

                      BoxAPIConnection

                      • BoxAPIConnection

                        -
                        public BoxAPIConnection(BoxConfig boxConfig)
                        +
                        public BoxAPIConnection(BoxConfig boxConfig)
                        Constructs a new BoxAPIConnection levaraging BoxConfig.
                        Parameters:
                        @@ -793,7 +798,7 @@

                        Method Detail

                        • modifyHttpClientBuilder

                          -
                          protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder)
                          +
                          protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder)
                          Can be used to modify OkHttp.Builder used to create connection. This method is called after all modifications were done, thus allowing others to create their own connections and further customize builder.
                          @@ -810,7 +815,7 @@

                          modifyHttpClientBuilder

                          • setProxyAuthenticator

                            -
                            public void setProxyAuthenticator(Authenticator authenticator)
                            +
                            public void setProxyAuthenticator(Authenticator authenticator)
                            Sets a proxy authenticator that will be used when proxy requires authentication. If you use setProxyBasicAuthentication(String, String) it adds an authenticator that performs Basic authorization. By calling this method you can override this behaviour. @@ -828,7 +833,7 @@

                            setProxyAuthenticator

                            • restore

                              -
                              public static BoxAPIConnection restore(String clientID,
                              +
                              public static BoxAPIConnection restore(String clientID,
                                                                      String clientSecret,
                                                                      String state)
                              Restores a BoxAPIConnection from a saved state.
                              @@ -850,7 +855,7 @@

                              restore

                              • getAuthorizationURL

                                -
                                public static URL getAuthorizationURL(String clientID,
                                +
                                public static URL getAuthorizationURL(String clientID,
                                                                       URI redirectUri,
                                                                       String state,
                                                                       List<String> scopes)
                                @@ -875,7 +880,7 @@

                                getAuthorizationURL

                                • authenticate

                                  -
                                  public void authenticate(String authCode)
                                  +
                                  public void authenticate(String authCode)
                                  Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained from the first half of OAuth.
                                  @@ -890,7 +895,7 @@

                                  authenticate

                                  • getClientID

                                    -
                                    public String getClientID()
                                    +
                                    public String getClientID()
                                    Gets the client ID.
                                    Returns:
                                    @@ -904,7 +909,7 @@

                                    getClientID

                                    • getClientSecret

                                      -
                                      public String getClientSecret()
                                      +
                                      public String getClientSecret()
                                      Gets the client secret.
                                      Returns:
                                      @@ -918,7 +923,7 @@

                                      getClientSecret

                                      • getExpires

                                        -
                                        public long getExpires()
                                        +
                                        public long getExpires()
                                        Gets the amount of time for which this connection's access token is valid.
                                        Returns:
                                        @@ -932,7 +937,7 @@

                                        getExpires

                                        • setExpires

                                          -
                                          public void setExpires(long milliseconds)
                                          +
                                          public void setExpires(long milliseconds)
                                          Sets the amount of time for which this connection's access token is valid before it must be refreshed.
                                          Parameters:
                                          @@ -946,7 +951,7 @@

                                          setExpires

                                          • getTokenURL

                                            -
                                            public String getTokenURL()
                                            +
                                            public String getTokenURL()
                                            Gets the token URL that's used to request access tokens. The default value is "https://www.box.com/api/oauth2/token". The URL is created from baseURL and TOKEN_URL_SUFFIX.
                                            @@ -962,7 +967,7 @@

                                            getTokenURL

                                            • getRevokeURL

                                              -
                                              public String getRevokeURL()
                                              +
                                              public String getRevokeURL()
                                              Returns the URL used for token revocation. The URL is created from baseURL and REVOKE_URL_SUFFIX.
                                              @@ -977,7 +982,7 @@

                                              getRevokeURL

                                              • getBaseURL

                                                -
                                                public String getBaseURL()
                                                +
                                                public String getBaseURL()
                                                Gets the base URL that's used when sending requests to the Box API. The URL is created from baseURL and API_VERSION. The default value is "https://api.box.com/2.0/".
                                                @@ -993,7 +998,7 @@

                                                getBaseURL

                                                • setBaseURL

                                                  -
                                                  public void setBaseURL(String baseURL)
                                                  +
                                                  public void setBaseURL(String baseURL)
                                                  Sets the base URL to be used when sending requests to the Box API. For example, the default base URL is "https://api.box.com/". This method changes how getRevokeURL() and getTokenURL() are constructed.
                                                  @@ -1009,7 +1014,7 @@

                                                  setBaseURL

                                                  • getBaseUploadURL

                                                    -
                                                    public String getBaseUploadURL()
                                                    +
                                                    public String getBaseUploadURL()
                                                    Gets the base upload URL that's used when performing file uploads to Box. The URL is created from baseUploadURL and API_VERSION.
                                                    @@ -1024,7 +1029,7 @@

                                                    getBaseUploadURL

                                                    • setBaseUploadURL

                                                      -
                                                      public void setBaseUploadURL(String baseUploadURL)
                                                      +
                                                      public void setBaseUploadURL(String baseUploadURL)
                                                      Sets the base upload URL to be used when performing file uploads to Box.
                                                      Parameters:
                                                      @@ -1038,7 +1043,7 @@

                                                      setBaseUploadURL

                                                      • getAuthorizationURL

                                                        -
                                                        public URL getAuthorizationURL(URI redirectUri,
                                                        +
                                                        public URL getAuthorizationURL(URI redirectUri,
                                                                                        String state,
                                                                                        List<String> scopes)
                                                        Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow. @@ -1061,7 +1066,7 @@

                                                        getAuthorizationURL

                                                        • setBaseAuthorizationURL

                                                          -
                                                          public void setBaseAuthorizationURL(String baseAuthorizationURL)
                                                          +
                                                          public void setBaseAuthorizationURL(String baseAuthorizationURL)
                                                          Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow.
                                                          Parameters:
                                                          @@ -1075,7 +1080,7 @@

                                                          setBaseAuthorizationURL

                                                          • getUserAgent

                                                            -
                                                            public String getUserAgent()
                                                            +
                                                            public String getUserAgent()
                                                            Gets the user agent that's used when sending requests to the Box API.
                                                            Returns:
                                                            @@ -1089,7 +1094,7 @@

                                                            getUserAgent

                                                            • setUserAgent

                                                              -
                                                              public void setUserAgent(String userAgent)
                                                              +
                                                              public void setUserAgent(String userAgent)
                                                              Sets the user agent to be used when sending requests to the Box API.
                                                              Parameters:
                                                              @@ -1103,7 +1108,7 @@

                                                              setUserAgent

                                                              • getBaseAppUrl

                                                                -
                                                                public String getBaseAppUrl()
                                                                +
                                                                public String getBaseAppUrl()
                                                                Gets the base App url. Used for e.g. file requests.
                                                                Returns:
                                                                @@ -1117,7 +1122,7 @@

                                                                getBaseAppUrl

                                                                • setBaseAppUrl

                                                                  -
                                                                  public void setBaseAppUrl(String baseAppURL)
                                                                  +
                                                                  public void setBaseAppUrl(String baseAppURL)
                                                                  Sets the base App url. Used for e.g. file requests.
                                                                  Parameters:
                                                                  @@ -1131,7 +1136,7 @@

                                                                  setBaseAppUrl

                                                                  • getAccessToken

                                                                    -
                                                                    public String getAccessToken()
                                                                    +
                                                                    public String getAccessToken()
                                                                    Gets an access token that can be used to authenticate an API request. This method will automatically refresh the access token if it has expired since the last call to getAccessToken().
                                                                    @@ -1146,7 +1151,7 @@

                                                                    getAccessToken

                                                                    • setAccessToken

                                                                      -
                                                                      public void setAccessToken(String accessToken)
                                                                      +
                                                                      public void setAccessToken(String accessToken)
                                                                      Sets the access token to use when authenticating API requests.
                                                                      Parameters:
                                                                      @@ -1160,7 +1165,7 @@

                                                                      setAccessToken

                                                                      • getRefreshLock

                                                                        -
                                                                        protected ReadWriteLock getRefreshLock()
                                                                        +
                                                                        protected ReadWriteLock getRefreshLock()
                                                                        Gets the refresh lock to be used when refreshing an access token.
                                                                        Returns:
                                                                        @@ -1174,7 +1179,7 @@

                                                                        getRefreshLock

                                                                        • getRefreshToken

                                                                          -
                                                                          public String getRefreshToken()
                                                                          +
                                                                          public String getRefreshToken()
                                                                          Gets a refresh token that can be used to refresh an access token.
                                                                          Returns:
                                                                          @@ -1188,7 +1193,7 @@

                                                                          getRefreshToken

                                                                          • setRefreshToken

                                                                            -
                                                                            public void setRefreshToken(String refreshToken)
                                                                            +
                                                                            public void setRefreshToken(String refreshToken)
                                                                            Sets the refresh token to use when refreshing an access token.
                                                                            Parameters:
                                                                            @@ -1202,7 +1207,7 @@

                                                                            setRefreshToken

                                                                            • getLastRefresh

                                                                              -
                                                                              public long getLastRefresh()
                                                                              +
                                                                              public long getLastRefresh()
                                                                              Gets the last time that the access token was refreshed.
                                                                              Returns:
                                                                              @@ -1216,7 +1221,7 @@

                                                                              getLastRefresh

                                                                              • setLastRefresh

                                                                                -
                                                                                public void setLastRefresh(long lastRefresh)
                                                                                +
                                                                                public void setLastRefresh(long lastRefresh)
                                                                                Sets the last time that the access token was refreshed.

                                                                                This value is used when determining if an access token needs to be auto-refreshed. If the amount of time since @@ -1233,7 +1238,7 @@

                                                                                setLastRefresh

                                                                                • getAutoRefresh

                                                                                  -
                                                                                  public boolean getAutoRefresh()
                                                                                  +
                                                                                  public boolean getAutoRefresh()
                                                                                  Gets whether or not automatic refreshing of this connection's access token is enabled. Defaults to true.
                                                                                  Returns:
                                                                                  @@ -1247,7 +1252,7 @@

                                                                                  getAutoRefresh

                                                                                  • setAutoRefresh

                                                                                    -
                                                                                    public void setAutoRefresh(boolean autoRefresh)
                                                                                    +
                                                                                    public void setAutoRefresh(boolean autoRefresh)
                                                                                    Enables or disables automatic refreshing of this connection's access token. Defaults to true.
                                                                                    Parameters:
                                                                                    @@ -1261,7 +1266,7 @@

                                                                                    setAutoRefresh

                                                                                    • getMaxRetryAttempts

                                                                                      -
                                                                                      public int getMaxRetryAttempts()
                                                                                      +
                                                                                      public int getMaxRetryAttempts()
                                                                                      Gets the maximum number of times an API request will be retried after an error response is received.
                                                                                      @@ -1276,7 +1281,7 @@

                                                                                      getMaxRetryAttempts

                                                                                      • setMaxRetryAttempts

                                                                                        -
                                                                                        public void setMaxRetryAttempts(int attempts)
                                                                                        +
                                                                                        public void setMaxRetryAttempts(int attempts)
                                                                                        Sets the maximum number of times an API request will be retried after an error response is received.
                                                                                        @@ -1291,7 +1296,7 @@

                                                                                        setMaxRetryAttempts

                                                                                        • getConnectTimeout

                                                                                          -
                                                                                          public int getConnectTimeout()
                                                                                          +
                                                                                          public int getConnectTimeout()
                                                                                          Gets the connect timeout for this connection in milliseconds.
                                                                                          Returns:
                                                                                          @@ -1305,7 +1310,7 @@

                                                                                          getConnectTimeout

                                                                                          • setConnectTimeout

                                                                                            -
                                                                                            public void setConnectTimeout(int connectTimeout)
                                                                                            +
                                                                                            public void setConnectTimeout(int connectTimeout)
                                                                                            Sets the connect timeout for this connection.
                                                                                            Parameters:
                                                                                            @@ -1319,7 +1324,7 @@

                                                                                            setConnectTimeout

                                                                                            • getReadTimeout

                                                                                              -
                                                                                              public int getReadTimeout()
                                                                                              +
                                                                                              public int getReadTimeout()
                                                                                              Gets the read timeout for this connection in milliseconds.
                                                                                              Returns:
                                                                                              @@ -1333,7 +1338,7 @@

                                                                                              getReadTimeout

                                                                                              • setReadTimeout

                                                                                                -
                                                                                                public void setReadTimeout(int readTimeout)
                                                                                                +
                                                                                                public void setReadTimeout(int readTimeout)
                                                                                                Sets the read timeout for this connection.
                                                                                                Parameters:
                                                                                                @@ -1347,7 +1352,7 @@

                                                                                                setReadTimeout

                                                                                                • getProxy

                                                                                                  -
                                                                                                  public Proxy getProxy()
                                                                                                  +
                                                                                                  public Proxy getProxy()
                                                                                                  Gets the proxy value to use for API calls to Box.
                                                                                                  Returns:
                                                                                                  @@ -1361,7 +1366,7 @@

                                                                                                  getProxy

                                                                                                  • setProxy

                                                                                                    -
                                                                                                    public void setProxy(Proxy proxy)
                                                                                                    +
                                                                                                    public void setProxy(Proxy proxy)
                                                                                                    Sets the proxy to use for API calls to Box.
                                                                                                    Parameters:
                                                                                                    @@ -1375,7 +1380,7 @@

                                                                                                    setProxy

                                                                                                    • getProxyUsername

                                                                                                      -
                                                                                                      public String getProxyUsername()
                                                                                                      +
                                                                                                      public String getProxyUsername()
                                                                                                      Gets the username to use for a proxy that requires basic auth.
                                                                                                      Returns:
                                                                                                      @@ -1389,7 +1394,7 @@

                                                                                                      getProxyUsername

                                                                                                      • setProxyUsername

                                                                                                        -
                                                                                                        public void setProxyUsername(String proxyUsername)
                                                                                                        +
                                                                                                        public void setProxyUsername(String proxyUsername)
                                                                                                        Sets the username to use for a proxy that requires basic auth.
                                                                                                        @@ -1404,7 +1409,7 @@

                                                                                                        setProxyUsername

                                                                                                        • getProxyPassword

                                                                                                          -
                                                                                                          public String getProxyPassword()
                                                                                                          +
                                                                                                          public String getProxyPassword()
                                                                                                          Gets the password to use for a proxy that requires basic auth.
                                                                                                          Returns:
                                                                                                          @@ -1418,7 +1423,7 @@

                                                                                                          getProxyPassword

                                                                                                          • setProxyBasicAuthentication

                                                                                                            -
                                                                                                            public void setProxyBasicAuthentication(String proxyUsername,
                                                                                                            +
                                                                                                            public void setProxyBasicAuthentication(String proxyUsername,
                                                                                                                                                     String proxyPassword)
                                                                                                            Sets the proxy user and password used in basic authentication
                                                                                                            @@ -1434,7 +1439,7 @@

                                                                                                            setProxyBasicAuthentication

                                                                                                            • setProxyPassword

                                                                                                              -
                                                                                                              public void setProxyPassword(String proxyPassword)
                                                                                                              +
                                                                                                              public void setProxyPassword(String proxyPassword)
                                                                                                              Sets the password to use for a proxy that requires basic auth.
                                                                                                              @@ -1449,7 +1454,7 @@

                                                                                                              setProxyPassword

                                                                                                              • canRefresh

                                                                                                                -
                                                                                                                public boolean canRefresh()
                                                                                                                +
                                                                                                                public boolean canRefresh()
                                                                                                                Determines if this connection's access token can be refreshed. An access token cannot be refreshed if a refresh token was never set.
                                                                                                                @@ -1464,7 +1469,7 @@

                                                                                                                canRefresh

                                                                                                                • needsRefresh

                                                                                                                  -
                                                                                                                  public boolean needsRefresh()
                                                                                                                  +
                                                                                                                  public boolean needsRefresh()
                                                                                                                  Determines if this connection's access token has expired and needs to be refreshed.
                                                                                                                  Returns:
                                                                                                                  @@ -1478,7 +1483,7 @@

                                                                                                                  needsRefresh

                                                                                                                  • refresh

                                                                                                                    -
                                                                                                                    public void refresh()
                                                                                                                    +
                                                                                                                    public void refresh()
                                                                                                                    Refresh's this connection's access token using its refresh token.
                                                                                                                    Throws:
                                                                                                                    @@ -1492,7 +1497,7 @@

                                                                                                                    refresh

                                                                                                                    • restore

                                                                                                                      -
                                                                                                                      public void restore(String state)
                                                                                                                      +
                                                                                                                      public void restore(String state)
                                                                                                                      Restores a saved connection state into this BoxAPIConnection.
                                                                                                                      Parameters:
                                                                                                                      @@ -1508,7 +1513,7 @@

                                                                                                                      restore

                                                                                                                      • getKeyValueOrDefault

                                                                                                                        -
                                                                                                                        protected String getKeyValueOrDefault(JsonObject json,
                                                                                                                        +
                                                                                                                        protected String getKeyValueOrDefault(JsonObject json,
                                                                                                                                                               String key,
                                                                                                                                                               String defaultValue)
                                                                                                                      • @@ -1519,7 +1524,7 @@

                                                                                                                        getKeyValueOrDefault

                                                                                                                        • notifyRefresh

                                                                                                                          -
                                                                                                                          protected void notifyRefresh()
                                                                                                                          +
                                                                                                                          protected void notifyRefresh()
                                                                                                                          Notifies a refresh event to all the listeners.
                                                                                                                        @@ -1529,7 +1534,7 @@

                                                                                                                        notifyRefresh

                                                                                                                        • notifyError

                                                                                                                          -
                                                                                                                          protected void notifyError(BoxAPIException error)
                                                                                                                          +
                                                                                                                          protected void notifyError(BoxAPIException error)
                                                                                                                          Notifies an error event to all the listeners.
                                                                                                                          Parameters:
                                                                                                                          @@ -1543,7 +1548,7 @@

                                                                                                                          notifyError

                                                                                                                          • addListener

                                                                                                                            -
                                                                                                                            public void addListener(BoxAPIConnectionListener listener)
                                                                                                                            +
                                                                                                                            public void addListener(BoxAPIConnectionListener listener)
                                                                                                                            Add a listener to listen to Box API connection events.
                                                                                                                            Parameters:
                                                                                                                            @@ -1557,7 +1562,7 @@

                                                                                                                            addListener

                                                                                                                            • removeListener

                                                                                                                              -
                                                                                                                              public void removeListener(BoxAPIConnectionListener listener)
                                                                                                                              +
                                                                                                                              public void removeListener(BoxAPIConnectionListener listener)
                                                                                                                              Remove a listener listening to Box API connection events.
                                                                                                                              Parameters:
                                                                                                                              @@ -1571,7 +1576,7 @@

                                                                                                                              removeListener

                                                                                                                              • getRequestInterceptor

                                                                                                                                -
                                                                                                                                public RequestInterceptor getRequestInterceptor()
                                                                                                                                +
                                                                                                                                public RequestInterceptor getRequestInterceptor()
                                                                                                                                Gets the RequestInterceptor associated with this API connection.
                                                                                                                                Returns:
                                                                                                                                @@ -1585,7 +1590,7 @@

                                                                                                                                getRequestInterceptor

                                                                                                                                • setRequestInterceptor

                                                                                                                                  -
                                                                                                                                  public void setRequestInterceptor(RequestInterceptor interceptor)
                                                                                                                                  +
                                                                                                                                  public void setRequestInterceptor(RequestInterceptor interceptor)
                                                                                                                                  Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API.
                                                                                                                                  Parameters:
                                                                                                                                  @@ -1599,7 +1604,7 @@

                                                                                                                                  setRequestInterceptor

                                                                                                                                  • getLowerScopedToken

                                                                                                                                    -
                                                                                                                                    public ScopedToken getLowerScopedToken(List<String> scopes,
                                                                                                                                    +
                                                                                                                                    public ScopedToken getLowerScopedToken(List<String> scopes,
                                                                                                                                                                            String resource)
                                                                                                                                    Get a lower-scoped token restricted to a resource for the list of scopes that are passed.
                                                                                                                                    @@ -1619,7 +1624,7 @@

                                                                                                                                    getLowerScopedToken

                                                                                                                                    • determineResourceLinkType

                                                                                                                                      -
                                                                                                                                      protected BoxAPIConnection.ResourceLinkType determineResourceLinkType(String resourceLink)
                                                                                                                                      +
                                                                                                                                      protected BoxAPIConnection.ResourceLinkType determineResourceLinkType(String resourceLink)
                                                                                                                                      Determines the type of resource, given a link to a Box resource.
                                                                                                                                      Parameters:
                                                                                                                                      @@ -1635,7 +1640,7 @@

                                                                                                                                      determineResourceLinkType

                                                                                                                                      • revokeToken

                                                                                                                                        -
                                                                                                                                        public void revokeToken()
                                                                                                                                        +
                                                                                                                                        public void revokeToken()
                                                                                                                                        Revokes the tokens associated with this API connection. This results in the connection no longer being able to make API calls until a fresh authorization is made by calling authenticate()
                                                                                                                                      • @@ -1646,7 +1651,7 @@

                                                                                                                                        revokeToken

                                                                                                                                        • save

                                                                                                                                          -
                                                                                                                                          public String save()
                                                                                                                                          +
                                                                                                                                          public String save()
                                                                                                                                          Saves the state of this connection to a string so that it can be persisted and restored at a later time.

                                                                                                                                          Note that proxy settings aren't automatically saved or restored. This is mainly due to security concerns @@ -1666,7 +1671,7 @@

                                                                                                                                          save

                                                                                                                                          • setCustomHeader

                                                                                                                                            -
                                                                                                                                            public void setCustomHeader(String header,
                                                                                                                                            +
                                                                                                                                            public void setCustomHeader(String header,
                                                                                                                                                                         String value)
                                                                                                                                            Sets a custom header to be sent on all requests through this API connection.
                                                                                                                                            @@ -1682,7 +1687,7 @@

                                                                                                                                            setCustomHeader

                                                                                                                                            • removeCustomHeader

                                                                                                                                              -
                                                                                                                                              public void removeCustomHeader(String header)
                                                                                                                                              +
                                                                                                                                              public void removeCustomHeader(String header)
                                                                                                                                              Removes a custom header, so it will no longer be sent on requests through this API connection.
                                                                                                                                              Parameters:
                                                                                                                                              @@ -1696,7 +1701,7 @@

                                                                                                                                              removeCustomHeader

                                                                                                                                              • suppressNotifications

                                                                                                                                                -
                                                                                                                                                public void suppressNotifications()
                                                                                                                                                +
                                                                                                                                                public void suppressNotifications()
                                                                                                                                                Suppresses email notifications from API actions. This is typically used by security or admin applications to prevent spamming end users when doing automated processing on their content.
                                                                                                                                              • @@ -1707,7 +1712,7 @@

                                                                                                                                                suppressNotifications

                                                                                                                                                • enableNotifications

                                                                                                                                                  -
                                                                                                                                                  public void enableNotifications()
                                                                                                                                                  +
                                                                                                                                                  public void enableNotifications()
                                                                                                                                                  Re-enable email notifications from API actions if they have been suppressed.
                                                                                                                                                  See Also:
                                                                                                                                                  @@ -1721,7 +1726,7 @@

                                                                                                                                                  enableNotifications

                                                                                                                                                  • asUser

                                                                                                                                                    -
                                                                                                                                                    public void asUser(String userID)
                                                                                                                                                    +
                                                                                                                                                    public void asUser(String userID)
                                                                                                                                                    Set this API connection to make API calls on behalf of another users, impersonating them. This functionality can only be used by admins and service accounts.
                                                                                                                                                    @@ -1736,7 +1741,7 @@

                                                                                                                                                    asUser

                                                                                                                                                    • asSelf

                                                                                                                                                      -
                                                                                                                                                      public void asSelf()
                                                                                                                                                      +
                                                                                                                                                      public void asSelf()
                                                                                                                                                      Sets this API connection to make API calls on behalf of the user with whom the access token is associated. This undoes any previous calls to asUser().
                                                                                                                                                      @@ -1751,7 +1756,7 @@

                                                                                                                                                      asSelf



                                                                                                                                                      -
                                                                                                                                                      public static class MetadataTemplate.Field
                                                                                                                                                      +
                                                                                                                                                      public static class MetadataTemplate.Field
                                                                                                                                                       extends BoxJSONObject
                                                                                                                                                      Class contains information about the metadata template field.
                                                                                                                                                    • @@ -150,48 +150,60 @@

                                                                                                                                                      Method Summary

                                                                                                                                                      +MetadataTemplate.StaticConfig +getStaticConfig() +
                                                                                                                                                      Gets static configuration for the classification.
                                                                                                                                                      + + + String getType()
                                                                                                                                                      Gets the data type of the field's value.
                                                                                                                                                      - + void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy)
                                                                                                                                                      Sets whether the copy operation should copy the metadata along with the item.
                                                                                                                                                      - + void setDescription(String description)
                                                                                                                                                      Sets the description of the field.
                                                                                                                                                      - + void setDisplayName(String displayName)
                                                                                                                                                      Sets the display name of the field.
                                                                                                                                                      - + void setIsHidden(boolean isHidden)
                                                                                                                                                      Sets is metadata template field hidden.
                                                                                                                                                      - + void setKey(String key)
                                                                                                                                                      Sets the key of the field.
                                                                                                                                                      - + void setOptions(List<String> options)
                                                                                                                                                      Sets list of possible options for enum type of the field.
                                                                                                                                                      - + +void +setStaticConfig(MetadataTemplate.StaticConfig staticConfig) +
                                                                                                                                                      Sets static configuration for the classification.
                                                                                                                                                      + + + void setType(String type)
                                                                                                                                                      Sets the data type of the field's value.
                                                                                                                                                      @@ -232,7 +244,7 @@

                                                                                                                                                      Constructor Detail

                                                                                                                                                      • Field

                                                                                                                                                        -
                                                                                                                                                        public Field()
                                                                                                                                                        +
                                                                                                                                                        public Field()
                                                                                                                                                        Constructs an empty metadata template.
                                                                                                                                                      @@ -242,7 +254,7 @@

                                                                                                                                                      Field

                                                                                                                                                      • Field

                                                                                                                                                        -
                                                                                                                                                        public Field(String json)
                                                                                                                                                        +
                                                                                                                                                        public Field(String json)
                                                                                                                                                        Constructs a metadate template field from a JSON string.
                                                                                                                                                        Parameters:
                                                                                                                                                        @@ -264,7 +276,7 @@

                                                                                                                                                        Method Detail

                                                                                                                                                        • getID

                                                                                                                                                          -
                                                                                                                                                          public String getID()
                                                                                                                                                          +
                                                                                                                                                          public String getID()
                                                                                                                                                          Gets the ID of the template field.
                                                                                                                                                          Returns:
                                                                                                                                                          @@ -278,7 +290,7 @@

                                                                                                                                                          getID

                                                                                                                                                          • getType

                                                                                                                                                            -
                                                                                                                                                            public String getType()
                                                                                                                                                            +
                                                                                                                                                            public String getType()
                                                                                                                                                            Gets the data type of the field's value.
                                                                                                                                                            Returns:
                                                                                                                                                            @@ -292,7 +304,7 @@

                                                                                                                                                            getType

                                                                                                                                                            • setType

                                                                                                                                                              -
                                                                                                                                                              public void setType(String type)
                                                                                                                                                              +
                                                                                                                                                              public void setType(String type)
                                                                                                                                                              Sets the data type of the field's value.
                                                                                                                                                              Parameters:
                                                                                                                                                              @@ -306,7 +318,7 @@

                                                                                                                                                              setType

                                                                                                                                                              • getKey

                                                                                                                                                                -
                                                                                                                                                                public String getKey()
                                                                                                                                                                +
                                                                                                                                                                public String getKey()
                                                                                                                                                                Gets the key of the field.
                                                                                                                                                                Returns:
                                                                                                                                                                @@ -320,7 +332,7 @@

                                                                                                                                                                getKey

                                                                                                                                                                • setKey

                                                                                                                                                                  -
                                                                                                                                                                  public void setKey(String key)
                                                                                                                                                                  +
                                                                                                                                                                  public void setKey(String key)
                                                                                                                                                                  Sets the key of the field.
                                                                                                                                                                  Parameters:
                                                                                                                                                                  @@ -334,7 +346,7 @@

                                                                                                                                                                  setKey

                                                                                                                                                                  • getDisplayName

                                                                                                                                                                    -
                                                                                                                                                                    public String getDisplayName()
                                                                                                                                                                    +
                                                                                                                                                                    public String getDisplayName()
                                                                                                                                                                    Gets the display name of the field.
                                                                                                                                                                    Returns:
                                                                                                                                                                    @@ -348,7 +360,7 @@

                                                                                                                                                                    getDisplayName

                                                                                                                                                                    • setDisplayName

                                                                                                                                                                      -
                                                                                                                                                                      public void setDisplayName(String displayName)
                                                                                                                                                                      +
                                                                                                                                                                      public void setDisplayName(String displayName)
                                                                                                                                                                      Sets the display name of the field.
                                                                                                                                                                      Parameters:
                                                                                                                                                                      @@ -362,7 +374,7 @@

                                                                                                                                                                      setDisplayName

                                                                                                                                                                      • getIsHidden

                                                                                                                                                                        -
                                                                                                                                                                        public Boolean getIsHidden()
                                                                                                                                                                        +
                                                                                                                                                                        public Boolean getIsHidden()
                                                                                                                                                                        Gets is metadata template field hidden.
                                                                                                                                                                        Returns:
                                                                                                                                                                        @@ -376,7 +388,7 @@

                                                                                                                                                                        getIsHidden

                                                                                                                                                                        • setIsHidden

                                                                                                                                                                          -
                                                                                                                                                                          public void setIsHidden(boolean isHidden)
                                                                                                                                                                          +
                                                                                                                                                                          public void setIsHidden(boolean isHidden)
                                                                                                                                                                          Sets is metadata template field hidden.
                                                                                                                                                                          Parameters:
                                                                                                                                                                          @@ -390,7 +402,7 @@

                                                                                                                                                                          setIsHidden

                                                                                                                                                                          • getDescription

                                                                                                                                                                            -
                                                                                                                                                                            public String getDescription()
                                                                                                                                                                            +
                                                                                                                                                                            public String getDescription()
                                                                                                                                                                            Gets the description of the field.
                                                                                                                                                                            Returns:
                                                                                                                                                                            @@ -404,7 +416,7 @@

                                                                                                                                                                            getDescription

                                                                                                                                                                            • setDescription

                                                                                                                                                                              -
                                                                                                                                                                              public void setDescription(String description)
                                                                                                                                                                              +
                                                                                                                                                                              public void setDescription(String description)
                                                                                                                                                                              Sets the description of the field.
                                                                                                                                                                              Parameters:
                                                                                                                                                                              @@ -418,7 +430,7 @@

                                                                                                                                                                              setDescription

                                                                                                                                                                              • getOptions

                                                                                                                                                                                -
                                                                                                                                                                                public List<StringgetOptions()
                                                                                                                                                                                +
                                                                                                                                                                                public List<StringgetOptions()
                                                                                                                                                                                Gets list of possible options for enum type of the field.
                                                                                                                                                                                Returns:
                                                                                                                                                                                @@ -432,7 +444,7 @@

                                                                                                                                                                                getOptions

                                                                                                                                                                                • setOptions

                                                                                                                                                                                  -
                                                                                                                                                                                  public void setOptions(List<String> options)
                                                                                                                                                                                  +
                                                                                                                                                                                  public void setOptions(List<String> options)
                                                                                                                                                                                  Sets list of possible options for enum type of the field.
                                                                                                                                                                                  Parameters:
                                                                                                                                                                                  @@ -446,7 +458,7 @@

                                                                                                                                                                                  setOptions

                                                                                                                                                                                  • getOptionsObjects

                                                                                                                                                                                    -
                                                                                                                                                                                    public List<MetadataTemplate.OptiongetOptionsObjects()
                                                                                                                                                                                    +
                                                                                                                                                                                    public List<MetadataTemplate.OptiongetOptionsObjects()
                                                                                                                                                                                    Gets list of possible options for options type of the field.
                                                                                                                                                                                    Returns:
                                                                                                                                                                                    @@ -460,7 +472,7 @@

                                                                                                                                                                                    getOptionsObjects

                                                                                                                                                                                    • getCopyInstanceOnItemCopy

                                                                                                                                                                                      -
                                                                                                                                                                                      public Boolean getCopyInstanceOnItemCopy()
                                                                                                                                                                                      +
                                                                                                                                                                                      public Boolean getCopyInstanceOnItemCopy()
                                                                                                                                                                                      Gets whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                      Returns:
                                                                                                                                                                                      @@ -471,10 +483,10 @@

                                                                                                                                                                                      getCopyInstanceOnItemCopy

                                                                                                                                                                                      -
                                                                                                                                                                                    • diff --git a/javadoc/com/box/sdk/MetadataTemplate.FieldOperation.html b/javadoc/com/box/sdk/MetadataTemplate.FieldOperation.html index 397eb3a9d..9b12a5747 100644 --- a/javadoc/com/box/sdk/MetadataTemplate.FieldOperation.html +++ b/javadoc/com/box/sdk/MetadataTemplate.FieldOperation.html @@ -56,7 +56,7 @@

                                                                                                                                                                                      Class MetadataTe



                                                                                                                                                                                    -
                                                                                                                                                                                    public static class MetadataTemplate.FieldOperation
                                                                                                                                                                                    +
                                                                                                                                                                                    public static class MetadataTemplate.FieldOperation
                                                                                                                                                                                     extends BoxJSONObject
                                                                                                                                                                                    Posssible operations that can be performed in a Metadata template.
                                                                                                                                                                                      @@ -249,7 +249,7 @@

                                                                                                                                                                                      Constructor Detail

                                                                                                                                                                                      @@ -259,7 +259,7 @@

                                                                                                                                                                                      FieldOperation

                                                                                                                                                                                      • FieldOperation

                                                                                                                                                                                        -
                                                                                                                                                                                        public FieldOperation(String json)
                                                                                                                                                                                        +
                                                                                                                                                                                        public FieldOperation(String json)
                                                                                                                                                                                        Constructs a Field operation from a JSON string.
                                                                                                                                                                                        Parameters:
                                                                                                                                                                                        @@ -281,7 +281,7 @@

                                                                                                                                                                                        Method Detail

                                                                                                                                                                                        • getOp

                                                                                                                                                                                          -
                                                                                                                                                                                          public MetadataTemplate.Operation getOp()
                                                                                                                                                                                          +
                                                                                                                                                                                          public MetadataTemplate.Operation getOp()
                                                                                                                                                                                          Gets the operation.
                                                                                                                                                                                          Returns:
                                                                                                                                                                                          @@ -295,7 +295,7 @@

                                                                                                                                                                                          getOp

                                                                                                                                                                                          • setOp

                                                                                                                                                                                            -
                                                                                                                                                                                            public void setOp(MetadataTemplate.Operation op)
                                                                                                                                                                                            +
                                                                                                                                                                                            public void setOp(MetadataTemplate.Operation op)
                                                                                                                                                                                            Sets the operation.
                                                                                                                                                                                            Parameters:
                                                                                                                                                                                            @@ -309,7 +309,7 @@

                                                                                                                                                                                            setOp

                                                                                                                                                                                            • getData

                                                                                                                                                                                              -
                                                                                                                                                                                              public MetadataTemplate.Field getData()
                                                                                                                                                                                              +
                                                                                                                                                                                              public MetadataTemplate.Field getData()
                                                                                                                                                                                              Gets the data associated with the operation.
                                                                                                                                                                                              Returns:
                                                                                                                                                                                              @@ -323,7 +323,7 @@

                                                                                                                                                                                              getData

                                                                                                                                                                                              • setData

                                                                                                                                                                                                -
                                                                                                                                                                                                public void setData(MetadataTemplate.Field data)
                                                                                                                                                                                                +
                                                                                                                                                                                                public void setData(MetadataTemplate.Field data)
                                                                                                                                                                                                Sets the data.
                                                                                                                                                                                                Parameters:
                                                                                                                                                                                                @@ -337,7 +337,7 @@

                                                                                                                                                                                                setData

                                                                                                                                                                                                • getFieldKey

                                                                                                                                                                                                  -
                                                                                                                                                                                                  public String getFieldKey()
                                                                                                                                                                                                  +
                                                                                                                                                                                                  public String getFieldKey()
                                                                                                                                                                                                  Gets the field key.
                                                                                                                                                                                                  Returns:
                                                                                                                                                                                                  @@ -351,7 +351,7 @@

                                                                                                                                                                                                  getFieldKey

                                                                                                                                                                                                  • setFieldKey

                                                                                                                                                                                                    -
                                                                                                                                                                                                    public void setFieldKey(String fieldKey)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    public void setFieldKey(String fieldKey)
                                                                                                                                                                                                    Sets the field key.
                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                    @@ -365,7 +365,7 @@

                                                                                                                                                                                                    setFieldKey

                                                                                                                                                                                                    • getFieldKeys

                                                                                                                                                                                                      -
                                                                                                                                                                                                      public List<StringgetFieldKeys()
                                                                                                                                                                                                      +
                                                                                                                                                                                                      public List<StringgetFieldKeys()
                                                                                                                                                                                                      Gets the list of field keys.
                                                                                                                                                                                                      Returns:
                                                                                                                                                                                                      @@ -379,7 +379,7 @@

                                                                                                                                                                                                      getFieldKeys

                                                                                                                                                                                                      • setFieldKeys

                                                                                                                                                                                                        -
                                                                                                                                                                                                        public void setFieldKeys(List<String> fieldKeys)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        public void setFieldKeys(List<String> fieldKeys)
                                                                                                                                                                                                        Sets the list of the field keys.
                                                                                                                                                                                                        Parameters:
                                                                                                                                                                                                        @@ -393,7 +393,7 @@

                                                                                                                                                                                                        setFieldKeys

                                                                                                                                                                                                        • getEnumOptionKeys

                                                                                                                                                                                                          -
                                                                                                                                                                                                          public List<StringgetEnumOptionKeys()
                                                                                                                                                                                                          +
                                                                                                                                                                                                          public List<StringgetEnumOptionKeys()
                                                                                                                                                                                                          Gets the list of keys of the Enum options.
                                                                                                                                                                                                          Returns:
                                                                                                                                                                                                          @@ -407,7 +407,7 @@

                                                                                                                                                                                                          getEnumOptionKeys

                                                                                                                                                                                                          • setEnumOptionKeys

                                                                                                                                                                                                            -
                                                                                                                                                                                                            public void setEnumOptionKeys(List<String> enumOptionKeys)
                                                                                                                                                                                                            +
                                                                                                                                                                                                            public void setEnumOptionKeys(List<String> enumOptionKeys)
                                                                                                                                                                                                            Sets the list of the enum option keys.
                                                                                                                                                                                                            Parameters:
                                                                                                                                                                                                            @@ -421,7 +421,7 @@

                                                                                                                                                                                                            setEnumOptionKeys

                                                                                                                                                                                                            • getEnumOptionKey

                                                                                                                                                                                                              -
                                                                                                                                                                                                              public String getEnumOptionKey()
                                                                                                                                                                                                              +
                                                                                                                                                                                                              public String getEnumOptionKey()
                                                                                                                                                                                                              Gets the enum option key.
                                                                                                                                                                                                              Returns:
                                                                                                                                                                                                              @@ -435,7 +435,7 @@

                                                                                                                                                                                                              getEnumOptionKey

                                                                                                                                                                                                              • setEnumOptionKey

                                                                                                                                                                                                                -
                                                                                                                                                                                                                public void setEnumOptionKey(String enumOptionKey)
                                                                                                                                                                                                                +
                                                                                                                                                                                                                public void setEnumOptionKey(String enumOptionKey)
                                                                                                                                                                                                                Sets the enum option key.
                                                                                                                                                                                                                Parameters:
                                                                                                                                                                                                                @@ -449,7 +449,7 @@

                                                                                                                                                                                                                setEnumOptionKey

                                                                                                                                                                                                                • getMultiSelectOptionKey

                                                                                                                                                                                                                  -
                                                                                                                                                                                                                  public String getMultiSelectOptionKey()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  public String getMultiSelectOptionKey()
                                                                                                                                                                                                                  Gets the multi-select option key.
                                                                                                                                                                                                                  Returns:
                                                                                                                                                                                                                  @@ -463,7 +463,7 @@

                                                                                                                                                                                                                  getMultiSelectOptionKey

                                                                                                                                                                                                                  • setMultiSelectOptionKey

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public void setMultiSelectOptionKey(String key)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    public void setMultiSelectOptionKey(String key)
                                                                                                                                                                                                                    Sets the multi-select option key.
                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                    @@ -477,7 +477,7 @@

                                                                                                                                                                                                                    setMultiSelectOptionKey

                                                                                                                                                                                                                    • getMultiSelectOptionKeys

                                                                                                                                                                                                                      -
                                                                                                                                                                                                                      public List<StringgetMultiSelectOptionKeys()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      public List<StringgetMultiSelectOptionKeys()
                                                                                                                                                                                                                      Gets the list of multiselect option keys.
                                                                                                                                                                                                                      Returns:
                                                                                                                                                                                                                      @@ -491,7 +491,7 @@

                                                                                                                                                                                                                      getMultiSelectOptionKeys

                                                                                                                                                                                                                      • setMultiSelectOptionKeys

                                                                                                                                                                                                                        -
                                                                                                                                                                                                                        public void setMultiSelectOptionKeys(List<String> keys)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        public void setMultiSelectOptionKeys(List<String> keys)
                                                                                                                                                                                                                        Sets the multi-select option keys.
                                                                                                                                                                                                                        Parameters:
                                                                                                                                                                                                                        @@ -505,7 +505,7 @@

                                                                                                                                                                                                                        setMultiSelectOptionKeys



                                                                                                                                                                                                                        -
                                                                                                                                                                                                                        public static class MetadataTemplate.Option
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        public static class MetadataTemplate.Option
                                                                                                                                                                                                                         extends BoxJSONObject
                                                                                                                                                                                                                        Class contains information about the metadata template option.
                                                                                                                                                                                                                      • @@ -113,6 +113,12 @@

                                                                                                                                                                                                                        Method Summary

                                                                                                                                                                                                                        Gets the key of the field.
                                                                                                                                                                                                                        + +MetadataTemplate.StaticConfig +getStaticConfig() +
                                                                                                                                                                                                                        Gets static configuration for the classification.
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        • @@ -148,7 +154,7 @@

                                                                                                                                                                                                                          Constructor Detail

                                                                                                                                                                                                                          @@ -158,7 +164,7 @@

                                                                                                                                                                                                                          Option

                                                                                                                                                                                                                          • Option

                                                                                                                                                                                                                            -
                                                                                                                                                                                                                            public Option(String json)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            public Option(String json)
                                                                                                                                                                                                                            Constructs a metadate template option from a JSON string.
                                                                                                                                                                                                                            Parameters:
                                                                                                                                                                                                                            @@ -180,7 +186,7 @@

                                                                                                                                                                                                                            Method Detail

                                                                                                                                                                                                                            • getID

                                                                                                                                                                                                                              -
                                                                                                                                                                                                                              public String getID()
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              public String getID()
                                                                                                                                                                                                                              Gets the ID of the template field.
                                                                                                                                                                                                                              Returns:
                                                                                                                                                                                                                              @@ -191,10 +197,10 @@

                                                                                                                                                                                                                              getID

                                                                                                                                                                                                                              -
                                                                                                                                                                                                                            • diff --git a/javadoc/com/box/sdk/MetadataTemplate.StaticConfig.html b/javadoc/com/box/sdk/MetadataTemplate.StaticConfig.html new file mode 100644 index 000000000..6a43baf8f --- /dev/null +++ b/javadoc/com/box/sdk/MetadataTemplate.StaticConfig.html @@ -0,0 +1,213 @@ + + + + + + +MetadataTemplate.StaticConfig (Box Java SDK) + + + + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              com.box.sdk
                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Class MetadataTemplate.StaticConfig

                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                • + + +

                                                                                                                                                                                                                                  Constructor Detail

                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                    StaticConfig

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public StaticConfig()
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Constructs an empty static configuration.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                    StaticConfig

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public StaticConfig(String json)
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Constructs a static configuration from a JSON string.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    json - the json encoded metadate template field.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                • + + +

                                                                                                                                                                                                                                  Method Detail

                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                    getClassification

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public JsonObject getClassification()
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Gets the classification of the static configuration.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    the classification of the static configuration.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                    setClassification

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public void setClassification(JsonObject classification)
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Sets the classification of the static configuration.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    classification - the classification of the static configuration.
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + diff --git a/javadoc/com/box/sdk/MetadataTemplate.html b/javadoc/com/box/sdk/MetadataTemplate.html index d33077740..1027dcd39 100644 --- a/javadoc/com/box/sdk/MetadataTemplate.html +++ b/javadoc/com/box/sdk/MetadataTemplate.html @@ -103,6 +103,12 @@

                                                                                                                                                                                                                              Nested Class Summary

                                                                                                                                                                                                                              Class contains information about the metadata template option.
                                                                                                                                                                                                                              + +static class  +MetadataTemplate.StaticConfig +
                                                                                                                                                                                                                              Class contains information about the static configuration for the classification.
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            @@ -554,7 +560,7 @@

                                                                                                                                                                                                                            executeMetadataQuery

                                                                                                                                                                                                                            • getMetadataTemplate

                                                                                                                                                                                                                              -
                                                                                                                                                                                                                              public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api)
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api)
                                                                                                                                                                                                                              Gets the metadata template of properties.
                                                                                                                                                                                                                              Parameters:
                                                                                                                                                                                                                              @@ -570,7 +576,7 @@

                                                                                                                                                                                                                              getMetadataTemplate

                                                                                                                                                                                                                              • getMetadataTemplate

                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api,
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api,
                                                                                                                                                                                                                                                                                    String templateName)
                                                                                                                                                                                                                                Gets the metadata template of specified template type.
                                                                                                                                                                                                                                @@ -588,7 +594,7 @@

                                                                                                                                                                                                                                getMetadataTemplate

                                                                                                                                                                                                                                • getMetadataTemplate

                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                  public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api,
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api,
                                                                                                                                                                                                                                                                                      String templateName,
                                                                                                                                                                                                                                                                                      String scope,
                                                                                                                                                                                                                                                                                      String... fields)
                                                                                                                                                                                                                                  @@ -610,7 +616,7 @@

                                                                                                                                                                                                                                  getMetadataTemplate

                                                                                                                                                                                                                                  • getMetadataTemplateByID

                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                    public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api,
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api,
                                                                                                                                                                                                                                                                                            String templateID)
                                                                                                                                                                                                                                    Geta the specified metadata template by its ID.
                                                                                                                                                                                                                                    @@ -628,7 +634,7 @@

                                                                                                                                                                                                                                    getMetadataTemplateByID

                                                                                                                                                                                                                                    • getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                      public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(BoxAPIConnection api,
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(BoxAPIConnection api,
                                                                                                                                                                                                                                                                                                               String... fields)
                                                                                                                                                                                                                                      Returns all metadata templates within a user's enterprise.
                                                                                                                                                                                                                                      @@ -646,7 +652,7 @@

                                                                                                                                                                                                                                      getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                      • getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                        public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(String scope,
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(String scope,
                                                                                                                                                                                                                                                                                                                 BoxAPIConnection api,
                                                                                                                                                                                                                                                                                                                 String... fields)
                                                                                                                                                                                                                                        Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported.
                                                                                                                                                                                                                                        @@ -666,7 +672,7 @@

                                                                                                                                                                                                                                        getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                        • getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                          public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(String scope,
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          public static Iterable<MetadataTemplategetEnterpriseMetadataTemplates(String scope,
                                                                                                                                                                                                                                                                                                                   int limit,
                                                                                                                                                                                                                                                                                                                   BoxAPIConnection api,
                                                                                                                                                                                                                                                                                                                   String... fields)
                                                                                                                                                                                                                                          @@ -688,7 +694,7 @@

                                                                                                                                                                                                                                          getEnterpriseMetadataTemplates

                                                                                                                                                                                                                                          • getID

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            public String getID()
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            public String getID()
                                                                                                                                                                                                                                            Gets the ID of the template.
                                                                                                                                                                                                                                            Returns:
                                                                                                                                                                                                                                            @@ -702,7 +708,7 @@

                                                                                                                                                                                                                                            getID

                                                                                                                                                                                                                                            • getTemplateKey

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public String getTemplateKey()
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public String getTemplateKey()
                                                                                                                                                                                                                                              Gets the unique template key to identify the metadata template.
                                                                                                                                                                                                                                              Returns:
                                                                                                                                                                                                                                              @@ -716,7 +722,7 @@

                                                                                                                                                                                                                                              getTemplateKey

                                                                                                                                                                                                                                              • getScope

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public String getScope()
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public String getScope()
                                                                                                                                                                                                                                                Gets the metadata template scope.
                                                                                                                                                                                                                                                Returns:
                                                                                                                                                                                                                                                @@ -730,7 +736,7 @@

                                                                                                                                                                                                                                                getScope

                                                                                                                                                                                                                                                • getDisplayName

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  public String getDisplayName()
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  public String getDisplayName()
                                                                                                                                                                                                                                                  Gets the displayed metadata template name.
                                                                                                                                                                                                                                                  Returns:
                                                                                                                                                                                                                                                  @@ -744,7 +750,7 @@

                                                                                                                                                                                                                                                  getDisplayName

                                                                                                                                                                                                                                                  • getIsHidden

                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                    public Boolean getIsHidden()
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    public Boolean getIsHidden()
                                                                                                                                                                                                                                                    Gets is the metadata template hidden.
                                                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                                                    @@ -758,7 +764,7 @@

                                                                                                                                                                                                                                                    getIsHidden

                                                                                                                                                                                                                                                    • getFields

                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      public List<MetadataTemplate.FieldgetFields()
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      public List<MetadataTemplate.FieldgetFields()
                                                                                                                                                                                                                                                      Gets the iterable with all fields the metadata template contains.
                                                                                                                                                                                                                                                      Returns:
                                                                                                                                                                                                                                                      @@ -772,7 +778,7 @@

                                                                                                                                                                                                                                                      getFields

                                                                                                                                                                                                                                                      • diff --git a/javadoc/com/box/sdk/package-frame.html b/javadoc/com/box/sdk/package-frame.html index 4c99d34a8..158d16159 100644 --- a/javadoc/com/box/sdk/package-frame.html +++ b/javadoc/com/box/sdk/package-frame.html @@ -139,6 +139,7 @@

                                                                                                                                                                                                                                                        Classes

                                                                                                                                                                                                                                                      • MetadataTemplate.Field
                                                                                                                                                                                                                                                      • MetadataTemplate.FieldOperation
                                                                                                                                                                                                                                                      • MetadataTemplate.Option
                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                      • MetadataTemplate.StaticConfig
                                                                                                                                                                                                                                                      • PagingParameters
                                                                                                                                                                                                                                                      • PartialCollection
                                                                                                                                                                                                                                                      • Representation
                                                                                                                                                                                                                                                      • diff --git a/javadoc/com/box/sdk/package-summary.html b/javadoc/com/box/sdk/package-summary.html index cf66fba84..681cebea6 100644 --- a/javadoc/com/box/sdk/package-summary.html +++ b/javadoc/com/box/sdk/package-summary.html @@ -786,58 +786,64 @@

                                                                                                                                                                                                                                                        Package com.box.sdk

                                                                                                                                                                                                                                                        +MetadataTemplate.StaticConfig + +
                                                                                                                                                                                                                                                        Class contains information about the static configuration for the classification.
                                                                                                                                                                                                                                                        + + + PagingParameters
                                                                                                                                                                                                                                                        Abstraction on how SDK is doing pagination.
                                                                                                                                                                                                                                                        - + PartialCollection<E>
                                                                                                                                                                                                                                                        A collection that contains a subset of items that are a part of a larger collection.
                                                                                                                                                                                                                                                        - + Representation
                                                                                                                                                                                                                                                        The class represents one instance of a file representation.
                                                                                                                                                                                                                                                        - + RetentionPolicyParams
                                                                                                                                                                                                                                                        Optional parameters for creating an updating a Retention Policy.
                                                                                                                                                                                                                                                        - + ScopedToken   - + SharedLinkAPIConnection Deprecated - + SizeRange
                                                                                                                                                                                                                                                        Class is used to be a range for two byte numbers.
                                                                                                                                                                                                                                                        - + SortParameters
                                                                                                                                                                                                                                                        Represents sorting parameters.
                                                                                                                                                                                                                                                        - + StandardCharsets
                                                                                                                                                                                                                                                        Constant definitions for the standard Charsets.
                                                                                                                                                                                                                                                        - + URLTemplate
                                                                                                                                                                                                                                                        A template class to build URLs from base URL, path, URL parameters and Query String.
                                                                                                                                                                                                                                                        diff --git a/javadoc/overview-summary.html b/javadoc/overview-summary.html index 8e674f5f6..105e3f0e3 100644 --- a/javadoc/overview-summary.html +++ b/javadoc/overview-summary.html @@ -23,7 +23,7 @@
                                                                                                                                                                                                                                                        JavaScript is disabled on your browser.
                                                                                                                                                                                                                                                        -

                                                                                                                                                                                                                                                        box-java-sdk-10 4.10.0 API

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        box-java-sdk-11 4.11.0 API

                                                                                                                                                                                                                                                        diff --git a/javadoc/src-html/com/box/sdk/BoxAPIConnection.ResourceLinkType.html b/javadoc/src-html/com/box/sdk/BoxAPIConnection.ResourceLinkType.html index 0a0703cc2..1a36e171a 100644 --- a/javadoc/src-html/com/box/sdk/BoxAPIConnection.ResourceLinkType.html +++ b/javadoc/src-html/com/box/sdk/BoxAPIConnection.ResourceLinkType.html @@ -37,1268 +37,1273 @@ 029import javax.net.ssl.TrustManager;030import javax.net.ssl.X509TrustManager;031import okhttp3.Authenticator; -032import okhttp3.Credentials; -033import okhttp3.OkHttpClient; -034import okhttp3.Request; -035import okhttp3.Response; -036 -037/** -038 * Represents an authenticated connection to the Box API. -039 * -040 * <p>This class handles storing authentication information, automatic token refresh, and rate-limiting. It can also be -041 * used to configure the Box API endpoint URL in order to hit a different version of the API. Multiple instances of -042 * BoxAPIConnection may be created to support multi-user login.</p> -043 */ -044public class BoxAPIConnection { -045 -046 /** -047 * Used as a marker to setup connection to use default HostnameVerifier -048 * Example:<pre>{@code -049 * BoxApiConnection api = new BoxApiConnection(...); -050 * HostnameVerifier myHostnameVerifier = ... -051 * api.configureSslCertificatesValidation(DEFAULT_TRUST_MANAGER, myHostnameVerifier); -052 * }</pre> -053 */ -054 public static final X509TrustManager DEFAULT_TRUST_MANAGER = null; -055 /** -056 * Used as a marker to setup connection to use default HostnameVerifier -057 * Example:<pre>{@code -058 * BoxApiConnection api = new BoxApiConnection(...); -059 * X509TrustManager myTrustManager = ... -060 * api.configureSslCertificatesValidation(myTrustManager, DEFAULT_HOSTNAME_VERIFIER); -061 * }</pre> -062 */ -063 public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = null; -064 -065 /** -066 * The default maximum number of times an API request will be retried after an error response -067 * is received. -068 */ -069 public static final int DEFAULT_MAX_RETRIES = 5; -070 /** -071 * Default authorization URL -072 */ -073 protected static final String DEFAULT_BASE_AUTHORIZATION_URL = "https://account.box.com/api/"; -074 static final String AS_USER_HEADER = "As-User"; -075 -076 private static final String API_VERSION = "2.0"; -077 private static final String OAUTH_SUFFIX = "oauth2/authorize"; -078 private static final String TOKEN_URL_SUFFIX = "oauth2/token"; -079 private static final String REVOKE_URL_SUFFIX = "oauth2/revoke"; -080 private static final String DEFAULT_BASE_URL = "https://api.box.com/"; -081 private static final String DEFAULT_BASE_UPLOAD_URL = "https://upload.box.com/api/"; -082 private static final String DEFAULT_BASE_APP_URL = "https://app.box.com"; -083 -084 private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications"; -085 -086 private static final String JAVA_VERSION = System.getProperty("java.version"); -087 private static final String SDK_VERSION = "4.10.0"; -088 -089 /** -090 * The amount of buffer time, in milliseconds, to use when determining if an access token should be refreshed. For -091 * example, if REFRESH_EPSILON = 60000 and the access token expires in less than one minute, it will be refreshed. -092 */ -093 private static final long REFRESH_EPSILON = 60000; -094 -095 private final String clientID; -096 private final String clientSecret; -097 private final ReadWriteLock refreshLock; -098 private X509TrustManager trustManager; -099 private HostnameVerifier hostnameVerifier; -100 -101 // These volatile fields are used when determining if the access token needs to be refreshed. Since they are used in -102 // the double-checked lock in getAccessToken(), they must be atomic. -103 private volatile long lastRefresh; -104 private volatile long expires; -105 -106 private Proxy proxy; -107 private String proxyUsername; -108 private String proxyPassword; -109 -110 private String userAgent; -111 private String accessToken; -112 private String refreshToken; -113 private String tokenURL; -114 private String revokeURL; -115 private String baseURL; -116 private String baseUploadURL; -117 private String baseAppURL; -118 private String baseAuthorizationURL; -119 private boolean autoRefresh; -120 private int maxRetryAttempts; -121 private int connectTimeout; -122 private int readTimeout; -123 private final List<BoxAPIConnectionListener> listeners; -124 private RequestInterceptor interceptor; -125 private final Map<String, String> customHeaders; -126 -127 private OkHttpClient httpClient; -128 private OkHttpClient noRedirectsHttpClient; -129 private Authenticator authenticator; -130 -131 /** -132 * Constructs a new BoxAPIConnection that authenticates with a developer or access token. -133 * -134 * @param accessToken a developer or access token to use for authenticating with the API. -135 */ -136 public BoxAPIConnection(String accessToken) { -137 this(null, null, accessToken, null); -138 } -139 -140 /** -141 * Constructs a new BoxAPIConnection with an access token that can be refreshed. -142 * -143 * @param clientID the client ID to use when refreshing the access token. -144 * @param clientSecret the client secret to use when refreshing the access token. -145 * @param accessToken an initial access token to use for authenticating with the API. -146 * @param refreshToken an initial refresh token to use when refreshing the access token. -147 */ -148 public BoxAPIConnection(String clientID, String clientSecret, String accessToken, String refreshToken) { -149 this.clientID = clientID; -150 this.clientSecret = clientSecret; -151 this.accessToken = accessToken; -152 this.refreshToken = refreshToken; -153 this.baseURL = fixBaseUrl(DEFAULT_BASE_URL); -154 this.baseUploadURL = fixBaseUrl(DEFAULT_BASE_UPLOAD_URL); -155 this.baseAppURL = DEFAULT_BASE_APP_URL; -156 this.baseAuthorizationURL = DEFAULT_BASE_AUTHORIZATION_URL; -157 this.autoRefresh = true; -158 this.maxRetryAttempts = BoxGlobalSettings.getMaxRetryAttempts(); -159 this.connectTimeout = BoxGlobalSettings.getConnectTimeout(); -160 this.readTimeout = BoxGlobalSettings.getReadTimeout(); -161 this.refreshLock = new ReentrantReadWriteLock(); -162 this.userAgent = "Box Java SDK v" + SDK_VERSION + " (Java " + JAVA_VERSION + ")"; -163 this.listeners = new ArrayList<>(); -164 this.customHeaders = new HashMap<>(); -165 -166 buildHttpClients(); -167 } -168 -169 /** -170 * Constructs a new BoxAPIConnection with an auth code that was obtained from the first half of OAuth. -171 * -172 * @param clientID the client ID to use when exchanging the auth code for an access token. -173 * @param clientSecret the client secret to use when exchanging the auth code for an access token. -174 * @param authCode an auth code obtained from the first half of the OAuth process. -175 */ -176 public BoxAPIConnection(String clientID, String clientSecret, String authCode) { -177 this(clientID, clientSecret, null, null); -178 this.authenticate(authCode); -179 } -180 -181 /** -182 * Constructs a new BoxAPIConnection. -183 * -184 * @param clientID the client ID to use when exchanging the auth code for an access token. -185 * @param clientSecret the client secret to use when exchanging the auth code for an access token. -186 */ -187 public BoxAPIConnection(String clientID, String clientSecret) { -188 this(clientID, clientSecret, null, null); -189 } -190 -191 /** -192 * Constructs a new BoxAPIConnection levaraging BoxConfig. -193 * -194 * @param boxConfig BoxConfig file, which should have clientId and clientSecret -195 */ -196 public BoxAPIConnection(BoxConfig boxConfig) { -197 this(boxConfig.getClientId(), boxConfig.getClientSecret(), null, null); -198 } -199 -200 private void buildHttpClients() { -201 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); -202 if (trustManager != null) { -203 try { -204 SSLContext sslContext = SSLContext.getInstance("SSL"); -205 sslContext.init(null, new TrustManager[]{trustManager}, new java.security.SecureRandom()); -206 httpClientBuilder.sslSocketFactory(sslContext.getSocketFactory(), trustManager); -207 } catch (NoSuchAlgorithmException | KeyManagementException e) { -208 throw new RuntimeException(e); -209 } -210 } -211 -212 OkHttpClient.Builder builder = httpClientBuilder -213 .followSslRedirects(true) -214 .followRedirects(true) -215 .connectTimeout(Duration.ofMillis(connectTimeout)) -216 .readTimeout(Duration.ofMillis(readTimeout)) -217 .connectionSpecs(singletonList(MODERN_TLS)); -218 -219 if (hostnameVerifier != null) { -220 httpClientBuilder.hostnameVerifier(hostnameVerifier); -221 } -222 -223 if (proxy != null) { -224 builder.proxy(proxy); -225 if (proxyUsername != null && proxyPassword != null) { -226 builder.proxyAuthenticator((route, response) -> { -227 String credential = Credentials.basic(proxyUsername, proxyPassword); -228 return response.request().newBuilder() -229 .header("Proxy-Authorization", credential) -230 .build(); -231 }); -232 } -233 if (this.authenticator != null) { -234 builder.proxyAuthenticator(authenticator); -235 } -236 } -237 builder = modifyHttpClientBuilder(builder); -238 -239 this.httpClient = builder.build(); -240 this.noRedirectsHttpClient = new OkHttpClient.Builder(httpClient) -241 .followSslRedirects(false) -242 .followRedirects(false) -243 .build(); -244 } -245 -246 /** -247 * Can be used to modify OkHttp.Builder used to create connection. This method is called after all modifications -248 * were done, thus allowing others to create their own connections and further customize builder. -249 * @param httpClientBuilder Builder that will be used to create http connection. -250 * @return Modified builder. -251 */ -252 protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder) { -253 return httpClientBuilder; -254 } -255 -256 /** -257 * Sets a proxy authenticator that will be used when proxy requires authentication. -258 * If you use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} it adds an authenticator -259 * that performs Basic authorization. By calling this method you can override this behaviour. -260 * You do not need to call {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -261 * in order to set custom authenticator. -262 * -263 * @param authenticator Custom authenticator that will be called when proxy asks for authorization. -264 */ -265 public void setProxyAuthenticator(Authenticator authenticator) { -266 this.authenticator = authenticator; -267 buildHttpClients(); -268 } -269 -270 /** -271 * Restores a BoxAPIConnection from a saved state. -272 * -273 * @param clientID the client ID to use with the connection. -274 * @param clientSecret the client secret to use with the connection. -275 * @param state the saved state that was created with {@link #save}. -276 * @return a restored API connection. -277 * @see #save -278 */ -279 public static BoxAPIConnection restore(String clientID, String clientSecret, String state) { -280 BoxAPIConnection api = new BoxAPIConnection(clientID, clientSecret); -281 api.restore(state); -282 return api; -283 } -284 -285 /** -286 * Returns the default authorization URL which is used to perform the authorization_code based OAuth2 flow. -287 * If custom Authorization URL is needed use instance method {@link BoxAPIConnection#getAuthorizationURL} -288 * -289 * @param clientID the client ID to use with the connection. -290 * @param redirectUri the URL to which Box redirects the browser when authentication completes. -291 * @param state the text string that you choose. -292 * Box sends the same string to your redirect URL when authentication is complete. -293 * @param scopes this optional parameter identifies the Box scopes available -294 * to the application once it's authenticated. -295 * @return the authorization URL -296 */ -297 public static URL getAuthorizationURL(String clientID, URI redirectUri, String state, List<String> scopes) { -298 return createFullAuthorizationUrl(DEFAULT_BASE_AUTHORIZATION_URL, clientID, redirectUri, state, scopes); -299 } -300 -301 private static URL createFullAuthorizationUrl( -302 String authorizationUrl, String clientID, URI redirectUri, String state, List<String> scopes -303 ) { -304 URLTemplate template = new URLTemplate(authorizationUrl + OAUTH_SUFFIX); -305 QueryStringBuilder queryBuilder = new QueryStringBuilder().appendParam("client_id", clientID) -306 .appendParam("response_type", "code") -307 .appendParam("redirect_uri", redirectUri.toString()) -308 .appendParam("state", state); -309 -310 if (scopes != null && !scopes.isEmpty()) { -311 queryBuilder.appendParam("scope", join(" ", scopes)); -312 } -313 -314 return template.buildWithQuery("", queryBuilder.toString()); -315 } -316 -317 /** -318 * Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained -319 * from the first half of OAuth. -320 * -321 * @param authCode the auth code obtained from the first half of the OAuth process. -322 */ -323 public void authenticate(String authCode) { -324 URL url; -325 try { -326 url = new URL(this.getTokenURL()); -327 } catch (MalformedURLException e) { -328 assert false : "An invalid token URL indicates a bug in the SDK."; -329 throw new RuntimeException("An invalid token URL indicates a bug in the SDK.", e); -330 } -331 -332 String urlParameters = format("grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s", -333 authCode, this.clientID, this.clientSecret); -334 -335 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -336 request.shouldAuthenticate(false); -337 request.setBody(urlParameters); -338 -339 // authentication uses form url encoded but response is JSON -340 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { -341 String json = response.getJSON(); -342 -343 JsonObject jsonObject = Json.parse(json).asObject(); -344 this.accessToken = jsonObject.get("access_token").asString(); -345 this.refreshToken = jsonObject.get("refresh_token").asString(); -346 this.lastRefresh = System.currentTimeMillis(); -347 this.expires = jsonObject.get("expires_in").asLong() * 1000; -348 } -349 } -350 -351 /** -352 * Gets the client ID. -353 * -354 * @return the client ID. -355 */ -356 public String getClientID() { -357 return this.clientID; -358 } -359 -360 /** -361 * Gets the client secret. -362 * -363 * @return the client secret. -364 */ -365 public String getClientSecret() { -366 return this.clientSecret; -367 } -368 -369 /** -370 * Gets the amount of time for which this connection's access token is valid. -371 * -372 * @return the amount of time in milliseconds. -373 */ -374 public long getExpires() { -375 return this.expires; -376 } -377 -378 /** -379 * Sets the amount of time for which this connection's access token is valid before it must be refreshed. -380 * -381 * @param milliseconds the number of milliseconds for which the access token is valid. -382 */ -383 public void setExpires(long milliseconds) { -384 this.expires = milliseconds; -385 } -386 -387 /** -388 * Gets the token URL that's used to request access tokens. The default value is -389 * "https://www.box.com/api/oauth2/token". -390 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#TOKEN_URL_SUFFIX}. -391 * -392 * @return the token URL. -393 */ -394 public String getTokenURL() { -395 if (this.tokenURL != null) { -396 return this.tokenURL; -397 } else { -398 return this.baseURL + TOKEN_URL_SUFFIX; -399 } -400 } -401 -402 /** -403 * Returns the URL used for token revocation. -404 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#REVOKE_URL_SUFFIX}. -405 * -406 * @return The url used for token revocation. -407 */ -408 public String getRevokeURL() { -409 if (this.revokeURL != null) { -410 return this.revokeURL; -411 } else { -412 return this.baseURL + REVOKE_URL_SUFFIX; -413 } -414 } -415 -416 /** -417 * Gets the base URL that's used when sending requests to the Box API. -418 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#API_VERSION}. -419 * The default value is "https://api.box.com/2.0/". -420 * -421 * @return the base URL. -422 */ -423 public String getBaseURL() { -424 return this.baseURL + API_VERSION + "/"; -425 } -426 -427 /** -428 * Sets the base URL to be used when sending requests to the Box API. For example, the default base URL is -429 * "https://api.box.com/". This method changes how {@link BoxAPIConnection#getRevokeURL()} -430 * and {@link BoxAPIConnection#getTokenURL()} are constructed. -431 * -432 * @param baseURL a base URL -433 */ -434 public void setBaseURL(String baseURL) { -435 this.baseURL = fixBaseUrl(baseURL); -436 } -437 -438 /** -439 * Gets the base upload URL that's used when performing file uploads to Box. -440 * The URL is created from {@link BoxAPIConnection#baseUploadURL} and {@link BoxAPIConnection#API_VERSION}. -441 * -442 * @return the base upload URL. -443 */ -444 public String getBaseUploadURL() { -445 return this.baseUploadURL + API_VERSION + "/"; -446 } -447 -448 /** -449 * Sets the base upload URL to be used when performing file uploads to Box. -450 * -451 * @param baseUploadURL a base upload URL. -452 */ -453 public void setBaseUploadURL(String baseUploadURL) { -454 this.baseUploadURL = fixBaseUrl(baseUploadURL); -455 } -456 -457 /** -458 * Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow. -459 * The URL is created from {@link BoxAPIConnection#baseAuthorizationURL} and {@link BoxAPIConnection#OAUTH_SUFFIX}. -460 * -461 * @param redirectUri the URL to which Box redirects the browser when authentication completes. -462 * @param state the text string that you choose. -463 * Box sends the same string to your redirect URL when authentication is complete. -464 * @param scopes this optional parameter identifies the Box scopes available -465 * to the application once it's authenticated. -466 * @return the authorization URL -467 */ -468 public URL getAuthorizationURL(URI redirectUri, String state, List<String> scopes) { -469 return createFullAuthorizationUrl(this.baseAuthorizationURL, this.clientID, redirectUri, state, scopes); -470 } -471 -472 /** -473 * Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow. -474 * -475 * @param baseAuthorizationURL Authorization URL. Default value is https://account.box.com/api/. -476 */ -477 public void setBaseAuthorizationURL(String baseAuthorizationURL) { -478 this.baseAuthorizationURL = fixBaseUrl(baseAuthorizationURL); -479 } -480 -481 /** -482 * Gets the user agent that's used when sending requests to the Box API. -483 * -484 * @return the user agent. -485 */ -486 public String getUserAgent() { -487 return this.userAgent; -488 } -489 -490 /** -491 * Sets the user agent to be used when sending requests to the Box API. -492 * -493 * @param userAgent the user agent. -494 */ -495 public void setUserAgent(String userAgent) { -496 this.userAgent = userAgent; -497 } -498 -499 /** -500 * Gets the base App url. Used for e.g. file requests. -501 * -502 * @return the base App Url. -503 */ -504 public String getBaseAppUrl() { -505 return this.baseAppURL; -506 } -507 -508 /** -509 * Sets the base App url. Used for e.g. file requests. -510 * -511 * @param baseAppURL a base App Url. -512 */ -513 public void setBaseAppUrl(String baseAppURL) { -514 this.baseAppURL = baseAppURL; -515 } -516 -517 /** -518 * Gets an access token that can be used to authenticate an API request. This method will automatically refresh the -519 * access token if it has expired since the last call to <code>getAccessToken()</code>. -520 * -521 * @return a valid access token that can be used to authenticate an API request. -522 */ -523 public String getAccessToken() { -524 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { -525 this.refreshLock.writeLock().lock(); -526 try { -527 if (this.needsRefresh()) { -528 this.refresh(); -529 } -530 } finally { -531 this.refreshLock.writeLock().unlock(); -532 } -533 } -534 -535 return this.accessToken; -536 } -537 -538 /** -539 * Sets the access token to use when authenticating API requests. -540 * -541 * @param accessToken a valid access token to use when authenticating API requests. -542 */ -543 public void setAccessToken(String accessToken) { -544 this.accessToken = accessToken; -545 } -546 -547 /** -548 * Gets the refresh lock to be used when refreshing an access token. -549 * -550 * @return the refresh lock. -551 */ -552 protected ReadWriteLock getRefreshLock() { -553 return this.refreshLock; -554 } -555 -556 /** -557 * Gets a refresh token that can be used to refresh an access token. -558 * -559 * @return a valid refresh token. -560 */ -561 public String getRefreshToken() { -562 return this.refreshToken; -563 } -564 -565 /** -566 * Sets the refresh token to use when refreshing an access token. -567 * -568 * @param refreshToken a valid refresh token. -569 */ -570 public void setRefreshToken(String refreshToken) { -571 this.refreshToken = refreshToken; -572 } -573 -574 /** -575 * Gets the last time that the access token was refreshed. -576 * -577 * @return the last refresh time in milliseconds. -578 */ -579 public long getLastRefresh() { -580 return this.lastRefresh; -581 } -582 -583 /** -584 * Sets the last time that the access token was refreshed. -585 * -586 * <p>This value is used when determining if an access token needs to be auto-refreshed. If the amount of time since -587 * the last refresh exceeds the access token's expiration time, then the access token will be refreshed.</p> -588 * -589 * @param lastRefresh the new last refresh time in milliseconds. -590 */ -591 public void setLastRefresh(long lastRefresh) { -592 this.lastRefresh = lastRefresh; -593 } -594 -595 /** -596 * Gets whether or not automatic refreshing of this connection's access token is enabled. Defaults to true. -597 * -598 * @return true if auto token refresh is enabled; otherwise false. -599 */ -600 public boolean getAutoRefresh() { -601 return this.autoRefresh; -602 } -603 -604 /** -605 * Enables or disables automatic refreshing of this connection's access token. Defaults to true. -606 * -607 * @param autoRefresh true to enable auto token refresh; otherwise false. -608 */ -609 public void setAutoRefresh(boolean autoRefresh) { -610 this.autoRefresh = autoRefresh; -611 } -612 +032import okhttp3.Call; +033import okhttp3.Credentials; +034import okhttp3.OkHttpClient; +035import okhttp3.Request; +036import okhttp3.Response; +037 +038/** +039 * Represents an authenticated connection to the Box API. +040 * +041 * <p>This class handles storing authentication information, automatic token refresh, and rate-limiting. It can also be +042 * used to configure the Box API endpoint URL in order to hit a different version of the API. Multiple instances of +043 * BoxAPIConnection may be created to support multi-user login.</p> +044 */ +045public class BoxAPIConnection { +046 +047 /** +048 * Used as a marker to setup connection to use default HostnameVerifier +049 * Example:<pre>{@code +050 * BoxApiConnection api = new BoxApiConnection(...); +051 * HostnameVerifier myHostnameVerifier = ... +052 * api.configureSslCertificatesValidation(DEFAULT_TRUST_MANAGER, myHostnameVerifier); +053 * }</pre> +054 */ +055 public static final X509TrustManager DEFAULT_TRUST_MANAGER = null; +056 /** +057 * Used as a marker to setup connection to use default HostnameVerifier +058 * Example:<pre>{@code +059 * BoxApiConnection api = new BoxApiConnection(...); +060 * X509TrustManager myTrustManager = ... +061 * api.configureSslCertificatesValidation(myTrustManager, DEFAULT_HOSTNAME_VERIFIER); +062 * }</pre> +063 */ +064 public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = null; +065 +066 /** +067 * The default maximum number of times an API request will be retried after an error response +068 * is received. +069 */ +070 public static final int DEFAULT_MAX_RETRIES = 5; +071 /** +072 * Default authorization URL +073 */ +074 protected static final String DEFAULT_BASE_AUTHORIZATION_URL = "https://account.box.com/api/"; +075 static final String AS_USER_HEADER = "As-User"; +076 +077 private static final String API_VERSION = "2.0"; +078 private static final String OAUTH_SUFFIX = "oauth2/authorize"; +079 private static final String TOKEN_URL_SUFFIX = "oauth2/token"; +080 private static final String REVOKE_URL_SUFFIX = "oauth2/revoke"; +081 private static final String DEFAULT_BASE_URL = "https://api.box.com/"; +082 private static final String DEFAULT_BASE_UPLOAD_URL = "https://upload.box.com/api/"; +083 private static final String DEFAULT_BASE_APP_URL = "https://app.box.com"; +084 +085 private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications"; +086 +087 private static final String JAVA_VERSION = System.getProperty("java.version"); +088 private static final String SDK_VERSION = "4.11.0"; +089 +090 /** +091 * The amount of buffer time, in milliseconds, to use when determining if an access token should be refreshed. For +092 * example, if REFRESH_EPSILON = 60000 and the access token expires in less than one minute, it will be refreshed. +093 */ +094 private static final long REFRESH_EPSILON = 60000; +095 +096 private final String clientID; +097 private final String clientSecret; +098 private final ReadWriteLock refreshLock; +099 private X509TrustManager trustManager; +100 private HostnameVerifier hostnameVerifier; +101 +102 // These volatile fields are used when determining if the access token needs to be refreshed. Since they are used in +103 // the double-checked lock in getAccessToken(), they must be atomic. +104 private volatile long lastRefresh; +105 private volatile long expires; +106 +107 private Proxy proxy; +108 private String proxyUsername; +109 private String proxyPassword; +110 +111 private String userAgent; +112 private String accessToken; +113 private String refreshToken; +114 private String tokenURL; +115 private String revokeURL; +116 private String baseURL; +117 private String baseUploadURL; +118 private String baseAppURL; +119 private String baseAuthorizationURL; +120 private boolean autoRefresh; +121 private int maxRetryAttempts; +122 private int connectTimeout; +123 private int readTimeout; +124 private final List<BoxAPIConnectionListener> listeners; +125 private RequestInterceptor interceptor; +126 private final Map<String, String> customHeaders; +127 +128 private OkHttpClient httpClient; +129 private OkHttpClient noRedirectsHttpClient; +130 private Authenticator authenticator; +131 +132 /** +133 * Constructs a new BoxAPIConnection that authenticates with a developer or access token. +134 * +135 * @param accessToken a developer or access token to use for authenticating with the API. +136 */ +137 public BoxAPIConnection(String accessToken) { +138 this(null, null, accessToken, null); +139 } +140 +141 /** +142 * Constructs a new BoxAPIConnection with an access token that can be refreshed. +143 * +144 * @param clientID the client ID to use when refreshing the access token. +145 * @param clientSecret the client secret to use when refreshing the access token. +146 * @param accessToken an initial access token to use for authenticating with the API. +147 * @param refreshToken an initial refresh token to use when refreshing the access token. +148 */ +149 public BoxAPIConnection(String clientID, String clientSecret, String accessToken, String refreshToken) { +150 this.clientID = clientID; +151 this.clientSecret = clientSecret; +152 this.accessToken = accessToken; +153 this.refreshToken = refreshToken; +154 this.baseURL = fixBaseUrl(DEFAULT_BASE_URL); +155 this.baseUploadURL = fixBaseUrl(DEFAULT_BASE_UPLOAD_URL); +156 this.baseAppURL = DEFAULT_BASE_APP_URL; +157 this.baseAuthorizationURL = DEFAULT_BASE_AUTHORIZATION_URL; +158 this.autoRefresh = true; +159 this.maxRetryAttempts = BoxGlobalSettings.getMaxRetryAttempts(); +160 this.connectTimeout = BoxGlobalSettings.getConnectTimeout(); +161 this.readTimeout = BoxGlobalSettings.getReadTimeout(); +162 this.refreshLock = new ReentrantReadWriteLock(); +163 this.userAgent = "Box Java SDK v" + SDK_VERSION + " (Java " + JAVA_VERSION + ")"; +164 this.listeners = new ArrayList<>(); +165 this.customHeaders = new HashMap<>(); +166 +167 buildHttpClients(); +168 } +169 +170 /** +171 * Constructs a new BoxAPIConnection with an auth code that was obtained from the first half of OAuth. +172 * +173 * @param clientID the client ID to use when exchanging the auth code for an access token. +174 * @param clientSecret the client secret to use when exchanging the auth code for an access token. +175 * @param authCode an auth code obtained from the first half of the OAuth process. +176 */ +177 public BoxAPIConnection(String clientID, String clientSecret, String authCode) { +178 this(clientID, clientSecret, null, null); +179 this.authenticate(authCode); +180 } +181 +182 /** +183 * Constructs a new BoxAPIConnection. +184 * +185 * @param clientID the client ID to use when exchanging the auth code for an access token. +186 * @param clientSecret the client secret to use when exchanging the auth code for an access token. +187 */ +188 public BoxAPIConnection(String clientID, String clientSecret) { +189 this(clientID, clientSecret, null, null); +190 } +191 +192 /** +193 * Constructs a new BoxAPIConnection levaraging BoxConfig. +194 * +195 * @param boxConfig BoxConfig file, which should have clientId and clientSecret +196 */ +197 public BoxAPIConnection(BoxConfig boxConfig) { +198 this(boxConfig.getClientId(), boxConfig.getClientSecret(), null, null); +199 } +200 +201 private void buildHttpClients() { +202 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); +203 if (trustManager != null) { +204 try { +205 SSLContext sslContext = SSLContext.getInstance("SSL"); +206 sslContext.init(null, new TrustManager[]{trustManager}, new java.security.SecureRandom()); +207 httpClientBuilder.sslSocketFactory(sslContext.getSocketFactory(), trustManager); +208 } catch (NoSuchAlgorithmException | KeyManagementException e) { +209 throw new RuntimeException(e); +210 } +211 } +212 +213 OkHttpClient.Builder builder = httpClientBuilder +214 .followSslRedirects(true) +215 .followRedirects(true) +216 .connectTimeout(Duration.ofMillis(connectTimeout)) +217 .readTimeout(Duration.ofMillis(readTimeout)) +218 .connectionSpecs(singletonList(MODERN_TLS)); +219 +220 if (hostnameVerifier != null) { +221 httpClientBuilder.hostnameVerifier(hostnameVerifier); +222 } +223 +224 if (proxy != null) { +225 builder.proxy(proxy); +226 if (proxyUsername != null && proxyPassword != null) { +227 builder.proxyAuthenticator((route, response) -> { +228 String credential = Credentials.basic(proxyUsername, proxyPassword); +229 return response.request().newBuilder() +230 .header("Proxy-Authorization", credential) +231 .build(); +232 }); +233 } +234 if (this.authenticator != null) { +235 builder.proxyAuthenticator(authenticator); +236 } +237 } +238 builder = modifyHttpClientBuilder(builder); +239 +240 this.httpClient = builder.build(); +241 this.noRedirectsHttpClient = new OkHttpClient.Builder(httpClient) +242 .followSslRedirects(false) +243 .followRedirects(false) +244 .build(); +245 } +246 +247 /** +248 * Can be used to modify OkHttp.Builder used to create connection. This method is called after all modifications +249 * were done, thus allowing others to create their own connections and further customize builder. +250 * @param httpClientBuilder Builder that will be used to create http connection. +251 * @return Modified builder. +252 */ +253 protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder) { +254 return httpClientBuilder; +255 } +256 +257 /** +258 * Sets a proxy authenticator that will be used when proxy requires authentication. +259 * If you use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} it adds an authenticator +260 * that performs Basic authorization. By calling this method you can override this behaviour. +261 * You do not need to call {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +262 * in order to set custom authenticator. +263 * +264 * @param authenticator Custom authenticator that will be called when proxy asks for authorization. +265 */ +266 public void setProxyAuthenticator(Authenticator authenticator) { +267 this.authenticator = authenticator; +268 buildHttpClients(); +269 } +270 +271 /** +272 * Restores a BoxAPIConnection from a saved state. +273 * +274 * @param clientID the client ID to use with the connection. +275 * @param clientSecret the client secret to use with the connection. +276 * @param state the saved state that was created with {@link #save}. +277 * @return a restored API connection. +278 * @see #save +279 */ +280 public static BoxAPIConnection restore(String clientID, String clientSecret, String state) { +281 BoxAPIConnection api = new BoxAPIConnection(clientID, clientSecret); +282 api.restore(state); +283 return api; +284 } +285 +286 /** +287 * Returns the default authorization URL which is used to perform the authorization_code based OAuth2 flow. +288 * If custom Authorization URL is needed use instance method {@link BoxAPIConnection#getAuthorizationURL} +289 * +290 * @param clientID the client ID to use with the connection. +291 * @param redirectUri the URL to which Box redirects the browser when authentication completes. +292 * @param state the text string that you choose. +293 * Box sends the same string to your redirect URL when authentication is complete. +294 * @param scopes this optional parameter identifies the Box scopes available +295 * to the application once it's authenticated. +296 * @return the authorization URL +297 */ +298 public static URL getAuthorizationURL(String clientID, URI redirectUri, String state, List<String> scopes) { +299 return createFullAuthorizationUrl(DEFAULT_BASE_AUTHORIZATION_URL, clientID, redirectUri, state, scopes); +300 } +301 +302 private static URL createFullAuthorizationUrl( +303 String authorizationUrl, String clientID, URI redirectUri, String state, List<String> scopes +304 ) { +305 URLTemplate template = new URLTemplate(authorizationUrl + OAUTH_SUFFIX); +306 QueryStringBuilder queryBuilder = new QueryStringBuilder().appendParam("client_id", clientID) +307 .appendParam("response_type", "code") +308 .appendParam("redirect_uri", redirectUri.toString()) +309 .appendParam("state", state); +310 +311 if (scopes != null && !scopes.isEmpty()) { +312 queryBuilder.appendParam("scope", join(" ", scopes)); +313 } +314 +315 return template.buildWithQuery("", queryBuilder.toString()); +316 } +317 +318 /** +319 * Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained +320 * from the first half of OAuth. +321 * +322 * @param authCode the auth code obtained from the first half of the OAuth process. +323 */ +324 public void authenticate(String authCode) { +325 URL url; +326 try { +327 url = new URL(this.getTokenURL()); +328 } catch (MalformedURLException e) { +329 assert false : "An invalid token URL indicates a bug in the SDK."; +330 throw new RuntimeException("An invalid token URL indicates a bug in the SDK.", e); +331 } +332 +333 String urlParameters = format("grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s", +334 authCode, this.clientID, this.clientSecret); +335 +336 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +337 request.shouldAuthenticate(false); +338 request.setBody(urlParameters); +339 +340 // authentication uses form url encoded but response is JSON +341 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { +342 String json = response.getJSON(); +343 +344 JsonObject jsonObject = Json.parse(json).asObject(); +345 this.accessToken = jsonObject.get("access_token").asString(); +346 this.refreshToken = jsonObject.get("refresh_token").asString(); +347 this.lastRefresh = System.currentTimeMillis(); +348 this.expires = jsonObject.get("expires_in").asLong() * 1000; +349 } +350 } +351 +352 /** +353 * Gets the client ID. +354 * +355 * @return the client ID. +356 */ +357 public String getClientID() { +358 return this.clientID; +359 } +360 +361 /** +362 * Gets the client secret. +363 * +364 * @return the client secret. +365 */ +366 public String getClientSecret() { +367 return this.clientSecret; +368 } +369 +370 /** +371 * Gets the amount of time for which this connection's access token is valid. +372 * +373 * @return the amount of time in milliseconds. +374 */ +375 public long getExpires() { +376 return this.expires; +377 } +378 +379 /** +380 * Sets the amount of time for which this connection's access token is valid before it must be refreshed. +381 * +382 * @param milliseconds the number of milliseconds for which the access token is valid. +383 */ +384 public void setExpires(long milliseconds) { +385 this.expires = milliseconds; +386 } +387 +388 /** +389 * Gets the token URL that's used to request access tokens. The default value is +390 * "https://www.box.com/api/oauth2/token". +391 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#TOKEN_URL_SUFFIX}. +392 * +393 * @return the token URL. +394 */ +395 public String getTokenURL() { +396 if (this.tokenURL != null) { +397 return this.tokenURL; +398 } else { +399 return this.baseURL + TOKEN_URL_SUFFIX; +400 } +401 } +402 +403 /** +404 * Returns the URL used for token revocation. +405 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#REVOKE_URL_SUFFIX}. +406 * +407 * @return The url used for token revocation. +408 */ +409 public String getRevokeURL() { +410 if (this.revokeURL != null) { +411 return this.revokeURL; +412 } else { +413 return this.baseURL + REVOKE_URL_SUFFIX; +414 } +415 } +416 +417 /** +418 * Gets the base URL that's used when sending requests to the Box API. +419 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#API_VERSION}. +420 * The default value is "https://api.box.com/2.0/". +421 * +422 * @return the base URL. +423 */ +424 public String getBaseURL() { +425 return this.baseURL + API_VERSION + "/"; +426 } +427 +428 /** +429 * Sets the base URL to be used when sending requests to the Box API. For example, the default base URL is +430 * "https://api.box.com/". This method changes how {@link BoxAPIConnection#getRevokeURL()} +431 * and {@link BoxAPIConnection#getTokenURL()} are constructed. +432 * +433 * @param baseURL a base URL +434 */ +435 public void setBaseURL(String baseURL) { +436 this.baseURL = fixBaseUrl(baseURL); +437 } +438 +439 /** +440 * Gets the base upload URL that's used when performing file uploads to Box. +441 * The URL is created from {@link BoxAPIConnection#baseUploadURL} and {@link BoxAPIConnection#API_VERSION}. +442 * +443 * @return the base upload URL. +444 */ +445 public String getBaseUploadURL() { +446 return this.baseUploadURL + API_VERSION + "/"; +447 } +448 +449 /** +450 * Sets the base upload URL to be used when performing file uploads to Box. +451 * +452 * @param baseUploadURL a base upload URL. +453 */ +454 public void setBaseUploadURL(String baseUploadURL) { +455 this.baseUploadURL = fixBaseUrl(baseUploadURL); +456 } +457 +458 /** +459 * Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow. +460 * The URL is created from {@link BoxAPIConnection#baseAuthorizationURL} and {@link BoxAPIConnection#OAUTH_SUFFIX}. +461 * +462 * @param redirectUri the URL to which Box redirects the browser when authentication completes. +463 * @param state the text string that you choose. +464 * Box sends the same string to your redirect URL when authentication is complete. +465 * @param scopes this optional parameter identifies the Box scopes available +466 * to the application once it's authenticated. +467 * @return the authorization URL +468 */ +469 public URL getAuthorizationURL(URI redirectUri, String state, List<String> scopes) { +470 return createFullAuthorizationUrl(this.baseAuthorizationURL, this.clientID, redirectUri, state, scopes); +471 } +472 +473 /** +474 * Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow. +475 * +476 * @param baseAuthorizationURL Authorization URL. Default value is https://account.box.com/api/. +477 */ +478 public void setBaseAuthorizationURL(String baseAuthorizationURL) { +479 this.baseAuthorizationURL = fixBaseUrl(baseAuthorizationURL); +480 } +481 +482 /** +483 * Gets the user agent that's used when sending requests to the Box API. +484 * +485 * @return the user agent. +486 */ +487 public String getUserAgent() { +488 return this.userAgent; +489 } +490 +491 /** +492 * Sets the user agent to be used when sending requests to the Box API. +493 * +494 * @param userAgent the user agent. +495 */ +496 public void setUserAgent(String userAgent) { +497 this.userAgent = userAgent; +498 } +499 +500 /** +501 * Gets the base App url. Used for e.g. file requests. +502 * +503 * @return the base App Url. +504 */ +505 public String getBaseAppUrl() { +506 return this.baseAppURL; +507 } +508 +509 /** +510 * Sets the base App url. Used for e.g. file requests. +511 * +512 * @param baseAppURL a base App Url. +513 */ +514 public void setBaseAppUrl(String baseAppURL) { +515 this.baseAppURL = baseAppURL; +516 } +517 +518 /** +519 * Gets an access token that can be used to authenticate an API request. This method will automatically refresh the +520 * access token if it has expired since the last call to <code>getAccessToken()</code>. +521 * +522 * @return a valid access token that can be used to authenticate an API request. +523 */ +524 public String getAccessToken() { +525 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { +526 this.refreshLock.writeLock().lock(); +527 try { +528 if (this.needsRefresh()) { +529 this.refresh(); +530 } +531 } finally { +532 this.refreshLock.writeLock().unlock(); +533 } +534 } +535 +536 return this.accessToken; +537 } +538 +539 /** +540 * Sets the access token to use when authenticating API requests. +541 * +542 * @param accessToken a valid access token to use when authenticating API requests. +543 */ +544 public void setAccessToken(String accessToken) { +545 this.accessToken = accessToken; +546 } +547 +548 /** +549 * Gets the refresh lock to be used when refreshing an access token. +550 * +551 * @return the refresh lock. +552 */ +553 protected ReadWriteLock getRefreshLock() { +554 return this.refreshLock; +555 } +556 +557 /** +558 * Gets a refresh token that can be used to refresh an access token. +559 * +560 * @return a valid refresh token. +561 */ +562 public String getRefreshToken() { +563 return this.refreshToken; +564 } +565 +566 /** +567 * Sets the refresh token to use when refreshing an access token. +568 * +569 * @param refreshToken a valid refresh token. +570 */ +571 public void setRefreshToken(String refreshToken) { +572 this.refreshToken = refreshToken; +573 } +574 +575 /** +576 * Gets the last time that the access token was refreshed. +577 * +578 * @return the last refresh time in milliseconds. +579 */ +580 public long getLastRefresh() { +581 return this.lastRefresh; +582 } +583 +584 /** +585 * Sets the last time that the access token was refreshed. +586 * +587 * <p>This value is used when determining if an access token needs to be auto-refreshed. If the amount of time since +588 * the last refresh exceeds the access token's expiration time, then the access token will be refreshed.</p> +589 * +590 * @param lastRefresh the new last refresh time in milliseconds. +591 */ +592 public void setLastRefresh(long lastRefresh) { +593 this.lastRefresh = lastRefresh; +594 } +595 +596 /** +597 * Gets whether or not automatic refreshing of this connection's access token is enabled. Defaults to true. +598 * +599 * @return true if auto token refresh is enabled; otherwise false. +600 */ +601 public boolean getAutoRefresh() { +602 return this.autoRefresh; +603 } +604 +605 /** +606 * Enables or disables automatic refreshing of this connection's access token. Defaults to true. +607 * +608 * @param autoRefresh true to enable auto token refresh; otherwise false. +609 */ +610 public void setAutoRefresh(boolean autoRefresh) { +611 this.autoRefresh = autoRefresh; +612 }613 -614 /** -615 * Gets the maximum number of times an API request will be retried after an error response -616 * is received. -617 * -618 * @return the maximum number of request attempts. -619 */ -620 public int getMaxRetryAttempts() { -621 return this.maxRetryAttempts; -622 } -623 -624 /** -625 * Sets the maximum number of times an API request will be retried after an error response -626 * is received. -627 * -628 * @param attempts the maximum number of request attempts. -629 */ -630 public void setMaxRetryAttempts(int attempts) { -631 this.maxRetryAttempts = attempts; -632 } -633 -634 /** -635 * Gets the connect timeout for this connection in milliseconds. -636 * -637 * @return the number of milliseconds to connect before timing out. -638 */ -639 public int getConnectTimeout() { -640 return this.connectTimeout; -641 } -642 -643 /** -644 * Sets the connect timeout for this connection. -645 * -646 * @param connectTimeout The number of milliseconds to wait for the connection to be established. -647 */ -648 public void setConnectTimeout(int connectTimeout) { -649 this.connectTimeout = connectTimeout; -650 buildHttpClients(); -651 } -652 -653 /** -654 * Gets the read timeout for this connection in milliseconds. -655 * -656 * @return the number of milliseconds to wait for bytes to be read before timing out. -657 */ -658 public int getReadTimeout() { -659 return this.readTimeout; -660 } -661 -662 /** -663 * Sets the read timeout for this connection. -664 * -665 * @param readTimeout The number of milliseconds to wait for bytes to be read. -666 */ -667 public void setReadTimeout(int readTimeout) { -668 this.readTimeout = readTimeout; -669 buildHttpClients(); -670 } -671 -672 /** -673 * Gets the proxy value to use for API calls to Box. -674 * -675 * @return the current proxy. -676 */ -677 public Proxy getProxy() { -678 return this.proxy; -679 } -680 -681 /** -682 * Sets the proxy to use for API calls to Box. -683 * -684 * @param proxy the proxy to use for API calls to Box. -685 */ -686 public void setProxy(Proxy proxy) { -687 this.proxy = proxy; -688 buildHttpClients(); -689 } -690 -691 /** -692 * Gets the username to use for a proxy that requires basic auth. -693 * -694 * @return the username to use for a proxy that requires basic auth. -695 */ -696 public String getProxyUsername() { -697 return this.proxyUsername; -698 } -699 -700 /** -701 * Sets the username to use for a proxy that requires basic auth. -702 * -703 * @param proxyUsername the username to use for a proxy that requires basic auth. -704 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -705 */ -706 public void setProxyUsername(String proxyUsername) { -707 this.proxyUsername = proxyUsername; -708 buildHttpClients(); -709 } -710 -711 /** -712 * Gets the password to use for a proxy that requires basic auth. -713 * -714 * @return the password to use for a proxy that requires basic auth. -715 */ -716 public String getProxyPassword() { -717 return this.proxyPassword; -718 } -719 -720 /** -721 * Sets the proxy user and password used in basic authentication -722 * -723 * @param proxyUsername Username to use for a proxy that requires basic auth. -724 * @param proxyPassword Password to use for a proxy that requires basic auth. -725 */ -726 public void setProxyBasicAuthentication(String proxyUsername, String proxyPassword) { -727 this.proxyUsername = proxyUsername; -728 this.proxyPassword = proxyPassword; -729 buildHttpClients(); -730 } -731 -732 /** -733 * Sets the password to use for a proxy that requires basic auth. -734 * -735 * @param proxyPassword the password to use for a proxy that requires basic auth. -736 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -737 */ -738 public void setProxyPassword(String proxyPassword) { -739 this.proxyPassword = proxyPassword; -740 buildHttpClients(); -741 } -742 -743 /** -744 * Determines if this connection's access token can be refreshed. An access token cannot be refreshed if a refresh -745 * token was never set. -746 * -747 * @return true if the access token can be refreshed; otherwise false. -748 */ -749 public boolean canRefresh() { -750 return this.refreshToken != null; -751 } -752 -753 /** -754 * Determines if this connection's access token has expired and needs to be refreshed. -755 * -756 * @return true if the access token needs to be refreshed; otherwise false. -757 */ -758 public boolean needsRefresh() { -759 boolean needsRefresh; -760 -761 this.refreshLock.readLock().lock(); -762 long now = System.currentTimeMillis(); -763 long tokenDuration = (now - this.lastRefresh); -764 needsRefresh = (tokenDuration >= this.expires - REFRESH_EPSILON); -765 this.refreshLock.readLock().unlock(); -766 -767 return needsRefresh; -768 } -769 -770 /** -771 * Refresh's this connection's access token using its refresh token. -772 * -773 * @throws IllegalStateException if this connection's access token cannot be refreshed. -774 */ -775 public void refresh() { -776 this.refreshLock.writeLock().lock(); -777 -778 if (!this.canRefresh()) { -779 this.refreshLock.writeLock().unlock(); -780 throw new IllegalStateException("The BoxAPIConnection cannot be refreshed because it doesn't have a " -781 + "refresh token."); -782 } -783 -784 URL url; -785 try { -786 url = new URL(getTokenURL()); -787 } catch (MalformedURLException e) { -788 this.refreshLock.writeLock().unlock(); -789 assert false : "An invalid refresh URL indicates a bug in the SDK."; -790 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); -791 } -792 -793 BoxAPIRequest request = createTokenRequest(url); -794 -795 String json; -796 try (BoxAPIResponse boxAPIResponse = request.send()) { -797 BoxJSONResponse response = (BoxJSONResponse) boxAPIResponse; -798 json = response.getJSON(); -799 } catch (BoxAPIException e) { -800 this.refreshLock.writeLock().unlock(); -801 this.notifyError(e); -802 throw e; -803 } -804 -805 try { -806 extractTokens(Json.parse(json).asObject()); -807 -808 this.notifyRefresh(); -809 } finally { -810 this.refreshLock.writeLock().unlock(); -811 } -812 } -813 -814 /** -815 * Restores a saved connection state into this BoxAPIConnection. -816 * -817 * @param state the saved state that was created with {@link #save}. -818 * @see #save -819 */ -820 public void restore(String state) { -821 JsonObject json = Json.parse(state).asObject(); -822 String accessToken = json.get("accessToken").asString(); -823 String refreshToken = getKeyValueOrDefault(json, "refreshToken", null); -824 long lastRefresh = json.get("lastRefresh").asLong(); -825 long expires = json.get("expires").asLong(); -826 String userAgent = json.get("userAgent").asString(); -827 String tokenURL = getKeyValueOrDefault(json, "tokenURL", null); -828 String revokeURL = getKeyValueOrDefault(json, "revokeURL", null); -829 String baseURL = adoptBaseUrlWhenLoadingFromOldVersion( -830 getKeyValueOrDefault(json, "baseURL", DEFAULT_BASE_URL) -831 ); -832 String baseUploadURL = adoptUploadBaseUrlWhenLoadingFromOldVersion( -833 getKeyValueOrDefault(json, "baseUploadURL", DEFAULT_BASE_UPLOAD_URL) -834 ); -835 String authorizationURL = -836 getKeyValueOrDefault(json, "authorizationURL", DEFAULT_BASE_AUTHORIZATION_URL); -837 boolean autoRefresh = json.get("autoRefresh").asBoolean(); -838 -839 // Try to read deprecated value -840 int maxRequestAttempts = -1; -841 if (json.names().contains("maxRequestAttempts")) { -842 maxRequestAttempts = json.get("maxRequestAttempts").asInt(); -843 } -844 -845 int maxRetryAttempts = -1; -846 if (json.names().contains("maxRetryAttempts")) { -847 maxRetryAttempts = json.get("maxRetryAttempts").asInt(); -848 } -849 -850 this.accessToken = accessToken; -851 this.refreshToken = refreshToken; -852 this.lastRefresh = lastRefresh; -853 this.expires = expires; -854 this.userAgent = userAgent; -855 this.tokenURL = tokenURL; -856 this.revokeURL = revokeURL; -857 this.setBaseURL(baseURL); -858 this.setBaseUploadURL(baseUploadURL); -859 this.setBaseAuthorizationURL(authorizationURL); -860 this.autoRefresh = autoRefresh; -861 -862 // Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts" -863 if (maxRequestAttempts > -1) { -864 this.maxRetryAttempts = maxRequestAttempts - 1; -865 } -866 if (maxRetryAttempts > -1) { -867 this.maxRetryAttempts = maxRetryAttempts; -868 } -869 -870 } -871 -872 private String adoptBaseUrlWhenLoadingFromOldVersion(String url) { -873 if (url == null) { -874 return null; -875 } -876 String urlEndingWithSlash = fixBaseUrl(url); -877 return urlEndingWithSlash.equals("https://api.box.com/2.0/") -878 ? DEFAULT_BASE_URL -879 : urlEndingWithSlash; -880 } -881 -882 private String adoptUploadBaseUrlWhenLoadingFromOldVersion(String url) { -883 if (url == null) { -884 return null; -885 } -886 String urlEndingWithSlash = fixBaseUrl(url); -887 return urlEndingWithSlash.equals("https://upload.box.com/api/2.0/") -888 ? DEFAULT_BASE_UPLOAD_URL -889 : urlEndingWithSlash; -890 } -891 -892 protected String getKeyValueOrDefault(JsonObject json, String key, String defaultValue) { -893 return Optional.ofNullable(json.get(key)) -894 .filter(js -> !js.isNull()) -895 .map(JsonValue::asString) -896 .orElse(defaultValue); -897 } -898 -899 /** -900 * Notifies a refresh event to all the listeners. -901 */ -902 protected void notifyRefresh() { -903 for (BoxAPIConnectionListener listener : this.listeners) { -904 listener.onRefresh(this); -905 } -906 } -907 -908 /** -909 * Notifies an error event to all the listeners. -910 * -911 * @param error A BoxAPIException instance. -912 */ -913 protected void notifyError(BoxAPIException error) { -914 for (BoxAPIConnectionListener listener : this.listeners) { -915 listener.onError(this, error); -916 } -917 } -918 -919 /** -920 * Add a listener to listen to Box API connection events. -921 * -922 * @param listener a listener to listen to Box API connection. -923 */ -924 public void addListener(BoxAPIConnectionListener listener) { -925 this.listeners.add(listener); -926 } -927 -928 /** -929 * Remove a listener listening to Box API connection events. -930 * -931 * @param listener the listener to remove. -932 */ -933 public void removeListener(BoxAPIConnectionListener listener) { -934 this.listeners.remove(listener); -935 } -936 -937 /** -938 * Gets the RequestInterceptor associated with this API connection. -939 * -940 * @return the RequestInterceptor associated with this API connection. -941 */ -942 public RequestInterceptor getRequestInterceptor() { -943 return this.interceptor; -944 } -945 -946 /** -947 * Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API. -948 * -949 * @param interceptor the RequestInterceptor. -950 */ -951 public void setRequestInterceptor(RequestInterceptor interceptor) { -952 this.interceptor = interceptor; -953 } -954 -955 /** -956 * Get a lower-scoped token restricted to a resource for the list of scopes that are passed. -957 * -958 * @param scopes the list of scopes to which the new token should be restricted for -959 * @param resource the resource for which the new token has to be obtained -960 * @return scopedToken which has access token and other details -961 * @throws BoxAPIException if resource is not a valid Box API endpoint or shared link -962 */ -963 public ScopedToken getLowerScopedToken(List<String> scopes, String resource) { -964 assert (scopes != null); -965 assert (scopes.size() > 0); -966 URL url; -967 try { -968 url = new URL(this.getTokenURL()); -969 } catch (MalformedURLException e) { -970 assert false : "An invalid refresh URL indicates a bug in the SDK."; -971 throw new BoxAPIException("An invalid refresh URL indicates a bug in the SDK.", e); -972 } -973 -974 StringBuilder spaceSeparatedScopes = this.buildScopesForTokenDownscoping(scopes); -975 -976 String urlParameters = format("grant_type=urn:ietf:params:oauth:grant-type:token-exchange" -977 + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" -978 + "&scope=%s", -979 this.getAccessToken(), spaceSeparatedScopes); -980 -981 if (resource != null) { -982 -983 ResourceLinkType resourceType = this.determineResourceLinkType(resource); -984 -985 if (resourceType == ResourceLinkType.APIEndpoint) { -986 urlParameters = format(urlParameters + "&resource=%s", resource); -987 } else if (resourceType == ResourceLinkType.SharedLink) { -988 urlParameters = format(urlParameters + "&box_shared_link=%s", resource); -989 } else if (resourceType == ResourceLinkType.Unknown) { -990 String argExceptionMessage = format("Unable to determine resource type: %s", resource); -991 BoxAPIException e = new BoxAPIException(argExceptionMessage); -992 this.notifyError(e); -993 throw e; -994 } else { -995 String argExceptionMessage = format("Unhandled resource type: %s", resource); -996 BoxAPIException e = new BoxAPIException(argExceptionMessage); -997 this.notifyError(e); -998 throw e; -999 } -1000 } -1001 -1002 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1003 request.shouldAuthenticate(false); -1004 request.setBody(urlParameters); -1005 -1006 String jsonResponse; -1007 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { -1008 jsonResponse = response.getJSON(); -1009 } catch (BoxAPIException e) { -1010 this.notifyError(e); -1011 throw e; -1012 } -1013 -1014 JsonObject jsonObject = Json.parse(jsonResponse).asObject(); -1015 ScopedToken token = new ScopedToken(jsonObject); -1016 token.setObtainedAt(System.currentTimeMillis()); -1017 token.setExpiresIn(jsonObject.get("expires_in").asLong() * 1000); -1018 return token; -1019 } -1020 -1021 /** -1022 * Convert List<String> to space-delimited String. -1023 * Needed for versions prior to Java 8, which don't have String.join(delimiter, list) -1024 * -1025 * @param scopes the list of scopes to read from -1026 * @return space-delimited String of scopes -1027 */ -1028 private StringBuilder buildScopesForTokenDownscoping(List<String> scopes) { -1029 StringBuilder spaceSeparatedScopes = new StringBuilder(); -1030 for (int i = 0; i < scopes.size(); i++) { -1031 spaceSeparatedScopes.append(scopes.get(i)); -1032 if (i < scopes.size() - 1) { -1033 spaceSeparatedScopes.append(" "); -1034 } -1035 } -1036 -1037 return spaceSeparatedScopes; -1038 } -1039 -1040 /** -1041 * Determines the type of resource, given a link to a Box resource. -1042 * -1043 * @param resourceLink the resource URL to check -1044 * @return ResourceLinkType that categorizes the provided resourceLink -1045 */ -1046 protected ResourceLinkType determineResourceLinkType(String resourceLink) { -1047 -1048 ResourceLinkType resourceType = ResourceLinkType.Unknown; -1049 -1050 try { -1051 URL validUrl = new URL(resourceLink); -1052 String validURLStr = validUrl.toString(); -1053 final String apiFilesEndpointPattern = ".*box.com/2.0/files/\\d+"; -1054 final String apiFoldersEndpointPattern = ".*box.com/2.0/folders/\\d+"; -1055 final String sharedLinkPattern = "(.*box.com/s/.*|.*box.com.*s=.*)"; -1056 -1057 if (Pattern.matches(apiFilesEndpointPattern, validURLStr) -1058 || Pattern.matches(apiFoldersEndpointPattern, validURLStr)) { -1059 resourceType = ResourceLinkType.APIEndpoint; -1060 } else if (Pattern.matches(sharedLinkPattern, validURLStr)) { -1061 resourceType = ResourceLinkType.SharedLink; -1062 } -1063 } catch (MalformedURLException e) { -1064 //Swallow exception and return default ResourceLinkType set at top of function -1065 } -1066 -1067 return resourceType; -1068 } -1069 -1070 /** -1071 * Revokes the tokens associated with this API connection. This results in the connection no -1072 * longer being able to make API calls until a fresh authorization is made by calling authenticate() -1073 */ -1074 public void revokeToken() { -1075 -1076 URL url; -1077 try { -1078 url = new URL(getRevokeURL()); -1079 } catch (MalformedURLException e) { -1080 assert false : "An invalid refresh URL indicates a bug in the SDK."; -1081 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); -1082 } -1083 -1084 String urlParameters = format("token=%s&client_id=%s&client_secret=%s", -1085 this.accessToken, this.clientID, this.clientSecret); -1086 -1087 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1088 request.shouldAuthenticate(false); -1089 request.setBody(urlParameters); -1090 -1091 request.send().close(); -1092 } -1093 -1094 /** -1095 * Saves the state of this connection to a string so that it can be persisted and restored at a later time. -1096 * -1097 * <p>Note that proxy settings aren't automatically saved or restored. This is mainly due to security concerns -1098 * around persisting proxy authentication details to the state string. If your connection uses a proxy, you will -1099 * have to manually configure it again after restoring the connection.</p> -1100 * -1101 * @return the state of this connection. -1102 * @see #restore -1103 */ -1104 public String save() { -1105 JsonObject state = new JsonObject() -1106 .add("accessToken", this.accessToken) -1107 .add("refreshToken", this.refreshToken) -1108 .add("lastRefresh", this.lastRefresh) -1109 .add("expires", this.expires) -1110 .add("userAgent", this.userAgent) -1111 .add("tokenURL", this.tokenURL) -1112 .add("revokeURL", this.revokeURL) -1113 .add("baseURL", this.baseURL) -1114 .add("baseUploadURL", this.baseUploadURL) -1115 .add("authorizationURL", this.baseAuthorizationURL) -1116 .add("autoRefresh", this.autoRefresh) -1117 .add("maxRetryAttempts", this.maxRetryAttempts); -1118 return state.toString(); -1119 } -1120 -1121 String lockAccessToken() { -1122 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { -1123 this.refreshLock.writeLock().lock(); -1124 try { -1125 if (this.needsRefresh()) { -1126 this.refresh(); -1127 } -1128 this.refreshLock.readLock().lock(); -1129 } finally { -1130 this.refreshLock.writeLock().unlock(); -1131 } -1132 } else { -1133 this.refreshLock.readLock().lock(); -1134 } -1135 -1136 return this.accessToken; -1137 } -1138 -1139 void unlockAccessToken() { -1140 this.refreshLock.readLock().unlock(); -1141 } -1142 -1143 /** -1144 * Get the value for the X-Box-UA header. -1145 * -1146 * @return the header value. -1147 */ -1148 String getBoxUAHeader() { -1149 -1150 return "agent=box-java-sdk/" + SDK_VERSION + "; env=Java/" + JAVA_VERSION; -1151 } -1152 -1153 /** -1154 * Sets a custom header to be sent on all requests through this API connection. -1155 * -1156 * @param header the header name. -1157 * @param value the header value. -1158 */ -1159 public void setCustomHeader(String header, String value) { -1160 this.customHeaders.put(header, value); -1161 } -1162 -1163 /** -1164 * Removes a custom header, so it will no longer be sent on requests through this API connection. -1165 * -1166 * @param header the header name. -1167 */ -1168 public void removeCustomHeader(String header) { -1169 this.customHeaders.remove(header); -1170 } -1171 -1172 /** -1173 * Suppresses email notifications from API actions. This is typically used by security or admin applications -1174 * to prevent spamming end users when doing automated processing on their content. -1175 */ -1176 public void suppressNotifications() { -1177 this.setCustomHeader(BOX_NOTIFICATIONS_HEADER, "off"); -1178 } -1179 -1180 /** -1181 * Re-enable email notifications from API actions if they have been suppressed. -1182 * -1183 * @see #suppressNotifications -1184 */ -1185 public void enableNotifications() { -1186 this.removeCustomHeader(BOX_NOTIFICATIONS_HEADER); -1187 } -1188 -1189 /** -1190 * Set this API connection to make API calls on behalf of another users, impersonating them. This -1191 * functionality can only be used by admins and service accounts. -1192 * -1193 * @param userID the ID of the user to act as. -1194 */ -1195 public void asUser(String userID) { -1196 this.setCustomHeader(AS_USER_HEADER, userID); -1197 } -1198 -1199 /** -1200 * Sets this API connection to make API calls on behalf of the user with whom the access token is associated. -1201 * This undoes any previous calls to asUser(). -1202 * -1203 * @see #asUser -1204 */ -1205 public void asSelf() { -1206 this.removeCustomHeader(AS_USER_HEADER); -1207 } -1208 -1209 /** -1210 * Used to override default SSL certification handling. For example, you can provide your own -1211 * trust manager or hostname verifier to allow self-signed certificates. -1212 * You can check examples <a href="https://github.com/box/box-java-sdk/blob/main/doc/configuration.md#ssl-configuration">here</a>. -1213 * -1214 * @param trustManager TrustManager that verifies certificates are valid. -1215 * @param hostnameVerifier HostnameVerifier that allows you to specify what hostnames are allowed. -1216 */ -1217 public void configureSslCertificatesValidation(X509TrustManager trustManager, HostnameVerifier hostnameVerifier) { -1218 this.trustManager = trustManager; -1219 this.hostnameVerifier = hostnameVerifier; -1220 buildHttpClients(); -1221 } -1222 -1223 Map<String, String> getHeaders() { -1224 return this.customHeaders; -1225 } -1226 -1227 protected void extractTokens(JsonObject jsonObject) { -1228 this.accessToken = jsonObject.get("access_token").asString(); -1229 this.refreshToken = jsonObject.get("refresh_token").asString(); -1230 this.lastRefresh = System.currentTimeMillis(); -1231 this.expires = jsonObject.get("expires_in").asLong() * 1000; -1232 } -1233 -1234 protected BoxAPIRequest createTokenRequest(URL url) { -1235 String urlParameters = format("grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s", -1236 this.refreshToken, this.clientID, this.clientSecret); -1237 -1238 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1239 request.shouldAuthenticate(false); -1240 request.setBody(urlParameters); -1241 return request; -1242 } -1243 -1244 private String fixBaseUrl(String baseUrl) { -1245 return baseUrl.endsWith("/") ? baseUrl : baseUrl + "/"; -1246 } -1247 -1248 Response execute(Request request) { -1249 return executeOnClient(httpClient, request); -1250 } -1251 -1252 Response executeWithoutRedirect(Request request) { -1253 return executeOnClient(noRedirectsHttpClient, request); -1254 } -1255 -1256 private Response executeOnClient(OkHttpClient httpClient, Request request) { -1257 try { -1258 return httpClient.newCall(request).execute(); -1259 } catch (IOException e) { -1260 throw new BoxAPIException("Couldn't connect to the Box API due to a network error. Request\n" + request, e); -1261 } -1262 } -1263 -1264 protected X509TrustManager getTrustManager() { -1265 return trustManager; -1266 } -1267 -1268 protected HostnameVerifier getHostnameVerifier() { -1269 return hostnameVerifier; -1270 } -1271 -1272 /** -1273 * Used to categorize the types of resource links. -1274 */ -1275 protected enum ResourceLinkType { -1276 /** -1277 * Catch-all default for resource links that are unknown. -1278 */ -1279 Unknown, -1280 +614 +615 /** +616 * Gets the maximum number of times an API request will be retried after an error response +617 * is received. +618 * +619 * @return the maximum number of request attempts. +620 */ +621 public int getMaxRetryAttempts() { +622 return this.maxRetryAttempts; +623 } +624 +625 /** +626 * Sets the maximum number of times an API request will be retried after an error response +627 * is received. +628 * +629 * @param attempts the maximum number of request attempts. +630 */ +631 public void setMaxRetryAttempts(int attempts) { +632 this.maxRetryAttempts = attempts; +633 } +634 +635 /** +636 * Gets the connect timeout for this connection in milliseconds. +637 * +638 * @return the number of milliseconds to connect before timing out. +639 */ +640 public int getConnectTimeout() { +641 return this.connectTimeout; +642 } +643 +644 /** +645 * Sets the connect timeout for this connection. +646 * +647 * @param connectTimeout The number of milliseconds to wait for the connection to be established. +648 */ +649 public void setConnectTimeout(int connectTimeout) { +650 this.connectTimeout = connectTimeout; +651 buildHttpClients(); +652 } +653 +654 /** +655 * Gets the read timeout for this connection in milliseconds. +656 * +657 * @return the number of milliseconds to wait for bytes to be read before timing out. +658 */ +659 public int getReadTimeout() { +660 return this.readTimeout; +661 } +662 +663 /** +664 * Sets the read timeout for this connection. +665 * +666 * @param readTimeout The number of milliseconds to wait for bytes to be read. +667 */ +668 public void setReadTimeout(int readTimeout) { +669 this.readTimeout = readTimeout; +670 buildHttpClients(); +671 } +672 +673 /** +674 * Gets the proxy value to use for API calls to Box. +675 * +676 * @return the current proxy. +677 */ +678 public Proxy getProxy() { +679 return this.proxy; +680 } +681 +682 /** +683 * Sets the proxy to use for API calls to Box. +684 * +685 * @param proxy the proxy to use for API calls to Box. +686 */ +687 public void setProxy(Proxy proxy) { +688 this.proxy = proxy; +689 buildHttpClients(); +690 } +691 +692 /** +693 * Gets the username to use for a proxy that requires basic auth. +694 * +695 * @return the username to use for a proxy that requires basic auth. +696 */ +697 public String getProxyUsername() { +698 return this.proxyUsername; +699 } +700 +701 /** +702 * Sets the username to use for a proxy that requires basic auth. +703 * +704 * @param proxyUsername the username to use for a proxy that requires basic auth. +705 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +706 */ +707 public void setProxyUsername(String proxyUsername) { +708 this.proxyUsername = proxyUsername; +709 buildHttpClients(); +710 } +711 +712 /** +713 * Gets the password to use for a proxy that requires basic auth. +714 * +715 * @return the password to use for a proxy that requires basic auth. +716 */ +717 public String getProxyPassword() { +718 return this.proxyPassword; +719 } +720 +721 /** +722 * Sets the proxy user and password used in basic authentication +723 * +724 * @param proxyUsername Username to use for a proxy that requires basic auth. +725 * @param proxyPassword Password to use for a proxy that requires basic auth. +726 */ +727 public void setProxyBasicAuthentication(String proxyUsername, String proxyPassword) { +728 this.proxyUsername = proxyUsername; +729 this.proxyPassword = proxyPassword; +730 buildHttpClients(); +731 } +732 +733 /** +734 * Sets the password to use for a proxy that requires basic auth. +735 * +736 * @param proxyPassword the password to use for a proxy that requires basic auth. +737 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +738 */ +739 public void setProxyPassword(String proxyPassword) { +740 this.proxyPassword = proxyPassword; +741 buildHttpClients(); +742 } +743 +744 /** +745 * Determines if this connection's access token can be refreshed. An access token cannot be refreshed if a refresh +746 * token was never set. +747 * +748 * @return true if the access token can be refreshed; otherwise false. +749 */ +750 public boolean canRefresh() { +751 return this.refreshToken != null; +752 } +753 +754 /** +755 * Determines if this connection's access token has expired and needs to be refreshed. +756 * +757 * @return true if the access token needs to be refreshed; otherwise false. +758 */ +759 public boolean needsRefresh() { +760 boolean needsRefresh; +761 +762 this.refreshLock.readLock().lock(); +763 long now = System.currentTimeMillis(); +764 long tokenDuration = (now - this.lastRefresh); +765 needsRefresh = (tokenDuration >= this.expires - REFRESH_EPSILON); +766 this.refreshLock.readLock().unlock(); +767 +768 return needsRefresh; +769 } +770 +771 /** +772 * Refresh's this connection's access token using its refresh token. +773 * +774 * @throws IllegalStateException if this connection's access token cannot be refreshed. +775 */ +776 public void refresh() { +777 this.refreshLock.writeLock().lock(); +778 +779 if (!this.canRefresh()) { +780 this.refreshLock.writeLock().unlock(); +781 throw new IllegalStateException("The BoxAPIConnection cannot be refreshed because it doesn't have a " +782 + "refresh token."); +783 } +784 +785 URL url; +786 try { +787 url = new URL(getTokenURL()); +788 } catch (MalformedURLException e) { +789 this.refreshLock.writeLock().unlock(); +790 assert false : "An invalid refresh URL indicates a bug in the SDK."; +791 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); +792 } +793 +794 BoxAPIRequest request = createTokenRequest(url); +795 +796 String json; +797 try (BoxAPIResponse boxAPIResponse = request.send()) { +798 BoxJSONResponse response = (BoxJSONResponse) boxAPIResponse; +799 json = response.getJSON(); +800 } catch (BoxAPIException e) { +801 this.refreshLock.writeLock().unlock(); +802 this.notifyError(e); +803 throw e; +804 } +805 +806 try { +807 extractTokens(Json.parse(json).asObject()); +808 +809 this.notifyRefresh(); +810 } finally { +811 this.refreshLock.writeLock().unlock(); +812 } +813 } +814 +815 /** +816 * Restores a saved connection state into this BoxAPIConnection. +817 * +818 * @param state the saved state that was created with {@link #save}. +819 * @see #save +820 */ +821 public void restore(String state) { +822 JsonObject json = Json.parse(state).asObject(); +823 String accessToken = json.get("accessToken").asString(); +824 String refreshToken = getKeyValueOrDefault(json, "refreshToken", null); +825 long lastRefresh = json.get("lastRefresh").asLong(); +826 long expires = json.get("expires").asLong(); +827 String userAgent = json.get("userAgent").asString(); +828 String tokenURL = getKeyValueOrDefault(json, "tokenURL", null); +829 String revokeURL = getKeyValueOrDefault(json, "revokeURL", null); +830 String baseURL = adoptBaseUrlWhenLoadingFromOldVersion( +831 getKeyValueOrDefault(json, "baseURL", DEFAULT_BASE_URL) +832 ); +833 String baseUploadURL = adoptUploadBaseUrlWhenLoadingFromOldVersion( +834 getKeyValueOrDefault(json, "baseUploadURL", DEFAULT_BASE_UPLOAD_URL) +835 ); +836 String authorizationURL = +837 getKeyValueOrDefault(json, "authorizationURL", DEFAULT_BASE_AUTHORIZATION_URL); +838 boolean autoRefresh = json.get("autoRefresh").asBoolean(); +839 +840 // Try to read deprecated value +841 int maxRequestAttempts = -1; +842 if (json.names().contains("maxRequestAttempts")) { +843 maxRequestAttempts = json.get("maxRequestAttempts").asInt(); +844 } +845 +846 int maxRetryAttempts = -1; +847 if (json.names().contains("maxRetryAttempts")) { +848 maxRetryAttempts = json.get("maxRetryAttempts").asInt(); +849 } +850 +851 this.accessToken = accessToken; +852 this.refreshToken = refreshToken; +853 this.lastRefresh = lastRefresh; +854 this.expires = expires; +855 this.userAgent = userAgent; +856 this.tokenURL = tokenURL; +857 this.revokeURL = revokeURL; +858 this.setBaseURL(baseURL); +859 this.setBaseUploadURL(baseUploadURL); +860 this.setBaseAuthorizationURL(authorizationURL); +861 this.autoRefresh = autoRefresh; +862 +863 // Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts" +864 if (maxRequestAttempts > -1) { +865 this.maxRetryAttempts = maxRequestAttempts - 1; +866 } +867 if (maxRetryAttempts > -1) { +868 this.maxRetryAttempts = maxRetryAttempts; +869 } +870 +871 } +872 +873 private String adoptBaseUrlWhenLoadingFromOldVersion(String url) { +874 if (url == null) { +875 return null; +876 } +877 String urlEndingWithSlash = fixBaseUrl(url); +878 return urlEndingWithSlash.equals("https://api.box.com/2.0/") +879 ? DEFAULT_BASE_URL +880 : urlEndingWithSlash; +881 } +882 +883 private String adoptUploadBaseUrlWhenLoadingFromOldVersion(String url) { +884 if (url == null) { +885 return null; +886 } +887 String urlEndingWithSlash = fixBaseUrl(url); +888 return urlEndingWithSlash.equals("https://upload.box.com/api/2.0/") +889 ? DEFAULT_BASE_UPLOAD_URL +890 : urlEndingWithSlash; +891 } +892 +893 protected String getKeyValueOrDefault(JsonObject json, String key, String defaultValue) { +894 return Optional.ofNullable(json.get(key)) +895 .filter(js -> !js.isNull()) +896 .map(JsonValue::asString) +897 .orElse(defaultValue); +898 } +899 +900 /** +901 * Notifies a refresh event to all the listeners. +902 */ +903 protected void notifyRefresh() { +904 for (BoxAPIConnectionListener listener : this.listeners) { +905 listener.onRefresh(this); +906 } +907 } +908 +909 /** +910 * Notifies an error event to all the listeners. +911 * +912 * @param error A BoxAPIException instance. +913 */ +914 protected void notifyError(BoxAPIException error) { +915 for (BoxAPIConnectionListener listener : this.listeners) { +916 listener.onError(this, error); +917 } +918 } +919 +920 /** +921 * Add a listener to listen to Box API connection events. +922 * +923 * @param listener a listener to listen to Box API connection. +924 */ +925 public void addListener(BoxAPIConnectionListener listener) { +926 this.listeners.add(listener); +927 } +928 +929 /** +930 * Remove a listener listening to Box API connection events. +931 * +932 * @param listener the listener to remove. +933 */ +934 public void removeListener(BoxAPIConnectionListener listener) { +935 this.listeners.remove(listener); +936 } +937 +938 /** +939 * Gets the RequestInterceptor associated with this API connection. +940 * +941 * @return the RequestInterceptor associated with this API connection. +942 */ +943 public RequestInterceptor getRequestInterceptor() { +944 return this.interceptor; +945 } +946 +947 /** +948 * Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API. +949 * +950 * @param interceptor the RequestInterceptor. +951 */ +952 public void setRequestInterceptor(RequestInterceptor interceptor) { +953 this.interceptor = interceptor; +954 } +955 +956 /** +957 * Get a lower-scoped token restricted to a resource for the list of scopes that are passed. +958 * +959 * @param scopes the list of scopes to which the new token should be restricted for +960 * @param resource the resource for which the new token has to be obtained +961 * @return scopedToken which has access token and other details +962 * @throws BoxAPIException if resource is not a valid Box API endpoint or shared link +963 */ +964 public ScopedToken getLowerScopedToken(List<String> scopes, String resource) { +965 assert (scopes != null); +966 assert (scopes.size() > 0); +967 URL url; +968 try { +969 url = new URL(this.getTokenURL()); +970 } catch (MalformedURLException e) { +971 assert false : "An invalid refresh URL indicates a bug in the SDK."; +972 throw new BoxAPIException("An invalid refresh URL indicates a bug in the SDK.", e); +973 } +974 +975 StringBuilder spaceSeparatedScopes = this.buildScopesForTokenDownscoping(scopes); +976 +977 String urlParameters = format("grant_type=urn:ietf:params:oauth:grant-type:token-exchange" +978 + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" +979 + "&scope=%s", +980 this.getAccessToken(), spaceSeparatedScopes); +981 +982 if (resource != null) { +983 +984 ResourceLinkType resourceType = this.determineResourceLinkType(resource); +985 +986 if (resourceType == ResourceLinkType.APIEndpoint) { +987 urlParameters = format(urlParameters + "&resource=%s", resource); +988 } else if (resourceType == ResourceLinkType.SharedLink) { +989 urlParameters = format(urlParameters + "&box_shared_link=%s", resource); +990 } else if (resourceType == ResourceLinkType.Unknown) { +991 String argExceptionMessage = format("Unable to determine resource type: %s", resource); +992 BoxAPIException e = new BoxAPIException(argExceptionMessage); +993 this.notifyError(e); +994 throw e; +995 } else { +996 String argExceptionMessage = format("Unhandled resource type: %s", resource); +997 BoxAPIException e = new BoxAPIException(argExceptionMessage); +998 this.notifyError(e); +999 throw e; +1000 } +1001 } +1002 +1003 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1004 request.shouldAuthenticate(false); +1005 request.setBody(urlParameters); +1006 +1007 String jsonResponse; +1008 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { +1009 jsonResponse = response.getJSON(); +1010 } catch (BoxAPIException e) { +1011 this.notifyError(e); +1012 throw e; +1013 } +1014 +1015 JsonObject jsonObject = Json.parse(jsonResponse).asObject(); +1016 ScopedToken token = new ScopedToken(jsonObject); +1017 token.setObtainedAt(System.currentTimeMillis()); +1018 token.setExpiresIn(jsonObject.get("expires_in").asLong() * 1000); +1019 return token; +1020 } +1021 +1022 /** +1023 * Convert List<String> to space-delimited String. +1024 * Needed for versions prior to Java 8, which don't have String.join(delimiter, list) +1025 * +1026 * @param scopes the list of scopes to read from +1027 * @return space-delimited String of scopes +1028 */ +1029 private StringBuilder buildScopesForTokenDownscoping(List<String> scopes) { +1030 StringBuilder spaceSeparatedScopes = new StringBuilder(); +1031 for (int i = 0; i < scopes.size(); i++) { +1032 spaceSeparatedScopes.append(scopes.get(i)); +1033 if (i < scopes.size() - 1) { +1034 spaceSeparatedScopes.append(" "); +1035 } +1036 } +1037 +1038 return spaceSeparatedScopes; +1039 } +1040 +1041 /** +1042 * Determines the type of resource, given a link to a Box resource. +1043 * +1044 * @param resourceLink the resource URL to check +1045 * @return ResourceLinkType that categorizes the provided resourceLink +1046 */ +1047 protected ResourceLinkType determineResourceLinkType(String resourceLink) { +1048 +1049 ResourceLinkType resourceType = ResourceLinkType.Unknown; +1050 +1051 try { +1052 URL validUrl = new URL(resourceLink); +1053 String validURLStr = validUrl.toString(); +1054 final String apiFilesEndpointPattern = ".*box.com/2.0/files/\\d+"; +1055 final String apiFoldersEndpointPattern = ".*box.com/2.0/folders/\\d+"; +1056 final String sharedLinkPattern = "(.*box.com/s/.*|.*box.com.*s=.*)"; +1057 +1058 if (Pattern.matches(apiFilesEndpointPattern, validURLStr) +1059 || Pattern.matches(apiFoldersEndpointPattern, validURLStr)) { +1060 resourceType = ResourceLinkType.APIEndpoint; +1061 } else if (Pattern.matches(sharedLinkPattern, validURLStr)) { +1062 resourceType = ResourceLinkType.SharedLink; +1063 } +1064 } catch (MalformedURLException e) { +1065 //Swallow exception and return default ResourceLinkType set at top of function +1066 } +1067 +1068 return resourceType; +1069 } +1070 +1071 /** +1072 * Revokes the tokens associated with this API connection. This results in the connection no +1073 * longer being able to make API calls until a fresh authorization is made by calling authenticate() +1074 */ +1075 public void revokeToken() { +1076 +1077 URL url; +1078 try { +1079 url = new URL(getRevokeURL()); +1080 } catch (MalformedURLException e) { +1081 assert false : "An invalid refresh URL indicates a bug in the SDK."; +1082 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); +1083 } +1084 +1085 String urlParameters = format("token=%s&client_id=%s&client_secret=%s", +1086 this.accessToken, this.clientID, this.clientSecret); +1087 +1088 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1089 request.shouldAuthenticate(false); +1090 request.setBody(urlParameters); +1091 +1092 request.send().close(); +1093 } +1094 +1095 /** +1096 * Saves the state of this connection to a string so that it can be persisted and restored at a later time. +1097 * +1098 * <p>Note that proxy settings aren't automatically saved or restored. This is mainly due to security concerns +1099 * around persisting proxy authentication details to the state string. If your connection uses a proxy, you will +1100 * have to manually configure it again after restoring the connection.</p> +1101 * +1102 * @return the state of this connection. +1103 * @see #restore +1104 */ +1105 public String save() { +1106 JsonObject state = new JsonObject() +1107 .add("accessToken", this.accessToken) +1108 .add("refreshToken", this.refreshToken) +1109 .add("lastRefresh", this.lastRefresh) +1110 .add("expires", this.expires) +1111 .add("userAgent", this.userAgent) +1112 .add("tokenURL", this.tokenURL) +1113 .add("revokeURL", this.revokeURL) +1114 .add("baseURL", this.baseURL) +1115 .add("baseUploadURL", this.baseUploadURL) +1116 .add("authorizationURL", this.baseAuthorizationURL) +1117 .add("autoRefresh", this.autoRefresh) +1118 .add("maxRetryAttempts", this.maxRetryAttempts); +1119 return state.toString(); +1120 } +1121 +1122 String lockAccessToken() { +1123 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { +1124 this.refreshLock.writeLock().lock(); +1125 try { +1126 if (this.needsRefresh()) { +1127 this.refresh(); +1128 } +1129 this.refreshLock.readLock().lock(); +1130 } finally { +1131 this.refreshLock.writeLock().unlock(); +1132 } +1133 } else { +1134 this.refreshLock.readLock().lock(); +1135 } +1136 +1137 return this.accessToken; +1138 } +1139 +1140 void unlockAccessToken() { +1141 this.refreshLock.readLock().unlock(); +1142 } +1143 +1144 /** +1145 * Get the value for the X-Box-UA header. +1146 * +1147 * @return the header value. +1148 */ +1149 String getBoxUAHeader() { +1150 +1151 return "agent=box-java-sdk/" + SDK_VERSION + "; env=Java/" + JAVA_VERSION; +1152 } +1153 +1154 /** +1155 * Sets a custom header to be sent on all requests through this API connection. +1156 * +1157 * @param header the header name. +1158 * @param value the header value. +1159 */ +1160 public void setCustomHeader(String header, String value) { +1161 this.customHeaders.put(header, value); +1162 } +1163 +1164 /** +1165 * Removes a custom header, so it will no longer be sent on requests through this API connection. +1166 * +1167 * @param header the header name. +1168 */ +1169 public void removeCustomHeader(String header) { +1170 this.customHeaders.remove(header); +1171 } +1172 +1173 /** +1174 * Suppresses email notifications from API actions. This is typically used by security or admin applications +1175 * to prevent spamming end users when doing automated processing on their content. +1176 */ +1177 public void suppressNotifications() { +1178 this.setCustomHeader(BOX_NOTIFICATIONS_HEADER, "off"); +1179 } +1180 +1181 /** +1182 * Re-enable email notifications from API actions if they have been suppressed. +1183 * +1184 * @see #suppressNotifications +1185 */ +1186 public void enableNotifications() { +1187 this.removeCustomHeader(BOX_NOTIFICATIONS_HEADER); +1188 } +1189 +1190 /** +1191 * Set this API connection to make API calls on behalf of another users, impersonating them. This +1192 * functionality can only be used by admins and service accounts. +1193 * +1194 * @param userID the ID of the user to act as. +1195 */ +1196 public void asUser(String userID) { +1197 this.setCustomHeader(AS_USER_HEADER, userID); +1198 } +1199 +1200 /** +1201 * Sets this API connection to make API calls on behalf of the user with whom the access token is associated. +1202 * This undoes any previous calls to asUser(). +1203 * +1204 * @see #asUser +1205 */ +1206 public void asSelf() { +1207 this.removeCustomHeader(AS_USER_HEADER); +1208 } +1209 +1210 /** +1211 * Used to override default SSL certification handling. For example, you can provide your own +1212 * trust manager or hostname verifier to allow self-signed certificates. +1213 * You can check examples <a href="https://github.com/box/box-java-sdk/blob/main/doc/configuration.md#ssl-configuration">here</a>. +1214 * +1215 * @param trustManager TrustManager that verifies certificates are valid. +1216 * @param hostnameVerifier HostnameVerifier that allows you to specify what hostnames are allowed. +1217 */ +1218 public void configureSslCertificatesValidation(X509TrustManager trustManager, HostnameVerifier hostnameVerifier) { +1219 this.trustManager = trustManager; +1220 this.hostnameVerifier = hostnameVerifier; +1221 buildHttpClients(); +1222 } +1223 +1224 Map<String, String> getHeaders() { +1225 return this.customHeaders; +1226 } +1227 +1228 protected void extractTokens(JsonObject jsonObject) { +1229 this.accessToken = jsonObject.get("access_token").asString(); +1230 this.refreshToken = jsonObject.get("refresh_token").asString(); +1231 this.lastRefresh = System.currentTimeMillis(); +1232 this.expires = jsonObject.get("expires_in").asLong() * 1000; +1233 } +1234 +1235 protected BoxAPIRequest createTokenRequest(URL url) { +1236 String urlParameters = format("grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s", +1237 this.refreshToken, this.clientID, this.clientSecret); +1238 +1239 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1240 request.shouldAuthenticate(false); +1241 request.setBody(urlParameters); +1242 return request; +1243 } +1244 +1245 private String fixBaseUrl(String baseUrl) { +1246 return baseUrl.endsWith("/") ? baseUrl : baseUrl + "/"; +1247 } +1248 +1249 Response execute(Request request) { +1250 return executeOnClient(httpClient, request); +1251 } +1252 +1253 Response executeWithoutRedirect(Request request) { +1254 return executeOnClient(noRedirectsHttpClient, request); +1255 } +1256 +1257 protected Call createNewCall(OkHttpClient httpClient, Request request) { +1258 return httpClient.newCall(request); +1259 } +1260 +1261 private Response executeOnClient(OkHttpClient httpClient, Request request) { +1262 try { +1263 return createNewCall(httpClient, request).execute(); +1264 } catch (IOException e) { +1265 throw new BoxAPIException("Couldn't connect to the Box API due to a network error. Request\n" + request, e); +1266 } +1267 } +1268 +1269 protected X509TrustManager getTrustManager() { +1270 return trustManager; +1271 } +1272 +1273 protected HostnameVerifier getHostnameVerifier() { +1274 return hostnameVerifier; +1275 } +1276 +1277 /** +1278 * Used to categorize the types of resource links. +1279 */ +1280 protected enum ResourceLinkType {1281 /** -1282 * Resource URLs that point to an API endipoint such as https://api.box.com/2.0/files/:file_id. +1282 * Catch-all default for resource links that are unknown.1283 */ -1284 APIEndpoint, +1284 Unknown,12851286 /** -1287 * Resource URLs that point to a resource that has been shared -1288 * such as https://example.box.com/s/qwertyuiop1234567890asdfghjk -1289 * or https://example.app.box.com/notes/0987654321?s=zxcvbnm1234567890asdfghjk. -1290 */ -1291 SharedLink -1292 } -1293} +1287 * Resource URLs that point to an API endipoint such as https://api.box.com/2.0/files/:file_id. +1288 */ +1289 APIEndpoint, +1290 +1291 /** +1292 * Resource URLs that point to a resource that has been shared +1293 * such as https://example.box.com/s/qwertyuiop1234567890asdfghjk +1294 * or https://example.app.box.com/notes/0987654321?s=zxcvbnm1234567890asdfghjk. +1295 */ +1296 SharedLink +1297 } +1298} diff --git a/javadoc/src-html/com/box/sdk/BoxAPIConnection.html b/javadoc/src-html/com/box/sdk/BoxAPIConnection.html index 0a0703cc2..1a36e171a 100644 --- a/javadoc/src-html/com/box/sdk/BoxAPIConnection.html +++ b/javadoc/src-html/com/box/sdk/BoxAPIConnection.html @@ -37,1268 +37,1273 @@ 029import javax.net.ssl.TrustManager;030import javax.net.ssl.X509TrustManager;031import okhttp3.Authenticator; -032import okhttp3.Credentials; -033import okhttp3.OkHttpClient; -034import okhttp3.Request; -035import okhttp3.Response; -036 -037/** -038 * Represents an authenticated connection to the Box API. -039 * -040 * <p>This class handles storing authentication information, automatic token refresh, and rate-limiting. It can also be -041 * used to configure the Box API endpoint URL in order to hit a different version of the API. Multiple instances of -042 * BoxAPIConnection may be created to support multi-user login.</p> -043 */ -044public class BoxAPIConnection { -045 -046 /** -047 * Used as a marker to setup connection to use default HostnameVerifier -048 * Example:<pre>{@code -049 * BoxApiConnection api = new BoxApiConnection(...); -050 * HostnameVerifier myHostnameVerifier = ... -051 * api.configureSslCertificatesValidation(DEFAULT_TRUST_MANAGER, myHostnameVerifier); -052 * }</pre> -053 */ -054 public static final X509TrustManager DEFAULT_TRUST_MANAGER = null; -055 /** -056 * Used as a marker to setup connection to use default HostnameVerifier -057 * Example:<pre>{@code -058 * BoxApiConnection api = new BoxApiConnection(...); -059 * X509TrustManager myTrustManager = ... -060 * api.configureSslCertificatesValidation(myTrustManager, DEFAULT_HOSTNAME_VERIFIER); -061 * }</pre> -062 */ -063 public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = null; -064 -065 /** -066 * The default maximum number of times an API request will be retried after an error response -067 * is received. -068 */ -069 public static final int DEFAULT_MAX_RETRIES = 5; -070 /** -071 * Default authorization URL -072 */ -073 protected static final String DEFAULT_BASE_AUTHORIZATION_URL = "https://account.box.com/api/"; -074 static final String AS_USER_HEADER = "As-User"; -075 -076 private static final String API_VERSION = "2.0"; -077 private static final String OAUTH_SUFFIX = "oauth2/authorize"; -078 private static final String TOKEN_URL_SUFFIX = "oauth2/token"; -079 private static final String REVOKE_URL_SUFFIX = "oauth2/revoke"; -080 private static final String DEFAULT_BASE_URL = "https://api.box.com/"; -081 private static final String DEFAULT_BASE_UPLOAD_URL = "https://upload.box.com/api/"; -082 private static final String DEFAULT_BASE_APP_URL = "https://app.box.com"; -083 -084 private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications"; -085 -086 private static final String JAVA_VERSION = System.getProperty("java.version"); -087 private static final String SDK_VERSION = "4.10.0"; -088 -089 /** -090 * The amount of buffer time, in milliseconds, to use when determining if an access token should be refreshed. For -091 * example, if REFRESH_EPSILON = 60000 and the access token expires in less than one minute, it will be refreshed. -092 */ -093 private static final long REFRESH_EPSILON = 60000; -094 -095 private final String clientID; -096 private final String clientSecret; -097 private final ReadWriteLock refreshLock; -098 private X509TrustManager trustManager; -099 private HostnameVerifier hostnameVerifier; -100 -101 // These volatile fields are used when determining if the access token needs to be refreshed. Since they are used in -102 // the double-checked lock in getAccessToken(), they must be atomic. -103 private volatile long lastRefresh; -104 private volatile long expires; -105 -106 private Proxy proxy; -107 private String proxyUsername; -108 private String proxyPassword; -109 -110 private String userAgent; -111 private String accessToken; -112 private String refreshToken; -113 private String tokenURL; -114 private String revokeURL; -115 private String baseURL; -116 private String baseUploadURL; -117 private String baseAppURL; -118 private String baseAuthorizationURL; -119 private boolean autoRefresh; -120 private int maxRetryAttempts; -121 private int connectTimeout; -122 private int readTimeout; -123 private final List<BoxAPIConnectionListener> listeners; -124 private RequestInterceptor interceptor; -125 private final Map<String, String> customHeaders; -126 -127 private OkHttpClient httpClient; -128 private OkHttpClient noRedirectsHttpClient; -129 private Authenticator authenticator; -130 -131 /** -132 * Constructs a new BoxAPIConnection that authenticates with a developer or access token. -133 * -134 * @param accessToken a developer or access token to use for authenticating with the API. -135 */ -136 public BoxAPIConnection(String accessToken) { -137 this(null, null, accessToken, null); -138 } -139 -140 /** -141 * Constructs a new BoxAPIConnection with an access token that can be refreshed. -142 * -143 * @param clientID the client ID to use when refreshing the access token. -144 * @param clientSecret the client secret to use when refreshing the access token. -145 * @param accessToken an initial access token to use for authenticating with the API. -146 * @param refreshToken an initial refresh token to use when refreshing the access token. -147 */ -148 public BoxAPIConnection(String clientID, String clientSecret, String accessToken, String refreshToken) { -149 this.clientID = clientID; -150 this.clientSecret = clientSecret; -151 this.accessToken = accessToken; -152 this.refreshToken = refreshToken; -153 this.baseURL = fixBaseUrl(DEFAULT_BASE_URL); -154 this.baseUploadURL = fixBaseUrl(DEFAULT_BASE_UPLOAD_URL); -155 this.baseAppURL = DEFAULT_BASE_APP_URL; -156 this.baseAuthorizationURL = DEFAULT_BASE_AUTHORIZATION_URL; -157 this.autoRefresh = true; -158 this.maxRetryAttempts = BoxGlobalSettings.getMaxRetryAttempts(); -159 this.connectTimeout = BoxGlobalSettings.getConnectTimeout(); -160 this.readTimeout = BoxGlobalSettings.getReadTimeout(); -161 this.refreshLock = new ReentrantReadWriteLock(); -162 this.userAgent = "Box Java SDK v" + SDK_VERSION + " (Java " + JAVA_VERSION + ")"; -163 this.listeners = new ArrayList<>(); -164 this.customHeaders = new HashMap<>(); -165 -166 buildHttpClients(); -167 } -168 -169 /** -170 * Constructs a new BoxAPIConnection with an auth code that was obtained from the first half of OAuth. -171 * -172 * @param clientID the client ID to use when exchanging the auth code for an access token. -173 * @param clientSecret the client secret to use when exchanging the auth code for an access token. -174 * @param authCode an auth code obtained from the first half of the OAuth process. -175 */ -176 public BoxAPIConnection(String clientID, String clientSecret, String authCode) { -177 this(clientID, clientSecret, null, null); -178 this.authenticate(authCode); -179 } -180 -181 /** -182 * Constructs a new BoxAPIConnection. -183 * -184 * @param clientID the client ID to use when exchanging the auth code for an access token. -185 * @param clientSecret the client secret to use when exchanging the auth code for an access token. -186 */ -187 public BoxAPIConnection(String clientID, String clientSecret) { -188 this(clientID, clientSecret, null, null); -189 } -190 -191 /** -192 * Constructs a new BoxAPIConnection levaraging BoxConfig. -193 * -194 * @param boxConfig BoxConfig file, which should have clientId and clientSecret -195 */ -196 public BoxAPIConnection(BoxConfig boxConfig) { -197 this(boxConfig.getClientId(), boxConfig.getClientSecret(), null, null); -198 } -199 -200 private void buildHttpClients() { -201 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); -202 if (trustManager != null) { -203 try { -204 SSLContext sslContext = SSLContext.getInstance("SSL"); -205 sslContext.init(null, new TrustManager[]{trustManager}, new java.security.SecureRandom()); -206 httpClientBuilder.sslSocketFactory(sslContext.getSocketFactory(), trustManager); -207 } catch (NoSuchAlgorithmException | KeyManagementException e) { -208 throw new RuntimeException(e); -209 } -210 } -211 -212 OkHttpClient.Builder builder = httpClientBuilder -213 .followSslRedirects(true) -214 .followRedirects(true) -215 .connectTimeout(Duration.ofMillis(connectTimeout)) -216 .readTimeout(Duration.ofMillis(readTimeout)) -217 .connectionSpecs(singletonList(MODERN_TLS)); -218 -219 if (hostnameVerifier != null) { -220 httpClientBuilder.hostnameVerifier(hostnameVerifier); -221 } -222 -223 if (proxy != null) { -224 builder.proxy(proxy); -225 if (proxyUsername != null && proxyPassword != null) { -226 builder.proxyAuthenticator((route, response) -> { -227 String credential = Credentials.basic(proxyUsername, proxyPassword); -228 return response.request().newBuilder() -229 .header("Proxy-Authorization", credential) -230 .build(); -231 }); -232 } -233 if (this.authenticator != null) { -234 builder.proxyAuthenticator(authenticator); -235 } -236 } -237 builder = modifyHttpClientBuilder(builder); -238 -239 this.httpClient = builder.build(); -240 this.noRedirectsHttpClient = new OkHttpClient.Builder(httpClient) -241 .followSslRedirects(false) -242 .followRedirects(false) -243 .build(); -244 } -245 -246 /** -247 * Can be used to modify OkHttp.Builder used to create connection. This method is called after all modifications -248 * were done, thus allowing others to create their own connections and further customize builder. -249 * @param httpClientBuilder Builder that will be used to create http connection. -250 * @return Modified builder. -251 */ -252 protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder) { -253 return httpClientBuilder; -254 } -255 -256 /** -257 * Sets a proxy authenticator that will be used when proxy requires authentication. -258 * If you use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} it adds an authenticator -259 * that performs Basic authorization. By calling this method you can override this behaviour. -260 * You do not need to call {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -261 * in order to set custom authenticator. -262 * -263 * @param authenticator Custom authenticator that will be called when proxy asks for authorization. -264 */ -265 public void setProxyAuthenticator(Authenticator authenticator) { -266 this.authenticator = authenticator; -267 buildHttpClients(); -268 } -269 -270 /** -271 * Restores a BoxAPIConnection from a saved state. -272 * -273 * @param clientID the client ID to use with the connection. -274 * @param clientSecret the client secret to use with the connection. -275 * @param state the saved state that was created with {@link #save}. -276 * @return a restored API connection. -277 * @see #save -278 */ -279 public static BoxAPIConnection restore(String clientID, String clientSecret, String state) { -280 BoxAPIConnection api = new BoxAPIConnection(clientID, clientSecret); -281 api.restore(state); -282 return api; -283 } -284 -285 /** -286 * Returns the default authorization URL which is used to perform the authorization_code based OAuth2 flow. -287 * If custom Authorization URL is needed use instance method {@link BoxAPIConnection#getAuthorizationURL} -288 * -289 * @param clientID the client ID to use with the connection. -290 * @param redirectUri the URL to which Box redirects the browser when authentication completes. -291 * @param state the text string that you choose. -292 * Box sends the same string to your redirect URL when authentication is complete. -293 * @param scopes this optional parameter identifies the Box scopes available -294 * to the application once it's authenticated. -295 * @return the authorization URL -296 */ -297 public static URL getAuthorizationURL(String clientID, URI redirectUri, String state, List<String> scopes) { -298 return createFullAuthorizationUrl(DEFAULT_BASE_AUTHORIZATION_URL, clientID, redirectUri, state, scopes); -299 } -300 -301 private static URL createFullAuthorizationUrl( -302 String authorizationUrl, String clientID, URI redirectUri, String state, List<String> scopes -303 ) { -304 URLTemplate template = new URLTemplate(authorizationUrl + OAUTH_SUFFIX); -305 QueryStringBuilder queryBuilder = new QueryStringBuilder().appendParam("client_id", clientID) -306 .appendParam("response_type", "code") -307 .appendParam("redirect_uri", redirectUri.toString()) -308 .appendParam("state", state); -309 -310 if (scopes != null && !scopes.isEmpty()) { -311 queryBuilder.appendParam("scope", join(" ", scopes)); -312 } -313 -314 return template.buildWithQuery("", queryBuilder.toString()); -315 } -316 -317 /** -318 * Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained -319 * from the first half of OAuth. -320 * -321 * @param authCode the auth code obtained from the first half of the OAuth process. -322 */ -323 public void authenticate(String authCode) { -324 URL url; -325 try { -326 url = new URL(this.getTokenURL()); -327 } catch (MalformedURLException e) { -328 assert false : "An invalid token URL indicates a bug in the SDK."; -329 throw new RuntimeException("An invalid token URL indicates a bug in the SDK.", e); -330 } -331 -332 String urlParameters = format("grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s", -333 authCode, this.clientID, this.clientSecret); -334 -335 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -336 request.shouldAuthenticate(false); -337 request.setBody(urlParameters); -338 -339 // authentication uses form url encoded but response is JSON -340 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { -341 String json = response.getJSON(); -342 -343 JsonObject jsonObject = Json.parse(json).asObject(); -344 this.accessToken = jsonObject.get("access_token").asString(); -345 this.refreshToken = jsonObject.get("refresh_token").asString(); -346 this.lastRefresh = System.currentTimeMillis(); -347 this.expires = jsonObject.get("expires_in").asLong() * 1000; -348 } -349 } -350 -351 /** -352 * Gets the client ID. -353 * -354 * @return the client ID. -355 */ -356 public String getClientID() { -357 return this.clientID; -358 } -359 -360 /** -361 * Gets the client secret. -362 * -363 * @return the client secret. -364 */ -365 public String getClientSecret() { -366 return this.clientSecret; -367 } -368 -369 /** -370 * Gets the amount of time for which this connection's access token is valid. -371 * -372 * @return the amount of time in milliseconds. -373 */ -374 public long getExpires() { -375 return this.expires; -376 } -377 -378 /** -379 * Sets the amount of time for which this connection's access token is valid before it must be refreshed. -380 * -381 * @param milliseconds the number of milliseconds for which the access token is valid. -382 */ -383 public void setExpires(long milliseconds) { -384 this.expires = milliseconds; -385 } -386 -387 /** -388 * Gets the token URL that's used to request access tokens. The default value is -389 * "https://www.box.com/api/oauth2/token". -390 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#TOKEN_URL_SUFFIX}. -391 * -392 * @return the token URL. -393 */ -394 public String getTokenURL() { -395 if (this.tokenURL != null) { -396 return this.tokenURL; -397 } else { -398 return this.baseURL + TOKEN_URL_SUFFIX; -399 } -400 } -401 -402 /** -403 * Returns the URL used for token revocation. -404 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#REVOKE_URL_SUFFIX}. -405 * -406 * @return The url used for token revocation. -407 */ -408 public String getRevokeURL() { -409 if (this.revokeURL != null) { -410 return this.revokeURL; -411 } else { -412 return this.baseURL + REVOKE_URL_SUFFIX; -413 } -414 } -415 -416 /** -417 * Gets the base URL that's used when sending requests to the Box API. -418 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#API_VERSION}. -419 * The default value is "https://api.box.com/2.0/". -420 * -421 * @return the base URL. -422 */ -423 public String getBaseURL() { -424 return this.baseURL + API_VERSION + "/"; -425 } -426 -427 /** -428 * Sets the base URL to be used when sending requests to the Box API. For example, the default base URL is -429 * "https://api.box.com/". This method changes how {@link BoxAPIConnection#getRevokeURL()} -430 * and {@link BoxAPIConnection#getTokenURL()} are constructed. -431 * -432 * @param baseURL a base URL -433 */ -434 public void setBaseURL(String baseURL) { -435 this.baseURL = fixBaseUrl(baseURL); -436 } -437 -438 /** -439 * Gets the base upload URL that's used when performing file uploads to Box. -440 * The URL is created from {@link BoxAPIConnection#baseUploadURL} and {@link BoxAPIConnection#API_VERSION}. -441 * -442 * @return the base upload URL. -443 */ -444 public String getBaseUploadURL() { -445 return this.baseUploadURL + API_VERSION + "/"; -446 } -447 -448 /** -449 * Sets the base upload URL to be used when performing file uploads to Box. -450 * -451 * @param baseUploadURL a base upload URL. -452 */ -453 public void setBaseUploadURL(String baseUploadURL) { -454 this.baseUploadURL = fixBaseUrl(baseUploadURL); -455 } -456 -457 /** -458 * Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow. -459 * The URL is created from {@link BoxAPIConnection#baseAuthorizationURL} and {@link BoxAPIConnection#OAUTH_SUFFIX}. -460 * -461 * @param redirectUri the URL to which Box redirects the browser when authentication completes. -462 * @param state the text string that you choose. -463 * Box sends the same string to your redirect URL when authentication is complete. -464 * @param scopes this optional parameter identifies the Box scopes available -465 * to the application once it's authenticated. -466 * @return the authorization URL -467 */ -468 public URL getAuthorizationURL(URI redirectUri, String state, List<String> scopes) { -469 return createFullAuthorizationUrl(this.baseAuthorizationURL, this.clientID, redirectUri, state, scopes); -470 } -471 -472 /** -473 * Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow. -474 * -475 * @param baseAuthorizationURL Authorization URL. Default value is https://account.box.com/api/. -476 */ -477 public void setBaseAuthorizationURL(String baseAuthorizationURL) { -478 this.baseAuthorizationURL = fixBaseUrl(baseAuthorizationURL); -479 } -480 -481 /** -482 * Gets the user agent that's used when sending requests to the Box API. -483 * -484 * @return the user agent. -485 */ -486 public String getUserAgent() { -487 return this.userAgent; -488 } -489 -490 /** -491 * Sets the user agent to be used when sending requests to the Box API. -492 * -493 * @param userAgent the user agent. -494 */ -495 public void setUserAgent(String userAgent) { -496 this.userAgent = userAgent; -497 } -498 -499 /** -500 * Gets the base App url. Used for e.g. file requests. -501 * -502 * @return the base App Url. -503 */ -504 public String getBaseAppUrl() { -505 return this.baseAppURL; -506 } -507 -508 /** -509 * Sets the base App url. Used for e.g. file requests. -510 * -511 * @param baseAppURL a base App Url. -512 */ -513 public void setBaseAppUrl(String baseAppURL) { -514 this.baseAppURL = baseAppURL; -515 } -516 -517 /** -518 * Gets an access token that can be used to authenticate an API request. This method will automatically refresh the -519 * access token if it has expired since the last call to <code>getAccessToken()</code>. -520 * -521 * @return a valid access token that can be used to authenticate an API request. -522 */ -523 public String getAccessToken() { -524 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { -525 this.refreshLock.writeLock().lock(); -526 try { -527 if (this.needsRefresh()) { -528 this.refresh(); -529 } -530 } finally { -531 this.refreshLock.writeLock().unlock(); -532 } -533 } -534 -535 return this.accessToken; -536 } -537 -538 /** -539 * Sets the access token to use when authenticating API requests. -540 * -541 * @param accessToken a valid access token to use when authenticating API requests. -542 */ -543 public void setAccessToken(String accessToken) { -544 this.accessToken = accessToken; -545 } -546 -547 /** -548 * Gets the refresh lock to be used when refreshing an access token. -549 * -550 * @return the refresh lock. -551 */ -552 protected ReadWriteLock getRefreshLock() { -553 return this.refreshLock; -554 } -555 -556 /** -557 * Gets a refresh token that can be used to refresh an access token. -558 * -559 * @return a valid refresh token. -560 */ -561 public String getRefreshToken() { -562 return this.refreshToken; -563 } -564 -565 /** -566 * Sets the refresh token to use when refreshing an access token. -567 * -568 * @param refreshToken a valid refresh token. -569 */ -570 public void setRefreshToken(String refreshToken) { -571 this.refreshToken = refreshToken; -572 } -573 -574 /** -575 * Gets the last time that the access token was refreshed. -576 * -577 * @return the last refresh time in milliseconds. -578 */ -579 public long getLastRefresh() { -580 return this.lastRefresh; -581 } -582 -583 /** -584 * Sets the last time that the access token was refreshed. -585 * -586 * <p>This value is used when determining if an access token needs to be auto-refreshed. If the amount of time since -587 * the last refresh exceeds the access token's expiration time, then the access token will be refreshed.</p> -588 * -589 * @param lastRefresh the new last refresh time in milliseconds. -590 */ -591 public void setLastRefresh(long lastRefresh) { -592 this.lastRefresh = lastRefresh; -593 } -594 -595 /** -596 * Gets whether or not automatic refreshing of this connection's access token is enabled. Defaults to true. -597 * -598 * @return true if auto token refresh is enabled; otherwise false. -599 */ -600 public boolean getAutoRefresh() { -601 return this.autoRefresh; -602 } -603 -604 /** -605 * Enables or disables automatic refreshing of this connection's access token. Defaults to true. -606 * -607 * @param autoRefresh true to enable auto token refresh; otherwise false. -608 */ -609 public void setAutoRefresh(boolean autoRefresh) { -610 this.autoRefresh = autoRefresh; -611 } -612 +032import okhttp3.Call; +033import okhttp3.Credentials; +034import okhttp3.OkHttpClient; +035import okhttp3.Request; +036import okhttp3.Response; +037 +038/** +039 * Represents an authenticated connection to the Box API. +040 * +041 * <p>This class handles storing authentication information, automatic token refresh, and rate-limiting. It can also be +042 * used to configure the Box API endpoint URL in order to hit a different version of the API. Multiple instances of +043 * BoxAPIConnection may be created to support multi-user login.</p> +044 */ +045public class BoxAPIConnection { +046 +047 /** +048 * Used as a marker to setup connection to use default HostnameVerifier +049 * Example:<pre>{@code +050 * BoxApiConnection api = new BoxApiConnection(...); +051 * HostnameVerifier myHostnameVerifier = ... +052 * api.configureSslCertificatesValidation(DEFAULT_TRUST_MANAGER, myHostnameVerifier); +053 * }</pre> +054 */ +055 public static final X509TrustManager DEFAULT_TRUST_MANAGER = null; +056 /** +057 * Used as a marker to setup connection to use default HostnameVerifier +058 * Example:<pre>{@code +059 * BoxApiConnection api = new BoxApiConnection(...); +060 * X509TrustManager myTrustManager = ... +061 * api.configureSslCertificatesValidation(myTrustManager, DEFAULT_HOSTNAME_VERIFIER); +062 * }</pre> +063 */ +064 public static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = null; +065 +066 /** +067 * The default maximum number of times an API request will be retried after an error response +068 * is received. +069 */ +070 public static final int DEFAULT_MAX_RETRIES = 5; +071 /** +072 * Default authorization URL +073 */ +074 protected static final String DEFAULT_BASE_AUTHORIZATION_URL = "https://account.box.com/api/"; +075 static final String AS_USER_HEADER = "As-User"; +076 +077 private static final String API_VERSION = "2.0"; +078 private static final String OAUTH_SUFFIX = "oauth2/authorize"; +079 private static final String TOKEN_URL_SUFFIX = "oauth2/token"; +080 private static final String REVOKE_URL_SUFFIX = "oauth2/revoke"; +081 private static final String DEFAULT_BASE_URL = "https://api.box.com/"; +082 private static final String DEFAULT_BASE_UPLOAD_URL = "https://upload.box.com/api/"; +083 private static final String DEFAULT_BASE_APP_URL = "https://app.box.com"; +084 +085 private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications"; +086 +087 private static final String JAVA_VERSION = System.getProperty("java.version"); +088 private static final String SDK_VERSION = "4.11.0"; +089 +090 /** +091 * The amount of buffer time, in milliseconds, to use when determining if an access token should be refreshed. For +092 * example, if REFRESH_EPSILON = 60000 and the access token expires in less than one minute, it will be refreshed. +093 */ +094 private static final long REFRESH_EPSILON = 60000; +095 +096 private final String clientID; +097 private final String clientSecret; +098 private final ReadWriteLock refreshLock; +099 private X509TrustManager trustManager; +100 private HostnameVerifier hostnameVerifier; +101 +102 // These volatile fields are used when determining if the access token needs to be refreshed. Since they are used in +103 // the double-checked lock in getAccessToken(), they must be atomic. +104 private volatile long lastRefresh; +105 private volatile long expires; +106 +107 private Proxy proxy; +108 private String proxyUsername; +109 private String proxyPassword; +110 +111 private String userAgent; +112 private String accessToken; +113 private String refreshToken; +114 private String tokenURL; +115 private String revokeURL; +116 private String baseURL; +117 private String baseUploadURL; +118 private String baseAppURL; +119 private String baseAuthorizationURL; +120 private boolean autoRefresh; +121 private int maxRetryAttempts; +122 private int connectTimeout; +123 private int readTimeout; +124 private final List<BoxAPIConnectionListener> listeners; +125 private RequestInterceptor interceptor; +126 private final Map<String, String> customHeaders; +127 +128 private OkHttpClient httpClient; +129 private OkHttpClient noRedirectsHttpClient; +130 private Authenticator authenticator; +131 +132 /** +133 * Constructs a new BoxAPIConnection that authenticates with a developer or access token. +134 * +135 * @param accessToken a developer or access token to use for authenticating with the API. +136 */ +137 public BoxAPIConnection(String accessToken) { +138 this(null, null, accessToken, null); +139 } +140 +141 /** +142 * Constructs a new BoxAPIConnection with an access token that can be refreshed. +143 * +144 * @param clientID the client ID to use when refreshing the access token. +145 * @param clientSecret the client secret to use when refreshing the access token. +146 * @param accessToken an initial access token to use for authenticating with the API. +147 * @param refreshToken an initial refresh token to use when refreshing the access token. +148 */ +149 public BoxAPIConnection(String clientID, String clientSecret, String accessToken, String refreshToken) { +150 this.clientID = clientID; +151 this.clientSecret = clientSecret; +152 this.accessToken = accessToken; +153 this.refreshToken = refreshToken; +154 this.baseURL = fixBaseUrl(DEFAULT_BASE_URL); +155 this.baseUploadURL = fixBaseUrl(DEFAULT_BASE_UPLOAD_URL); +156 this.baseAppURL = DEFAULT_BASE_APP_URL; +157 this.baseAuthorizationURL = DEFAULT_BASE_AUTHORIZATION_URL; +158 this.autoRefresh = true; +159 this.maxRetryAttempts = BoxGlobalSettings.getMaxRetryAttempts(); +160 this.connectTimeout = BoxGlobalSettings.getConnectTimeout(); +161 this.readTimeout = BoxGlobalSettings.getReadTimeout(); +162 this.refreshLock = new ReentrantReadWriteLock(); +163 this.userAgent = "Box Java SDK v" + SDK_VERSION + " (Java " + JAVA_VERSION + ")"; +164 this.listeners = new ArrayList<>(); +165 this.customHeaders = new HashMap<>(); +166 +167 buildHttpClients(); +168 } +169 +170 /** +171 * Constructs a new BoxAPIConnection with an auth code that was obtained from the first half of OAuth. +172 * +173 * @param clientID the client ID to use when exchanging the auth code for an access token. +174 * @param clientSecret the client secret to use when exchanging the auth code for an access token. +175 * @param authCode an auth code obtained from the first half of the OAuth process. +176 */ +177 public BoxAPIConnection(String clientID, String clientSecret, String authCode) { +178 this(clientID, clientSecret, null, null); +179 this.authenticate(authCode); +180 } +181 +182 /** +183 * Constructs a new BoxAPIConnection. +184 * +185 * @param clientID the client ID to use when exchanging the auth code for an access token. +186 * @param clientSecret the client secret to use when exchanging the auth code for an access token. +187 */ +188 public BoxAPIConnection(String clientID, String clientSecret) { +189 this(clientID, clientSecret, null, null); +190 } +191 +192 /** +193 * Constructs a new BoxAPIConnection levaraging BoxConfig. +194 * +195 * @param boxConfig BoxConfig file, which should have clientId and clientSecret +196 */ +197 public BoxAPIConnection(BoxConfig boxConfig) { +198 this(boxConfig.getClientId(), boxConfig.getClientSecret(), null, null); +199 } +200 +201 private void buildHttpClients() { +202 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); +203 if (trustManager != null) { +204 try { +205 SSLContext sslContext = SSLContext.getInstance("SSL"); +206 sslContext.init(null, new TrustManager[]{trustManager}, new java.security.SecureRandom()); +207 httpClientBuilder.sslSocketFactory(sslContext.getSocketFactory(), trustManager); +208 } catch (NoSuchAlgorithmException | KeyManagementException e) { +209 throw new RuntimeException(e); +210 } +211 } +212 +213 OkHttpClient.Builder builder = httpClientBuilder +214 .followSslRedirects(true) +215 .followRedirects(true) +216 .connectTimeout(Duration.ofMillis(connectTimeout)) +217 .readTimeout(Duration.ofMillis(readTimeout)) +218 .connectionSpecs(singletonList(MODERN_TLS)); +219 +220 if (hostnameVerifier != null) { +221 httpClientBuilder.hostnameVerifier(hostnameVerifier); +222 } +223 +224 if (proxy != null) { +225 builder.proxy(proxy); +226 if (proxyUsername != null && proxyPassword != null) { +227 builder.proxyAuthenticator((route, response) -> { +228 String credential = Credentials.basic(proxyUsername, proxyPassword); +229 return response.request().newBuilder() +230 .header("Proxy-Authorization", credential) +231 .build(); +232 }); +233 } +234 if (this.authenticator != null) { +235 builder.proxyAuthenticator(authenticator); +236 } +237 } +238 builder = modifyHttpClientBuilder(builder); +239 +240 this.httpClient = builder.build(); +241 this.noRedirectsHttpClient = new OkHttpClient.Builder(httpClient) +242 .followSslRedirects(false) +243 .followRedirects(false) +244 .build(); +245 } +246 +247 /** +248 * Can be used to modify OkHttp.Builder used to create connection. This method is called after all modifications +249 * were done, thus allowing others to create their own connections and further customize builder. +250 * @param httpClientBuilder Builder that will be used to create http connection. +251 * @return Modified builder. +252 */ +253 protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder) { +254 return httpClientBuilder; +255 } +256 +257 /** +258 * Sets a proxy authenticator that will be used when proxy requires authentication. +259 * If you use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} it adds an authenticator +260 * that performs Basic authorization. By calling this method you can override this behaviour. +261 * You do not need to call {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +262 * in order to set custom authenticator. +263 * +264 * @param authenticator Custom authenticator that will be called when proxy asks for authorization. +265 */ +266 public void setProxyAuthenticator(Authenticator authenticator) { +267 this.authenticator = authenticator; +268 buildHttpClients(); +269 } +270 +271 /** +272 * Restores a BoxAPIConnection from a saved state. +273 * +274 * @param clientID the client ID to use with the connection. +275 * @param clientSecret the client secret to use with the connection. +276 * @param state the saved state that was created with {@link #save}. +277 * @return a restored API connection. +278 * @see #save +279 */ +280 public static BoxAPIConnection restore(String clientID, String clientSecret, String state) { +281 BoxAPIConnection api = new BoxAPIConnection(clientID, clientSecret); +282 api.restore(state); +283 return api; +284 } +285 +286 /** +287 * Returns the default authorization URL which is used to perform the authorization_code based OAuth2 flow. +288 * If custom Authorization URL is needed use instance method {@link BoxAPIConnection#getAuthorizationURL} +289 * +290 * @param clientID the client ID to use with the connection. +291 * @param redirectUri the URL to which Box redirects the browser when authentication completes. +292 * @param state the text string that you choose. +293 * Box sends the same string to your redirect URL when authentication is complete. +294 * @param scopes this optional parameter identifies the Box scopes available +295 * to the application once it's authenticated. +296 * @return the authorization URL +297 */ +298 public static URL getAuthorizationURL(String clientID, URI redirectUri, String state, List<String> scopes) { +299 return createFullAuthorizationUrl(DEFAULT_BASE_AUTHORIZATION_URL, clientID, redirectUri, state, scopes); +300 } +301 +302 private static URL createFullAuthorizationUrl( +303 String authorizationUrl, String clientID, URI redirectUri, String state, List<String> scopes +304 ) { +305 URLTemplate template = new URLTemplate(authorizationUrl + OAUTH_SUFFIX); +306 QueryStringBuilder queryBuilder = new QueryStringBuilder().appendParam("client_id", clientID) +307 .appendParam("response_type", "code") +308 .appendParam("redirect_uri", redirectUri.toString()) +309 .appendParam("state", state); +310 +311 if (scopes != null && !scopes.isEmpty()) { +312 queryBuilder.appendParam("scope", join(" ", scopes)); +313 } +314 +315 return template.buildWithQuery("", queryBuilder.toString()); +316 } +317 +318 /** +319 * Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained +320 * from the first half of OAuth. +321 * +322 * @param authCode the auth code obtained from the first half of the OAuth process. +323 */ +324 public void authenticate(String authCode) { +325 URL url; +326 try { +327 url = new URL(this.getTokenURL()); +328 } catch (MalformedURLException e) { +329 assert false : "An invalid token URL indicates a bug in the SDK."; +330 throw new RuntimeException("An invalid token URL indicates a bug in the SDK.", e); +331 } +332 +333 String urlParameters = format("grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s", +334 authCode, this.clientID, this.clientSecret); +335 +336 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +337 request.shouldAuthenticate(false); +338 request.setBody(urlParameters); +339 +340 // authentication uses form url encoded but response is JSON +341 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { +342 String json = response.getJSON(); +343 +344 JsonObject jsonObject = Json.parse(json).asObject(); +345 this.accessToken = jsonObject.get("access_token").asString(); +346 this.refreshToken = jsonObject.get("refresh_token").asString(); +347 this.lastRefresh = System.currentTimeMillis(); +348 this.expires = jsonObject.get("expires_in").asLong() * 1000; +349 } +350 } +351 +352 /** +353 * Gets the client ID. +354 * +355 * @return the client ID. +356 */ +357 public String getClientID() { +358 return this.clientID; +359 } +360 +361 /** +362 * Gets the client secret. +363 * +364 * @return the client secret. +365 */ +366 public String getClientSecret() { +367 return this.clientSecret; +368 } +369 +370 /** +371 * Gets the amount of time for which this connection's access token is valid. +372 * +373 * @return the amount of time in milliseconds. +374 */ +375 public long getExpires() { +376 return this.expires; +377 } +378 +379 /** +380 * Sets the amount of time for which this connection's access token is valid before it must be refreshed. +381 * +382 * @param milliseconds the number of milliseconds for which the access token is valid. +383 */ +384 public void setExpires(long milliseconds) { +385 this.expires = milliseconds; +386 } +387 +388 /** +389 * Gets the token URL that's used to request access tokens. The default value is +390 * "https://www.box.com/api/oauth2/token". +391 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#TOKEN_URL_SUFFIX}. +392 * +393 * @return the token URL. +394 */ +395 public String getTokenURL() { +396 if (this.tokenURL != null) { +397 return this.tokenURL; +398 } else { +399 return this.baseURL + TOKEN_URL_SUFFIX; +400 } +401 } +402 +403 /** +404 * Returns the URL used for token revocation. +405 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#REVOKE_URL_SUFFIX}. +406 * +407 * @return The url used for token revocation. +408 */ +409 public String getRevokeURL() { +410 if (this.revokeURL != null) { +411 return this.revokeURL; +412 } else { +413 return this.baseURL + REVOKE_URL_SUFFIX; +414 } +415 } +416 +417 /** +418 * Gets the base URL that's used when sending requests to the Box API. +419 * The URL is created from {@link BoxAPIConnection#baseURL} and {@link BoxAPIConnection#API_VERSION}. +420 * The default value is "https://api.box.com/2.0/". +421 * +422 * @return the base URL. +423 */ +424 public String getBaseURL() { +425 return this.baseURL + API_VERSION + "/"; +426 } +427 +428 /** +429 * Sets the base URL to be used when sending requests to the Box API. For example, the default base URL is +430 * "https://api.box.com/". This method changes how {@link BoxAPIConnection#getRevokeURL()} +431 * and {@link BoxAPIConnection#getTokenURL()} are constructed. +432 * +433 * @param baseURL a base URL +434 */ +435 public void setBaseURL(String baseURL) { +436 this.baseURL = fixBaseUrl(baseURL); +437 } +438 +439 /** +440 * Gets the base upload URL that's used when performing file uploads to Box. +441 * The URL is created from {@link BoxAPIConnection#baseUploadURL} and {@link BoxAPIConnection#API_VERSION}. +442 * +443 * @return the base upload URL. +444 */ +445 public String getBaseUploadURL() { +446 return this.baseUploadURL + API_VERSION + "/"; +447 } +448 +449 /** +450 * Sets the base upload URL to be used when performing file uploads to Box. +451 * +452 * @param baseUploadURL a base upload URL. +453 */ +454 public void setBaseUploadURL(String baseUploadURL) { +455 this.baseUploadURL = fixBaseUrl(baseUploadURL); +456 } +457 +458 /** +459 * Returns the authorization URL which is used to perform the authorization_code based OAuth2 flow. +460 * The URL is created from {@link BoxAPIConnection#baseAuthorizationURL} and {@link BoxAPIConnection#OAUTH_SUFFIX}. +461 * +462 * @param redirectUri the URL to which Box redirects the browser when authentication completes. +463 * @param state the text string that you choose. +464 * Box sends the same string to your redirect URL when authentication is complete. +465 * @param scopes this optional parameter identifies the Box scopes available +466 * to the application once it's authenticated. +467 * @return the authorization URL +468 */ +469 public URL getAuthorizationURL(URI redirectUri, String state, List<String> scopes) { +470 return createFullAuthorizationUrl(this.baseAuthorizationURL, this.clientID, redirectUri, state, scopes); +471 } +472 +473 /** +474 * Sets authorization base URL which is used to perform the authorization_code based OAuth2 flow. +475 * +476 * @param baseAuthorizationURL Authorization URL. Default value is https://account.box.com/api/. +477 */ +478 public void setBaseAuthorizationURL(String baseAuthorizationURL) { +479 this.baseAuthorizationURL = fixBaseUrl(baseAuthorizationURL); +480 } +481 +482 /** +483 * Gets the user agent that's used when sending requests to the Box API. +484 * +485 * @return the user agent. +486 */ +487 public String getUserAgent() { +488 return this.userAgent; +489 } +490 +491 /** +492 * Sets the user agent to be used when sending requests to the Box API. +493 * +494 * @param userAgent the user agent. +495 */ +496 public void setUserAgent(String userAgent) { +497 this.userAgent = userAgent; +498 } +499 +500 /** +501 * Gets the base App url. Used for e.g. file requests. +502 * +503 * @return the base App Url. +504 */ +505 public String getBaseAppUrl() { +506 return this.baseAppURL; +507 } +508 +509 /** +510 * Sets the base App url. Used for e.g. file requests. +511 * +512 * @param baseAppURL a base App Url. +513 */ +514 public void setBaseAppUrl(String baseAppURL) { +515 this.baseAppURL = baseAppURL; +516 } +517 +518 /** +519 * Gets an access token that can be used to authenticate an API request. This method will automatically refresh the +520 * access token if it has expired since the last call to <code>getAccessToken()</code>. +521 * +522 * @return a valid access token that can be used to authenticate an API request. +523 */ +524 public String getAccessToken() { +525 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { +526 this.refreshLock.writeLock().lock(); +527 try { +528 if (this.needsRefresh()) { +529 this.refresh(); +530 } +531 } finally { +532 this.refreshLock.writeLock().unlock(); +533 } +534 } +535 +536 return this.accessToken; +537 } +538 +539 /** +540 * Sets the access token to use when authenticating API requests. +541 * +542 * @param accessToken a valid access token to use when authenticating API requests. +543 */ +544 public void setAccessToken(String accessToken) { +545 this.accessToken = accessToken; +546 } +547 +548 /** +549 * Gets the refresh lock to be used when refreshing an access token. +550 * +551 * @return the refresh lock. +552 */ +553 protected ReadWriteLock getRefreshLock() { +554 return this.refreshLock; +555 } +556 +557 /** +558 * Gets a refresh token that can be used to refresh an access token. +559 * +560 * @return a valid refresh token. +561 */ +562 public String getRefreshToken() { +563 return this.refreshToken; +564 } +565 +566 /** +567 * Sets the refresh token to use when refreshing an access token. +568 * +569 * @param refreshToken a valid refresh token. +570 */ +571 public void setRefreshToken(String refreshToken) { +572 this.refreshToken = refreshToken; +573 } +574 +575 /** +576 * Gets the last time that the access token was refreshed. +577 * +578 * @return the last refresh time in milliseconds. +579 */ +580 public long getLastRefresh() { +581 return this.lastRefresh; +582 } +583 +584 /** +585 * Sets the last time that the access token was refreshed. +586 * +587 * <p>This value is used when determining if an access token needs to be auto-refreshed. If the amount of time since +588 * the last refresh exceeds the access token's expiration time, then the access token will be refreshed.</p> +589 * +590 * @param lastRefresh the new last refresh time in milliseconds. +591 */ +592 public void setLastRefresh(long lastRefresh) { +593 this.lastRefresh = lastRefresh; +594 } +595 +596 /** +597 * Gets whether or not automatic refreshing of this connection's access token is enabled. Defaults to true. +598 * +599 * @return true if auto token refresh is enabled; otherwise false. +600 */ +601 public boolean getAutoRefresh() { +602 return this.autoRefresh; +603 } +604 +605 /** +606 * Enables or disables automatic refreshing of this connection's access token. Defaults to true. +607 * +608 * @param autoRefresh true to enable auto token refresh; otherwise false. +609 */ +610 public void setAutoRefresh(boolean autoRefresh) { +611 this.autoRefresh = autoRefresh; +612 }613 -614 /** -615 * Gets the maximum number of times an API request will be retried after an error response -616 * is received. -617 * -618 * @return the maximum number of request attempts. -619 */ -620 public int getMaxRetryAttempts() { -621 return this.maxRetryAttempts; -622 } -623 -624 /** -625 * Sets the maximum number of times an API request will be retried after an error response -626 * is received. -627 * -628 * @param attempts the maximum number of request attempts. -629 */ -630 public void setMaxRetryAttempts(int attempts) { -631 this.maxRetryAttempts = attempts; -632 } -633 -634 /** -635 * Gets the connect timeout for this connection in milliseconds. -636 * -637 * @return the number of milliseconds to connect before timing out. -638 */ -639 public int getConnectTimeout() { -640 return this.connectTimeout; -641 } -642 -643 /** -644 * Sets the connect timeout for this connection. -645 * -646 * @param connectTimeout The number of milliseconds to wait for the connection to be established. -647 */ -648 public void setConnectTimeout(int connectTimeout) { -649 this.connectTimeout = connectTimeout; -650 buildHttpClients(); -651 } -652 -653 /** -654 * Gets the read timeout for this connection in milliseconds. -655 * -656 * @return the number of milliseconds to wait for bytes to be read before timing out. -657 */ -658 public int getReadTimeout() { -659 return this.readTimeout; -660 } -661 -662 /** -663 * Sets the read timeout for this connection. -664 * -665 * @param readTimeout The number of milliseconds to wait for bytes to be read. -666 */ -667 public void setReadTimeout(int readTimeout) { -668 this.readTimeout = readTimeout; -669 buildHttpClients(); -670 } -671 -672 /** -673 * Gets the proxy value to use for API calls to Box. -674 * -675 * @return the current proxy. -676 */ -677 public Proxy getProxy() { -678 return this.proxy; -679 } -680 -681 /** -682 * Sets the proxy to use for API calls to Box. -683 * -684 * @param proxy the proxy to use for API calls to Box. -685 */ -686 public void setProxy(Proxy proxy) { -687 this.proxy = proxy; -688 buildHttpClients(); -689 } -690 -691 /** -692 * Gets the username to use for a proxy that requires basic auth. -693 * -694 * @return the username to use for a proxy that requires basic auth. -695 */ -696 public String getProxyUsername() { -697 return this.proxyUsername; -698 } -699 -700 /** -701 * Sets the username to use for a proxy that requires basic auth. -702 * -703 * @param proxyUsername the username to use for a proxy that requires basic auth. -704 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -705 */ -706 public void setProxyUsername(String proxyUsername) { -707 this.proxyUsername = proxyUsername; -708 buildHttpClients(); -709 } -710 -711 /** -712 * Gets the password to use for a proxy that requires basic auth. -713 * -714 * @return the password to use for a proxy that requires basic auth. -715 */ -716 public String getProxyPassword() { -717 return this.proxyPassword; -718 } -719 -720 /** -721 * Sets the proxy user and password used in basic authentication -722 * -723 * @param proxyUsername Username to use for a proxy that requires basic auth. -724 * @param proxyPassword Password to use for a proxy that requires basic auth. -725 */ -726 public void setProxyBasicAuthentication(String proxyUsername, String proxyPassword) { -727 this.proxyUsername = proxyUsername; -728 this.proxyPassword = proxyPassword; -729 buildHttpClients(); -730 } -731 -732 /** -733 * Sets the password to use for a proxy that requires basic auth. -734 * -735 * @param proxyPassword the password to use for a proxy that requires basic auth. -736 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} -737 */ -738 public void setProxyPassword(String proxyPassword) { -739 this.proxyPassword = proxyPassword; -740 buildHttpClients(); -741 } -742 -743 /** -744 * Determines if this connection's access token can be refreshed. An access token cannot be refreshed if a refresh -745 * token was never set. -746 * -747 * @return true if the access token can be refreshed; otherwise false. -748 */ -749 public boolean canRefresh() { -750 return this.refreshToken != null; -751 } -752 -753 /** -754 * Determines if this connection's access token has expired and needs to be refreshed. -755 * -756 * @return true if the access token needs to be refreshed; otherwise false. -757 */ -758 public boolean needsRefresh() { -759 boolean needsRefresh; -760 -761 this.refreshLock.readLock().lock(); -762 long now = System.currentTimeMillis(); -763 long tokenDuration = (now - this.lastRefresh); -764 needsRefresh = (tokenDuration >= this.expires - REFRESH_EPSILON); -765 this.refreshLock.readLock().unlock(); -766 -767 return needsRefresh; -768 } -769 -770 /** -771 * Refresh's this connection's access token using its refresh token. -772 * -773 * @throws IllegalStateException if this connection's access token cannot be refreshed. -774 */ -775 public void refresh() { -776 this.refreshLock.writeLock().lock(); -777 -778 if (!this.canRefresh()) { -779 this.refreshLock.writeLock().unlock(); -780 throw new IllegalStateException("The BoxAPIConnection cannot be refreshed because it doesn't have a " -781 + "refresh token."); -782 } -783 -784 URL url; -785 try { -786 url = new URL(getTokenURL()); -787 } catch (MalformedURLException e) { -788 this.refreshLock.writeLock().unlock(); -789 assert false : "An invalid refresh URL indicates a bug in the SDK."; -790 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); -791 } -792 -793 BoxAPIRequest request = createTokenRequest(url); -794 -795 String json; -796 try (BoxAPIResponse boxAPIResponse = request.send()) { -797 BoxJSONResponse response = (BoxJSONResponse) boxAPIResponse; -798 json = response.getJSON(); -799 } catch (BoxAPIException e) { -800 this.refreshLock.writeLock().unlock(); -801 this.notifyError(e); -802 throw e; -803 } -804 -805 try { -806 extractTokens(Json.parse(json).asObject()); -807 -808 this.notifyRefresh(); -809 } finally { -810 this.refreshLock.writeLock().unlock(); -811 } -812 } -813 -814 /** -815 * Restores a saved connection state into this BoxAPIConnection. -816 * -817 * @param state the saved state that was created with {@link #save}. -818 * @see #save -819 */ -820 public void restore(String state) { -821 JsonObject json = Json.parse(state).asObject(); -822 String accessToken = json.get("accessToken").asString(); -823 String refreshToken = getKeyValueOrDefault(json, "refreshToken", null); -824 long lastRefresh = json.get("lastRefresh").asLong(); -825 long expires = json.get("expires").asLong(); -826 String userAgent = json.get("userAgent").asString(); -827 String tokenURL = getKeyValueOrDefault(json, "tokenURL", null); -828 String revokeURL = getKeyValueOrDefault(json, "revokeURL", null); -829 String baseURL = adoptBaseUrlWhenLoadingFromOldVersion( -830 getKeyValueOrDefault(json, "baseURL", DEFAULT_BASE_URL) -831 ); -832 String baseUploadURL = adoptUploadBaseUrlWhenLoadingFromOldVersion( -833 getKeyValueOrDefault(json, "baseUploadURL", DEFAULT_BASE_UPLOAD_URL) -834 ); -835 String authorizationURL = -836 getKeyValueOrDefault(json, "authorizationURL", DEFAULT_BASE_AUTHORIZATION_URL); -837 boolean autoRefresh = json.get("autoRefresh").asBoolean(); -838 -839 // Try to read deprecated value -840 int maxRequestAttempts = -1; -841 if (json.names().contains("maxRequestAttempts")) { -842 maxRequestAttempts = json.get("maxRequestAttempts").asInt(); -843 } -844 -845 int maxRetryAttempts = -1; -846 if (json.names().contains("maxRetryAttempts")) { -847 maxRetryAttempts = json.get("maxRetryAttempts").asInt(); -848 } -849 -850 this.accessToken = accessToken; -851 this.refreshToken = refreshToken; -852 this.lastRefresh = lastRefresh; -853 this.expires = expires; -854 this.userAgent = userAgent; -855 this.tokenURL = tokenURL; -856 this.revokeURL = revokeURL; -857 this.setBaseURL(baseURL); -858 this.setBaseUploadURL(baseUploadURL); -859 this.setBaseAuthorizationURL(authorizationURL); -860 this.autoRefresh = autoRefresh; -861 -862 // Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts" -863 if (maxRequestAttempts > -1) { -864 this.maxRetryAttempts = maxRequestAttempts - 1; -865 } -866 if (maxRetryAttempts > -1) { -867 this.maxRetryAttempts = maxRetryAttempts; -868 } -869 -870 } -871 -872 private String adoptBaseUrlWhenLoadingFromOldVersion(String url) { -873 if (url == null) { -874 return null; -875 } -876 String urlEndingWithSlash = fixBaseUrl(url); -877 return urlEndingWithSlash.equals("https://api.box.com/2.0/") -878 ? DEFAULT_BASE_URL -879 : urlEndingWithSlash; -880 } -881 -882 private String adoptUploadBaseUrlWhenLoadingFromOldVersion(String url) { -883 if (url == null) { -884 return null; -885 } -886 String urlEndingWithSlash = fixBaseUrl(url); -887 return urlEndingWithSlash.equals("https://upload.box.com/api/2.0/") -888 ? DEFAULT_BASE_UPLOAD_URL -889 : urlEndingWithSlash; -890 } -891 -892 protected String getKeyValueOrDefault(JsonObject json, String key, String defaultValue) { -893 return Optional.ofNullable(json.get(key)) -894 .filter(js -> !js.isNull()) -895 .map(JsonValue::asString) -896 .orElse(defaultValue); -897 } -898 -899 /** -900 * Notifies a refresh event to all the listeners. -901 */ -902 protected void notifyRefresh() { -903 for (BoxAPIConnectionListener listener : this.listeners) { -904 listener.onRefresh(this); -905 } -906 } -907 -908 /** -909 * Notifies an error event to all the listeners. -910 * -911 * @param error A BoxAPIException instance. -912 */ -913 protected void notifyError(BoxAPIException error) { -914 for (BoxAPIConnectionListener listener : this.listeners) { -915 listener.onError(this, error); -916 } -917 } -918 -919 /** -920 * Add a listener to listen to Box API connection events. -921 * -922 * @param listener a listener to listen to Box API connection. -923 */ -924 public void addListener(BoxAPIConnectionListener listener) { -925 this.listeners.add(listener); -926 } -927 -928 /** -929 * Remove a listener listening to Box API connection events. -930 * -931 * @param listener the listener to remove. -932 */ -933 public void removeListener(BoxAPIConnectionListener listener) { -934 this.listeners.remove(listener); -935 } -936 -937 /** -938 * Gets the RequestInterceptor associated with this API connection. -939 * -940 * @return the RequestInterceptor associated with this API connection. -941 */ -942 public RequestInterceptor getRequestInterceptor() { -943 return this.interceptor; -944 } -945 -946 /** -947 * Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API. -948 * -949 * @param interceptor the RequestInterceptor. -950 */ -951 public void setRequestInterceptor(RequestInterceptor interceptor) { -952 this.interceptor = interceptor; -953 } -954 -955 /** -956 * Get a lower-scoped token restricted to a resource for the list of scopes that are passed. -957 * -958 * @param scopes the list of scopes to which the new token should be restricted for -959 * @param resource the resource for which the new token has to be obtained -960 * @return scopedToken which has access token and other details -961 * @throws BoxAPIException if resource is not a valid Box API endpoint or shared link -962 */ -963 public ScopedToken getLowerScopedToken(List<String> scopes, String resource) { -964 assert (scopes != null); -965 assert (scopes.size() > 0); -966 URL url; -967 try { -968 url = new URL(this.getTokenURL()); -969 } catch (MalformedURLException e) { -970 assert false : "An invalid refresh URL indicates a bug in the SDK."; -971 throw new BoxAPIException("An invalid refresh URL indicates a bug in the SDK.", e); -972 } -973 -974 StringBuilder spaceSeparatedScopes = this.buildScopesForTokenDownscoping(scopes); -975 -976 String urlParameters = format("grant_type=urn:ietf:params:oauth:grant-type:token-exchange" -977 + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" -978 + "&scope=%s", -979 this.getAccessToken(), spaceSeparatedScopes); -980 -981 if (resource != null) { -982 -983 ResourceLinkType resourceType = this.determineResourceLinkType(resource); -984 -985 if (resourceType == ResourceLinkType.APIEndpoint) { -986 urlParameters = format(urlParameters + "&resource=%s", resource); -987 } else if (resourceType == ResourceLinkType.SharedLink) { -988 urlParameters = format(urlParameters + "&box_shared_link=%s", resource); -989 } else if (resourceType == ResourceLinkType.Unknown) { -990 String argExceptionMessage = format("Unable to determine resource type: %s", resource); -991 BoxAPIException e = new BoxAPIException(argExceptionMessage); -992 this.notifyError(e); -993 throw e; -994 } else { -995 String argExceptionMessage = format("Unhandled resource type: %s", resource); -996 BoxAPIException e = new BoxAPIException(argExceptionMessage); -997 this.notifyError(e); -998 throw e; -999 } -1000 } -1001 -1002 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1003 request.shouldAuthenticate(false); -1004 request.setBody(urlParameters); -1005 -1006 String jsonResponse; -1007 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { -1008 jsonResponse = response.getJSON(); -1009 } catch (BoxAPIException e) { -1010 this.notifyError(e); -1011 throw e; -1012 } -1013 -1014 JsonObject jsonObject = Json.parse(jsonResponse).asObject(); -1015 ScopedToken token = new ScopedToken(jsonObject); -1016 token.setObtainedAt(System.currentTimeMillis()); -1017 token.setExpiresIn(jsonObject.get("expires_in").asLong() * 1000); -1018 return token; -1019 } -1020 -1021 /** -1022 * Convert List<String> to space-delimited String. -1023 * Needed for versions prior to Java 8, which don't have String.join(delimiter, list) -1024 * -1025 * @param scopes the list of scopes to read from -1026 * @return space-delimited String of scopes -1027 */ -1028 private StringBuilder buildScopesForTokenDownscoping(List<String> scopes) { -1029 StringBuilder spaceSeparatedScopes = new StringBuilder(); -1030 for (int i = 0; i < scopes.size(); i++) { -1031 spaceSeparatedScopes.append(scopes.get(i)); -1032 if (i < scopes.size() - 1) { -1033 spaceSeparatedScopes.append(" "); -1034 } -1035 } -1036 -1037 return spaceSeparatedScopes; -1038 } -1039 -1040 /** -1041 * Determines the type of resource, given a link to a Box resource. -1042 * -1043 * @param resourceLink the resource URL to check -1044 * @return ResourceLinkType that categorizes the provided resourceLink -1045 */ -1046 protected ResourceLinkType determineResourceLinkType(String resourceLink) { -1047 -1048 ResourceLinkType resourceType = ResourceLinkType.Unknown; -1049 -1050 try { -1051 URL validUrl = new URL(resourceLink); -1052 String validURLStr = validUrl.toString(); -1053 final String apiFilesEndpointPattern = ".*box.com/2.0/files/\\d+"; -1054 final String apiFoldersEndpointPattern = ".*box.com/2.0/folders/\\d+"; -1055 final String sharedLinkPattern = "(.*box.com/s/.*|.*box.com.*s=.*)"; -1056 -1057 if (Pattern.matches(apiFilesEndpointPattern, validURLStr) -1058 || Pattern.matches(apiFoldersEndpointPattern, validURLStr)) { -1059 resourceType = ResourceLinkType.APIEndpoint; -1060 } else if (Pattern.matches(sharedLinkPattern, validURLStr)) { -1061 resourceType = ResourceLinkType.SharedLink; -1062 } -1063 } catch (MalformedURLException e) { -1064 //Swallow exception and return default ResourceLinkType set at top of function -1065 } -1066 -1067 return resourceType; -1068 } -1069 -1070 /** -1071 * Revokes the tokens associated with this API connection. This results in the connection no -1072 * longer being able to make API calls until a fresh authorization is made by calling authenticate() -1073 */ -1074 public void revokeToken() { -1075 -1076 URL url; -1077 try { -1078 url = new URL(getRevokeURL()); -1079 } catch (MalformedURLException e) { -1080 assert false : "An invalid refresh URL indicates a bug in the SDK."; -1081 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); -1082 } -1083 -1084 String urlParameters = format("token=%s&client_id=%s&client_secret=%s", -1085 this.accessToken, this.clientID, this.clientSecret); -1086 -1087 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1088 request.shouldAuthenticate(false); -1089 request.setBody(urlParameters); -1090 -1091 request.send().close(); -1092 } -1093 -1094 /** -1095 * Saves the state of this connection to a string so that it can be persisted and restored at a later time. -1096 * -1097 * <p>Note that proxy settings aren't automatically saved or restored. This is mainly due to security concerns -1098 * around persisting proxy authentication details to the state string. If your connection uses a proxy, you will -1099 * have to manually configure it again after restoring the connection.</p> -1100 * -1101 * @return the state of this connection. -1102 * @see #restore -1103 */ -1104 public String save() { -1105 JsonObject state = new JsonObject() -1106 .add("accessToken", this.accessToken) -1107 .add("refreshToken", this.refreshToken) -1108 .add("lastRefresh", this.lastRefresh) -1109 .add("expires", this.expires) -1110 .add("userAgent", this.userAgent) -1111 .add("tokenURL", this.tokenURL) -1112 .add("revokeURL", this.revokeURL) -1113 .add("baseURL", this.baseURL) -1114 .add("baseUploadURL", this.baseUploadURL) -1115 .add("authorizationURL", this.baseAuthorizationURL) -1116 .add("autoRefresh", this.autoRefresh) -1117 .add("maxRetryAttempts", this.maxRetryAttempts); -1118 return state.toString(); -1119 } -1120 -1121 String lockAccessToken() { -1122 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { -1123 this.refreshLock.writeLock().lock(); -1124 try { -1125 if (this.needsRefresh()) { -1126 this.refresh(); -1127 } -1128 this.refreshLock.readLock().lock(); -1129 } finally { -1130 this.refreshLock.writeLock().unlock(); -1131 } -1132 } else { -1133 this.refreshLock.readLock().lock(); -1134 } -1135 -1136 return this.accessToken; -1137 } -1138 -1139 void unlockAccessToken() { -1140 this.refreshLock.readLock().unlock(); -1141 } -1142 -1143 /** -1144 * Get the value for the X-Box-UA header. -1145 * -1146 * @return the header value. -1147 */ -1148 String getBoxUAHeader() { -1149 -1150 return "agent=box-java-sdk/" + SDK_VERSION + "; env=Java/" + JAVA_VERSION; -1151 } -1152 -1153 /** -1154 * Sets a custom header to be sent on all requests through this API connection. -1155 * -1156 * @param header the header name. -1157 * @param value the header value. -1158 */ -1159 public void setCustomHeader(String header, String value) { -1160 this.customHeaders.put(header, value); -1161 } -1162 -1163 /** -1164 * Removes a custom header, so it will no longer be sent on requests through this API connection. -1165 * -1166 * @param header the header name. -1167 */ -1168 public void removeCustomHeader(String header) { -1169 this.customHeaders.remove(header); -1170 } -1171 -1172 /** -1173 * Suppresses email notifications from API actions. This is typically used by security or admin applications -1174 * to prevent spamming end users when doing automated processing on their content. -1175 */ -1176 public void suppressNotifications() { -1177 this.setCustomHeader(BOX_NOTIFICATIONS_HEADER, "off"); -1178 } -1179 -1180 /** -1181 * Re-enable email notifications from API actions if they have been suppressed. -1182 * -1183 * @see #suppressNotifications -1184 */ -1185 public void enableNotifications() { -1186 this.removeCustomHeader(BOX_NOTIFICATIONS_HEADER); -1187 } -1188 -1189 /** -1190 * Set this API connection to make API calls on behalf of another users, impersonating them. This -1191 * functionality can only be used by admins and service accounts. -1192 * -1193 * @param userID the ID of the user to act as. -1194 */ -1195 public void asUser(String userID) { -1196 this.setCustomHeader(AS_USER_HEADER, userID); -1197 } -1198 -1199 /** -1200 * Sets this API connection to make API calls on behalf of the user with whom the access token is associated. -1201 * This undoes any previous calls to asUser(). -1202 * -1203 * @see #asUser -1204 */ -1205 public void asSelf() { -1206 this.removeCustomHeader(AS_USER_HEADER); -1207 } -1208 -1209 /** -1210 * Used to override default SSL certification handling. For example, you can provide your own -1211 * trust manager or hostname verifier to allow self-signed certificates. -1212 * You can check examples <a href="https://github.com/box/box-java-sdk/blob/main/doc/configuration.md#ssl-configuration">here</a>. -1213 * -1214 * @param trustManager TrustManager that verifies certificates are valid. -1215 * @param hostnameVerifier HostnameVerifier that allows you to specify what hostnames are allowed. -1216 */ -1217 public void configureSslCertificatesValidation(X509TrustManager trustManager, HostnameVerifier hostnameVerifier) { -1218 this.trustManager = trustManager; -1219 this.hostnameVerifier = hostnameVerifier; -1220 buildHttpClients(); -1221 } -1222 -1223 Map<String, String> getHeaders() { -1224 return this.customHeaders; -1225 } -1226 -1227 protected void extractTokens(JsonObject jsonObject) { -1228 this.accessToken = jsonObject.get("access_token").asString(); -1229 this.refreshToken = jsonObject.get("refresh_token").asString(); -1230 this.lastRefresh = System.currentTimeMillis(); -1231 this.expires = jsonObject.get("expires_in").asLong() * 1000; -1232 } -1233 -1234 protected BoxAPIRequest createTokenRequest(URL url) { -1235 String urlParameters = format("grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s", -1236 this.refreshToken, this.clientID, this.clientSecret); -1237 -1238 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); -1239 request.shouldAuthenticate(false); -1240 request.setBody(urlParameters); -1241 return request; -1242 } -1243 -1244 private String fixBaseUrl(String baseUrl) { -1245 return baseUrl.endsWith("/") ? baseUrl : baseUrl + "/"; -1246 } -1247 -1248 Response execute(Request request) { -1249 return executeOnClient(httpClient, request); -1250 } -1251 -1252 Response executeWithoutRedirect(Request request) { -1253 return executeOnClient(noRedirectsHttpClient, request); -1254 } -1255 -1256 private Response executeOnClient(OkHttpClient httpClient, Request request) { -1257 try { -1258 return httpClient.newCall(request).execute(); -1259 } catch (IOException e) { -1260 throw new BoxAPIException("Couldn't connect to the Box API due to a network error. Request\n" + request, e); -1261 } -1262 } -1263 -1264 protected X509TrustManager getTrustManager() { -1265 return trustManager; -1266 } -1267 -1268 protected HostnameVerifier getHostnameVerifier() { -1269 return hostnameVerifier; -1270 } -1271 -1272 /** -1273 * Used to categorize the types of resource links. -1274 */ -1275 protected enum ResourceLinkType { -1276 /** -1277 * Catch-all default for resource links that are unknown. -1278 */ -1279 Unknown, -1280 +614 +615 /** +616 * Gets the maximum number of times an API request will be retried after an error response +617 * is received. +618 * +619 * @return the maximum number of request attempts. +620 */ +621 public int getMaxRetryAttempts() { +622 return this.maxRetryAttempts; +623 } +624 +625 /** +626 * Sets the maximum number of times an API request will be retried after an error response +627 * is received. +628 * +629 * @param attempts the maximum number of request attempts. +630 */ +631 public void setMaxRetryAttempts(int attempts) { +632 this.maxRetryAttempts = attempts; +633 } +634 +635 /** +636 * Gets the connect timeout for this connection in milliseconds. +637 * +638 * @return the number of milliseconds to connect before timing out. +639 */ +640 public int getConnectTimeout() { +641 return this.connectTimeout; +642 } +643 +644 /** +645 * Sets the connect timeout for this connection. +646 * +647 * @param connectTimeout The number of milliseconds to wait for the connection to be established. +648 */ +649 public void setConnectTimeout(int connectTimeout) { +650 this.connectTimeout = connectTimeout; +651 buildHttpClients(); +652 } +653 +654 /** +655 * Gets the read timeout for this connection in milliseconds. +656 * +657 * @return the number of milliseconds to wait for bytes to be read before timing out. +658 */ +659 public int getReadTimeout() { +660 return this.readTimeout; +661 } +662 +663 /** +664 * Sets the read timeout for this connection. +665 * +666 * @param readTimeout The number of milliseconds to wait for bytes to be read. +667 */ +668 public void setReadTimeout(int readTimeout) { +669 this.readTimeout = readTimeout; +670 buildHttpClients(); +671 } +672 +673 /** +674 * Gets the proxy value to use for API calls to Box. +675 * +676 * @return the current proxy. +677 */ +678 public Proxy getProxy() { +679 return this.proxy; +680 } +681 +682 /** +683 * Sets the proxy to use for API calls to Box. +684 * +685 * @param proxy the proxy to use for API calls to Box. +686 */ +687 public void setProxy(Proxy proxy) { +688 this.proxy = proxy; +689 buildHttpClients(); +690 } +691 +692 /** +693 * Gets the username to use for a proxy that requires basic auth. +694 * +695 * @return the username to use for a proxy that requires basic auth. +696 */ +697 public String getProxyUsername() { +698 return this.proxyUsername; +699 } +700 +701 /** +702 * Sets the username to use for a proxy that requires basic auth. +703 * +704 * @param proxyUsername the username to use for a proxy that requires basic auth. +705 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +706 */ +707 public void setProxyUsername(String proxyUsername) { +708 this.proxyUsername = proxyUsername; +709 buildHttpClients(); +710 } +711 +712 /** +713 * Gets the password to use for a proxy that requires basic auth. +714 * +715 * @return the password to use for a proxy that requires basic auth. +716 */ +717 public String getProxyPassword() { +718 return this.proxyPassword; +719 } +720 +721 /** +722 * Sets the proxy user and password used in basic authentication +723 * +724 * @param proxyUsername Username to use for a proxy that requires basic auth. +725 * @param proxyPassword Password to use for a proxy that requires basic auth. +726 */ +727 public void setProxyBasicAuthentication(String proxyUsername, String proxyPassword) { +728 this.proxyUsername = proxyUsername; +729 this.proxyPassword = proxyPassword; +730 buildHttpClients(); +731 } +732 +733 /** +734 * Sets the password to use for a proxy that requires basic auth. +735 * +736 * @param proxyPassword the password to use for a proxy that requires basic auth. +737 * @deprecated Use {@link BoxAPIConnection#setProxyBasicAuthentication(String, String)} +738 */ +739 public void setProxyPassword(String proxyPassword) { +740 this.proxyPassword = proxyPassword; +741 buildHttpClients(); +742 } +743 +744 /** +745 * Determines if this connection's access token can be refreshed. An access token cannot be refreshed if a refresh +746 * token was never set. +747 * +748 * @return true if the access token can be refreshed; otherwise false. +749 */ +750 public boolean canRefresh() { +751 return this.refreshToken != null; +752 } +753 +754 /** +755 * Determines if this connection's access token has expired and needs to be refreshed. +756 * +757 * @return true if the access token needs to be refreshed; otherwise false. +758 */ +759 public boolean needsRefresh() { +760 boolean needsRefresh; +761 +762 this.refreshLock.readLock().lock(); +763 long now = System.currentTimeMillis(); +764 long tokenDuration = (now - this.lastRefresh); +765 needsRefresh = (tokenDuration >= this.expires - REFRESH_EPSILON); +766 this.refreshLock.readLock().unlock(); +767 +768 return needsRefresh; +769 } +770 +771 /** +772 * Refresh's this connection's access token using its refresh token. +773 * +774 * @throws IllegalStateException if this connection's access token cannot be refreshed. +775 */ +776 public void refresh() { +777 this.refreshLock.writeLock().lock(); +778 +779 if (!this.canRefresh()) { +780 this.refreshLock.writeLock().unlock(); +781 throw new IllegalStateException("The BoxAPIConnection cannot be refreshed because it doesn't have a " +782 + "refresh token."); +783 } +784 +785 URL url; +786 try { +787 url = new URL(getTokenURL()); +788 } catch (MalformedURLException e) { +789 this.refreshLock.writeLock().unlock(); +790 assert false : "An invalid refresh URL indicates a bug in the SDK."; +791 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); +792 } +793 +794 BoxAPIRequest request = createTokenRequest(url); +795 +796 String json; +797 try (BoxAPIResponse boxAPIResponse = request.send()) { +798 BoxJSONResponse response = (BoxJSONResponse) boxAPIResponse; +799 json = response.getJSON(); +800 } catch (BoxAPIException e) { +801 this.refreshLock.writeLock().unlock(); +802 this.notifyError(e); +803 throw e; +804 } +805 +806 try { +807 extractTokens(Json.parse(json).asObject()); +808 +809 this.notifyRefresh(); +810 } finally { +811 this.refreshLock.writeLock().unlock(); +812 } +813 } +814 +815 /** +816 * Restores a saved connection state into this BoxAPIConnection. +817 * +818 * @param state the saved state that was created with {@link #save}. +819 * @see #save +820 */ +821 public void restore(String state) { +822 JsonObject json = Json.parse(state).asObject(); +823 String accessToken = json.get("accessToken").asString(); +824 String refreshToken = getKeyValueOrDefault(json, "refreshToken", null); +825 long lastRefresh = json.get("lastRefresh").asLong(); +826 long expires = json.get("expires").asLong(); +827 String userAgent = json.get("userAgent").asString(); +828 String tokenURL = getKeyValueOrDefault(json, "tokenURL", null); +829 String revokeURL = getKeyValueOrDefault(json, "revokeURL", null); +830 String baseURL = adoptBaseUrlWhenLoadingFromOldVersion( +831 getKeyValueOrDefault(json, "baseURL", DEFAULT_BASE_URL) +832 ); +833 String baseUploadURL = adoptUploadBaseUrlWhenLoadingFromOldVersion( +834 getKeyValueOrDefault(json, "baseUploadURL", DEFAULT_BASE_UPLOAD_URL) +835 ); +836 String authorizationURL = +837 getKeyValueOrDefault(json, "authorizationURL", DEFAULT_BASE_AUTHORIZATION_URL); +838 boolean autoRefresh = json.get("autoRefresh").asBoolean(); +839 +840 // Try to read deprecated value +841 int maxRequestAttempts = -1; +842 if (json.names().contains("maxRequestAttempts")) { +843 maxRequestAttempts = json.get("maxRequestAttempts").asInt(); +844 } +845 +846 int maxRetryAttempts = -1; +847 if (json.names().contains("maxRetryAttempts")) { +848 maxRetryAttempts = json.get("maxRetryAttempts").asInt(); +849 } +850 +851 this.accessToken = accessToken; +852 this.refreshToken = refreshToken; +853 this.lastRefresh = lastRefresh; +854 this.expires = expires; +855 this.userAgent = userAgent; +856 this.tokenURL = tokenURL; +857 this.revokeURL = revokeURL; +858 this.setBaseURL(baseURL); +859 this.setBaseUploadURL(baseUploadURL); +860 this.setBaseAuthorizationURL(authorizationURL); +861 this.autoRefresh = autoRefresh; +862 +863 // Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts" +864 if (maxRequestAttempts > -1) { +865 this.maxRetryAttempts = maxRequestAttempts - 1; +866 } +867 if (maxRetryAttempts > -1) { +868 this.maxRetryAttempts = maxRetryAttempts; +869 } +870 +871 } +872 +873 private String adoptBaseUrlWhenLoadingFromOldVersion(String url) { +874 if (url == null) { +875 return null; +876 } +877 String urlEndingWithSlash = fixBaseUrl(url); +878 return urlEndingWithSlash.equals("https://api.box.com/2.0/") +879 ? DEFAULT_BASE_URL +880 : urlEndingWithSlash; +881 } +882 +883 private String adoptUploadBaseUrlWhenLoadingFromOldVersion(String url) { +884 if (url == null) { +885 return null; +886 } +887 String urlEndingWithSlash = fixBaseUrl(url); +888 return urlEndingWithSlash.equals("https://upload.box.com/api/2.0/") +889 ? DEFAULT_BASE_UPLOAD_URL +890 : urlEndingWithSlash; +891 } +892 +893 protected String getKeyValueOrDefault(JsonObject json, String key, String defaultValue) { +894 return Optional.ofNullable(json.get(key)) +895 .filter(js -> !js.isNull()) +896 .map(JsonValue::asString) +897 .orElse(defaultValue); +898 } +899 +900 /** +901 * Notifies a refresh event to all the listeners. +902 */ +903 protected void notifyRefresh() { +904 for (BoxAPIConnectionListener listener : this.listeners) { +905 listener.onRefresh(this); +906 } +907 } +908 +909 /** +910 * Notifies an error event to all the listeners. +911 * +912 * @param error A BoxAPIException instance. +913 */ +914 protected void notifyError(BoxAPIException error) { +915 for (BoxAPIConnectionListener listener : this.listeners) { +916 listener.onError(this, error); +917 } +918 } +919 +920 /** +921 * Add a listener to listen to Box API connection events. +922 * +923 * @param listener a listener to listen to Box API connection. +924 */ +925 public void addListener(BoxAPIConnectionListener listener) { +926 this.listeners.add(listener); +927 } +928 +929 /** +930 * Remove a listener listening to Box API connection events. +931 * +932 * @param listener the listener to remove. +933 */ +934 public void removeListener(BoxAPIConnectionListener listener) { +935 this.listeners.remove(listener); +936 } +937 +938 /** +939 * Gets the RequestInterceptor associated with this API connection. +940 * +941 * @return the RequestInterceptor associated with this API connection. +942 */ +943 public RequestInterceptor getRequestInterceptor() { +944 return this.interceptor; +945 } +946 +947 /** +948 * Sets a RequestInterceptor that can intercept requests and manipulate them before they're sent to the Box API. +949 * +950 * @param interceptor the RequestInterceptor. +951 */ +952 public void setRequestInterceptor(RequestInterceptor interceptor) { +953 this.interceptor = interceptor; +954 } +955 +956 /** +957 * Get a lower-scoped token restricted to a resource for the list of scopes that are passed. +958 * +959 * @param scopes the list of scopes to which the new token should be restricted for +960 * @param resource the resource for which the new token has to be obtained +961 * @return scopedToken which has access token and other details +962 * @throws BoxAPIException if resource is not a valid Box API endpoint or shared link +963 */ +964 public ScopedToken getLowerScopedToken(List<String> scopes, String resource) { +965 assert (scopes != null); +966 assert (scopes.size() > 0); +967 URL url; +968 try { +969 url = new URL(this.getTokenURL()); +970 } catch (MalformedURLException e) { +971 assert false : "An invalid refresh URL indicates a bug in the SDK."; +972 throw new BoxAPIException("An invalid refresh URL indicates a bug in the SDK.", e); +973 } +974 +975 StringBuilder spaceSeparatedScopes = this.buildScopesForTokenDownscoping(scopes); +976 +977 String urlParameters = format("grant_type=urn:ietf:params:oauth:grant-type:token-exchange" +978 + "&subject_token_type=urn:ietf:params:oauth:token-type:access_token&subject_token=%s" +979 + "&scope=%s", +980 this.getAccessToken(), spaceSeparatedScopes); +981 +982 if (resource != null) { +983 +984 ResourceLinkType resourceType = this.determineResourceLinkType(resource); +985 +986 if (resourceType == ResourceLinkType.APIEndpoint) { +987 urlParameters = format(urlParameters + "&resource=%s", resource); +988 } else if (resourceType == ResourceLinkType.SharedLink) { +989 urlParameters = format(urlParameters + "&box_shared_link=%s", resource); +990 } else if (resourceType == ResourceLinkType.Unknown) { +991 String argExceptionMessage = format("Unable to determine resource type: %s", resource); +992 BoxAPIException e = new BoxAPIException(argExceptionMessage); +993 this.notifyError(e); +994 throw e; +995 } else { +996 String argExceptionMessage = format("Unhandled resource type: %s", resource); +997 BoxAPIException e = new BoxAPIException(argExceptionMessage); +998 this.notifyError(e); +999 throw e; +1000 } +1001 } +1002 +1003 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1004 request.shouldAuthenticate(false); +1005 request.setBody(urlParameters); +1006 +1007 String jsonResponse; +1008 try (BoxJSONResponse response = (BoxJSONResponse) request.send()) { +1009 jsonResponse = response.getJSON(); +1010 } catch (BoxAPIException e) { +1011 this.notifyError(e); +1012 throw e; +1013 } +1014 +1015 JsonObject jsonObject = Json.parse(jsonResponse).asObject(); +1016 ScopedToken token = new ScopedToken(jsonObject); +1017 token.setObtainedAt(System.currentTimeMillis()); +1018 token.setExpiresIn(jsonObject.get("expires_in").asLong() * 1000); +1019 return token; +1020 } +1021 +1022 /** +1023 * Convert List<String> to space-delimited String. +1024 * Needed for versions prior to Java 8, which don't have String.join(delimiter, list) +1025 * +1026 * @param scopes the list of scopes to read from +1027 * @return space-delimited String of scopes +1028 */ +1029 private StringBuilder buildScopesForTokenDownscoping(List<String> scopes) { +1030 StringBuilder spaceSeparatedScopes = new StringBuilder(); +1031 for (int i = 0; i < scopes.size(); i++) { +1032 spaceSeparatedScopes.append(scopes.get(i)); +1033 if (i < scopes.size() - 1) { +1034 spaceSeparatedScopes.append(" "); +1035 } +1036 } +1037 +1038 return spaceSeparatedScopes; +1039 } +1040 +1041 /** +1042 * Determines the type of resource, given a link to a Box resource. +1043 * +1044 * @param resourceLink the resource URL to check +1045 * @return ResourceLinkType that categorizes the provided resourceLink +1046 */ +1047 protected ResourceLinkType determineResourceLinkType(String resourceLink) { +1048 +1049 ResourceLinkType resourceType = ResourceLinkType.Unknown; +1050 +1051 try { +1052 URL validUrl = new URL(resourceLink); +1053 String validURLStr = validUrl.toString(); +1054 final String apiFilesEndpointPattern = ".*box.com/2.0/files/\\d+"; +1055 final String apiFoldersEndpointPattern = ".*box.com/2.0/folders/\\d+"; +1056 final String sharedLinkPattern = "(.*box.com/s/.*|.*box.com.*s=.*)"; +1057 +1058 if (Pattern.matches(apiFilesEndpointPattern, validURLStr) +1059 || Pattern.matches(apiFoldersEndpointPattern, validURLStr)) { +1060 resourceType = ResourceLinkType.APIEndpoint; +1061 } else if (Pattern.matches(sharedLinkPattern, validURLStr)) { +1062 resourceType = ResourceLinkType.SharedLink; +1063 } +1064 } catch (MalformedURLException e) { +1065 //Swallow exception and return default ResourceLinkType set at top of function +1066 } +1067 +1068 return resourceType; +1069 } +1070 +1071 /** +1072 * Revokes the tokens associated with this API connection. This results in the connection no +1073 * longer being able to make API calls until a fresh authorization is made by calling authenticate() +1074 */ +1075 public void revokeToken() { +1076 +1077 URL url; +1078 try { +1079 url = new URL(getRevokeURL()); +1080 } catch (MalformedURLException e) { +1081 assert false : "An invalid refresh URL indicates a bug in the SDK."; +1082 throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e); +1083 } +1084 +1085 String urlParameters = format("token=%s&client_id=%s&client_secret=%s", +1086 this.accessToken, this.clientID, this.clientSecret); +1087 +1088 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1089 request.shouldAuthenticate(false); +1090 request.setBody(urlParameters); +1091 +1092 request.send().close(); +1093 } +1094 +1095 /** +1096 * Saves the state of this connection to a string so that it can be persisted and restored at a later time. +1097 * +1098 * <p>Note that proxy settings aren't automatically saved or restored. This is mainly due to security concerns +1099 * around persisting proxy authentication details to the state string. If your connection uses a proxy, you will +1100 * have to manually configure it again after restoring the connection.</p> +1101 * +1102 * @return the state of this connection. +1103 * @see #restore +1104 */ +1105 public String save() { +1106 JsonObject state = new JsonObject() +1107 .add("accessToken", this.accessToken) +1108 .add("refreshToken", this.refreshToken) +1109 .add("lastRefresh", this.lastRefresh) +1110 .add("expires", this.expires) +1111 .add("userAgent", this.userAgent) +1112 .add("tokenURL", this.tokenURL) +1113 .add("revokeURL", this.revokeURL) +1114 .add("baseURL", this.baseURL) +1115 .add("baseUploadURL", this.baseUploadURL) +1116 .add("authorizationURL", this.baseAuthorizationURL) +1117 .add("autoRefresh", this.autoRefresh) +1118 .add("maxRetryAttempts", this.maxRetryAttempts); +1119 return state.toString(); +1120 } +1121 +1122 String lockAccessToken() { +1123 if (this.autoRefresh && this.canRefresh() && this.needsRefresh()) { +1124 this.refreshLock.writeLock().lock(); +1125 try { +1126 if (this.needsRefresh()) { +1127 this.refresh(); +1128 } +1129 this.refreshLock.readLock().lock(); +1130 } finally { +1131 this.refreshLock.writeLock().unlock(); +1132 } +1133 } else { +1134 this.refreshLock.readLock().lock(); +1135 } +1136 +1137 return this.accessToken; +1138 } +1139 +1140 void unlockAccessToken() { +1141 this.refreshLock.readLock().unlock(); +1142 } +1143 +1144 /** +1145 * Get the value for the X-Box-UA header. +1146 * +1147 * @return the header value. +1148 */ +1149 String getBoxUAHeader() { +1150 +1151 return "agent=box-java-sdk/" + SDK_VERSION + "; env=Java/" + JAVA_VERSION; +1152 } +1153 +1154 /** +1155 * Sets a custom header to be sent on all requests through this API connection. +1156 * +1157 * @param header the header name. +1158 * @param value the header value. +1159 */ +1160 public void setCustomHeader(String header, String value) { +1161 this.customHeaders.put(header, value); +1162 } +1163 +1164 /** +1165 * Removes a custom header, so it will no longer be sent on requests through this API connection. +1166 * +1167 * @param header the header name. +1168 */ +1169 public void removeCustomHeader(String header) { +1170 this.customHeaders.remove(header); +1171 } +1172 +1173 /** +1174 * Suppresses email notifications from API actions. This is typically used by security or admin applications +1175 * to prevent spamming end users when doing automated processing on their content. +1176 */ +1177 public void suppressNotifications() { +1178 this.setCustomHeader(BOX_NOTIFICATIONS_HEADER, "off"); +1179 } +1180 +1181 /** +1182 * Re-enable email notifications from API actions if they have been suppressed. +1183 * +1184 * @see #suppressNotifications +1185 */ +1186 public void enableNotifications() { +1187 this.removeCustomHeader(BOX_NOTIFICATIONS_HEADER); +1188 } +1189 +1190 /** +1191 * Set this API connection to make API calls on behalf of another users, impersonating them. This +1192 * functionality can only be used by admins and service accounts. +1193 * +1194 * @param userID the ID of the user to act as. +1195 */ +1196 public void asUser(String userID) { +1197 this.setCustomHeader(AS_USER_HEADER, userID); +1198 } +1199 +1200 /** +1201 * Sets this API connection to make API calls on behalf of the user with whom the access token is associated. +1202 * This undoes any previous calls to asUser(). +1203 * +1204 * @see #asUser +1205 */ +1206 public void asSelf() { +1207 this.removeCustomHeader(AS_USER_HEADER); +1208 } +1209 +1210 /** +1211 * Used to override default SSL certification handling. For example, you can provide your own +1212 * trust manager or hostname verifier to allow self-signed certificates. +1213 * You can check examples <a href="https://github.com/box/box-java-sdk/blob/main/doc/configuration.md#ssl-configuration">here</a>. +1214 * +1215 * @param trustManager TrustManager that verifies certificates are valid. +1216 * @param hostnameVerifier HostnameVerifier that allows you to specify what hostnames are allowed. +1217 */ +1218 public void configureSslCertificatesValidation(X509TrustManager trustManager, HostnameVerifier hostnameVerifier) { +1219 this.trustManager = trustManager; +1220 this.hostnameVerifier = hostnameVerifier; +1221 buildHttpClients(); +1222 } +1223 +1224 Map<String, String> getHeaders() { +1225 return this.customHeaders; +1226 } +1227 +1228 protected void extractTokens(JsonObject jsonObject) { +1229 this.accessToken = jsonObject.get("access_token").asString(); +1230 this.refreshToken = jsonObject.get("refresh_token").asString(); +1231 this.lastRefresh = System.currentTimeMillis(); +1232 this.expires = jsonObject.get("expires_in").asLong() * 1000; +1233 } +1234 +1235 protected BoxAPIRequest createTokenRequest(URL url) { +1236 String urlParameters = format("grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s", +1237 this.refreshToken, this.clientID, this.clientSecret); +1238 +1239 BoxAPIRequest request = new BoxAPIRequest(this, url, "POST"); +1240 request.shouldAuthenticate(false); +1241 request.setBody(urlParameters); +1242 return request; +1243 } +1244 +1245 private String fixBaseUrl(String baseUrl) { +1246 return baseUrl.endsWith("/") ? baseUrl : baseUrl + "/"; +1247 } +1248 +1249 Response execute(Request request) { +1250 return executeOnClient(httpClient, request); +1251 } +1252 +1253 Response executeWithoutRedirect(Request request) { +1254 return executeOnClient(noRedirectsHttpClient, request); +1255 } +1256 +1257 protected Call createNewCall(OkHttpClient httpClient, Request request) { +1258 return httpClient.newCall(request); +1259 } +1260 +1261 private Response executeOnClient(OkHttpClient httpClient, Request request) { +1262 try { +1263 return createNewCall(httpClient, request).execute(); +1264 } catch (IOException e) { +1265 throw new BoxAPIException("Couldn't connect to the Box API due to a network error. Request\n" + request, e); +1266 } +1267 } +1268 +1269 protected X509TrustManager getTrustManager() { +1270 return trustManager; +1271 } +1272 +1273 protected HostnameVerifier getHostnameVerifier() { +1274 return hostnameVerifier; +1275 } +1276 +1277 /** +1278 * Used to categorize the types of resource links. +1279 */ +1280 protected enum ResourceLinkType {1281 /** -1282 * Resource URLs that point to an API endipoint such as https://api.box.com/2.0/files/:file_id. +1282 * Catch-all default for resource links that are unknown.1283 */ -1284 APIEndpoint, +1284 Unknown,12851286 /** -1287 * Resource URLs that point to a resource that has been shared -1288 * such as https://example.box.com/s/qwertyuiop1234567890asdfghjk -1289 * or https://example.app.box.com/notes/0987654321?s=zxcvbnm1234567890asdfghjk. -1290 */ -1291 SharedLink -1292 } -1293} +1287 * Resource URLs that point to an API endipoint such as https://api.box.com/2.0/files/:file_id. +1288 */ +1289 APIEndpoint, +1290 +1291 /** +1292 * Resource URLs that point to a resource that has been shared +1293 * such as https://example.box.com/s/qwertyuiop1234567890asdfghjk +1294 * or https://example.app.box.com/notes/0987654321?s=zxcvbnm1234567890asdfghjk. +1295 */ +1296 SharedLink +1297 } +1298} diff --git a/javadoc/src-html/com/box/sdk/BoxFile.Info.html b/javadoc/src-html/com/box/sdk/BoxFile.Info.html index 2fcf9c1db..64dd8c545 100644 --- a/javadoc/src-html/com/box/sdk/BoxFile.Info.html +++ b/javadoc/src-html/com/box/sdk/BoxFile.Info.html @@ -1972,53 +1972,31 @@ 1964 if (value.isNull() || !value.asBoolean()) {1965 continue;1966 } -1967 -1968 switch (member.getName()) { -1969 case "can_download": -1970 permissions.add(Permission.CAN_DOWNLOAD); -1971 break; -1972 case "can_upload": -1973 permissions.add(Permission.CAN_UPLOAD); -1974 break; -1975 case "can_rename": -1976 permissions.add(Permission.CAN_RENAME); -1977 break; -1978 case "can_delete": -1979 permissions.add(Permission.CAN_DELETE); -1980 break; -1981 case "can_share": -1982 permissions.add(Permission.CAN_SHARE); -1983 break; -1984 case "can_set_share_access": -1985 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1986 break; -1987 case "can_preview": -1988 permissions.add(Permission.CAN_PREVIEW); -1989 break; -1990 case "can_comment": -1991 permissions.add(Permission.CAN_COMMENT); -1992 break; -1993 } -1994 } -1995 -1996 return permissions; -1997 } -1998 -1999 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { -2000 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); -2001 } -2002 -2003 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -2004 List<String> roles = new ArrayList<>(jsonArray.size()); -2005 for (JsonValue value : jsonArray) { -2006 roles.add(value.asString()); -2007 } -2008 -2009 return roles; -2010 } -2011 } -2012 -2013} +1967 try { +1968 permissions.add(Permission.fromJSONValue(member.getName())); +1969 } catch (IllegalArgumentException ignored) { +1970 // If the permission is not recognized, we ignore it. +1971 } +1972 } +1973 +1974 return permissions; +1975 } +1976 +1977 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { +1978 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); +1979 } +1980 +1981 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1982 List<String> roles = new ArrayList<>(jsonArray.size()); +1983 for (JsonValue value : jsonArray) { +1984 roles.add(value.asString()); +1985 } +1986 +1987 return roles; +1988 } +1989 } +1990 +1991} diff --git a/javadoc/src-html/com/box/sdk/BoxFile.Permission.html b/javadoc/src-html/com/box/sdk/BoxFile.Permission.html index 2fcf9c1db..64dd8c545 100644 --- a/javadoc/src-html/com/box/sdk/BoxFile.Permission.html +++ b/javadoc/src-html/com/box/sdk/BoxFile.Permission.html @@ -1972,53 +1972,31 @@ 1964 if (value.isNull() || !value.asBoolean()) {1965 continue;1966 } -1967 -1968 switch (member.getName()) { -1969 case "can_download": -1970 permissions.add(Permission.CAN_DOWNLOAD); -1971 break; -1972 case "can_upload": -1973 permissions.add(Permission.CAN_UPLOAD); -1974 break; -1975 case "can_rename": -1976 permissions.add(Permission.CAN_RENAME); -1977 break; -1978 case "can_delete": -1979 permissions.add(Permission.CAN_DELETE); -1980 break; -1981 case "can_share": -1982 permissions.add(Permission.CAN_SHARE); -1983 break; -1984 case "can_set_share_access": -1985 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1986 break; -1987 case "can_preview": -1988 permissions.add(Permission.CAN_PREVIEW); -1989 break; -1990 case "can_comment": -1991 permissions.add(Permission.CAN_COMMENT); -1992 break; -1993 } -1994 } -1995 -1996 return permissions; -1997 } -1998 -1999 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { -2000 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); -2001 } -2002 -2003 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -2004 List<String> roles = new ArrayList<>(jsonArray.size()); -2005 for (JsonValue value : jsonArray) { -2006 roles.add(value.asString()); -2007 } -2008 -2009 return roles; -2010 } -2011 } -2012 -2013} +1967 try { +1968 permissions.add(Permission.fromJSONValue(member.getName())); +1969 } catch (IllegalArgumentException ignored) { +1970 // If the permission is not recognized, we ignore it. +1971 } +1972 } +1973 +1974 return permissions; +1975 } +1976 +1977 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { +1978 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); +1979 } +1980 +1981 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1982 List<String> roles = new ArrayList<>(jsonArray.size()); +1983 for (JsonValue value : jsonArray) { +1984 roles.add(value.asString()); +1985 } +1986 +1987 return roles; +1988 } +1989 } +1990 +1991} diff --git a/javadoc/src-html/com/box/sdk/BoxFile.ThumbnailFileType.html b/javadoc/src-html/com/box/sdk/BoxFile.ThumbnailFileType.html index 2fcf9c1db..64dd8c545 100644 --- a/javadoc/src-html/com/box/sdk/BoxFile.ThumbnailFileType.html +++ b/javadoc/src-html/com/box/sdk/BoxFile.ThumbnailFileType.html @@ -1972,53 +1972,31 @@ 1964 if (value.isNull() || !value.asBoolean()) {1965 continue;1966 } -1967 -1968 switch (member.getName()) { -1969 case "can_download": -1970 permissions.add(Permission.CAN_DOWNLOAD); -1971 break; -1972 case "can_upload": -1973 permissions.add(Permission.CAN_UPLOAD); -1974 break; -1975 case "can_rename": -1976 permissions.add(Permission.CAN_RENAME); -1977 break; -1978 case "can_delete": -1979 permissions.add(Permission.CAN_DELETE); -1980 break; -1981 case "can_share": -1982 permissions.add(Permission.CAN_SHARE); -1983 break; -1984 case "can_set_share_access": -1985 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1986 break; -1987 case "can_preview": -1988 permissions.add(Permission.CAN_PREVIEW); -1989 break; -1990 case "can_comment": -1991 permissions.add(Permission.CAN_COMMENT); -1992 break; -1993 } -1994 } -1995 -1996 return permissions; -1997 } -1998 -1999 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { -2000 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); -2001 } -2002 -2003 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -2004 List<String> roles = new ArrayList<>(jsonArray.size()); -2005 for (JsonValue value : jsonArray) { -2006 roles.add(value.asString()); -2007 } -2008 -2009 return roles; -2010 } -2011 } -2012 -2013} +1967 try { +1968 permissions.add(Permission.fromJSONValue(member.getName())); +1969 } catch (IllegalArgumentException ignored) { +1970 // If the permission is not recognized, we ignore it. +1971 } +1972 } +1973 +1974 return permissions; +1975 } +1976 +1977 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { +1978 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); +1979 } +1980 +1981 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1982 List<String> roles = new ArrayList<>(jsonArray.size()); +1983 for (JsonValue value : jsonArray) { +1984 roles.add(value.asString()); +1985 } +1986 +1987 return roles; +1988 } +1989 } +1990 +1991} diff --git a/javadoc/src-html/com/box/sdk/BoxFile.html b/javadoc/src-html/com/box/sdk/BoxFile.html index 2fcf9c1db..64dd8c545 100644 --- a/javadoc/src-html/com/box/sdk/BoxFile.html +++ b/javadoc/src-html/com/box/sdk/BoxFile.html @@ -1972,53 +1972,31 @@ 1964 if (value.isNull() || !value.asBoolean()) {1965 continue;1966 } -1967 -1968 switch (member.getName()) { -1969 case "can_download": -1970 permissions.add(Permission.CAN_DOWNLOAD); -1971 break; -1972 case "can_upload": -1973 permissions.add(Permission.CAN_UPLOAD); -1974 break; -1975 case "can_rename": -1976 permissions.add(Permission.CAN_RENAME); -1977 break; -1978 case "can_delete": -1979 permissions.add(Permission.CAN_DELETE); -1980 break; -1981 case "can_share": -1982 permissions.add(Permission.CAN_SHARE); -1983 break; -1984 case "can_set_share_access": -1985 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1986 break; -1987 case "can_preview": -1988 permissions.add(Permission.CAN_PREVIEW); -1989 break; -1990 case "can_comment": -1991 permissions.add(Permission.CAN_COMMENT); -1992 break; -1993 } -1994 } -1995 -1996 return permissions; -1997 } -1998 -1999 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { -2000 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); -2001 } -2002 -2003 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -2004 List<String> roles = new ArrayList<>(jsonArray.size()); -2005 for (JsonValue value : jsonArray) { -2006 roles.add(value.asString()); -2007 } -2008 -2009 return roles; -2010 } -2011 } -2012 -2013} +1967 try { +1968 permissions.add(Permission.fromJSONValue(member.getName())); +1969 } catch (IllegalArgumentException ignored) { +1970 // If the permission is not recognized, we ignore it. +1971 } +1972 } +1973 +1974 return permissions; +1975 } +1976 +1977 private BoxFileVersion parseFileVersion(JsonObject jsonObject) { +1978 return new BoxFileVersion(BoxFile.this.getAPI(), jsonObject, BoxFile.this.getID()); +1979 } +1980 +1981 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1982 List<String> roles = new ArrayList<>(jsonArray.size()); +1983 for (JsonValue value : jsonArray) { +1984 roles.add(value.asString()); +1985 } +1986 +1987 return roles; +1988 } +1989 } +1990 +1991} diff --git a/javadoc/src-html/com/box/sdk/BoxFolder.Info.html b/javadoc/src-html/com/box/sdk/BoxFolder.Info.html index d7bb025d9..402bf4cea 100644 --- a/javadoc/src-html/com/box/sdk/BoxFolder.Info.html +++ b/javadoc/src-html/com/box/sdk/BoxFolder.Info.html @@ -1753,55 +1753,35 @@ 1745 continue;1746 }1747 -1748 switch (member.getName()) { -1749 case "can_download": -1750 permissions.add(Permission.CAN_DOWNLOAD); -1751 break; -1752 case "can_upload": -1753 permissions.add(Permission.CAN_UPLOAD); -1754 break; -1755 case "can_rename": -1756 permissions.add(Permission.CAN_RENAME); -1757 break; -1758 case "can_delete": -1759 permissions.add(Permission.CAN_DELETE); -1760 break; -1761 case "can_share": -1762 permissions.add(Permission.CAN_SHARE); -1763 break; -1764 case "can_invite_collaborator": -1765 permissions.add(Permission.CAN_INVITE_COLLABORATOR); -1766 break; -1767 case "can_set_share_access": -1768 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1769 break; -1770 default: -1771 break; -1772 } -1773 } -1774 -1775 return permissions; -1776 } -1777 -1778 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { -1779 List<String> accessLevels = new ArrayList<>(jsonArray.size()); -1780 for (JsonValue value : jsonArray) { -1781 accessLevels.add(value.asString()); -1782 } -1783 -1784 return accessLevels; -1785 } -1786 -1787 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -1788 List<String> roles = new ArrayList<>(jsonArray.size()); -1789 for (JsonValue value : jsonArray) { -1790 roles.add(value.asString()); -1791 } -1792 -1793 return roles; -1794 } -1795 } -1796} +1748 try { +1749 permissions.add(BoxFolder.Permission.fromJSONValue(member.getName())); +1750 } catch (IllegalArgumentException ignored) { +1751 // If the permission is not recognized, we ignore it. +1752 } +1753 } +1754 +1755 return permissions; +1756 } +1757 +1758 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { +1759 List<String> accessLevels = new ArrayList<>(jsonArray.size()); +1760 for (JsonValue value : jsonArray) { +1761 accessLevels.add(value.asString()); +1762 } +1763 +1764 return accessLevels; +1765 } +1766 +1767 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1768 List<String> roles = new ArrayList<>(jsonArray.size()); +1769 for (JsonValue value : jsonArray) { +1770 roles.add(value.asString()); +1771 } +1772 +1773 return roles; +1774 } +1775 } +1776} diff --git a/javadoc/src-html/com/box/sdk/BoxFolder.Permission.html b/javadoc/src-html/com/box/sdk/BoxFolder.Permission.html index d7bb025d9..402bf4cea 100644 --- a/javadoc/src-html/com/box/sdk/BoxFolder.Permission.html +++ b/javadoc/src-html/com/box/sdk/BoxFolder.Permission.html @@ -1753,55 +1753,35 @@ 1745 continue;1746 }1747 -1748 switch (member.getName()) { -1749 case "can_download": -1750 permissions.add(Permission.CAN_DOWNLOAD); -1751 break; -1752 case "can_upload": -1753 permissions.add(Permission.CAN_UPLOAD); -1754 break; -1755 case "can_rename": -1756 permissions.add(Permission.CAN_RENAME); -1757 break; -1758 case "can_delete": -1759 permissions.add(Permission.CAN_DELETE); -1760 break; -1761 case "can_share": -1762 permissions.add(Permission.CAN_SHARE); -1763 break; -1764 case "can_invite_collaborator": -1765 permissions.add(Permission.CAN_INVITE_COLLABORATOR); -1766 break; -1767 case "can_set_share_access": -1768 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1769 break; -1770 default: -1771 break; -1772 } -1773 } -1774 -1775 return permissions; -1776 } -1777 -1778 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { -1779 List<String> accessLevels = new ArrayList<>(jsonArray.size()); -1780 for (JsonValue value : jsonArray) { -1781 accessLevels.add(value.asString()); -1782 } -1783 -1784 return accessLevels; -1785 } -1786 -1787 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -1788 List<String> roles = new ArrayList<>(jsonArray.size()); -1789 for (JsonValue value : jsonArray) { -1790 roles.add(value.asString()); -1791 } -1792 -1793 return roles; -1794 } -1795 } -1796} +1748 try { +1749 permissions.add(BoxFolder.Permission.fromJSONValue(member.getName())); +1750 } catch (IllegalArgumentException ignored) { +1751 // If the permission is not recognized, we ignore it. +1752 } +1753 } +1754 +1755 return permissions; +1756 } +1757 +1758 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { +1759 List<String> accessLevels = new ArrayList<>(jsonArray.size()); +1760 for (JsonValue value : jsonArray) { +1761 accessLevels.add(value.asString()); +1762 } +1763 +1764 return accessLevels; +1765 } +1766 +1767 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1768 List<String> roles = new ArrayList<>(jsonArray.size()); +1769 for (JsonValue value : jsonArray) { +1770 roles.add(value.asString()); +1771 } +1772 +1773 return roles; +1774 } +1775 } +1776} diff --git a/javadoc/src-html/com/box/sdk/BoxFolder.SortDirection.html b/javadoc/src-html/com/box/sdk/BoxFolder.SortDirection.html index d7bb025d9..402bf4cea 100644 --- a/javadoc/src-html/com/box/sdk/BoxFolder.SortDirection.html +++ b/javadoc/src-html/com/box/sdk/BoxFolder.SortDirection.html @@ -1753,55 +1753,35 @@ 1745 continue;1746 }1747 -1748 switch (member.getName()) { -1749 case "can_download": -1750 permissions.add(Permission.CAN_DOWNLOAD); -1751 break; -1752 case "can_upload": -1753 permissions.add(Permission.CAN_UPLOAD); -1754 break; -1755 case "can_rename": -1756 permissions.add(Permission.CAN_RENAME); -1757 break; -1758 case "can_delete": -1759 permissions.add(Permission.CAN_DELETE); -1760 break; -1761 case "can_share": -1762 permissions.add(Permission.CAN_SHARE); -1763 break; -1764 case "can_invite_collaborator": -1765 permissions.add(Permission.CAN_INVITE_COLLABORATOR); -1766 break; -1767 case "can_set_share_access": -1768 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1769 break; -1770 default: -1771 break; -1772 } -1773 } -1774 -1775 return permissions; -1776 } -1777 -1778 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { -1779 List<String> accessLevels = new ArrayList<>(jsonArray.size()); -1780 for (JsonValue value : jsonArray) { -1781 accessLevels.add(value.asString()); -1782 } -1783 -1784 return accessLevels; -1785 } -1786 -1787 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -1788 List<String> roles = new ArrayList<>(jsonArray.size()); -1789 for (JsonValue value : jsonArray) { -1790 roles.add(value.asString()); -1791 } -1792 -1793 return roles; -1794 } -1795 } -1796} +1748 try { +1749 permissions.add(BoxFolder.Permission.fromJSONValue(member.getName())); +1750 } catch (IllegalArgumentException ignored) { +1751 // If the permission is not recognized, we ignore it. +1752 } +1753 } +1754 +1755 return permissions; +1756 } +1757 +1758 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { +1759 List<String> accessLevels = new ArrayList<>(jsonArray.size()); +1760 for (JsonValue value : jsonArray) { +1761 accessLevels.add(value.asString()); +1762 } +1763 +1764 return accessLevels; +1765 } +1766 +1767 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1768 List<String> roles = new ArrayList<>(jsonArray.size()); +1769 for (JsonValue value : jsonArray) { +1770 roles.add(value.asString()); +1771 } +1772 +1773 return roles; +1774 } +1775 } +1776} diff --git a/javadoc/src-html/com/box/sdk/BoxFolder.SyncState.html b/javadoc/src-html/com/box/sdk/BoxFolder.SyncState.html index d7bb025d9..402bf4cea 100644 --- a/javadoc/src-html/com/box/sdk/BoxFolder.SyncState.html +++ b/javadoc/src-html/com/box/sdk/BoxFolder.SyncState.html @@ -1753,55 +1753,35 @@ 1745 continue;1746 }1747 -1748 switch (member.getName()) { -1749 case "can_download": -1750 permissions.add(Permission.CAN_DOWNLOAD); -1751 break; -1752 case "can_upload": -1753 permissions.add(Permission.CAN_UPLOAD); -1754 break; -1755 case "can_rename": -1756 permissions.add(Permission.CAN_RENAME); -1757 break; -1758 case "can_delete": -1759 permissions.add(Permission.CAN_DELETE); -1760 break; -1761 case "can_share": -1762 permissions.add(Permission.CAN_SHARE); -1763 break; -1764 case "can_invite_collaborator": -1765 permissions.add(Permission.CAN_INVITE_COLLABORATOR); -1766 break; -1767 case "can_set_share_access": -1768 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1769 break; -1770 default: -1771 break; -1772 } -1773 } -1774 -1775 return permissions; -1776 } -1777 -1778 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { -1779 List<String> accessLevels = new ArrayList<>(jsonArray.size()); -1780 for (JsonValue value : jsonArray) { -1781 accessLevels.add(value.asString()); -1782 } -1783 -1784 return accessLevels; -1785 } -1786 -1787 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -1788 List<String> roles = new ArrayList<>(jsonArray.size()); -1789 for (JsonValue value : jsonArray) { -1790 roles.add(value.asString()); -1791 } -1792 -1793 return roles; -1794 } -1795 } -1796} +1748 try { +1749 permissions.add(BoxFolder.Permission.fromJSONValue(member.getName())); +1750 } catch (IllegalArgumentException ignored) { +1751 // If the permission is not recognized, we ignore it. +1752 } +1753 } +1754 +1755 return permissions; +1756 } +1757 +1758 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { +1759 List<String> accessLevels = new ArrayList<>(jsonArray.size()); +1760 for (JsonValue value : jsonArray) { +1761 accessLevels.add(value.asString()); +1762 } +1763 +1764 return accessLevels; +1765 } +1766 +1767 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1768 List<String> roles = new ArrayList<>(jsonArray.size()); +1769 for (JsonValue value : jsonArray) { +1770 roles.add(value.asString()); +1771 } +1772 +1773 return roles; +1774 } +1775 } +1776} diff --git a/javadoc/src-html/com/box/sdk/BoxFolder.html b/javadoc/src-html/com/box/sdk/BoxFolder.html index d7bb025d9..402bf4cea 100644 --- a/javadoc/src-html/com/box/sdk/BoxFolder.html +++ b/javadoc/src-html/com/box/sdk/BoxFolder.html @@ -1753,55 +1753,35 @@ 1745 continue;1746 }1747 -1748 switch (member.getName()) { -1749 case "can_download": -1750 permissions.add(Permission.CAN_DOWNLOAD); -1751 break; -1752 case "can_upload": -1753 permissions.add(Permission.CAN_UPLOAD); -1754 break; -1755 case "can_rename": -1756 permissions.add(Permission.CAN_RENAME); -1757 break; -1758 case "can_delete": -1759 permissions.add(Permission.CAN_DELETE); -1760 break; -1761 case "can_share": -1762 permissions.add(Permission.CAN_SHARE); -1763 break; -1764 case "can_invite_collaborator": -1765 permissions.add(Permission.CAN_INVITE_COLLABORATOR); -1766 break; -1767 case "can_set_share_access": -1768 permissions.add(Permission.CAN_SET_SHARE_ACCESS); -1769 break; -1770 default: -1771 break; -1772 } -1773 } -1774 -1775 return permissions; -1776 } -1777 -1778 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { -1779 List<String> accessLevels = new ArrayList<>(jsonArray.size()); -1780 for (JsonValue value : jsonArray) { -1781 accessLevels.add(value.asString()); -1782 } -1783 -1784 return accessLevels; -1785 } -1786 -1787 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { -1788 List<String> roles = new ArrayList<>(jsonArray.size()); -1789 for (JsonValue value : jsonArray) { -1790 roles.add(value.asString()); -1791 } -1792 -1793 return roles; -1794 } -1795 } -1796} +1748 try { +1749 permissions.add(BoxFolder.Permission.fromJSONValue(member.getName())); +1750 } catch (IllegalArgumentException ignored) { +1751 // If the permission is not recognized, we ignore it. +1752 } +1753 } +1754 +1755 return permissions; +1756 } +1757 +1758 private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { +1759 List<String> accessLevels = new ArrayList<>(jsonArray.size()); +1760 for (JsonValue value : jsonArray) { +1761 accessLevels.add(value.asString()); +1762 } +1763 +1764 return accessLevels; +1765 } +1766 +1767 private List<String> parseAllowedInviteeRoles(JsonArray jsonArray) { +1768 List<String> roles = new ArrayList<>(jsonArray.size()); +1769 for (JsonValue value : jsonArray) { +1770 roles.add(value.asString()); +1771 } +1772 +1773 return roles; +1774 } +1775 } +1776} diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.Field.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.Field.html index 76e3722aa..494a461b2 100644 --- a/javadoc/src-html/com/box/sdk/MetadataTemplate.Field.html +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.Field.html @@ -402,944 +402,1066 @@ 394 fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);395 }396 -397 jsonObject.add("data", fieldObj); -398 } -399 -400 List<String> fieldKeys = fieldOperation.getFieldKeys(); -401 if (fieldKeys != null) { -402 jsonObject.add("fieldKeys", getJsonArray(fieldKeys)); -403 } -404 -405 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); -406 if (enumOptionKeys != null) { -407 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys)); +397 StaticConfig staticConfig = field.getStaticConfig(); +398 if (staticConfig != null) { +399 JsonObject staticConfigObj = new JsonObject(); +400 JsonObject classification = staticConfig.getClassification(); +401 if (classification != null) { +402 staticConfigObj.add("classification", classification); +403 } +404 fieldObj.add("staticConfig", staticConfigObj); +405 } +406 +407 jsonObject.add("data", fieldObj);408 }409 -410 String enumOptionKey = fieldOperation.getEnumOptionKey(); -411 if (enumOptionKey != null) { -412 jsonObject.add("enumOptionKey", enumOptionKey); +410 List<String> fieldKeys = fieldOperation.getFieldKeys(); +411 if (fieldKeys != null) { +412 jsonObject.add("fieldKeys", getJsonArray(fieldKeys));413 }414 -415 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); -416 if (multiSelectOptionKey != null) { -417 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +415 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); +416 if (enumOptionKeys != null) { +417 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));418 }419 -420 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); -421 if (multiSelectOptionKeys != null) { -422 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +420 String enumOptionKey = fieldOperation.getEnumOptionKey(); +421 if (enumOptionKey != null) { +422 jsonObject.add("enumOptionKey", enumOptionKey);423 }424 -425 return jsonObject; -426 } -427 -428 /** -429 * Gets the Json Array representation of the given list of strings. -430 * -431 * @param keys List of strings -432 * @return the JsonArray represents the list of keys -433 */ -434 private static JsonArray getJsonArray(List<String> keys) { -435 JsonArray array = new JsonArray(); -436 for (String key : keys) { -437 array.add(key); -438 } -439 -440 return array; -441 } -442 -443 /** -444 * Gets the metadata template of properties. -445 * -446 * @param api the API connection to be used. -447 * @return the metadata template returned from the server. -448 */ -449 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { -450 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +425 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); +426 if (multiSelectOptionKey != null) { +427 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +428 } +429 +430 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); +431 if (multiSelectOptionKeys != null) { +432 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +433 } +434 +435 return jsonObject; +436 } +437 +438 /** +439 * Gets the Json Array representation of the given list of strings. +440 * +441 * @param keys List of strings +442 * @return the JsonArray represents the list of keys +443 */ +444 private static JsonArray getJsonArray(List<String> keys) { +445 JsonArray array = new JsonArray(); +446 for (String key : keys) { +447 array.add(key); +448 } +449 +450 return array;451 }452453 /** -454 * Gets the metadata template of specified template type. +454 * Gets the metadata template of properties.455 * -456 * @param api the API connection to be used. -457 * @param templateName the metadata template type name. -458 * @return the metadata template returned from the server. -459 */ -460 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { -461 String scope = scopeBasedOnType(templateName); -462 return getMetadataTemplate(api, templateName, scope); -463 } -464 -465 /** -466 * Gets the metadata template of specified template type. -467 * -468 * @param api the API connection to be used. -469 * @param templateName the metadata template type name. -470 * @param scope the metadata template scope (global or enterprise). -471 * @param fields the fields to retrieve. -472 * @return the metadata template returned from the server. -473 */ -474 public static MetadataTemplate getMetadataTemplate( -475 BoxAPIConnection api, String templateName, String scope, String... fields) { -476 QueryStringBuilder builder = new QueryStringBuilder(); -477 if (fields.length > 0) { -478 builder.appendParam("fields", fields); -479 } -480 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( -481 api.getBaseURL(), builder.toString(), scope, templateName); -482 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -483 try (BoxJSONResponse response = request.send()) { -484 return new MetadataTemplate(response.getJSON()); -485 } -486 } -487 -488 /** -489 * Geta the specified metadata template by its ID. -490 * -491 * @param api the API connection to be used. -492 * @param templateID the ID of the template to get. -493 * @return the metadata template object. -494 */ -495 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { -496 -497 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); -498 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -499 try (BoxJSONResponse response = request.send()) { -500 return new MetadataTemplate(response.getJSON()); -501 } -502 } -503 -504 /** -505 * Returns all metadata templates within a user's enterprise. -506 * -507 * @param api the API connection to be used. -508 * @param fields the fields to retrieve. -509 * @return the metadata template returned from the server. -510 */ -511 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { -512 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); -513 } -514 -515 /** -516 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -517 * -518 * @param scope the scope of the metadata templates. -519 * @param api the API connection to be used. -520 * @param fields the fields to retrieve. -521 * @return the metadata template returned from the server. -522 */ -523 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -524 String scope, BoxAPIConnection api, String... fields -525 ) { -526 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); -527 } -528 -529 /** -530 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -531 * -532 * @param scope the scope of the metadata templates. -533 * @param limit maximum number of entries per response. -534 * @param api the API connection to be used. -535 * @param fields the fields to retrieve. -536 * @return the metadata template returned from the server. -537 */ -538 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -539 String scope, int limit, BoxAPIConnection api, String... fields) { -540 QueryStringBuilder builder = new QueryStringBuilder(); -541 if (fields.length > 0) { -542 builder.appendParam("fields", fields); -543 } -544 return new BoxResourceIterable<MetadataTemplate>( -545 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( -546 api.getBaseURL(), builder.toString(), scope), limit) { -547 -548 @Override -549 protected MetadataTemplate factory(JsonObject jsonObject) { -550 return new MetadataTemplate(jsonObject); -551 } -552 }; -553 } -554 -555 /** -556 * Determines the metadata scope based on type. -557 * -558 * @param typeName type of the metadata. -559 * @return scope of the metadata. -560 */ -561 private static String scopeBasedOnType(String typeName) { -562 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +456 * @param api the API connection to be used. +457 * @return the metadata template returned from the server. +458 */ +459 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { +460 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +461 } +462 +463 /** +464 * Gets the metadata template of specified template type. +465 * +466 * @param api the API connection to be used. +467 * @param templateName the metadata template type name. +468 * @return the metadata template returned from the server. +469 */ +470 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { +471 String scope = scopeBasedOnType(templateName); +472 return getMetadataTemplate(api, templateName, scope); +473 } +474 +475 /** +476 * Gets the metadata template of specified template type. +477 * +478 * @param api the API connection to be used. +479 * @param templateName the metadata template type name. +480 * @param scope the metadata template scope (global or enterprise). +481 * @param fields the fields to retrieve. +482 * @return the metadata template returned from the server. +483 */ +484 public static MetadataTemplate getMetadataTemplate( +485 BoxAPIConnection api, String templateName, String scope, String... fields) { +486 QueryStringBuilder builder = new QueryStringBuilder(); +487 if (fields.length > 0) { +488 builder.appendParam("fields", fields); +489 } +490 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( +491 api.getBaseURL(), builder.toString(), scope, templateName); +492 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +493 try (BoxJSONResponse response = request.send()) { +494 return new MetadataTemplate(response.getJSON()); +495 } +496 } +497 +498 /** +499 * Geta the specified metadata template by its ID. +500 * +501 * @param api the API connection to be used. +502 * @param templateID the ID of the template to get. +503 * @return the metadata template object. +504 */ +505 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { +506 +507 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); +508 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +509 try (BoxJSONResponse response = request.send()) { +510 return new MetadataTemplate(response.getJSON()); +511 } +512 } +513 +514 /** +515 * Returns all metadata templates within a user's enterprise. +516 * +517 * @param api the API connection to be used. +518 * @param fields the fields to retrieve. +519 * @return the metadata template returned from the server. +520 */ +521 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { +522 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); +523 } +524 +525 /** +526 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +527 * +528 * @param scope the scope of the metadata templates. +529 * @param api the API connection to be used. +530 * @param fields the fields to retrieve. +531 * @return the metadata template returned from the server. +532 */ +533 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +534 String scope, BoxAPIConnection api, String... fields +535 ) { +536 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); +537 } +538 +539 /** +540 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +541 * +542 * @param scope the scope of the metadata templates. +543 * @param limit maximum number of entries per response. +544 * @param api the API connection to be used. +545 * @param fields the fields to retrieve. +546 * @return the metadata template returned from the server. +547 */ +548 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +549 String scope, int limit, BoxAPIConnection api, String... fields) { +550 QueryStringBuilder builder = new QueryStringBuilder(); +551 if (fields.length > 0) { +552 builder.appendParam("fields", fields); +553 } +554 return new BoxResourceIterable<MetadataTemplate>( +555 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( +556 api.getBaseURL(), builder.toString(), scope), limit) { +557 +558 @Override +559 protected MetadataTemplate factory(JsonObject jsonObject) { +560 return new MetadataTemplate(jsonObject); +561 } +562 };563 }564565 /** -566 * Gets the ID of the template. +566 * Determines the metadata scope based on type.567 * -568 * @return the template ID. -569 */ -570 public String getID() { -571 return this.id; -572 } -573 -574 /** -575 * Gets the unique template key to identify the metadata template. -576 * -577 * @return the unique template key to identify the metadata template. -578 */ -579 public String getTemplateKey() { -580 return this.templateKey; -581 } -582 -583 /** -584 * Gets the metadata template scope. -585 * -586 * @return the metadata template scope. -587 */ -588 public String getScope() { -589 return this.scope; -590 } -591 -592 /** -593 * Gets the displayed metadata template name. -594 * -595 * @return the displayed metadata template name. -596 */ -597 public String getDisplayName() { -598 return this.displayName; -599 } -600 -601 /** -602 * Gets is the metadata template hidden. -603 * -604 * @return is the metadata template hidden. -605 */ -606 public Boolean getIsHidden() { -607 return this.isHidden; -608 } -609 -610 /** -611 * Gets the iterable with all fields the metadata template contains. -612 * -613 * @return the iterable with all fields the metadata template contains. -614 */ -615 public List<Field> getFields() { -616 return this.fields; -617 } -618 -619 /** -620 * Gets whether the copy operation should copy the metadata along with the item. -621 * -622 * @return whether the copy operation should copy the metadata along with the item. -623 */ -624 public Boolean getCopyInstanceOnItemCopy() { -625 return this.copyInstanceOnItemCopy; -626 } -627 -628 /** -629 * {@inheritDoc} -630 */ -631 @Override -632 void parseJSONMember(JsonObject.Member member) { -633 JsonValue value = member.getValue(); -634 String memberName = member.getName(); -635 switch (memberName) { -636 case "templateKey": -637 this.templateKey = value.asString(); -638 break; -639 case "scope": -640 this.scope = value.asString(); -641 break; -642 case "displayName": -643 this.displayName = value.asString(); -644 break; -645 case "hidden": -646 this.isHidden = value.asBoolean(); -647 break; -648 case "fields": -649 this.fields = new ArrayList<>(); -650 for (JsonValue field : value.asArray()) { -651 this.fields.add(new Field(field.asObject())); -652 } -653 break; -654 case "id": -655 this.id = value.asString(); -656 break; -657 case "copyInstanceOnItemCopy": -658 this.copyInstanceOnItemCopy = value.asBoolean(); -659 break; -660 default: -661 break; -662 } -663 } -664 -665 /** -666 * Possible template operations. -667 */ -668 public enum Operation { -669 -670 /** -671 * Adds an enum option at the end of the enum option list for the specified field. -672 */ -673 addEnumOption, +568 * @param typeName type of the metadata. +569 * @return scope of the metadata. +570 */ +571 private static String scopeBasedOnType(String typeName) { +572 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +573 } +574 +575 /** +576 * Gets the ID of the template. +577 * +578 * @return the template ID. +579 */ +580 public String getID() { +581 return this.id; +582 } +583 +584 /** +585 * Gets the unique template key to identify the metadata template. +586 * +587 * @return the unique template key to identify the metadata template. +588 */ +589 public String getTemplateKey() { +590 return this.templateKey; +591 } +592 +593 /** +594 * Gets the metadata template scope. +595 * +596 * @return the metadata template scope. +597 */ +598 public String getScope() { +599 return this.scope; +600 } +601 +602 /** +603 * Gets the displayed metadata template name. +604 * +605 * @return the displayed metadata template name. +606 */ +607 public String getDisplayName() { +608 return this.displayName; +609 } +610 +611 /** +612 * Gets is the metadata template hidden. +613 * +614 * @return is the metadata template hidden. +615 */ +616 public Boolean getIsHidden() { +617 return this.isHidden; +618 } +619 +620 /** +621 * Gets the iterable with all fields the metadata template contains. +622 * +623 * @return the iterable with all fields the metadata template contains. +624 */ +625 public List<Field> getFields() { +626 return this.fields; +627 } +628 +629 /** +630 * Gets whether the copy operation should copy the metadata along with the item. +631 * +632 * @return whether the copy operation should copy the metadata along with the item. +633 */ +634 public Boolean getCopyInstanceOnItemCopy() { +635 return this.copyInstanceOnItemCopy; +636 } +637 +638 /** +639 * {@inheritDoc} +640 */ +641 @Override +642 void parseJSONMember(JsonObject.Member member) { +643 JsonValue value = member.getValue(); +644 String memberName = member.getName(); +645 switch (memberName) { +646 case "templateKey": +647 this.templateKey = value.asString(); +648 break; +649 case "scope": +650 this.scope = value.asString(); +651 break; +652 case "displayName": +653 this.displayName = value.asString(); +654 break; +655 case "hidden": +656 this.isHidden = value.asBoolean(); +657 break; +658 case "fields": +659 this.fields = new ArrayList<>(); +660 for (JsonValue field : value.asArray()) { +661 this.fields.add(new Field(field.asObject())); +662 } +663 break; +664 case "id": +665 this.id = value.asString(); +666 break; +667 case "copyInstanceOnItemCopy": +668 this.copyInstanceOnItemCopy = value.asBoolean(); +669 break; +670 default: +671 break; +672 } +673 }674 -675 /** -676 * Edits the enum option. -677 */ -678 editEnumOption, +675 /** +676 * Possible template operations. +677 */ +678 public enum Operation {679680 /** -681 * Removes the specified enum option from the specified enum field. +681 * Adds an enum option at the end of the enum option list for the specified field.682 */ -683 removeEnumOption, +683 addEnumOption,684685 /** -686 * Adds a field at the end of the field list for the template. +686 * Edits the enum option.687 */ -688 addField, +688 editEnumOption,689690 /** -691 * Edits any number of the base properties of a field: displayName, hidden, description. +691 * Removes the specified enum option from the specified enum field.692 */ -693 editField, +693 removeEnumOption,694695 /** -696 * Removes the specified field from the template. +696 * Adds a field at the end of the field list for the template.697 */ -698 removeField, +698 addField,699700 /** -701 * Edits any number of the base properties of a template: displayName, hidden. +701 * Edits any number of the base properties of a field: displayName, hidden, description.702 */ -703 editTemplate, +703 editField,704705 /** -706 * Reorders the enum option list to match the requested enum option list. +706 * Removes the specified field from the template.707 */ -708 reorderEnumOptions, +708 removeField,709710 /** -711 * Reorders the field list to match the requested field list. +711 * Edits any number of the base properties of a template: displayName, hidden.712 */ -713 reorderFields, +713 editTemplate,714715 /** -716 * Adds a new option to a multiselect field. +716 * Reorders the enum option list to match the requested enum option list.717 */ -718 addMultiSelectOption, +718 reorderEnumOptions,719720 /** -721 * Edits an existing option in a multiselect field. +721 * Reorders the field list to match the requested field list.722 */ -723 editMultiSelectOption, +723 reorderFields,724725 /** -726 * Removes an option from a multiselect field. +726 * Adds a new option to a multiselect field.727 */ -728 removeMultiSelectOption, +728 addMultiSelectOption,729730 /** -731 * Changes the display order of options in a multiselect field. +731 * Edits an existing option in a multiselect field.732 */ -733 reorderMultiSelectOptions -734 } -735 -736 /** -737 * Class contains information about the metadata template field. -738 */ -739 public static class Field extends BoxJSONObject { -740 -741 /** -742 * @see #getID() -743 */ -744 private String id; +733 editMultiSelectOption, +734 +735 /** +736 * Removes an option from a multiselect field. +737 */ +738 removeMultiSelectOption, +739 +740 /** +741 * Changes the display order of options in a multiselect field. +742 */ +743 reorderMultiSelectOptions +744 }745 -746 /** -747 * @see #getType() -748 */ -749 private String type; -750 -751 /** -752 * @see #getKey() -753 */ -754 private String key; -755 -756 /** -757 * @see #getDisplayName() -758 */ -759 private String displayName; -760 -761 /** -762 * @see #getIsHidden() +746 /** +747 * Class contains information about the static configuration for the classification. +748 */ +749 public static class StaticConfig extends BoxJSONObject { +750 private JsonObject classification; +751 +752 /** +753 * Constructs an empty static configuration. +754 */ +755 public StaticConfig() { +756 super(); +757 } +758 +759 /** +760 * Constructs a static configuration from a JSON string. +761 * +762 * @param json the json encoded metadate template field.763 */ -764 private Boolean isHidden; -765 -766 /** -767 * @see #getDescription() -768 */ -769 private String description; -770 -771 /** -772 * @see #getOptionsObjects() -773 */ -774 private List<Option> options; +764 public StaticConfig(String json) { +765 super(json); +766 } +767 +768 /** Constructs a static configuration from a JSON object. +769 * +770 * @param jsonObject the json encoded metadate template field. +771 */ +772 StaticConfig(JsonObject jsonObject) { +773 super(jsonObject); +774 }775776 /** -777 * @see #getCopyInstanceOnItemCopy() -778 */ -779 private Boolean copyInstanceOnItemCopy; -780 -781 /** -782 * Constructs an empty metadata template. -783 */ -784 public Field() { -785 super(); -786 } -787 -788 /** -789 * Constructs a metadate template field from a JSON string. -790 * -791 * @param json the json encoded metadate template field. -792 */ -793 public Field(String json) { -794 super(json); -795 } -796 -797 /** -798 * Constructs a metadate template field from a JSON object. -799 * -800 * @param jsonObject the json encoded metadate template field. -801 */ -802 Field(JsonObject jsonObject) { -803 super(jsonObject); -804 } -805 -806 /** -807 * Gets the ID of the template field. -808 * -809 * @return the template field ID. -810 */ -811 public String getID() { -812 return this.id; -813 } -814 -815 /** -816 * Gets the data type of the field's value. -817 * -818 * @return the data type of the field's value. -819 */ -820 public String getType() { -821 return this.type; -822 } -823 -824 /** -825 * Sets the data type of the field's value. -826 * -827 * @param type the data type of the field's value. +777 * Gets the classification of the static configuration. +778 * +779 * @return the classification of the static configuration. +780 */ +781 public JsonObject getClassification() { +782 return this.classification; +783 } +784 +785 /** +786 * Sets the classification of the static configuration. +787 * +788 * @param classification the classification of the static configuration. +789 */ +790 public void setClassification(JsonObject classification) { +791 this.classification = classification; +792 } +793 +794 /** +795 * {@inheritDoc} +796 */ +797 @Override +798 void parseJSONMember(JsonObject.Member member) { +799 JsonValue value = member.getValue(); +800 String memberName = member.getName(); +801 switch (memberName) { +802 case "classification": +803 this.classification = value.asObject(); +804 break; +805 default: +806 break; +807 } +808 } +809 } +810 +811 /** +812 * Class contains information about the metadata template field. +813 */ +814 public static class Field extends BoxJSONObject { +815 +816 /** +817 * @see #getID() +818 */ +819 private String id; +820 +821 /** +822 * @see #getType() +823 */ +824 private String type; +825 +826 /** +827 * @see #getKey()828 */ -829 public void setType(String type) { -830 this.type = type; -831 } -832 -833 /** -834 * Gets the key of the field. -835 * -836 * @return the key of the field. -837 */ -838 public String getKey() { -839 return this.key; -840 } -841 -842 /** -843 * Sets the key of the field. -844 * -845 * @param key the key of the field. -846 */ -847 public void setKey(String key) { -848 this.key = key; -849 } +829 private String key; +830 +831 /** +832 * @see #getDisplayName() +833 */ +834 private String displayName; +835 +836 /** +837 * @see #getIsHidden() +838 */ +839 private Boolean isHidden; +840 +841 /** +842 * @see #getDescription() +843 */ +844 private String description; +845 +846 /** +847 * @see #getOptionsObjects() +848 */ +849 private List<Option> options;850851 /** -852 * Gets the display name of the field. -853 * -854 * @return the display name of the field. -855 */ -856 public String getDisplayName() { -857 return this.displayName; -858 } -859 -860 /** -861 * Sets the display name of the field. -862 * -863 * @param displayName the display name of the field. -864 */ -865 public void setDisplayName(String displayName) { -866 this.displayName = displayName; -867 } -868 -869 /** -870 * Gets is metadata template field hidden. -871 * -872 * @return is metadata template field hidden. -873 */ -874 public Boolean getIsHidden() { -875 return this.isHidden; -876 } -877 -878 /** -879 * Sets is metadata template field hidden. -880 * -881 * @param isHidden is metadata template field hidden? -882 */ -883 public void setIsHidden(boolean isHidden) { -884 this.isHidden = isHidden; -885 } -886 -887 /** -888 * Gets the description of the field. -889 * -890 * @return the description of the field. -891 */ -892 public String getDescription() { -893 return this.description; -894 } -895 -896 /** -897 * Sets the description of the field. -898 * -899 * @param description the description of the field. -900 */ -901 public void setDescription(String description) { -902 this.description = description; -903 } -904 -905 /** -906 * Gets list of possible options for enum type of the field. -907 * -908 * @return list of possible options for enum type of the field. -909 */ -910 public List<String> getOptions() { -911 if (this.options == null) { -912 return null; -913 } -914 List<String> optionsList = new ArrayList<>(); -915 for (Option option : this.options) { -916 optionsList.add(option.getKey()); -917 } -918 return optionsList; -919 } -920 -921 /** -922 * Sets list of possible options for enum type of the field. -923 * -924 * @param options list of possible options for enum type of the field. -925 */ -926 public void setOptions(List<String> options) { -927 if (options == null) { -928 this.options = null; -929 return; -930 } -931 List<Option> optionList = new ArrayList<>(); -932 for (String key : options) { -933 JsonObject optionObject = new JsonObject(); -934 optionObject.add("key", key); -935 Option newOption = new Option(optionObject); -936 optionList.add(newOption); -937 } -938 this.options = optionList; -939 } -940 -941 /** -942 * Gets list of possible options for options type of the field. -943 * -944 * @return list of possible options for option type of the field. -945 */ -946 public List<Option> getOptionsObjects() { -947 return this.options; -948 } -949 -950 /** -951 * Gets whether the copy operation should copy the metadata along with the item. -952 * -953 * @return whether the copy operation should copy the metadata along with the item. -954 */ -955 public Boolean getCopyInstanceOnItemCopy() { -956 return this.copyInstanceOnItemCopy; -957 } -958 -959 /** -960 * Sets whether the copy operation should copy the metadata along with the item. -961 * -962 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. -963 */ -964 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { -965 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; -966 } -967 -968 /** -969 * {@inheritDoc} -970 */ -971 @Override -972 void parseJSONMember(JsonObject.Member member) { -973 JsonValue value = member.getValue(); -974 String memberName = member.getName(); -975 switch (memberName) { -976 case "type": -977 this.type = value.asString(); -978 break; -979 case "key": -980 this.key = value.asString(); -981 break; -982 case "displayName": -983 this.displayName = value.asString(); -984 break; -985 case "hidden": -986 this.isHidden = value.asBoolean(); -987 break; -988 case "description": -989 this.description = value.asString(); -990 break; -991 case "options": -992 this.options = new ArrayList<>(); -993 for (JsonValue option : value.asArray()) { -994 this.options.add(new Option(option.asObject())); -995 } -996 break; -997 case "id": -998 this.id = value.asString(); -999 break; -1000 case "copyInstanceOnItemCopy": -1001 this.copyInstanceOnItemCopy = value.asBoolean(); -1002 break; -1003 default: -1004 break; -1005 } -1006 } -1007 } -1008 -1009 /** -1010 * Class contains information about the metadata template option. -1011 */ -1012 public static class Option extends BoxJSONObject { -1013 /** -1014 * @see #getID() -1015 */ -1016 private String id; -1017 /** -1018 * @see #getKey() -1019 */ -1020 private String key; -1021 -1022 /** -1023 * Constructs an empty metadata template. -1024 */ -1025 public Option() { -1026 super(); -1027 } -1028 -1029 /** -1030 * Constructs a metadate template option from a JSON string. -1031 * -1032 * @param json the json encoded metadata template option. -1033 */ -1034 public Option(String json) { -1035 super(json); -1036 } -1037 -1038 /** -1039 * Constructs a metadate template option from a JSON object. -1040 * -1041 * @param jsonObject the json encoded metadate template option. -1042 */ -1043 Option(JsonObject jsonObject) { -1044 super(jsonObject); -1045 } -1046 -1047 /** -1048 * Gets the ID of the template field. -1049 * -1050 * @return the template field ID. -1051 */ -1052 public String getID() { -1053 return this.id; -1054 } -1055 -1056 /** -1057 * Gets the key of the field. -1058 * -1059 * @return the key of the field. -1060 */ -1061 public String getKey() { -1062 return this.key; -1063 } -1064 -1065 /** -1066 * {@inheritDoc} -1067 */ -1068 @Override -1069 void parseJSONMember(JsonObject.Member member) { -1070 JsonValue value = member.getValue(); -1071 String memberName = member.getName(); -1072 if (memberName.equals("id")) { -1073 this.id = value.asString(); -1074 } else if (memberName.equals("key")) { -1075 this.key = value.asString(); -1076 } -1077 } -1078 } -1079 -1080 /** -1081 * Posssible operations that can be performed in a Metadata template. -1082 * <ul> -1083 * <li>Add an enum option</li> -1084 * <li>Edit an enum option</li> -1085 * <li>Remove an enum option</li> -1086 * <li>Add a field</li> -1087 * <li>Edit a field</li> -1088 * <li>Remove a field</li> -1089 * <li>Edit template</li> -1090 * <li>Reorder the enum option</li> -1091 * <li>Reorder the field list</li> -1092 * </ul> -1093 */ -1094 public static class FieldOperation extends BoxJSONObject { -1095 -1096 private Operation op; -1097 private Field data; -1098 private String fieldKey; -1099 private List<String> fieldKeys; -1100 private List<String> enumOptionKeys; -1101 private String enumOptionKey; -1102 private String multiSelectOptionKey; -1103 private List<String> multiSelectOptionKeys; -1104 -1105 /** -1106 * Constructs an empty FieldOperation. -1107 */ -1108 public FieldOperation() { -1109 super(); -1110 } -1111 -1112 /** -1113 * Constructs a Field operation from a JSON string. -1114 * -1115 * @param json the json encoded metadate template field. +852 * @see #getCopyInstanceOnItemCopy() +853 */ +854 private Boolean copyInstanceOnItemCopy; +855 +856 /** +857 * @see #getStaticConfig() +858 */ +859 private StaticConfig staticConfig; +860 +861 /** +862 * Constructs an empty metadata template. +863 */ +864 public Field() { +865 super(); +866 } +867 +868 /** +869 * Constructs a metadate template field from a JSON string. +870 * +871 * @param json the json encoded metadate template field. +872 */ +873 public Field(String json) { +874 super(json); +875 } +876 +877 /** +878 * Constructs a metadate template field from a JSON object. +879 * +880 * @param jsonObject the json encoded metadate template field. +881 */ +882 Field(JsonObject jsonObject) { +883 super(jsonObject); +884 } +885 +886 /** +887 * Gets the ID of the template field. +888 * +889 * @return the template field ID. +890 */ +891 public String getID() { +892 return this.id; +893 } +894 +895 /** +896 * Gets the data type of the field's value. +897 * +898 * @return the data type of the field's value. +899 */ +900 public String getType() { +901 return this.type; +902 } +903 +904 /** +905 * Sets the data type of the field's value. +906 * +907 * @param type the data type of the field's value. +908 */ +909 public void setType(String type) { +910 this.type = type; +911 } +912 +913 /** +914 * Gets the key of the field. +915 * +916 * @return the key of the field. +917 */ +918 public String getKey() { +919 return this.key; +920 } +921 +922 /** +923 * Sets the key of the field. +924 * +925 * @param key the key of the field. +926 */ +927 public void setKey(String key) { +928 this.key = key; +929 } +930 +931 /** +932 * Gets the display name of the field. +933 * +934 * @return the display name of the field. +935 */ +936 public String getDisplayName() { +937 return this.displayName; +938 } +939 +940 /** +941 * Sets the display name of the field. +942 * +943 * @param displayName the display name of the field. +944 */ +945 public void setDisplayName(String displayName) { +946 this.displayName = displayName; +947 } +948 +949 /** +950 * Gets is metadata template field hidden. +951 * +952 * @return is metadata template field hidden. +953 */ +954 public Boolean getIsHidden() { +955 return this.isHidden; +956 } +957 +958 /** +959 * Sets is metadata template field hidden. +960 * +961 * @param isHidden is metadata template field hidden? +962 */ +963 public void setIsHidden(boolean isHidden) { +964 this.isHidden = isHidden; +965 } +966 +967 /** +968 * Gets the description of the field. +969 * +970 * @return the description of the field. +971 */ +972 public String getDescription() { +973 return this.description; +974 } +975 +976 /** +977 * Sets the description of the field. +978 * +979 * @param description the description of the field. +980 */ +981 public void setDescription(String description) { +982 this.description = description; +983 } +984 +985 /** +986 * Gets list of possible options for enum type of the field. +987 * +988 * @return list of possible options for enum type of the field. +989 */ +990 public List<String> getOptions() { +991 if (this.options == null) { +992 return null; +993 } +994 List<String> optionsList = new ArrayList<>(); +995 for (Option option : this.options) { +996 optionsList.add(option.getKey()); +997 } +998 return optionsList; +999 } +1000 +1001 /** +1002 * Sets list of possible options for enum type of the field. +1003 * +1004 * @param options list of possible options for enum type of the field. +1005 */ +1006 public void setOptions(List<String> options) { +1007 if (options == null) { +1008 this.options = null; +1009 return; +1010 } +1011 List<Option> optionList = new ArrayList<>(); +1012 for (String key : options) { +1013 JsonObject optionObject = new JsonObject(); +1014 optionObject.add("key", key); +1015 Option newOption = new Option(optionObject); +1016 optionList.add(newOption); +1017 } +1018 this.options = optionList; +1019 } +1020 +1021 /** +1022 * Gets list of possible options for options type of the field. +1023 * +1024 * @return list of possible options for option type of the field. +1025 */ +1026 public List<Option> getOptionsObjects() { +1027 return this.options; +1028 } +1029 +1030 /** +1031 * Gets whether the copy operation should copy the metadata along with the item. +1032 * +1033 * @return whether the copy operation should copy the metadata along with the item. +1034 */ +1035 public Boolean getCopyInstanceOnItemCopy() { +1036 return this.copyInstanceOnItemCopy; +1037 } +1038 +1039 /** +1040 * Sets whether the copy operation should copy the metadata along with the item. +1041 * +1042 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. +1043 */ +1044 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { +1045 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; +1046 } +1047 +1048 /** +1049 * Gets static configuration for the classification. +1050 * +1051 * @return static configuration for the classification. +1052 */ +1053 public StaticConfig getStaticConfig() { +1054 return this.staticConfig; +1055 } +1056 +1057 /** +1058 * Sets static configuration for the classification. +1059 * +1060 * @param staticConfig static configuration for the classification. +1061 */ +1062 public void setStaticConfig(StaticConfig staticConfig) { +1063 this.staticConfig = staticConfig; +1064 } +1065 +1066 /** +1067 * {@inheritDoc} +1068 */ +1069 @Override +1070 void parseJSONMember(JsonObject.Member member) { +1071 JsonValue value = member.getValue(); +1072 String memberName = member.getName(); +1073 switch (memberName) { +1074 case "type": +1075 this.type = value.asString(); +1076 break; +1077 case "key": +1078 this.key = value.asString(); +1079 break; +1080 case "displayName": +1081 this.displayName = value.asString(); +1082 break; +1083 case "hidden": +1084 this.isHidden = value.asBoolean(); +1085 break; +1086 case "description": +1087 this.description = value.asString(); +1088 break; +1089 case "options": +1090 this.options = new ArrayList<>(); +1091 for (JsonValue option : value.asArray()) { +1092 this.options.add(new Option(option.asObject())); +1093 } +1094 break; +1095 case "id": +1096 this.id = value.asString(); +1097 break; +1098 case "copyInstanceOnItemCopy": +1099 this.copyInstanceOnItemCopy = value.asBoolean(); +1100 break; +1101 case "staticConfig": +1102 this.staticConfig = new StaticConfig(value.asObject()); +1103 break; +1104 default: +1105 break; +1106 } +1107 } +1108 } +1109 +1110 /** +1111 * Class contains information about the metadata template option. +1112 */ +1113 public static class Option extends BoxJSONObject { +1114 /** +1115 * @see #getID()1116 */ -1117 public FieldOperation(String json) { -1118 super(json); -1119 } -1120 -1121 /** -1122 * Constructs a Field operation from a JSON object. -1123 * -1124 * @param jsonObject the json encoded metadate template field. -1125 */ -1126 FieldOperation(JsonObject jsonObject) { -1127 super(jsonObject); -1128 } -1129 -1130 /** -1131 * Gets the operation. -1132 * -1133 * @return the operation -1134 */ -1135 public Operation getOp() { -1136 return this.op; -1137 } -1138 -1139 /** -1140 * Sets the operation. -1141 * -1142 * @param op the operation -1143 */ -1144 public void setOp(Operation op) { -1145 this.op = op; -1146 } -1147 -1148 /** -1149 * Gets the data associated with the operation. -1150 * -1151 * @return the field object representing the data -1152 */ -1153 public Field getData() { -1154 return this.data; -1155 } -1156 -1157 /** -1158 * Sets the data. -1159 * -1160 * @param data the Field object representing the data -1161 */ -1162 public void setData(Field data) { -1163 this.data = data; -1164 } -1165 -1166 /** -1167 * Gets the field key. -1168 * -1169 * @return the field key -1170 */ -1171 public String getFieldKey() { -1172 return this.fieldKey; -1173 } -1174 -1175 /** -1176 * Sets the field key. -1177 * -1178 * @param fieldKey the key of the field -1179 */ -1180 public void setFieldKey(String fieldKey) { -1181 this.fieldKey = fieldKey; -1182 } -1183 -1184 /** -1185 * Gets the list of field keys. -1186 * -1187 * @return the list of Strings -1188 */ -1189 public List<String> getFieldKeys() { -1190 return this.fieldKeys; -1191 } -1192 -1193 /** -1194 * Sets the list of the field keys. -1195 * -1196 * @param fieldKeys the list of strings -1197 */ -1198 public void setFieldKeys(List<String> fieldKeys) { -1199 this.fieldKeys = fieldKeys; -1200 } +1117 private String id; +1118 /** +1119 * @see #getKey() +1120 */ +1121 private String key; +1122 /** +1123 * @see #getStaticConfig() +1124 */ +1125 private StaticConfig staticConfig; +1126 +1127 /** +1128 * Constructs an empty metadata template. +1129 */ +1130 public Option() { +1131 super(); +1132 } +1133 +1134 /** +1135 * Constructs a metadate template option from a JSON string. +1136 * +1137 * @param json the json encoded metadata template option. +1138 */ +1139 public Option(String json) { +1140 super(json); +1141 } +1142 +1143 /** +1144 * Constructs a metadate template option from a JSON object. +1145 * +1146 * @param jsonObject the json encoded metadate template option. +1147 */ +1148 Option(JsonObject jsonObject) { +1149 super(jsonObject); +1150 } +1151 +1152 /** +1153 * Gets the ID of the template field. +1154 * +1155 * @return the template field ID. +1156 */ +1157 public String getID() { +1158 return this.id; +1159 } +1160 +1161 /** +1162 * Gets the key of the field. +1163 * +1164 * @return the key of the field. +1165 */ +1166 public String getKey() { +1167 return this.key; +1168 } +1169 +1170 /** +1171 * Gets static configuration for the classification. +1172 * +1173 * @return static configuration for the classification. +1174 */ +1175 public StaticConfig getStaticConfig() { +1176 return this.staticConfig; +1177 } +1178 +1179 /** +1180 * {@inheritDoc} +1181 */ +1182 @Override +1183 void parseJSONMember(JsonObject.Member member) { +1184 JsonValue value = member.getValue(); +1185 String memberName = member.getName(); +1186 switch (memberName) { +1187 case "id": +1188 this.id = value.asString(); +1189 break; +1190 case "key": +1191 this.key = value.asString(); +1192 break; +1193 case "staticConfig": +1194 this.staticConfig = new StaticConfig(value.asObject()); +1195 break; +1196 default: +1197 break; +1198 } +1199 } +1200 }1201 -1202 /** -1203 * Gets the list of keys of the Enum options. -1204 * -1205 * @return the list of Strings -1206 */ -1207 public List<String> getEnumOptionKeys() { -1208 return this.enumOptionKeys; -1209 } -1210 -1211 /** -1212 * Sets the list of the enum option keys. -1213 * -1214 * @param enumOptionKeys the list of Strings -1215 */ -1216 public void setEnumOptionKeys(List<String> enumOptionKeys) { -1217 this.enumOptionKeys = enumOptionKeys; -1218 } -1219 -1220 /** -1221 * Gets the enum option key. -1222 * -1223 * @return the enum option key -1224 */ -1225 public String getEnumOptionKey() { -1226 return this.enumOptionKey; -1227 } -1228 -1229 /** -1230 * Sets the enum option key. -1231 * -1232 * @param enumOptionKey the enum option key -1233 */ -1234 public void setEnumOptionKey(String enumOptionKey) { -1235 this.enumOptionKey = enumOptionKey; -1236 } -1237 -1238 /** -1239 * Gets the multi-select option key. -1240 * -1241 * @return the key. -1242 */ -1243 public String getMultiSelectOptionKey() { -1244 return this.multiSelectOptionKey; -1245 } -1246 -1247 /** -1248 * Sets the multi-select option key. -1249 * -1250 * @param key the key. -1251 */ -1252 public void setMultiSelectOptionKey(String key) { -1253 this.multiSelectOptionKey = key; -1254 } -1255 -1256 /** -1257 * Gets the list of multiselect option keys. -1258 * -1259 * @return the list of keys. -1260 */ -1261 public List<String> getMultiSelectOptionKeys() { -1262 return this.multiSelectOptionKeys; -1263 } -1264 -1265 /** -1266 * Sets the multi-select option keys. -1267 * -1268 * @param keys the list of keys. -1269 */ -1270 public void setMultiSelectOptionKeys(List<String> keys) { -1271 this.multiSelectOptionKeys = keys; -1272 } -1273 -1274 @Override -1275 public void clearPendingChanges() { -1276 super.clearPendingChanges(); +1202 /** +1203 * Posssible operations that can be performed in a Metadata template. +1204 * <ul> +1205 * <li>Add an enum option</li> +1206 * <li>Edit an enum option</li> +1207 * <li>Remove an enum option</li> +1208 * <li>Add a field</li> +1209 * <li>Edit a field</li> +1210 * <li>Remove a field</li> +1211 * <li>Edit template</li> +1212 * <li>Reorder the enum option</li> +1213 * <li>Reorder the field list</li> +1214 * </ul> +1215 */ +1216 public static class FieldOperation extends BoxJSONObject { +1217 +1218 private Operation op; +1219 private Field data; +1220 private String fieldKey; +1221 private List<String> fieldKeys; +1222 private List<String> enumOptionKeys; +1223 private String enumOptionKey; +1224 private String multiSelectOptionKey; +1225 private List<String> multiSelectOptionKeys; +1226 +1227 /** +1228 * Constructs an empty FieldOperation. +1229 */ +1230 public FieldOperation() { +1231 super(); +1232 } +1233 +1234 /** +1235 * Constructs a Field operation from a JSON string. +1236 * +1237 * @param json the json encoded metadate template field. +1238 */ +1239 public FieldOperation(String json) { +1240 super(json); +1241 } +1242 +1243 /** +1244 * Constructs a Field operation from a JSON object. +1245 * +1246 * @param jsonObject the json encoded metadate template field. +1247 */ +1248 FieldOperation(JsonObject jsonObject) { +1249 super(jsonObject); +1250 } +1251 +1252 /** +1253 * Gets the operation. +1254 * +1255 * @return the operation +1256 */ +1257 public Operation getOp() { +1258 return this.op; +1259 } +1260 +1261 /** +1262 * Sets the operation. +1263 * +1264 * @param op the operation +1265 */ +1266 public void setOp(Operation op) { +1267 this.op = op; +1268 } +1269 +1270 /** +1271 * Gets the data associated with the operation. +1272 * +1273 * @return the field object representing the data +1274 */ +1275 public Field getData() { +1276 return this.data;1277 }12781279 /** -1280 * {@inheritDoc} -1281 */ -1282 @Override -1283 void parseJSONMember(JsonObject.Member member) { -1284 JsonValue value = member.getValue(); -1285 String memberName = member.getName(); -1286 switch (memberName) { -1287 case "op": -1288 this.op = Operation.valueOf(value.asString()); -1289 break; -1290 case "data": -1291 this.data = new Field(value.asObject()); -1292 break; -1293 case "fieldKey": -1294 this.fieldKey = value.asString(); -1295 break; -1296 case "fieldKeys": -1297 if (this.fieldKeys == null) { -1298 this.fieldKeys = new ArrayList<>(); -1299 } else { -1300 this.fieldKeys.clear(); -1301 } -1302 for (JsonValue jsonValue : value.asArray()) { -1303 this.fieldKeys.add(jsonValue.asString()); -1304 } -1305 break; -1306 case "enumOptionKeys": -1307 if (this.enumOptionKeys == null) { -1308 this.enumOptionKeys = new ArrayList<>(); -1309 } else { -1310 this.enumOptionKeys.clear(); -1311 } -1312 -1313 for (JsonValue jsonValue : value.asArray()) { -1314 this.enumOptionKeys.add(jsonValue.asString()); -1315 } -1316 break; -1317 case "enumOptionKey": -1318 this.enumOptionKey = value.asString(); -1319 break; -1320 case "multiSelectOptionKey": -1321 this.multiSelectOptionKey = value.asString(); -1322 break; -1323 case "multiSelectOptionKeys": -1324 this.multiSelectOptionKeys = new ArrayList<>(); -1325 for (JsonValue key : value.asArray()) { -1326 this.multiSelectOptionKeys.add(key.asString()); -1327 } -1328 break; -1329 default: -1330 break; -1331 } -1332 } -1333 } -1334} +1280 * Sets the data. +1281 * +1282 * @param data the Field object representing the data +1283 */ +1284 public void setData(Field data) { +1285 this.data = data; +1286 } +1287 +1288 /** +1289 * Gets the field key. +1290 * +1291 * @return the field key +1292 */ +1293 public String getFieldKey() { +1294 return this.fieldKey; +1295 } +1296 +1297 /** +1298 * Sets the field key. +1299 * +1300 * @param fieldKey the key of the field +1301 */ +1302 public void setFieldKey(String fieldKey) { +1303 this.fieldKey = fieldKey; +1304 } +1305 +1306 /** +1307 * Gets the list of field keys. +1308 * +1309 * @return the list of Strings +1310 */ +1311 public List<String> getFieldKeys() { +1312 return this.fieldKeys; +1313 } +1314 +1315 /** +1316 * Sets the list of the field keys. +1317 * +1318 * @param fieldKeys the list of strings +1319 */ +1320 public void setFieldKeys(List<String> fieldKeys) { +1321 this.fieldKeys = fieldKeys; +1322 } +1323 +1324 /** +1325 * Gets the list of keys of the Enum options. +1326 * +1327 * @return the list of Strings +1328 */ +1329 public List<String> getEnumOptionKeys() { +1330 return this.enumOptionKeys; +1331 } +1332 +1333 /** +1334 * Sets the list of the enum option keys. +1335 * +1336 * @param enumOptionKeys the list of Strings +1337 */ +1338 public void setEnumOptionKeys(List<String> enumOptionKeys) { +1339 this.enumOptionKeys = enumOptionKeys; +1340 } +1341 +1342 /** +1343 * Gets the enum option key. +1344 * +1345 * @return the enum option key +1346 */ +1347 public String getEnumOptionKey() { +1348 return this.enumOptionKey; +1349 } +1350 +1351 /** +1352 * Sets the enum option key. +1353 * +1354 * @param enumOptionKey the enum option key +1355 */ +1356 public void setEnumOptionKey(String enumOptionKey) { +1357 this.enumOptionKey = enumOptionKey; +1358 } +1359 +1360 /** +1361 * Gets the multi-select option key. +1362 * +1363 * @return the key. +1364 */ +1365 public String getMultiSelectOptionKey() { +1366 return this.multiSelectOptionKey; +1367 } +1368 +1369 /** +1370 * Sets the multi-select option key. +1371 * +1372 * @param key the key. +1373 */ +1374 public void setMultiSelectOptionKey(String key) { +1375 this.multiSelectOptionKey = key; +1376 } +1377 +1378 /** +1379 * Gets the list of multiselect option keys. +1380 * +1381 * @return the list of keys. +1382 */ +1383 public List<String> getMultiSelectOptionKeys() { +1384 return this.multiSelectOptionKeys; +1385 } +1386 +1387 /** +1388 * Sets the multi-select option keys. +1389 * +1390 * @param keys the list of keys. +1391 */ +1392 public void setMultiSelectOptionKeys(List<String> keys) { +1393 this.multiSelectOptionKeys = keys; +1394 } +1395 +1396 @Override +1397 public void clearPendingChanges() { +1398 super.clearPendingChanges(); +1399 } +1400 +1401 /** +1402 * {@inheritDoc} +1403 */ +1404 @Override +1405 void parseJSONMember(JsonObject.Member member) { +1406 JsonValue value = member.getValue(); +1407 String memberName = member.getName(); +1408 switch (memberName) { +1409 case "op": +1410 this.op = Operation.valueOf(value.asString()); +1411 break; +1412 case "data": +1413 this.data = new Field(value.asObject()); +1414 break; +1415 case "fieldKey": +1416 this.fieldKey = value.asString(); +1417 break; +1418 case "fieldKeys": +1419 if (this.fieldKeys == null) { +1420 this.fieldKeys = new ArrayList<>(); +1421 } else { +1422 this.fieldKeys.clear(); +1423 } +1424 for (JsonValue jsonValue : value.asArray()) { +1425 this.fieldKeys.add(jsonValue.asString()); +1426 } +1427 break; +1428 case "enumOptionKeys": +1429 if (this.enumOptionKeys == null) { +1430 this.enumOptionKeys = new ArrayList<>(); +1431 } else { +1432 this.enumOptionKeys.clear(); +1433 } +1434 +1435 for (JsonValue jsonValue : value.asArray()) { +1436 this.enumOptionKeys.add(jsonValue.asString()); +1437 } +1438 break; +1439 case "enumOptionKey": +1440 this.enumOptionKey = value.asString(); +1441 break; +1442 case "multiSelectOptionKey": +1443 this.multiSelectOptionKey = value.asString(); +1444 break; +1445 case "multiSelectOptionKeys": +1446 this.multiSelectOptionKeys = new ArrayList<>(); +1447 for (JsonValue key : value.asArray()) { +1448 this.multiSelectOptionKeys.add(key.asString()); +1449 } +1450 break; +1451 default: +1452 break; +1453 } +1454 } +1455 } +1456} diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.FieldOperation.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.FieldOperation.html index 76e3722aa..494a461b2 100644 --- a/javadoc/src-html/com/box/sdk/MetadataTemplate.FieldOperation.html +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.FieldOperation.html @@ -402,944 +402,1066 @@ 394 fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);395 }396 -397 jsonObject.add("data", fieldObj); -398 } -399 -400 List<String> fieldKeys = fieldOperation.getFieldKeys(); -401 if (fieldKeys != null) { -402 jsonObject.add("fieldKeys", getJsonArray(fieldKeys)); -403 } -404 -405 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); -406 if (enumOptionKeys != null) { -407 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys)); +397 StaticConfig staticConfig = field.getStaticConfig(); +398 if (staticConfig != null) { +399 JsonObject staticConfigObj = new JsonObject(); +400 JsonObject classification = staticConfig.getClassification(); +401 if (classification != null) { +402 staticConfigObj.add("classification", classification); +403 } +404 fieldObj.add("staticConfig", staticConfigObj); +405 } +406 +407 jsonObject.add("data", fieldObj);408 }409 -410 String enumOptionKey = fieldOperation.getEnumOptionKey(); -411 if (enumOptionKey != null) { -412 jsonObject.add("enumOptionKey", enumOptionKey); +410 List<String> fieldKeys = fieldOperation.getFieldKeys(); +411 if (fieldKeys != null) { +412 jsonObject.add("fieldKeys", getJsonArray(fieldKeys));413 }414 -415 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); -416 if (multiSelectOptionKey != null) { -417 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +415 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); +416 if (enumOptionKeys != null) { +417 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));418 }419 -420 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); -421 if (multiSelectOptionKeys != null) { -422 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +420 String enumOptionKey = fieldOperation.getEnumOptionKey(); +421 if (enumOptionKey != null) { +422 jsonObject.add("enumOptionKey", enumOptionKey);423 }424 -425 return jsonObject; -426 } -427 -428 /** -429 * Gets the Json Array representation of the given list of strings. -430 * -431 * @param keys List of strings -432 * @return the JsonArray represents the list of keys -433 */ -434 private static JsonArray getJsonArray(List<String> keys) { -435 JsonArray array = new JsonArray(); -436 for (String key : keys) { -437 array.add(key); -438 } -439 -440 return array; -441 } -442 -443 /** -444 * Gets the metadata template of properties. -445 * -446 * @param api the API connection to be used. -447 * @return the metadata template returned from the server. -448 */ -449 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { -450 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +425 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); +426 if (multiSelectOptionKey != null) { +427 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +428 } +429 +430 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); +431 if (multiSelectOptionKeys != null) { +432 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +433 } +434 +435 return jsonObject; +436 } +437 +438 /** +439 * Gets the Json Array representation of the given list of strings. +440 * +441 * @param keys List of strings +442 * @return the JsonArray represents the list of keys +443 */ +444 private static JsonArray getJsonArray(List<String> keys) { +445 JsonArray array = new JsonArray(); +446 for (String key : keys) { +447 array.add(key); +448 } +449 +450 return array;451 }452453 /** -454 * Gets the metadata template of specified template type. +454 * Gets the metadata template of properties.455 * -456 * @param api the API connection to be used. -457 * @param templateName the metadata template type name. -458 * @return the metadata template returned from the server. -459 */ -460 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { -461 String scope = scopeBasedOnType(templateName); -462 return getMetadataTemplate(api, templateName, scope); -463 } -464 -465 /** -466 * Gets the metadata template of specified template type. -467 * -468 * @param api the API connection to be used. -469 * @param templateName the metadata template type name. -470 * @param scope the metadata template scope (global or enterprise). -471 * @param fields the fields to retrieve. -472 * @return the metadata template returned from the server. -473 */ -474 public static MetadataTemplate getMetadataTemplate( -475 BoxAPIConnection api, String templateName, String scope, String... fields) { -476 QueryStringBuilder builder = new QueryStringBuilder(); -477 if (fields.length > 0) { -478 builder.appendParam("fields", fields); -479 } -480 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( -481 api.getBaseURL(), builder.toString(), scope, templateName); -482 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -483 try (BoxJSONResponse response = request.send()) { -484 return new MetadataTemplate(response.getJSON()); -485 } -486 } -487 -488 /** -489 * Geta the specified metadata template by its ID. -490 * -491 * @param api the API connection to be used. -492 * @param templateID the ID of the template to get. -493 * @return the metadata template object. -494 */ -495 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { -496 -497 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); -498 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -499 try (BoxJSONResponse response = request.send()) { -500 return new MetadataTemplate(response.getJSON()); -501 } -502 } -503 -504 /** -505 * Returns all metadata templates within a user's enterprise. -506 * -507 * @param api the API connection to be used. -508 * @param fields the fields to retrieve. -509 * @return the metadata template returned from the server. -510 */ -511 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { -512 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); -513 } -514 -515 /** -516 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -517 * -518 * @param scope the scope of the metadata templates. -519 * @param api the API connection to be used. -520 * @param fields the fields to retrieve. -521 * @return the metadata template returned from the server. -522 */ -523 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -524 String scope, BoxAPIConnection api, String... fields -525 ) { -526 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); -527 } -528 -529 /** -530 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -531 * -532 * @param scope the scope of the metadata templates. -533 * @param limit maximum number of entries per response. -534 * @param api the API connection to be used. -535 * @param fields the fields to retrieve. -536 * @return the metadata template returned from the server. -537 */ -538 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -539 String scope, int limit, BoxAPIConnection api, String... fields) { -540 QueryStringBuilder builder = new QueryStringBuilder(); -541 if (fields.length > 0) { -542 builder.appendParam("fields", fields); -543 } -544 return new BoxResourceIterable<MetadataTemplate>( -545 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( -546 api.getBaseURL(), builder.toString(), scope), limit) { -547 -548 @Override -549 protected MetadataTemplate factory(JsonObject jsonObject) { -550 return new MetadataTemplate(jsonObject); -551 } -552 }; -553 } -554 -555 /** -556 * Determines the metadata scope based on type. -557 * -558 * @param typeName type of the metadata. -559 * @return scope of the metadata. -560 */ -561 private static String scopeBasedOnType(String typeName) { -562 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +456 * @param api the API connection to be used. +457 * @return the metadata template returned from the server. +458 */ +459 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { +460 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +461 } +462 +463 /** +464 * Gets the metadata template of specified template type. +465 * +466 * @param api the API connection to be used. +467 * @param templateName the metadata template type name. +468 * @return the metadata template returned from the server. +469 */ +470 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { +471 String scope = scopeBasedOnType(templateName); +472 return getMetadataTemplate(api, templateName, scope); +473 } +474 +475 /** +476 * Gets the metadata template of specified template type. +477 * +478 * @param api the API connection to be used. +479 * @param templateName the metadata template type name. +480 * @param scope the metadata template scope (global or enterprise). +481 * @param fields the fields to retrieve. +482 * @return the metadata template returned from the server. +483 */ +484 public static MetadataTemplate getMetadataTemplate( +485 BoxAPIConnection api, String templateName, String scope, String... fields) { +486 QueryStringBuilder builder = new QueryStringBuilder(); +487 if (fields.length > 0) { +488 builder.appendParam("fields", fields); +489 } +490 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( +491 api.getBaseURL(), builder.toString(), scope, templateName); +492 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +493 try (BoxJSONResponse response = request.send()) { +494 return new MetadataTemplate(response.getJSON()); +495 } +496 } +497 +498 /** +499 * Geta the specified metadata template by its ID. +500 * +501 * @param api the API connection to be used. +502 * @param templateID the ID of the template to get. +503 * @return the metadata template object. +504 */ +505 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { +506 +507 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); +508 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +509 try (BoxJSONResponse response = request.send()) { +510 return new MetadataTemplate(response.getJSON()); +511 } +512 } +513 +514 /** +515 * Returns all metadata templates within a user's enterprise. +516 * +517 * @param api the API connection to be used. +518 * @param fields the fields to retrieve. +519 * @return the metadata template returned from the server. +520 */ +521 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { +522 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); +523 } +524 +525 /** +526 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +527 * +528 * @param scope the scope of the metadata templates. +529 * @param api the API connection to be used. +530 * @param fields the fields to retrieve. +531 * @return the metadata template returned from the server. +532 */ +533 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +534 String scope, BoxAPIConnection api, String... fields +535 ) { +536 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); +537 } +538 +539 /** +540 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +541 * +542 * @param scope the scope of the metadata templates. +543 * @param limit maximum number of entries per response. +544 * @param api the API connection to be used. +545 * @param fields the fields to retrieve. +546 * @return the metadata template returned from the server. +547 */ +548 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +549 String scope, int limit, BoxAPIConnection api, String... fields) { +550 QueryStringBuilder builder = new QueryStringBuilder(); +551 if (fields.length > 0) { +552 builder.appendParam("fields", fields); +553 } +554 return new BoxResourceIterable<MetadataTemplate>( +555 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( +556 api.getBaseURL(), builder.toString(), scope), limit) { +557 +558 @Override +559 protected MetadataTemplate factory(JsonObject jsonObject) { +560 return new MetadataTemplate(jsonObject); +561 } +562 };563 }564565 /** -566 * Gets the ID of the template. +566 * Determines the metadata scope based on type.567 * -568 * @return the template ID. -569 */ -570 public String getID() { -571 return this.id; -572 } -573 -574 /** -575 * Gets the unique template key to identify the metadata template. -576 * -577 * @return the unique template key to identify the metadata template. -578 */ -579 public String getTemplateKey() { -580 return this.templateKey; -581 } -582 -583 /** -584 * Gets the metadata template scope. -585 * -586 * @return the metadata template scope. -587 */ -588 public String getScope() { -589 return this.scope; -590 } -591 -592 /** -593 * Gets the displayed metadata template name. -594 * -595 * @return the displayed metadata template name. -596 */ -597 public String getDisplayName() { -598 return this.displayName; -599 } -600 -601 /** -602 * Gets is the metadata template hidden. -603 * -604 * @return is the metadata template hidden. -605 */ -606 public Boolean getIsHidden() { -607 return this.isHidden; -608 } -609 -610 /** -611 * Gets the iterable with all fields the metadata template contains. -612 * -613 * @return the iterable with all fields the metadata template contains. -614 */ -615 public List<Field> getFields() { -616 return this.fields; -617 } -618 -619 /** -620 * Gets whether the copy operation should copy the metadata along with the item. -621 * -622 * @return whether the copy operation should copy the metadata along with the item. -623 */ -624 public Boolean getCopyInstanceOnItemCopy() { -625 return this.copyInstanceOnItemCopy; -626 } -627 -628 /** -629 * {@inheritDoc} -630 */ -631 @Override -632 void parseJSONMember(JsonObject.Member member) { -633 JsonValue value = member.getValue(); -634 String memberName = member.getName(); -635 switch (memberName) { -636 case "templateKey": -637 this.templateKey = value.asString(); -638 break; -639 case "scope": -640 this.scope = value.asString(); -641 break; -642 case "displayName": -643 this.displayName = value.asString(); -644 break; -645 case "hidden": -646 this.isHidden = value.asBoolean(); -647 break; -648 case "fields": -649 this.fields = new ArrayList<>(); -650 for (JsonValue field : value.asArray()) { -651 this.fields.add(new Field(field.asObject())); -652 } -653 break; -654 case "id": -655 this.id = value.asString(); -656 break; -657 case "copyInstanceOnItemCopy": -658 this.copyInstanceOnItemCopy = value.asBoolean(); -659 break; -660 default: -661 break; -662 } -663 } -664 -665 /** -666 * Possible template operations. -667 */ -668 public enum Operation { -669 -670 /** -671 * Adds an enum option at the end of the enum option list for the specified field. -672 */ -673 addEnumOption, +568 * @param typeName type of the metadata. +569 * @return scope of the metadata. +570 */ +571 private static String scopeBasedOnType(String typeName) { +572 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +573 } +574 +575 /** +576 * Gets the ID of the template. +577 * +578 * @return the template ID. +579 */ +580 public String getID() { +581 return this.id; +582 } +583 +584 /** +585 * Gets the unique template key to identify the metadata template. +586 * +587 * @return the unique template key to identify the metadata template. +588 */ +589 public String getTemplateKey() { +590 return this.templateKey; +591 } +592 +593 /** +594 * Gets the metadata template scope. +595 * +596 * @return the metadata template scope. +597 */ +598 public String getScope() { +599 return this.scope; +600 } +601 +602 /** +603 * Gets the displayed metadata template name. +604 * +605 * @return the displayed metadata template name. +606 */ +607 public String getDisplayName() { +608 return this.displayName; +609 } +610 +611 /** +612 * Gets is the metadata template hidden. +613 * +614 * @return is the metadata template hidden. +615 */ +616 public Boolean getIsHidden() { +617 return this.isHidden; +618 } +619 +620 /** +621 * Gets the iterable with all fields the metadata template contains. +622 * +623 * @return the iterable with all fields the metadata template contains. +624 */ +625 public List<Field> getFields() { +626 return this.fields; +627 } +628 +629 /** +630 * Gets whether the copy operation should copy the metadata along with the item. +631 * +632 * @return whether the copy operation should copy the metadata along with the item. +633 */ +634 public Boolean getCopyInstanceOnItemCopy() { +635 return this.copyInstanceOnItemCopy; +636 } +637 +638 /** +639 * {@inheritDoc} +640 */ +641 @Override +642 void parseJSONMember(JsonObject.Member member) { +643 JsonValue value = member.getValue(); +644 String memberName = member.getName(); +645 switch (memberName) { +646 case "templateKey": +647 this.templateKey = value.asString(); +648 break; +649 case "scope": +650 this.scope = value.asString(); +651 break; +652 case "displayName": +653 this.displayName = value.asString(); +654 break; +655 case "hidden": +656 this.isHidden = value.asBoolean(); +657 break; +658 case "fields": +659 this.fields = new ArrayList<>(); +660 for (JsonValue field : value.asArray()) { +661 this.fields.add(new Field(field.asObject())); +662 } +663 break; +664 case "id": +665 this.id = value.asString(); +666 break; +667 case "copyInstanceOnItemCopy": +668 this.copyInstanceOnItemCopy = value.asBoolean(); +669 break; +670 default: +671 break; +672 } +673 }674 -675 /** -676 * Edits the enum option. -677 */ -678 editEnumOption, +675 /** +676 * Possible template operations. +677 */ +678 public enum Operation {679680 /** -681 * Removes the specified enum option from the specified enum field. +681 * Adds an enum option at the end of the enum option list for the specified field.682 */ -683 removeEnumOption, +683 addEnumOption,684685 /** -686 * Adds a field at the end of the field list for the template. +686 * Edits the enum option.687 */ -688 addField, +688 editEnumOption,689690 /** -691 * Edits any number of the base properties of a field: displayName, hidden, description. +691 * Removes the specified enum option from the specified enum field.692 */ -693 editField, +693 removeEnumOption,694695 /** -696 * Removes the specified field from the template. +696 * Adds a field at the end of the field list for the template.697 */ -698 removeField, +698 addField,699700 /** -701 * Edits any number of the base properties of a template: displayName, hidden. +701 * Edits any number of the base properties of a field: displayName, hidden, description.702 */ -703 editTemplate, +703 editField,704705 /** -706 * Reorders the enum option list to match the requested enum option list. +706 * Removes the specified field from the template.707 */ -708 reorderEnumOptions, +708 removeField,709710 /** -711 * Reorders the field list to match the requested field list. +711 * Edits any number of the base properties of a template: displayName, hidden.712 */ -713 reorderFields, +713 editTemplate,714715 /** -716 * Adds a new option to a multiselect field. +716 * Reorders the enum option list to match the requested enum option list.717 */ -718 addMultiSelectOption, +718 reorderEnumOptions,719720 /** -721 * Edits an existing option in a multiselect field. +721 * Reorders the field list to match the requested field list.722 */ -723 editMultiSelectOption, +723 reorderFields,724725 /** -726 * Removes an option from a multiselect field. +726 * Adds a new option to a multiselect field.727 */ -728 removeMultiSelectOption, +728 addMultiSelectOption,729730 /** -731 * Changes the display order of options in a multiselect field. +731 * Edits an existing option in a multiselect field.732 */ -733 reorderMultiSelectOptions -734 } -735 -736 /** -737 * Class contains information about the metadata template field. -738 */ -739 public static class Field extends BoxJSONObject { -740 -741 /** -742 * @see #getID() -743 */ -744 private String id; +733 editMultiSelectOption, +734 +735 /** +736 * Removes an option from a multiselect field. +737 */ +738 removeMultiSelectOption, +739 +740 /** +741 * Changes the display order of options in a multiselect field. +742 */ +743 reorderMultiSelectOptions +744 }745 -746 /** -747 * @see #getType() -748 */ -749 private String type; -750 -751 /** -752 * @see #getKey() -753 */ -754 private String key; -755 -756 /** -757 * @see #getDisplayName() -758 */ -759 private String displayName; -760 -761 /** -762 * @see #getIsHidden() +746 /** +747 * Class contains information about the static configuration for the classification. +748 */ +749 public static class StaticConfig extends BoxJSONObject { +750 private JsonObject classification; +751 +752 /** +753 * Constructs an empty static configuration. +754 */ +755 public StaticConfig() { +756 super(); +757 } +758 +759 /** +760 * Constructs a static configuration from a JSON string. +761 * +762 * @param json the json encoded metadate template field.763 */ -764 private Boolean isHidden; -765 -766 /** -767 * @see #getDescription() -768 */ -769 private String description; -770 -771 /** -772 * @see #getOptionsObjects() -773 */ -774 private List<Option> options; +764 public StaticConfig(String json) { +765 super(json); +766 } +767 +768 /** Constructs a static configuration from a JSON object. +769 * +770 * @param jsonObject the json encoded metadate template field. +771 */ +772 StaticConfig(JsonObject jsonObject) { +773 super(jsonObject); +774 }775776 /** -777 * @see #getCopyInstanceOnItemCopy() -778 */ -779 private Boolean copyInstanceOnItemCopy; -780 -781 /** -782 * Constructs an empty metadata template. -783 */ -784 public Field() { -785 super(); -786 } -787 -788 /** -789 * Constructs a metadate template field from a JSON string. -790 * -791 * @param json the json encoded metadate template field. -792 */ -793 public Field(String json) { -794 super(json); -795 } -796 -797 /** -798 * Constructs a metadate template field from a JSON object. -799 * -800 * @param jsonObject the json encoded metadate template field. -801 */ -802 Field(JsonObject jsonObject) { -803 super(jsonObject); -804 } -805 -806 /** -807 * Gets the ID of the template field. -808 * -809 * @return the template field ID. -810 */ -811 public String getID() { -812 return this.id; -813 } -814 -815 /** -816 * Gets the data type of the field's value. -817 * -818 * @return the data type of the field's value. -819 */ -820 public String getType() { -821 return this.type; -822 } -823 -824 /** -825 * Sets the data type of the field's value. -826 * -827 * @param type the data type of the field's value. +777 * Gets the classification of the static configuration. +778 * +779 * @return the classification of the static configuration. +780 */ +781 public JsonObject getClassification() { +782 return this.classification; +783 } +784 +785 /** +786 * Sets the classification of the static configuration. +787 * +788 * @param classification the classification of the static configuration. +789 */ +790 public void setClassification(JsonObject classification) { +791 this.classification = classification; +792 } +793 +794 /** +795 * {@inheritDoc} +796 */ +797 @Override +798 void parseJSONMember(JsonObject.Member member) { +799 JsonValue value = member.getValue(); +800 String memberName = member.getName(); +801 switch (memberName) { +802 case "classification": +803 this.classification = value.asObject(); +804 break; +805 default: +806 break; +807 } +808 } +809 } +810 +811 /** +812 * Class contains information about the metadata template field. +813 */ +814 public static class Field extends BoxJSONObject { +815 +816 /** +817 * @see #getID() +818 */ +819 private String id; +820 +821 /** +822 * @see #getType() +823 */ +824 private String type; +825 +826 /** +827 * @see #getKey()828 */ -829 public void setType(String type) { -830 this.type = type; -831 } -832 -833 /** -834 * Gets the key of the field. -835 * -836 * @return the key of the field. -837 */ -838 public String getKey() { -839 return this.key; -840 } -841 -842 /** -843 * Sets the key of the field. -844 * -845 * @param key the key of the field. -846 */ -847 public void setKey(String key) { -848 this.key = key; -849 } +829 private String key; +830 +831 /** +832 * @see #getDisplayName() +833 */ +834 private String displayName; +835 +836 /** +837 * @see #getIsHidden() +838 */ +839 private Boolean isHidden; +840 +841 /** +842 * @see #getDescription() +843 */ +844 private String description; +845 +846 /** +847 * @see #getOptionsObjects() +848 */ +849 private List<Option> options;850851 /** -852 * Gets the display name of the field. -853 * -854 * @return the display name of the field. -855 */ -856 public String getDisplayName() { -857 return this.displayName; -858 } -859 -860 /** -861 * Sets the display name of the field. -862 * -863 * @param displayName the display name of the field. -864 */ -865 public void setDisplayName(String displayName) { -866 this.displayName = displayName; -867 } -868 -869 /** -870 * Gets is metadata template field hidden. -871 * -872 * @return is metadata template field hidden. -873 */ -874 public Boolean getIsHidden() { -875 return this.isHidden; -876 } -877 -878 /** -879 * Sets is metadata template field hidden. -880 * -881 * @param isHidden is metadata template field hidden? -882 */ -883 public void setIsHidden(boolean isHidden) { -884 this.isHidden = isHidden; -885 } -886 -887 /** -888 * Gets the description of the field. -889 * -890 * @return the description of the field. -891 */ -892 public String getDescription() { -893 return this.description; -894 } -895 -896 /** -897 * Sets the description of the field. -898 * -899 * @param description the description of the field. -900 */ -901 public void setDescription(String description) { -902 this.description = description; -903 } -904 -905 /** -906 * Gets list of possible options for enum type of the field. -907 * -908 * @return list of possible options for enum type of the field. -909 */ -910 public List<String> getOptions() { -911 if (this.options == null) { -912 return null; -913 } -914 List<String> optionsList = new ArrayList<>(); -915 for (Option option : this.options) { -916 optionsList.add(option.getKey()); -917 } -918 return optionsList; -919 } -920 -921 /** -922 * Sets list of possible options for enum type of the field. -923 * -924 * @param options list of possible options for enum type of the field. -925 */ -926 public void setOptions(List<String> options) { -927 if (options == null) { -928 this.options = null; -929 return; -930 } -931 List<Option> optionList = new ArrayList<>(); -932 for (String key : options) { -933 JsonObject optionObject = new JsonObject(); -934 optionObject.add("key", key); -935 Option newOption = new Option(optionObject); -936 optionList.add(newOption); -937 } -938 this.options = optionList; -939 } -940 -941 /** -942 * Gets list of possible options for options type of the field. -943 * -944 * @return list of possible options for option type of the field. -945 */ -946 public List<Option> getOptionsObjects() { -947 return this.options; -948 } -949 -950 /** -951 * Gets whether the copy operation should copy the metadata along with the item. -952 * -953 * @return whether the copy operation should copy the metadata along with the item. -954 */ -955 public Boolean getCopyInstanceOnItemCopy() { -956 return this.copyInstanceOnItemCopy; -957 } -958 -959 /** -960 * Sets whether the copy operation should copy the metadata along with the item. -961 * -962 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. -963 */ -964 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { -965 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; -966 } -967 -968 /** -969 * {@inheritDoc} -970 */ -971 @Override -972 void parseJSONMember(JsonObject.Member member) { -973 JsonValue value = member.getValue(); -974 String memberName = member.getName(); -975 switch (memberName) { -976 case "type": -977 this.type = value.asString(); -978 break; -979 case "key": -980 this.key = value.asString(); -981 break; -982 case "displayName": -983 this.displayName = value.asString(); -984 break; -985 case "hidden": -986 this.isHidden = value.asBoolean(); -987 break; -988 case "description": -989 this.description = value.asString(); -990 break; -991 case "options": -992 this.options = new ArrayList<>(); -993 for (JsonValue option : value.asArray()) { -994 this.options.add(new Option(option.asObject())); -995 } -996 break; -997 case "id": -998 this.id = value.asString(); -999 break; -1000 case "copyInstanceOnItemCopy": -1001 this.copyInstanceOnItemCopy = value.asBoolean(); -1002 break; -1003 default: -1004 break; -1005 } -1006 } -1007 } -1008 -1009 /** -1010 * Class contains information about the metadata template option. -1011 */ -1012 public static class Option extends BoxJSONObject { -1013 /** -1014 * @see #getID() -1015 */ -1016 private String id; -1017 /** -1018 * @see #getKey() -1019 */ -1020 private String key; -1021 -1022 /** -1023 * Constructs an empty metadata template. -1024 */ -1025 public Option() { -1026 super(); -1027 } -1028 -1029 /** -1030 * Constructs a metadate template option from a JSON string. -1031 * -1032 * @param json the json encoded metadata template option. -1033 */ -1034 public Option(String json) { -1035 super(json); -1036 } -1037 -1038 /** -1039 * Constructs a metadate template option from a JSON object. -1040 * -1041 * @param jsonObject the json encoded metadate template option. -1042 */ -1043 Option(JsonObject jsonObject) { -1044 super(jsonObject); -1045 } -1046 -1047 /** -1048 * Gets the ID of the template field. -1049 * -1050 * @return the template field ID. -1051 */ -1052 public String getID() { -1053 return this.id; -1054 } -1055 -1056 /** -1057 * Gets the key of the field. -1058 * -1059 * @return the key of the field. -1060 */ -1061 public String getKey() { -1062 return this.key; -1063 } -1064 -1065 /** -1066 * {@inheritDoc} -1067 */ -1068 @Override -1069 void parseJSONMember(JsonObject.Member member) { -1070 JsonValue value = member.getValue(); -1071 String memberName = member.getName(); -1072 if (memberName.equals("id")) { -1073 this.id = value.asString(); -1074 } else if (memberName.equals("key")) { -1075 this.key = value.asString(); -1076 } -1077 } -1078 } -1079 -1080 /** -1081 * Posssible operations that can be performed in a Metadata template. -1082 * <ul> -1083 * <li>Add an enum option</li> -1084 * <li>Edit an enum option</li> -1085 * <li>Remove an enum option</li> -1086 * <li>Add a field</li> -1087 * <li>Edit a field</li> -1088 * <li>Remove a field</li> -1089 * <li>Edit template</li> -1090 * <li>Reorder the enum option</li> -1091 * <li>Reorder the field list</li> -1092 * </ul> -1093 */ -1094 public static class FieldOperation extends BoxJSONObject { -1095 -1096 private Operation op; -1097 private Field data; -1098 private String fieldKey; -1099 private List<String> fieldKeys; -1100 private List<String> enumOptionKeys; -1101 private String enumOptionKey; -1102 private String multiSelectOptionKey; -1103 private List<String> multiSelectOptionKeys; -1104 -1105 /** -1106 * Constructs an empty FieldOperation. -1107 */ -1108 public FieldOperation() { -1109 super(); -1110 } -1111 -1112 /** -1113 * Constructs a Field operation from a JSON string. -1114 * -1115 * @param json the json encoded metadate template field. +852 * @see #getCopyInstanceOnItemCopy() +853 */ +854 private Boolean copyInstanceOnItemCopy; +855 +856 /** +857 * @see #getStaticConfig() +858 */ +859 private StaticConfig staticConfig; +860 +861 /** +862 * Constructs an empty metadata template. +863 */ +864 public Field() { +865 super(); +866 } +867 +868 /** +869 * Constructs a metadate template field from a JSON string. +870 * +871 * @param json the json encoded metadate template field. +872 */ +873 public Field(String json) { +874 super(json); +875 } +876 +877 /** +878 * Constructs a metadate template field from a JSON object. +879 * +880 * @param jsonObject the json encoded metadate template field. +881 */ +882 Field(JsonObject jsonObject) { +883 super(jsonObject); +884 } +885 +886 /** +887 * Gets the ID of the template field. +888 * +889 * @return the template field ID. +890 */ +891 public String getID() { +892 return this.id; +893 } +894 +895 /** +896 * Gets the data type of the field's value. +897 * +898 * @return the data type of the field's value. +899 */ +900 public String getType() { +901 return this.type; +902 } +903 +904 /** +905 * Sets the data type of the field's value. +906 * +907 * @param type the data type of the field's value. +908 */ +909 public void setType(String type) { +910 this.type = type; +911 } +912 +913 /** +914 * Gets the key of the field. +915 * +916 * @return the key of the field. +917 */ +918 public String getKey() { +919 return this.key; +920 } +921 +922 /** +923 * Sets the key of the field. +924 * +925 * @param key the key of the field. +926 */ +927 public void setKey(String key) { +928 this.key = key; +929 } +930 +931 /** +932 * Gets the display name of the field. +933 * +934 * @return the display name of the field. +935 */ +936 public String getDisplayName() { +937 return this.displayName; +938 } +939 +940 /** +941 * Sets the display name of the field. +942 * +943 * @param displayName the display name of the field. +944 */ +945 public void setDisplayName(String displayName) { +946 this.displayName = displayName; +947 } +948 +949 /** +950 * Gets is metadata template field hidden. +951 * +952 * @return is metadata template field hidden. +953 */ +954 public Boolean getIsHidden() { +955 return this.isHidden; +956 } +957 +958 /** +959 * Sets is metadata template field hidden. +960 * +961 * @param isHidden is metadata template field hidden? +962 */ +963 public void setIsHidden(boolean isHidden) { +964 this.isHidden = isHidden; +965 } +966 +967 /** +968 * Gets the description of the field. +969 * +970 * @return the description of the field. +971 */ +972 public String getDescription() { +973 return this.description; +974 } +975 +976 /** +977 * Sets the description of the field. +978 * +979 * @param description the description of the field. +980 */ +981 public void setDescription(String description) { +982 this.description = description; +983 } +984 +985 /** +986 * Gets list of possible options for enum type of the field. +987 * +988 * @return list of possible options for enum type of the field. +989 */ +990 public List<String> getOptions() { +991 if (this.options == null) { +992 return null; +993 } +994 List<String> optionsList = new ArrayList<>(); +995 for (Option option : this.options) { +996 optionsList.add(option.getKey()); +997 } +998 return optionsList; +999 } +1000 +1001 /** +1002 * Sets list of possible options for enum type of the field. +1003 * +1004 * @param options list of possible options for enum type of the field. +1005 */ +1006 public void setOptions(List<String> options) { +1007 if (options == null) { +1008 this.options = null; +1009 return; +1010 } +1011 List<Option> optionList = new ArrayList<>(); +1012 for (String key : options) { +1013 JsonObject optionObject = new JsonObject(); +1014 optionObject.add("key", key); +1015 Option newOption = new Option(optionObject); +1016 optionList.add(newOption); +1017 } +1018 this.options = optionList; +1019 } +1020 +1021 /** +1022 * Gets list of possible options for options type of the field. +1023 * +1024 * @return list of possible options for option type of the field. +1025 */ +1026 public List<Option> getOptionsObjects() { +1027 return this.options; +1028 } +1029 +1030 /** +1031 * Gets whether the copy operation should copy the metadata along with the item. +1032 * +1033 * @return whether the copy operation should copy the metadata along with the item. +1034 */ +1035 public Boolean getCopyInstanceOnItemCopy() { +1036 return this.copyInstanceOnItemCopy; +1037 } +1038 +1039 /** +1040 * Sets whether the copy operation should copy the metadata along with the item. +1041 * +1042 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. +1043 */ +1044 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { +1045 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; +1046 } +1047 +1048 /** +1049 * Gets static configuration for the classification. +1050 * +1051 * @return static configuration for the classification. +1052 */ +1053 public StaticConfig getStaticConfig() { +1054 return this.staticConfig; +1055 } +1056 +1057 /** +1058 * Sets static configuration for the classification. +1059 * +1060 * @param staticConfig static configuration for the classification. +1061 */ +1062 public void setStaticConfig(StaticConfig staticConfig) { +1063 this.staticConfig = staticConfig; +1064 } +1065 +1066 /** +1067 * {@inheritDoc} +1068 */ +1069 @Override +1070 void parseJSONMember(JsonObject.Member member) { +1071 JsonValue value = member.getValue(); +1072 String memberName = member.getName(); +1073 switch (memberName) { +1074 case "type": +1075 this.type = value.asString(); +1076 break; +1077 case "key": +1078 this.key = value.asString(); +1079 break; +1080 case "displayName": +1081 this.displayName = value.asString(); +1082 break; +1083 case "hidden": +1084 this.isHidden = value.asBoolean(); +1085 break; +1086 case "description": +1087 this.description = value.asString(); +1088 break; +1089 case "options": +1090 this.options = new ArrayList<>(); +1091 for (JsonValue option : value.asArray()) { +1092 this.options.add(new Option(option.asObject())); +1093 } +1094 break; +1095 case "id": +1096 this.id = value.asString(); +1097 break; +1098 case "copyInstanceOnItemCopy": +1099 this.copyInstanceOnItemCopy = value.asBoolean(); +1100 break; +1101 case "staticConfig": +1102 this.staticConfig = new StaticConfig(value.asObject()); +1103 break; +1104 default: +1105 break; +1106 } +1107 } +1108 } +1109 +1110 /** +1111 * Class contains information about the metadata template option. +1112 */ +1113 public static class Option extends BoxJSONObject { +1114 /** +1115 * @see #getID()1116 */ -1117 public FieldOperation(String json) { -1118 super(json); -1119 } -1120 -1121 /** -1122 * Constructs a Field operation from a JSON object. -1123 * -1124 * @param jsonObject the json encoded metadate template field. -1125 */ -1126 FieldOperation(JsonObject jsonObject) { -1127 super(jsonObject); -1128 } -1129 -1130 /** -1131 * Gets the operation. -1132 * -1133 * @return the operation -1134 */ -1135 public Operation getOp() { -1136 return this.op; -1137 } -1138 -1139 /** -1140 * Sets the operation. -1141 * -1142 * @param op the operation -1143 */ -1144 public void setOp(Operation op) { -1145 this.op = op; -1146 } -1147 -1148 /** -1149 * Gets the data associated with the operation. -1150 * -1151 * @return the field object representing the data -1152 */ -1153 public Field getData() { -1154 return this.data; -1155 } -1156 -1157 /** -1158 * Sets the data. -1159 * -1160 * @param data the Field object representing the data -1161 */ -1162 public void setData(Field data) { -1163 this.data = data; -1164 } -1165 -1166 /** -1167 * Gets the field key. -1168 * -1169 * @return the field key -1170 */ -1171 public String getFieldKey() { -1172 return this.fieldKey; -1173 } -1174 -1175 /** -1176 * Sets the field key. -1177 * -1178 * @param fieldKey the key of the field -1179 */ -1180 public void setFieldKey(String fieldKey) { -1181 this.fieldKey = fieldKey; -1182 } -1183 -1184 /** -1185 * Gets the list of field keys. -1186 * -1187 * @return the list of Strings -1188 */ -1189 public List<String> getFieldKeys() { -1190 return this.fieldKeys; -1191 } -1192 -1193 /** -1194 * Sets the list of the field keys. -1195 * -1196 * @param fieldKeys the list of strings -1197 */ -1198 public void setFieldKeys(List<String> fieldKeys) { -1199 this.fieldKeys = fieldKeys; -1200 } +1117 private String id; +1118 /** +1119 * @see #getKey() +1120 */ +1121 private String key; +1122 /** +1123 * @see #getStaticConfig() +1124 */ +1125 private StaticConfig staticConfig; +1126 +1127 /** +1128 * Constructs an empty metadata template. +1129 */ +1130 public Option() { +1131 super(); +1132 } +1133 +1134 /** +1135 * Constructs a metadate template option from a JSON string. +1136 * +1137 * @param json the json encoded metadata template option. +1138 */ +1139 public Option(String json) { +1140 super(json); +1141 } +1142 +1143 /** +1144 * Constructs a metadate template option from a JSON object. +1145 * +1146 * @param jsonObject the json encoded metadate template option. +1147 */ +1148 Option(JsonObject jsonObject) { +1149 super(jsonObject); +1150 } +1151 +1152 /** +1153 * Gets the ID of the template field. +1154 * +1155 * @return the template field ID. +1156 */ +1157 public String getID() { +1158 return this.id; +1159 } +1160 +1161 /** +1162 * Gets the key of the field. +1163 * +1164 * @return the key of the field. +1165 */ +1166 public String getKey() { +1167 return this.key; +1168 } +1169 +1170 /** +1171 * Gets static configuration for the classification. +1172 * +1173 * @return static configuration for the classification. +1174 */ +1175 public StaticConfig getStaticConfig() { +1176 return this.staticConfig; +1177 } +1178 +1179 /** +1180 * {@inheritDoc} +1181 */ +1182 @Override +1183 void parseJSONMember(JsonObject.Member member) { +1184 JsonValue value = member.getValue(); +1185 String memberName = member.getName(); +1186 switch (memberName) { +1187 case "id": +1188 this.id = value.asString(); +1189 break; +1190 case "key": +1191 this.key = value.asString(); +1192 break; +1193 case "staticConfig": +1194 this.staticConfig = new StaticConfig(value.asObject()); +1195 break; +1196 default: +1197 break; +1198 } +1199 } +1200 }1201 -1202 /** -1203 * Gets the list of keys of the Enum options. -1204 * -1205 * @return the list of Strings -1206 */ -1207 public List<String> getEnumOptionKeys() { -1208 return this.enumOptionKeys; -1209 } -1210 -1211 /** -1212 * Sets the list of the enum option keys. -1213 * -1214 * @param enumOptionKeys the list of Strings -1215 */ -1216 public void setEnumOptionKeys(List<String> enumOptionKeys) { -1217 this.enumOptionKeys = enumOptionKeys; -1218 } -1219 -1220 /** -1221 * Gets the enum option key. -1222 * -1223 * @return the enum option key -1224 */ -1225 public String getEnumOptionKey() { -1226 return this.enumOptionKey; -1227 } -1228 -1229 /** -1230 * Sets the enum option key. -1231 * -1232 * @param enumOptionKey the enum option key -1233 */ -1234 public void setEnumOptionKey(String enumOptionKey) { -1235 this.enumOptionKey = enumOptionKey; -1236 } -1237 -1238 /** -1239 * Gets the multi-select option key. -1240 * -1241 * @return the key. -1242 */ -1243 public String getMultiSelectOptionKey() { -1244 return this.multiSelectOptionKey; -1245 } -1246 -1247 /** -1248 * Sets the multi-select option key. -1249 * -1250 * @param key the key. -1251 */ -1252 public void setMultiSelectOptionKey(String key) { -1253 this.multiSelectOptionKey = key; -1254 } -1255 -1256 /** -1257 * Gets the list of multiselect option keys. -1258 * -1259 * @return the list of keys. -1260 */ -1261 public List<String> getMultiSelectOptionKeys() { -1262 return this.multiSelectOptionKeys; -1263 } -1264 -1265 /** -1266 * Sets the multi-select option keys. -1267 * -1268 * @param keys the list of keys. -1269 */ -1270 public void setMultiSelectOptionKeys(List<String> keys) { -1271 this.multiSelectOptionKeys = keys; -1272 } -1273 -1274 @Override -1275 public void clearPendingChanges() { -1276 super.clearPendingChanges(); +1202 /** +1203 * Posssible operations that can be performed in a Metadata template. +1204 * <ul> +1205 * <li>Add an enum option</li> +1206 * <li>Edit an enum option</li> +1207 * <li>Remove an enum option</li> +1208 * <li>Add a field</li> +1209 * <li>Edit a field</li> +1210 * <li>Remove a field</li> +1211 * <li>Edit template</li> +1212 * <li>Reorder the enum option</li> +1213 * <li>Reorder the field list</li> +1214 * </ul> +1215 */ +1216 public static class FieldOperation extends BoxJSONObject { +1217 +1218 private Operation op; +1219 private Field data; +1220 private String fieldKey; +1221 private List<String> fieldKeys; +1222 private List<String> enumOptionKeys; +1223 private String enumOptionKey; +1224 private String multiSelectOptionKey; +1225 private List<String> multiSelectOptionKeys; +1226 +1227 /** +1228 * Constructs an empty FieldOperation. +1229 */ +1230 public FieldOperation() { +1231 super(); +1232 } +1233 +1234 /** +1235 * Constructs a Field operation from a JSON string. +1236 * +1237 * @param json the json encoded metadate template field. +1238 */ +1239 public FieldOperation(String json) { +1240 super(json); +1241 } +1242 +1243 /** +1244 * Constructs a Field operation from a JSON object. +1245 * +1246 * @param jsonObject the json encoded metadate template field. +1247 */ +1248 FieldOperation(JsonObject jsonObject) { +1249 super(jsonObject); +1250 } +1251 +1252 /** +1253 * Gets the operation. +1254 * +1255 * @return the operation +1256 */ +1257 public Operation getOp() { +1258 return this.op; +1259 } +1260 +1261 /** +1262 * Sets the operation. +1263 * +1264 * @param op the operation +1265 */ +1266 public void setOp(Operation op) { +1267 this.op = op; +1268 } +1269 +1270 /** +1271 * Gets the data associated with the operation. +1272 * +1273 * @return the field object representing the data +1274 */ +1275 public Field getData() { +1276 return this.data;1277 }12781279 /** -1280 * {@inheritDoc} -1281 */ -1282 @Override -1283 void parseJSONMember(JsonObject.Member member) { -1284 JsonValue value = member.getValue(); -1285 String memberName = member.getName(); -1286 switch (memberName) { -1287 case "op": -1288 this.op = Operation.valueOf(value.asString()); -1289 break; -1290 case "data": -1291 this.data = new Field(value.asObject()); -1292 break; -1293 case "fieldKey": -1294 this.fieldKey = value.asString(); -1295 break; -1296 case "fieldKeys": -1297 if (this.fieldKeys == null) { -1298 this.fieldKeys = new ArrayList<>(); -1299 } else { -1300 this.fieldKeys.clear(); -1301 } -1302 for (JsonValue jsonValue : value.asArray()) { -1303 this.fieldKeys.add(jsonValue.asString()); -1304 } -1305 break; -1306 case "enumOptionKeys": -1307 if (this.enumOptionKeys == null) { -1308 this.enumOptionKeys = new ArrayList<>(); -1309 } else { -1310 this.enumOptionKeys.clear(); -1311 } -1312 -1313 for (JsonValue jsonValue : value.asArray()) { -1314 this.enumOptionKeys.add(jsonValue.asString()); -1315 } -1316 break; -1317 case "enumOptionKey": -1318 this.enumOptionKey = value.asString(); -1319 break; -1320 case "multiSelectOptionKey": -1321 this.multiSelectOptionKey = value.asString(); -1322 break; -1323 case "multiSelectOptionKeys": -1324 this.multiSelectOptionKeys = new ArrayList<>(); -1325 for (JsonValue key : value.asArray()) { -1326 this.multiSelectOptionKeys.add(key.asString()); -1327 } -1328 break; -1329 default: -1330 break; -1331 } -1332 } -1333 } -1334} +1280 * Sets the data. +1281 * +1282 * @param data the Field object representing the data +1283 */ +1284 public void setData(Field data) { +1285 this.data = data; +1286 } +1287 +1288 /** +1289 * Gets the field key. +1290 * +1291 * @return the field key +1292 */ +1293 public String getFieldKey() { +1294 return this.fieldKey; +1295 } +1296 +1297 /** +1298 * Sets the field key. +1299 * +1300 * @param fieldKey the key of the field +1301 */ +1302 public void setFieldKey(String fieldKey) { +1303 this.fieldKey = fieldKey; +1304 } +1305 +1306 /** +1307 * Gets the list of field keys. +1308 * +1309 * @return the list of Strings +1310 */ +1311 public List<String> getFieldKeys() { +1312 return this.fieldKeys; +1313 } +1314 +1315 /** +1316 * Sets the list of the field keys. +1317 * +1318 * @param fieldKeys the list of strings +1319 */ +1320 public void setFieldKeys(List<String> fieldKeys) { +1321 this.fieldKeys = fieldKeys; +1322 } +1323 +1324 /** +1325 * Gets the list of keys of the Enum options. +1326 * +1327 * @return the list of Strings +1328 */ +1329 public List<String> getEnumOptionKeys() { +1330 return this.enumOptionKeys; +1331 } +1332 +1333 /** +1334 * Sets the list of the enum option keys. +1335 * +1336 * @param enumOptionKeys the list of Strings +1337 */ +1338 public void setEnumOptionKeys(List<String> enumOptionKeys) { +1339 this.enumOptionKeys = enumOptionKeys; +1340 } +1341 +1342 /** +1343 * Gets the enum option key. +1344 * +1345 * @return the enum option key +1346 */ +1347 public String getEnumOptionKey() { +1348 return this.enumOptionKey; +1349 } +1350 +1351 /** +1352 * Sets the enum option key. +1353 * +1354 * @param enumOptionKey the enum option key +1355 */ +1356 public void setEnumOptionKey(String enumOptionKey) { +1357 this.enumOptionKey = enumOptionKey; +1358 } +1359 +1360 /** +1361 * Gets the multi-select option key. +1362 * +1363 * @return the key. +1364 */ +1365 public String getMultiSelectOptionKey() { +1366 return this.multiSelectOptionKey; +1367 } +1368 +1369 /** +1370 * Sets the multi-select option key. +1371 * +1372 * @param key the key. +1373 */ +1374 public void setMultiSelectOptionKey(String key) { +1375 this.multiSelectOptionKey = key; +1376 } +1377 +1378 /** +1379 * Gets the list of multiselect option keys. +1380 * +1381 * @return the list of keys. +1382 */ +1383 public List<String> getMultiSelectOptionKeys() { +1384 return this.multiSelectOptionKeys; +1385 } +1386 +1387 /** +1388 * Sets the multi-select option keys. +1389 * +1390 * @param keys the list of keys. +1391 */ +1392 public void setMultiSelectOptionKeys(List<String> keys) { +1393 this.multiSelectOptionKeys = keys; +1394 } +1395 +1396 @Override +1397 public void clearPendingChanges() { +1398 super.clearPendingChanges(); +1399 } +1400 +1401 /** +1402 * {@inheritDoc} +1403 */ +1404 @Override +1405 void parseJSONMember(JsonObject.Member member) { +1406 JsonValue value = member.getValue(); +1407 String memberName = member.getName(); +1408 switch (memberName) { +1409 case "op": +1410 this.op = Operation.valueOf(value.asString()); +1411 break; +1412 case "data": +1413 this.data = new Field(value.asObject()); +1414 break; +1415 case "fieldKey": +1416 this.fieldKey = value.asString(); +1417 break; +1418 case "fieldKeys": +1419 if (this.fieldKeys == null) { +1420 this.fieldKeys = new ArrayList<>(); +1421 } else { +1422 this.fieldKeys.clear(); +1423 } +1424 for (JsonValue jsonValue : value.asArray()) { +1425 this.fieldKeys.add(jsonValue.asString()); +1426 } +1427 break; +1428 case "enumOptionKeys": +1429 if (this.enumOptionKeys == null) { +1430 this.enumOptionKeys = new ArrayList<>(); +1431 } else { +1432 this.enumOptionKeys.clear(); +1433 } +1434 +1435 for (JsonValue jsonValue : value.asArray()) { +1436 this.enumOptionKeys.add(jsonValue.asString()); +1437 } +1438 break; +1439 case "enumOptionKey": +1440 this.enumOptionKey = value.asString(); +1441 break; +1442 case "multiSelectOptionKey": +1443 this.multiSelectOptionKey = value.asString(); +1444 break; +1445 case "multiSelectOptionKeys": +1446 this.multiSelectOptionKeys = new ArrayList<>(); +1447 for (JsonValue key : value.asArray()) { +1448 this.multiSelectOptionKeys.add(key.asString()); +1449 } +1450 break; +1451 default: +1452 break; +1453 } +1454 } +1455 } +1456} diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.Operation.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.Operation.html index 76e3722aa..494a461b2 100644 --- a/javadoc/src-html/com/box/sdk/MetadataTemplate.Operation.html +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.Operation.html @@ -402,944 +402,1066 @@ 394 fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);395 }396 -397 jsonObject.add("data", fieldObj); -398 } -399 -400 List<String> fieldKeys = fieldOperation.getFieldKeys(); -401 if (fieldKeys != null) { -402 jsonObject.add("fieldKeys", getJsonArray(fieldKeys)); -403 } -404 -405 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); -406 if (enumOptionKeys != null) { -407 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys)); +397 StaticConfig staticConfig = field.getStaticConfig(); +398 if (staticConfig != null) { +399 JsonObject staticConfigObj = new JsonObject(); +400 JsonObject classification = staticConfig.getClassification(); +401 if (classification != null) { +402 staticConfigObj.add("classification", classification); +403 } +404 fieldObj.add("staticConfig", staticConfigObj); +405 } +406 +407 jsonObject.add("data", fieldObj);408 }409 -410 String enumOptionKey = fieldOperation.getEnumOptionKey(); -411 if (enumOptionKey != null) { -412 jsonObject.add("enumOptionKey", enumOptionKey); +410 List<String> fieldKeys = fieldOperation.getFieldKeys(); +411 if (fieldKeys != null) { +412 jsonObject.add("fieldKeys", getJsonArray(fieldKeys));413 }414 -415 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); -416 if (multiSelectOptionKey != null) { -417 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +415 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); +416 if (enumOptionKeys != null) { +417 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));418 }419 -420 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); -421 if (multiSelectOptionKeys != null) { -422 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +420 String enumOptionKey = fieldOperation.getEnumOptionKey(); +421 if (enumOptionKey != null) { +422 jsonObject.add("enumOptionKey", enumOptionKey);423 }424 -425 return jsonObject; -426 } -427 -428 /** -429 * Gets the Json Array representation of the given list of strings. -430 * -431 * @param keys List of strings -432 * @return the JsonArray represents the list of keys -433 */ -434 private static JsonArray getJsonArray(List<String> keys) { -435 JsonArray array = new JsonArray(); -436 for (String key : keys) { -437 array.add(key); -438 } -439 -440 return array; -441 } -442 -443 /** -444 * Gets the metadata template of properties. -445 * -446 * @param api the API connection to be used. -447 * @return the metadata template returned from the server. -448 */ -449 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { -450 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +425 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); +426 if (multiSelectOptionKey != null) { +427 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +428 } +429 +430 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); +431 if (multiSelectOptionKeys != null) { +432 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +433 } +434 +435 return jsonObject; +436 } +437 +438 /** +439 * Gets the Json Array representation of the given list of strings. +440 * +441 * @param keys List of strings +442 * @return the JsonArray represents the list of keys +443 */ +444 private static JsonArray getJsonArray(List<String> keys) { +445 JsonArray array = new JsonArray(); +446 for (String key : keys) { +447 array.add(key); +448 } +449 +450 return array;451 }452453 /** -454 * Gets the metadata template of specified template type. +454 * Gets the metadata template of properties.455 * -456 * @param api the API connection to be used. -457 * @param templateName the metadata template type name. -458 * @return the metadata template returned from the server. -459 */ -460 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { -461 String scope = scopeBasedOnType(templateName); -462 return getMetadataTemplate(api, templateName, scope); -463 } -464 -465 /** -466 * Gets the metadata template of specified template type. -467 * -468 * @param api the API connection to be used. -469 * @param templateName the metadata template type name. -470 * @param scope the metadata template scope (global or enterprise). -471 * @param fields the fields to retrieve. -472 * @return the metadata template returned from the server. -473 */ -474 public static MetadataTemplate getMetadataTemplate( -475 BoxAPIConnection api, String templateName, String scope, String... fields) { -476 QueryStringBuilder builder = new QueryStringBuilder(); -477 if (fields.length > 0) { -478 builder.appendParam("fields", fields); -479 } -480 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( -481 api.getBaseURL(), builder.toString(), scope, templateName); -482 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -483 try (BoxJSONResponse response = request.send()) { -484 return new MetadataTemplate(response.getJSON()); -485 } -486 } -487 -488 /** -489 * Geta the specified metadata template by its ID. -490 * -491 * @param api the API connection to be used. -492 * @param templateID the ID of the template to get. -493 * @return the metadata template object. -494 */ -495 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { -496 -497 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); -498 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -499 try (BoxJSONResponse response = request.send()) { -500 return new MetadataTemplate(response.getJSON()); -501 } -502 } -503 -504 /** -505 * Returns all metadata templates within a user's enterprise. -506 * -507 * @param api the API connection to be used. -508 * @param fields the fields to retrieve. -509 * @return the metadata template returned from the server. -510 */ -511 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { -512 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); -513 } -514 -515 /** -516 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -517 * -518 * @param scope the scope of the metadata templates. -519 * @param api the API connection to be used. -520 * @param fields the fields to retrieve. -521 * @return the metadata template returned from the server. -522 */ -523 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -524 String scope, BoxAPIConnection api, String... fields -525 ) { -526 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); -527 } -528 -529 /** -530 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -531 * -532 * @param scope the scope of the metadata templates. -533 * @param limit maximum number of entries per response. -534 * @param api the API connection to be used. -535 * @param fields the fields to retrieve. -536 * @return the metadata template returned from the server. -537 */ -538 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -539 String scope, int limit, BoxAPIConnection api, String... fields) { -540 QueryStringBuilder builder = new QueryStringBuilder(); -541 if (fields.length > 0) { -542 builder.appendParam("fields", fields); -543 } -544 return new BoxResourceIterable<MetadataTemplate>( -545 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( -546 api.getBaseURL(), builder.toString(), scope), limit) { -547 -548 @Override -549 protected MetadataTemplate factory(JsonObject jsonObject) { -550 return new MetadataTemplate(jsonObject); -551 } -552 }; -553 } -554 -555 /** -556 * Determines the metadata scope based on type. -557 * -558 * @param typeName type of the metadata. -559 * @return scope of the metadata. -560 */ -561 private static String scopeBasedOnType(String typeName) { -562 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +456 * @param api the API connection to be used. +457 * @return the metadata template returned from the server. +458 */ +459 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { +460 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +461 } +462 +463 /** +464 * Gets the metadata template of specified template type. +465 * +466 * @param api the API connection to be used. +467 * @param templateName the metadata template type name. +468 * @return the metadata template returned from the server. +469 */ +470 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { +471 String scope = scopeBasedOnType(templateName); +472 return getMetadataTemplate(api, templateName, scope); +473 } +474 +475 /** +476 * Gets the metadata template of specified template type. +477 * +478 * @param api the API connection to be used. +479 * @param templateName the metadata template type name. +480 * @param scope the metadata template scope (global or enterprise). +481 * @param fields the fields to retrieve. +482 * @return the metadata template returned from the server. +483 */ +484 public static MetadataTemplate getMetadataTemplate( +485 BoxAPIConnection api, String templateName, String scope, String... fields) { +486 QueryStringBuilder builder = new QueryStringBuilder(); +487 if (fields.length > 0) { +488 builder.appendParam("fields", fields); +489 } +490 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( +491 api.getBaseURL(), builder.toString(), scope, templateName); +492 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +493 try (BoxJSONResponse response = request.send()) { +494 return new MetadataTemplate(response.getJSON()); +495 } +496 } +497 +498 /** +499 * Geta the specified metadata template by its ID. +500 * +501 * @param api the API connection to be used. +502 * @param templateID the ID of the template to get. +503 * @return the metadata template object. +504 */ +505 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { +506 +507 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); +508 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +509 try (BoxJSONResponse response = request.send()) { +510 return new MetadataTemplate(response.getJSON()); +511 } +512 } +513 +514 /** +515 * Returns all metadata templates within a user's enterprise. +516 * +517 * @param api the API connection to be used. +518 * @param fields the fields to retrieve. +519 * @return the metadata template returned from the server. +520 */ +521 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { +522 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); +523 } +524 +525 /** +526 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +527 * +528 * @param scope the scope of the metadata templates. +529 * @param api the API connection to be used. +530 * @param fields the fields to retrieve. +531 * @return the metadata template returned from the server. +532 */ +533 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +534 String scope, BoxAPIConnection api, String... fields +535 ) { +536 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); +537 } +538 +539 /** +540 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +541 * +542 * @param scope the scope of the metadata templates. +543 * @param limit maximum number of entries per response. +544 * @param api the API connection to be used. +545 * @param fields the fields to retrieve. +546 * @return the metadata template returned from the server. +547 */ +548 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +549 String scope, int limit, BoxAPIConnection api, String... fields) { +550 QueryStringBuilder builder = new QueryStringBuilder(); +551 if (fields.length > 0) { +552 builder.appendParam("fields", fields); +553 } +554 return new BoxResourceIterable<MetadataTemplate>( +555 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( +556 api.getBaseURL(), builder.toString(), scope), limit) { +557 +558 @Override +559 protected MetadataTemplate factory(JsonObject jsonObject) { +560 return new MetadataTemplate(jsonObject); +561 } +562 };563 }564565 /** -566 * Gets the ID of the template. +566 * Determines the metadata scope based on type.567 * -568 * @return the template ID. -569 */ -570 public String getID() { -571 return this.id; -572 } -573 -574 /** -575 * Gets the unique template key to identify the metadata template. -576 * -577 * @return the unique template key to identify the metadata template. -578 */ -579 public String getTemplateKey() { -580 return this.templateKey; -581 } -582 -583 /** -584 * Gets the metadata template scope. -585 * -586 * @return the metadata template scope. -587 */ -588 public String getScope() { -589 return this.scope; -590 } -591 -592 /** -593 * Gets the displayed metadata template name. -594 * -595 * @return the displayed metadata template name. -596 */ -597 public String getDisplayName() { -598 return this.displayName; -599 } -600 -601 /** -602 * Gets is the metadata template hidden. -603 * -604 * @return is the metadata template hidden. -605 */ -606 public Boolean getIsHidden() { -607 return this.isHidden; -608 } -609 -610 /** -611 * Gets the iterable with all fields the metadata template contains. -612 * -613 * @return the iterable with all fields the metadata template contains. -614 */ -615 public List<Field> getFields() { -616 return this.fields; -617 } -618 -619 /** -620 * Gets whether the copy operation should copy the metadata along with the item. -621 * -622 * @return whether the copy operation should copy the metadata along with the item. -623 */ -624 public Boolean getCopyInstanceOnItemCopy() { -625 return this.copyInstanceOnItemCopy; -626 } -627 -628 /** -629 * {@inheritDoc} -630 */ -631 @Override -632 void parseJSONMember(JsonObject.Member member) { -633 JsonValue value = member.getValue(); -634 String memberName = member.getName(); -635 switch (memberName) { -636 case "templateKey": -637 this.templateKey = value.asString(); -638 break; -639 case "scope": -640 this.scope = value.asString(); -641 break; -642 case "displayName": -643 this.displayName = value.asString(); -644 break; -645 case "hidden": -646 this.isHidden = value.asBoolean(); -647 break; -648 case "fields": -649 this.fields = new ArrayList<>(); -650 for (JsonValue field : value.asArray()) { -651 this.fields.add(new Field(field.asObject())); -652 } -653 break; -654 case "id": -655 this.id = value.asString(); -656 break; -657 case "copyInstanceOnItemCopy": -658 this.copyInstanceOnItemCopy = value.asBoolean(); -659 break; -660 default: -661 break; -662 } -663 } -664 -665 /** -666 * Possible template operations. -667 */ -668 public enum Operation { -669 -670 /** -671 * Adds an enum option at the end of the enum option list for the specified field. -672 */ -673 addEnumOption, +568 * @param typeName type of the metadata. +569 * @return scope of the metadata. +570 */ +571 private static String scopeBasedOnType(String typeName) { +572 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +573 } +574 +575 /** +576 * Gets the ID of the template. +577 * +578 * @return the template ID. +579 */ +580 public String getID() { +581 return this.id; +582 } +583 +584 /** +585 * Gets the unique template key to identify the metadata template. +586 * +587 * @return the unique template key to identify the metadata template. +588 */ +589 public String getTemplateKey() { +590 return this.templateKey; +591 } +592 +593 /** +594 * Gets the metadata template scope. +595 * +596 * @return the metadata template scope. +597 */ +598 public String getScope() { +599 return this.scope; +600 } +601 +602 /** +603 * Gets the displayed metadata template name. +604 * +605 * @return the displayed metadata template name. +606 */ +607 public String getDisplayName() { +608 return this.displayName; +609 } +610 +611 /** +612 * Gets is the metadata template hidden. +613 * +614 * @return is the metadata template hidden. +615 */ +616 public Boolean getIsHidden() { +617 return this.isHidden; +618 } +619 +620 /** +621 * Gets the iterable with all fields the metadata template contains. +622 * +623 * @return the iterable with all fields the metadata template contains. +624 */ +625 public List<Field> getFields() { +626 return this.fields; +627 } +628 +629 /** +630 * Gets whether the copy operation should copy the metadata along with the item. +631 * +632 * @return whether the copy operation should copy the metadata along with the item. +633 */ +634 public Boolean getCopyInstanceOnItemCopy() { +635 return this.copyInstanceOnItemCopy; +636 } +637 +638 /** +639 * {@inheritDoc} +640 */ +641 @Override +642 void parseJSONMember(JsonObject.Member member) { +643 JsonValue value = member.getValue(); +644 String memberName = member.getName(); +645 switch (memberName) { +646 case "templateKey": +647 this.templateKey = value.asString(); +648 break; +649 case "scope": +650 this.scope = value.asString(); +651 break; +652 case "displayName": +653 this.displayName = value.asString(); +654 break; +655 case "hidden": +656 this.isHidden = value.asBoolean(); +657 break; +658 case "fields": +659 this.fields = new ArrayList<>(); +660 for (JsonValue field : value.asArray()) { +661 this.fields.add(new Field(field.asObject())); +662 } +663 break; +664 case "id": +665 this.id = value.asString(); +666 break; +667 case "copyInstanceOnItemCopy": +668 this.copyInstanceOnItemCopy = value.asBoolean(); +669 break; +670 default: +671 break; +672 } +673 }674 -675 /** -676 * Edits the enum option. -677 */ -678 editEnumOption, +675 /** +676 * Possible template operations. +677 */ +678 public enum Operation {679680 /** -681 * Removes the specified enum option from the specified enum field. +681 * Adds an enum option at the end of the enum option list for the specified field.682 */ -683 removeEnumOption, +683 addEnumOption,684685 /** -686 * Adds a field at the end of the field list for the template. +686 * Edits the enum option.687 */ -688 addField, +688 editEnumOption,689690 /** -691 * Edits any number of the base properties of a field: displayName, hidden, description. +691 * Removes the specified enum option from the specified enum field.692 */ -693 editField, +693 removeEnumOption,694695 /** -696 * Removes the specified field from the template. +696 * Adds a field at the end of the field list for the template.697 */ -698 removeField, +698 addField,699700 /** -701 * Edits any number of the base properties of a template: displayName, hidden. +701 * Edits any number of the base properties of a field: displayName, hidden, description.702 */ -703 editTemplate, +703 editField,704705 /** -706 * Reorders the enum option list to match the requested enum option list. +706 * Removes the specified field from the template.707 */ -708 reorderEnumOptions, +708 removeField,709710 /** -711 * Reorders the field list to match the requested field list. +711 * Edits any number of the base properties of a template: displayName, hidden.712 */ -713 reorderFields, +713 editTemplate,714715 /** -716 * Adds a new option to a multiselect field. +716 * Reorders the enum option list to match the requested enum option list.717 */ -718 addMultiSelectOption, +718 reorderEnumOptions,719720 /** -721 * Edits an existing option in a multiselect field. +721 * Reorders the field list to match the requested field list.722 */ -723 editMultiSelectOption, +723 reorderFields,724725 /** -726 * Removes an option from a multiselect field. +726 * Adds a new option to a multiselect field.727 */ -728 removeMultiSelectOption, +728 addMultiSelectOption,729730 /** -731 * Changes the display order of options in a multiselect field. +731 * Edits an existing option in a multiselect field.732 */ -733 reorderMultiSelectOptions -734 } -735 -736 /** -737 * Class contains information about the metadata template field. -738 */ -739 public static class Field extends BoxJSONObject { -740 -741 /** -742 * @see #getID() -743 */ -744 private String id; +733 editMultiSelectOption, +734 +735 /** +736 * Removes an option from a multiselect field. +737 */ +738 removeMultiSelectOption, +739 +740 /** +741 * Changes the display order of options in a multiselect field. +742 */ +743 reorderMultiSelectOptions +744 }745 -746 /** -747 * @see #getType() -748 */ -749 private String type; -750 -751 /** -752 * @see #getKey() -753 */ -754 private String key; -755 -756 /** -757 * @see #getDisplayName() -758 */ -759 private String displayName; -760 -761 /** -762 * @see #getIsHidden() +746 /** +747 * Class contains information about the static configuration for the classification. +748 */ +749 public static class StaticConfig extends BoxJSONObject { +750 private JsonObject classification; +751 +752 /** +753 * Constructs an empty static configuration. +754 */ +755 public StaticConfig() { +756 super(); +757 } +758 +759 /** +760 * Constructs a static configuration from a JSON string. +761 * +762 * @param json the json encoded metadate template field.763 */ -764 private Boolean isHidden; -765 -766 /** -767 * @see #getDescription() -768 */ -769 private String description; -770 -771 /** -772 * @see #getOptionsObjects() -773 */ -774 private List<Option> options; +764 public StaticConfig(String json) { +765 super(json); +766 } +767 +768 /** Constructs a static configuration from a JSON object. +769 * +770 * @param jsonObject the json encoded metadate template field. +771 */ +772 StaticConfig(JsonObject jsonObject) { +773 super(jsonObject); +774 }775776 /** -777 * @see #getCopyInstanceOnItemCopy() -778 */ -779 private Boolean copyInstanceOnItemCopy; -780 -781 /** -782 * Constructs an empty metadata template. -783 */ -784 public Field() { -785 super(); -786 } -787 -788 /** -789 * Constructs a metadate template field from a JSON string. -790 * -791 * @param json the json encoded metadate template field. -792 */ -793 public Field(String json) { -794 super(json); -795 } -796 -797 /** -798 * Constructs a metadate template field from a JSON object. -799 * -800 * @param jsonObject the json encoded metadate template field. -801 */ -802 Field(JsonObject jsonObject) { -803 super(jsonObject); -804 } -805 -806 /** -807 * Gets the ID of the template field. -808 * -809 * @return the template field ID. -810 */ -811 public String getID() { -812 return this.id; -813 } -814 -815 /** -816 * Gets the data type of the field's value. -817 * -818 * @return the data type of the field's value. -819 */ -820 public String getType() { -821 return this.type; -822 } -823 -824 /** -825 * Sets the data type of the field's value. -826 * -827 * @param type the data type of the field's value. +777 * Gets the classification of the static configuration. +778 * +779 * @return the classification of the static configuration. +780 */ +781 public JsonObject getClassification() { +782 return this.classification; +783 } +784 +785 /** +786 * Sets the classification of the static configuration. +787 * +788 * @param classification the classification of the static configuration. +789 */ +790 public void setClassification(JsonObject classification) { +791 this.classification = classification; +792 } +793 +794 /** +795 * {@inheritDoc} +796 */ +797 @Override +798 void parseJSONMember(JsonObject.Member member) { +799 JsonValue value = member.getValue(); +800 String memberName = member.getName(); +801 switch (memberName) { +802 case "classification": +803 this.classification = value.asObject(); +804 break; +805 default: +806 break; +807 } +808 } +809 } +810 +811 /** +812 * Class contains information about the metadata template field. +813 */ +814 public static class Field extends BoxJSONObject { +815 +816 /** +817 * @see #getID() +818 */ +819 private String id; +820 +821 /** +822 * @see #getType() +823 */ +824 private String type; +825 +826 /** +827 * @see #getKey()828 */ -829 public void setType(String type) { -830 this.type = type; -831 } -832 -833 /** -834 * Gets the key of the field. -835 * -836 * @return the key of the field. -837 */ -838 public String getKey() { -839 return this.key; -840 } -841 -842 /** -843 * Sets the key of the field. -844 * -845 * @param key the key of the field. -846 */ -847 public void setKey(String key) { -848 this.key = key; -849 } +829 private String key; +830 +831 /** +832 * @see #getDisplayName() +833 */ +834 private String displayName; +835 +836 /** +837 * @see #getIsHidden() +838 */ +839 private Boolean isHidden; +840 +841 /** +842 * @see #getDescription() +843 */ +844 private String description; +845 +846 /** +847 * @see #getOptionsObjects() +848 */ +849 private List<Option> options;850851 /** -852 * Gets the display name of the field. -853 * -854 * @return the display name of the field. -855 */ -856 public String getDisplayName() { -857 return this.displayName; -858 } -859 -860 /** -861 * Sets the display name of the field. -862 * -863 * @param displayName the display name of the field. -864 */ -865 public void setDisplayName(String displayName) { -866 this.displayName = displayName; -867 } -868 -869 /** -870 * Gets is metadata template field hidden. -871 * -872 * @return is metadata template field hidden. -873 */ -874 public Boolean getIsHidden() { -875 return this.isHidden; -876 } -877 -878 /** -879 * Sets is metadata template field hidden. -880 * -881 * @param isHidden is metadata template field hidden? -882 */ -883 public void setIsHidden(boolean isHidden) { -884 this.isHidden = isHidden; -885 } -886 -887 /** -888 * Gets the description of the field. -889 * -890 * @return the description of the field. -891 */ -892 public String getDescription() { -893 return this.description; -894 } -895 -896 /** -897 * Sets the description of the field. -898 * -899 * @param description the description of the field. -900 */ -901 public void setDescription(String description) { -902 this.description = description; -903 } -904 -905 /** -906 * Gets list of possible options for enum type of the field. -907 * -908 * @return list of possible options for enum type of the field. -909 */ -910 public List<String> getOptions() { -911 if (this.options == null) { -912 return null; -913 } -914 List<String> optionsList = new ArrayList<>(); -915 for (Option option : this.options) { -916 optionsList.add(option.getKey()); -917 } -918 return optionsList; -919 } -920 -921 /** -922 * Sets list of possible options for enum type of the field. -923 * -924 * @param options list of possible options for enum type of the field. -925 */ -926 public void setOptions(List<String> options) { -927 if (options == null) { -928 this.options = null; -929 return; -930 } -931 List<Option> optionList = new ArrayList<>(); -932 for (String key : options) { -933 JsonObject optionObject = new JsonObject(); -934 optionObject.add("key", key); -935 Option newOption = new Option(optionObject); -936 optionList.add(newOption); -937 } -938 this.options = optionList; -939 } -940 -941 /** -942 * Gets list of possible options for options type of the field. -943 * -944 * @return list of possible options for option type of the field. -945 */ -946 public List<Option> getOptionsObjects() { -947 return this.options; -948 } -949 -950 /** -951 * Gets whether the copy operation should copy the metadata along with the item. -952 * -953 * @return whether the copy operation should copy the metadata along with the item. -954 */ -955 public Boolean getCopyInstanceOnItemCopy() { -956 return this.copyInstanceOnItemCopy; -957 } -958 -959 /** -960 * Sets whether the copy operation should copy the metadata along with the item. -961 * -962 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. -963 */ -964 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { -965 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; -966 } -967 -968 /** -969 * {@inheritDoc} -970 */ -971 @Override -972 void parseJSONMember(JsonObject.Member member) { -973 JsonValue value = member.getValue(); -974 String memberName = member.getName(); -975 switch (memberName) { -976 case "type": -977 this.type = value.asString(); -978 break; -979 case "key": -980 this.key = value.asString(); -981 break; -982 case "displayName": -983 this.displayName = value.asString(); -984 break; -985 case "hidden": -986 this.isHidden = value.asBoolean(); -987 break; -988 case "description": -989 this.description = value.asString(); -990 break; -991 case "options": -992 this.options = new ArrayList<>(); -993 for (JsonValue option : value.asArray()) { -994 this.options.add(new Option(option.asObject())); -995 } -996 break; -997 case "id": -998 this.id = value.asString(); -999 break; -1000 case "copyInstanceOnItemCopy": -1001 this.copyInstanceOnItemCopy = value.asBoolean(); -1002 break; -1003 default: -1004 break; -1005 } -1006 } -1007 } -1008 -1009 /** -1010 * Class contains information about the metadata template option. -1011 */ -1012 public static class Option extends BoxJSONObject { -1013 /** -1014 * @see #getID() -1015 */ -1016 private String id; -1017 /** -1018 * @see #getKey() -1019 */ -1020 private String key; -1021 -1022 /** -1023 * Constructs an empty metadata template. -1024 */ -1025 public Option() { -1026 super(); -1027 } -1028 -1029 /** -1030 * Constructs a metadate template option from a JSON string. -1031 * -1032 * @param json the json encoded metadata template option. -1033 */ -1034 public Option(String json) { -1035 super(json); -1036 } -1037 -1038 /** -1039 * Constructs a metadate template option from a JSON object. -1040 * -1041 * @param jsonObject the json encoded metadate template option. -1042 */ -1043 Option(JsonObject jsonObject) { -1044 super(jsonObject); -1045 } -1046 -1047 /** -1048 * Gets the ID of the template field. -1049 * -1050 * @return the template field ID. -1051 */ -1052 public String getID() { -1053 return this.id; -1054 } -1055 -1056 /** -1057 * Gets the key of the field. -1058 * -1059 * @return the key of the field. -1060 */ -1061 public String getKey() { -1062 return this.key; -1063 } -1064 -1065 /** -1066 * {@inheritDoc} -1067 */ -1068 @Override -1069 void parseJSONMember(JsonObject.Member member) { -1070 JsonValue value = member.getValue(); -1071 String memberName = member.getName(); -1072 if (memberName.equals("id")) { -1073 this.id = value.asString(); -1074 } else if (memberName.equals("key")) { -1075 this.key = value.asString(); -1076 } -1077 } -1078 } -1079 -1080 /** -1081 * Posssible operations that can be performed in a Metadata template. -1082 * <ul> -1083 * <li>Add an enum option</li> -1084 * <li>Edit an enum option</li> -1085 * <li>Remove an enum option</li> -1086 * <li>Add a field</li> -1087 * <li>Edit a field</li> -1088 * <li>Remove a field</li> -1089 * <li>Edit template</li> -1090 * <li>Reorder the enum option</li> -1091 * <li>Reorder the field list</li> -1092 * </ul> -1093 */ -1094 public static class FieldOperation extends BoxJSONObject { -1095 -1096 private Operation op; -1097 private Field data; -1098 private String fieldKey; -1099 private List<String> fieldKeys; -1100 private List<String> enumOptionKeys; -1101 private String enumOptionKey; -1102 private String multiSelectOptionKey; -1103 private List<String> multiSelectOptionKeys; -1104 -1105 /** -1106 * Constructs an empty FieldOperation. -1107 */ -1108 public FieldOperation() { -1109 super(); -1110 } -1111 -1112 /** -1113 * Constructs a Field operation from a JSON string. -1114 * -1115 * @param json the json encoded metadate template field. +852 * @see #getCopyInstanceOnItemCopy() +853 */ +854 private Boolean copyInstanceOnItemCopy; +855 +856 /** +857 * @see #getStaticConfig() +858 */ +859 private StaticConfig staticConfig; +860 +861 /** +862 * Constructs an empty metadata template. +863 */ +864 public Field() { +865 super(); +866 } +867 +868 /** +869 * Constructs a metadate template field from a JSON string. +870 * +871 * @param json the json encoded metadate template field. +872 */ +873 public Field(String json) { +874 super(json); +875 } +876 +877 /** +878 * Constructs a metadate template field from a JSON object. +879 * +880 * @param jsonObject the json encoded metadate template field. +881 */ +882 Field(JsonObject jsonObject) { +883 super(jsonObject); +884 } +885 +886 /** +887 * Gets the ID of the template field. +888 * +889 * @return the template field ID. +890 */ +891 public String getID() { +892 return this.id; +893 } +894 +895 /** +896 * Gets the data type of the field's value. +897 * +898 * @return the data type of the field's value. +899 */ +900 public String getType() { +901 return this.type; +902 } +903 +904 /** +905 * Sets the data type of the field's value. +906 * +907 * @param type the data type of the field's value. +908 */ +909 public void setType(String type) { +910 this.type = type; +911 } +912 +913 /** +914 * Gets the key of the field. +915 * +916 * @return the key of the field. +917 */ +918 public String getKey() { +919 return this.key; +920 } +921 +922 /** +923 * Sets the key of the field. +924 * +925 * @param key the key of the field. +926 */ +927 public void setKey(String key) { +928 this.key = key; +929 } +930 +931 /** +932 * Gets the display name of the field. +933 * +934 * @return the display name of the field. +935 */ +936 public String getDisplayName() { +937 return this.displayName; +938 } +939 +940 /** +941 * Sets the display name of the field. +942 * +943 * @param displayName the display name of the field. +944 */ +945 public void setDisplayName(String displayName) { +946 this.displayName = displayName; +947 } +948 +949 /** +950 * Gets is metadata template field hidden. +951 * +952 * @return is metadata template field hidden. +953 */ +954 public Boolean getIsHidden() { +955 return this.isHidden; +956 } +957 +958 /** +959 * Sets is metadata template field hidden. +960 * +961 * @param isHidden is metadata template field hidden? +962 */ +963 public void setIsHidden(boolean isHidden) { +964 this.isHidden = isHidden; +965 } +966 +967 /** +968 * Gets the description of the field. +969 * +970 * @return the description of the field. +971 */ +972 public String getDescription() { +973 return this.description; +974 } +975 +976 /** +977 * Sets the description of the field. +978 * +979 * @param description the description of the field. +980 */ +981 public void setDescription(String description) { +982 this.description = description; +983 } +984 +985 /** +986 * Gets list of possible options for enum type of the field. +987 * +988 * @return list of possible options for enum type of the field. +989 */ +990 public List<String> getOptions() { +991 if (this.options == null) { +992 return null; +993 } +994 List<String> optionsList = new ArrayList<>(); +995 for (Option option : this.options) { +996 optionsList.add(option.getKey()); +997 } +998 return optionsList; +999 } +1000 +1001 /** +1002 * Sets list of possible options for enum type of the field. +1003 * +1004 * @param options list of possible options for enum type of the field. +1005 */ +1006 public void setOptions(List<String> options) { +1007 if (options == null) { +1008 this.options = null; +1009 return; +1010 } +1011 List<Option> optionList = new ArrayList<>(); +1012 for (String key : options) { +1013 JsonObject optionObject = new JsonObject(); +1014 optionObject.add("key", key); +1015 Option newOption = new Option(optionObject); +1016 optionList.add(newOption); +1017 } +1018 this.options = optionList; +1019 } +1020 +1021 /** +1022 * Gets list of possible options for options type of the field. +1023 * +1024 * @return list of possible options for option type of the field. +1025 */ +1026 public List<Option> getOptionsObjects() { +1027 return this.options; +1028 } +1029 +1030 /** +1031 * Gets whether the copy operation should copy the metadata along with the item. +1032 * +1033 * @return whether the copy operation should copy the metadata along with the item. +1034 */ +1035 public Boolean getCopyInstanceOnItemCopy() { +1036 return this.copyInstanceOnItemCopy; +1037 } +1038 +1039 /** +1040 * Sets whether the copy operation should copy the metadata along with the item. +1041 * +1042 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. +1043 */ +1044 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { +1045 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; +1046 } +1047 +1048 /** +1049 * Gets static configuration for the classification. +1050 * +1051 * @return static configuration for the classification. +1052 */ +1053 public StaticConfig getStaticConfig() { +1054 return this.staticConfig; +1055 } +1056 +1057 /** +1058 * Sets static configuration for the classification. +1059 * +1060 * @param staticConfig static configuration for the classification. +1061 */ +1062 public void setStaticConfig(StaticConfig staticConfig) { +1063 this.staticConfig = staticConfig; +1064 } +1065 +1066 /** +1067 * {@inheritDoc} +1068 */ +1069 @Override +1070 void parseJSONMember(JsonObject.Member member) { +1071 JsonValue value = member.getValue(); +1072 String memberName = member.getName(); +1073 switch (memberName) { +1074 case "type": +1075 this.type = value.asString(); +1076 break; +1077 case "key": +1078 this.key = value.asString(); +1079 break; +1080 case "displayName": +1081 this.displayName = value.asString(); +1082 break; +1083 case "hidden": +1084 this.isHidden = value.asBoolean(); +1085 break; +1086 case "description": +1087 this.description = value.asString(); +1088 break; +1089 case "options": +1090 this.options = new ArrayList<>(); +1091 for (JsonValue option : value.asArray()) { +1092 this.options.add(new Option(option.asObject())); +1093 } +1094 break; +1095 case "id": +1096 this.id = value.asString(); +1097 break; +1098 case "copyInstanceOnItemCopy": +1099 this.copyInstanceOnItemCopy = value.asBoolean(); +1100 break; +1101 case "staticConfig": +1102 this.staticConfig = new StaticConfig(value.asObject()); +1103 break; +1104 default: +1105 break; +1106 } +1107 } +1108 } +1109 +1110 /** +1111 * Class contains information about the metadata template option. +1112 */ +1113 public static class Option extends BoxJSONObject { +1114 /** +1115 * @see #getID()1116 */ -1117 public FieldOperation(String json) { -1118 super(json); -1119 } -1120 -1121 /** -1122 * Constructs a Field operation from a JSON object. -1123 * -1124 * @param jsonObject the json encoded metadate template field. -1125 */ -1126 FieldOperation(JsonObject jsonObject) { -1127 super(jsonObject); -1128 } -1129 -1130 /** -1131 * Gets the operation. -1132 * -1133 * @return the operation -1134 */ -1135 public Operation getOp() { -1136 return this.op; -1137 } -1138 -1139 /** -1140 * Sets the operation. -1141 * -1142 * @param op the operation -1143 */ -1144 public void setOp(Operation op) { -1145 this.op = op; -1146 } -1147 -1148 /** -1149 * Gets the data associated with the operation. -1150 * -1151 * @return the field object representing the data -1152 */ -1153 public Field getData() { -1154 return this.data; -1155 } -1156 -1157 /** -1158 * Sets the data. -1159 * -1160 * @param data the Field object representing the data -1161 */ -1162 public void setData(Field data) { -1163 this.data = data; -1164 } -1165 -1166 /** -1167 * Gets the field key. -1168 * -1169 * @return the field key -1170 */ -1171 public String getFieldKey() { -1172 return this.fieldKey; -1173 } -1174 -1175 /** -1176 * Sets the field key. -1177 * -1178 * @param fieldKey the key of the field -1179 */ -1180 public void setFieldKey(String fieldKey) { -1181 this.fieldKey = fieldKey; -1182 } -1183 -1184 /** -1185 * Gets the list of field keys. -1186 * -1187 * @return the list of Strings -1188 */ -1189 public List<String> getFieldKeys() { -1190 return this.fieldKeys; -1191 } -1192 -1193 /** -1194 * Sets the list of the field keys. -1195 * -1196 * @param fieldKeys the list of strings -1197 */ -1198 public void setFieldKeys(List<String> fieldKeys) { -1199 this.fieldKeys = fieldKeys; -1200 } +1117 private String id; +1118 /** +1119 * @see #getKey() +1120 */ +1121 private String key; +1122 /** +1123 * @see #getStaticConfig() +1124 */ +1125 private StaticConfig staticConfig; +1126 +1127 /** +1128 * Constructs an empty metadata template. +1129 */ +1130 public Option() { +1131 super(); +1132 } +1133 +1134 /** +1135 * Constructs a metadate template option from a JSON string. +1136 * +1137 * @param json the json encoded metadata template option. +1138 */ +1139 public Option(String json) { +1140 super(json); +1141 } +1142 +1143 /** +1144 * Constructs a metadate template option from a JSON object. +1145 * +1146 * @param jsonObject the json encoded metadate template option. +1147 */ +1148 Option(JsonObject jsonObject) { +1149 super(jsonObject); +1150 } +1151 +1152 /** +1153 * Gets the ID of the template field. +1154 * +1155 * @return the template field ID. +1156 */ +1157 public String getID() { +1158 return this.id; +1159 } +1160 +1161 /** +1162 * Gets the key of the field. +1163 * +1164 * @return the key of the field. +1165 */ +1166 public String getKey() { +1167 return this.key; +1168 } +1169 +1170 /** +1171 * Gets static configuration for the classification. +1172 * +1173 * @return static configuration for the classification. +1174 */ +1175 public StaticConfig getStaticConfig() { +1176 return this.staticConfig; +1177 } +1178 +1179 /** +1180 * {@inheritDoc} +1181 */ +1182 @Override +1183 void parseJSONMember(JsonObject.Member member) { +1184 JsonValue value = member.getValue(); +1185 String memberName = member.getName(); +1186 switch (memberName) { +1187 case "id": +1188 this.id = value.asString(); +1189 break; +1190 case "key": +1191 this.key = value.asString(); +1192 break; +1193 case "staticConfig": +1194 this.staticConfig = new StaticConfig(value.asObject()); +1195 break; +1196 default: +1197 break; +1198 } +1199 } +1200 }1201 -1202 /** -1203 * Gets the list of keys of the Enum options. -1204 * -1205 * @return the list of Strings -1206 */ -1207 public List<String> getEnumOptionKeys() { -1208 return this.enumOptionKeys; -1209 } -1210 -1211 /** -1212 * Sets the list of the enum option keys. -1213 * -1214 * @param enumOptionKeys the list of Strings -1215 */ -1216 public void setEnumOptionKeys(List<String> enumOptionKeys) { -1217 this.enumOptionKeys = enumOptionKeys; -1218 } -1219 -1220 /** -1221 * Gets the enum option key. -1222 * -1223 * @return the enum option key -1224 */ -1225 public String getEnumOptionKey() { -1226 return this.enumOptionKey; -1227 } -1228 -1229 /** -1230 * Sets the enum option key. -1231 * -1232 * @param enumOptionKey the enum option key -1233 */ -1234 public void setEnumOptionKey(String enumOptionKey) { -1235 this.enumOptionKey = enumOptionKey; -1236 } -1237 -1238 /** -1239 * Gets the multi-select option key. -1240 * -1241 * @return the key. -1242 */ -1243 public String getMultiSelectOptionKey() { -1244 return this.multiSelectOptionKey; -1245 } -1246 -1247 /** -1248 * Sets the multi-select option key. -1249 * -1250 * @param key the key. -1251 */ -1252 public void setMultiSelectOptionKey(String key) { -1253 this.multiSelectOptionKey = key; -1254 } -1255 -1256 /** -1257 * Gets the list of multiselect option keys. -1258 * -1259 * @return the list of keys. -1260 */ -1261 public List<String> getMultiSelectOptionKeys() { -1262 return this.multiSelectOptionKeys; -1263 } -1264 -1265 /** -1266 * Sets the multi-select option keys. -1267 * -1268 * @param keys the list of keys. -1269 */ -1270 public void setMultiSelectOptionKeys(List<String> keys) { -1271 this.multiSelectOptionKeys = keys; -1272 } -1273 -1274 @Override -1275 public void clearPendingChanges() { -1276 super.clearPendingChanges(); +1202 /** +1203 * Posssible operations that can be performed in a Metadata template. +1204 * <ul> +1205 * <li>Add an enum option</li> +1206 * <li>Edit an enum option</li> +1207 * <li>Remove an enum option</li> +1208 * <li>Add a field</li> +1209 * <li>Edit a field</li> +1210 * <li>Remove a field</li> +1211 * <li>Edit template</li> +1212 * <li>Reorder the enum option</li> +1213 * <li>Reorder the field list</li> +1214 * </ul> +1215 */ +1216 public static class FieldOperation extends BoxJSONObject { +1217 +1218 private Operation op; +1219 private Field data; +1220 private String fieldKey; +1221 private List<String> fieldKeys; +1222 private List<String> enumOptionKeys; +1223 private String enumOptionKey; +1224 private String multiSelectOptionKey; +1225 private List<String> multiSelectOptionKeys; +1226 +1227 /** +1228 * Constructs an empty FieldOperation. +1229 */ +1230 public FieldOperation() { +1231 super(); +1232 } +1233 +1234 /** +1235 * Constructs a Field operation from a JSON string. +1236 * +1237 * @param json the json encoded metadate template field. +1238 */ +1239 public FieldOperation(String json) { +1240 super(json); +1241 } +1242 +1243 /** +1244 * Constructs a Field operation from a JSON object. +1245 * +1246 * @param jsonObject the json encoded metadate template field. +1247 */ +1248 FieldOperation(JsonObject jsonObject) { +1249 super(jsonObject); +1250 } +1251 +1252 /** +1253 * Gets the operation. +1254 * +1255 * @return the operation +1256 */ +1257 public Operation getOp() { +1258 return this.op; +1259 } +1260 +1261 /** +1262 * Sets the operation. +1263 * +1264 * @param op the operation +1265 */ +1266 public void setOp(Operation op) { +1267 this.op = op; +1268 } +1269 +1270 /** +1271 * Gets the data associated with the operation. +1272 * +1273 * @return the field object representing the data +1274 */ +1275 public Field getData() { +1276 return this.data;1277 }12781279 /** -1280 * {@inheritDoc} -1281 */ -1282 @Override -1283 void parseJSONMember(JsonObject.Member member) { -1284 JsonValue value = member.getValue(); -1285 String memberName = member.getName(); -1286 switch (memberName) { -1287 case "op": -1288 this.op = Operation.valueOf(value.asString()); -1289 break; -1290 case "data": -1291 this.data = new Field(value.asObject()); -1292 break; -1293 case "fieldKey": -1294 this.fieldKey = value.asString(); -1295 break; -1296 case "fieldKeys": -1297 if (this.fieldKeys == null) { -1298 this.fieldKeys = new ArrayList<>(); -1299 } else { -1300 this.fieldKeys.clear(); -1301 } -1302 for (JsonValue jsonValue : value.asArray()) { -1303 this.fieldKeys.add(jsonValue.asString()); -1304 } -1305 break; -1306 case "enumOptionKeys": -1307 if (this.enumOptionKeys == null) { -1308 this.enumOptionKeys = new ArrayList<>(); -1309 } else { -1310 this.enumOptionKeys.clear(); -1311 } -1312 -1313 for (JsonValue jsonValue : value.asArray()) { -1314 this.enumOptionKeys.add(jsonValue.asString()); -1315 } -1316 break; -1317 case "enumOptionKey": -1318 this.enumOptionKey = value.asString(); -1319 break; -1320 case "multiSelectOptionKey": -1321 this.multiSelectOptionKey = value.asString(); -1322 break; -1323 case "multiSelectOptionKeys": -1324 this.multiSelectOptionKeys = new ArrayList<>(); -1325 for (JsonValue key : value.asArray()) { -1326 this.multiSelectOptionKeys.add(key.asString()); -1327 } -1328 break; -1329 default: -1330 break; -1331 } -1332 } -1333 } -1334} +1280 * Sets the data. +1281 * +1282 * @param data the Field object representing the data +1283 */ +1284 public void setData(Field data) { +1285 this.data = data; +1286 } +1287 +1288 /** +1289 * Gets the field key. +1290 * +1291 * @return the field key +1292 */ +1293 public String getFieldKey() { +1294 return this.fieldKey; +1295 } +1296 +1297 /** +1298 * Sets the field key. +1299 * +1300 * @param fieldKey the key of the field +1301 */ +1302 public void setFieldKey(String fieldKey) { +1303 this.fieldKey = fieldKey; +1304 } +1305 +1306 /** +1307 * Gets the list of field keys. +1308 * +1309 * @return the list of Strings +1310 */ +1311 public List<String> getFieldKeys() { +1312 return this.fieldKeys; +1313 } +1314 +1315 /** +1316 * Sets the list of the field keys. +1317 * +1318 * @param fieldKeys the list of strings +1319 */ +1320 public void setFieldKeys(List<String> fieldKeys) { +1321 this.fieldKeys = fieldKeys; +1322 } +1323 +1324 /** +1325 * Gets the list of keys of the Enum options. +1326 * +1327 * @return the list of Strings +1328 */ +1329 public List<String> getEnumOptionKeys() { +1330 return this.enumOptionKeys; +1331 } +1332 +1333 /** +1334 * Sets the list of the enum option keys. +1335 * +1336 * @param enumOptionKeys the list of Strings +1337 */ +1338 public void setEnumOptionKeys(List<String> enumOptionKeys) { +1339 this.enumOptionKeys = enumOptionKeys; +1340 } +1341 +1342 /** +1343 * Gets the enum option key. +1344 * +1345 * @return the enum option key +1346 */ +1347 public String getEnumOptionKey() { +1348 return this.enumOptionKey; +1349 } +1350 +1351 /** +1352 * Sets the enum option key. +1353 * +1354 * @param enumOptionKey the enum option key +1355 */ +1356 public void setEnumOptionKey(String enumOptionKey) { +1357 this.enumOptionKey = enumOptionKey; +1358 } +1359 +1360 /** +1361 * Gets the multi-select option key. +1362 * +1363 * @return the key. +1364 */ +1365 public String getMultiSelectOptionKey() { +1366 return this.multiSelectOptionKey; +1367 } +1368 +1369 /** +1370 * Sets the multi-select option key. +1371 * +1372 * @param key the key. +1373 */ +1374 public void setMultiSelectOptionKey(String key) { +1375 this.multiSelectOptionKey = key; +1376 } +1377 +1378 /** +1379 * Gets the list of multiselect option keys. +1380 * +1381 * @return the list of keys. +1382 */ +1383 public List<String> getMultiSelectOptionKeys() { +1384 return this.multiSelectOptionKeys; +1385 } +1386 +1387 /** +1388 * Sets the multi-select option keys. +1389 * +1390 * @param keys the list of keys. +1391 */ +1392 public void setMultiSelectOptionKeys(List<String> keys) { +1393 this.multiSelectOptionKeys = keys; +1394 } +1395 +1396 @Override +1397 public void clearPendingChanges() { +1398 super.clearPendingChanges(); +1399 } +1400 +1401 /** +1402 * {@inheritDoc} +1403 */ +1404 @Override +1405 void parseJSONMember(JsonObject.Member member) { +1406 JsonValue value = member.getValue(); +1407 String memberName = member.getName(); +1408 switch (memberName) { +1409 case "op": +1410 this.op = Operation.valueOf(value.asString()); +1411 break; +1412 case "data": +1413 this.data = new Field(value.asObject()); +1414 break; +1415 case "fieldKey": +1416 this.fieldKey = value.asString(); +1417 break; +1418 case "fieldKeys": +1419 if (this.fieldKeys == null) { +1420 this.fieldKeys = new ArrayList<>(); +1421 } else { +1422 this.fieldKeys.clear(); +1423 } +1424 for (JsonValue jsonValue : value.asArray()) { +1425 this.fieldKeys.add(jsonValue.asString()); +1426 } +1427 break; +1428 case "enumOptionKeys": +1429 if (this.enumOptionKeys == null) { +1430 this.enumOptionKeys = new ArrayList<>(); +1431 } else { +1432 this.enumOptionKeys.clear(); +1433 } +1434 +1435 for (JsonValue jsonValue : value.asArray()) { +1436 this.enumOptionKeys.add(jsonValue.asString()); +1437 } +1438 break; +1439 case "enumOptionKey": +1440 this.enumOptionKey = value.asString(); +1441 break; +1442 case "multiSelectOptionKey": +1443 this.multiSelectOptionKey = value.asString(); +1444 break; +1445 case "multiSelectOptionKeys": +1446 this.multiSelectOptionKeys = new ArrayList<>(); +1447 for (JsonValue key : value.asArray()) { +1448 this.multiSelectOptionKeys.add(key.asString()); +1449 } +1450 break; +1451 default: +1452 break; +1453 } +1454 } +1455 } +1456} diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.Option.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.Option.html index 76e3722aa..494a461b2 100644 --- a/javadoc/src-html/com/box/sdk/MetadataTemplate.Option.html +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.Option.html @@ -402,944 +402,1066 @@ 394 fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);395 }396 -397 jsonObject.add("data", fieldObj); -398 } -399 -400 List<String> fieldKeys = fieldOperation.getFieldKeys(); -401 if (fieldKeys != null) { -402 jsonObject.add("fieldKeys", getJsonArray(fieldKeys)); -403 } -404 -405 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); -406 if (enumOptionKeys != null) { -407 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys)); +397 StaticConfig staticConfig = field.getStaticConfig(); +398 if (staticConfig != null) { +399 JsonObject staticConfigObj = new JsonObject(); +400 JsonObject classification = staticConfig.getClassification(); +401 if (classification != null) { +402 staticConfigObj.add("classification", classification); +403 } +404 fieldObj.add("staticConfig", staticConfigObj); +405 } +406 +407 jsonObject.add("data", fieldObj);408 }409 -410 String enumOptionKey = fieldOperation.getEnumOptionKey(); -411 if (enumOptionKey != null) { -412 jsonObject.add("enumOptionKey", enumOptionKey); +410 List<String> fieldKeys = fieldOperation.getFieldKeys(); +411 if (fieldKeys != null) { +412 jsonObject.add("fieldKeys", getJsonArray(fieldKeys));413 }414 -415 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); -416 if (multiSelectOptionKey != null) { -417 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +415 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); +416 if (enumOptionKeys != null) { +417 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));418 }419 -420 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); -421 if (multiSelectOptionKeys != null) { -422 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +420 String enumOptionKey = fieldOperation.getEnumOptionKey(); +421 if (enumOptionKey != null) { +422 jsonObject.add("enumOptionKey", enumOptionKey);423 }424 -425 return jsonObject; -426 } -427 -428 /** -429 * Gets the Json Array representation of the given list of strings. -430 * -431 * @param keys List of strings -432 * @return the JsonArray represents the list of keys -433 */ -434 private static JsonArray getJsonArray(List<String> keys) { -435 JsonArray array = new JsonArray(); -436 for (String key : keys) { -437 array.add(key); -438 } -439 -440 return array; -441 } -442 -443 /** -444 * Gets the metadata template of properties. -445 * -446 * @param api the API connection to be used. -447 * @return the metadata template returned from the server. -448 */ -449 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { -450 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +425 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); +426 if (multiSelectOptionKey != null) { +427 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +428 } +429 +430 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); +431 if (multiSelectOptionKeys != null) { +432 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +433 } +434 +435 return jsonObject; +436 } +437 +438 /** +439 * Gets the Json Array representation of the given list of strings. +440 * +441 * @param keys List of strings +442 * @return the JsonArray represents the list of keys +443 */ +444 private static JsonArray getJsonArray(List<String> keys) { +445 JsonArray array = new JsonArray(); +446 for (String key : keys) { +447 array.add(key); +448 } +449 +450 return array;451 }452453 /** -454 * Gets the metadata template of specified template type. +454 * Gets the metadata template of properties.455 * -456 * @param api the API connection to be used. -457 * @param templateName the metadata template type name. -458 * @return the metadata template returned from the server. -459 */ -460 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { -461 String scope = scopeBasedOnType(templateName); -462 return getMetadataTemplate(api, templateName, scope); -463 } -464 -465 /** -466 * Gets the metadata template of specified template type. -467 * -468 * @param api the API connection to be used. -469 * @param templateName the metadata template type name. -470 * @param scope the metadata template scope (global or enterprise). -471 * @param fields the fields to retrieve. -472 * @return the metadata template returned from the server. -473 */ -474 public static MetadataTemplate getMetadataTemplate( -475 BoxAPIConnection api, String templateName, String scope, String... fields) { -476 QueryStringBuilder builder = new QueryStringBuilder(); -477 if (fields.length > 0) { -478 builder.appendParam("fields", fields); -479 } -480 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( -481 api.getBaseURL(), builder.toString(), scope, templateName); -482 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -483 try (BoxJSONResponse response = request.send()) { -484 return new MetadataTemplate(response.getJSON()); -485 } -486 } -487 -488 /** -489 * Geta the specified metadata template by its ID. -490 * -491 * @param api the API connection to be used. -492 * @param templateID the ID of the template to get. -493 * @return the metadata template object. -494 */ -495 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { -496 -497 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); -498 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -499 try (BoxJSONResponse response = request.send()) { -500 return new MetadataTemplate(response.getJSON()); -501 } -502 } -503 -504 /** -505 * Returns all metadata templates within a user's enterprise. -506 * -507 * @param api the API connection to be used. -508 * @param fields the fields to retrieve. -509 * @return the metadata template returned from the server. -510 */ -511 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { -512 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); -513 } -514 -515 /** -516 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -517 * -518 * @param scope the scope of the metadata templates. -519 * @param api the API connection to be used. -520 * @param fields the fields to retrieve. -521 * @return the metadata template returned from the server. -522 */ -523 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -524 String scope, BoxAPIConnection api, String... fields -525 ) { -526 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); -527 } -528 -529 /** -530 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -531 * -532 * @param scope the scope of the metadata templates. -533 * @param limit maximum number of entries per response. -534 * @param api the API connection to be used. -535 * @param fields the fields to retrieve. -536 * @return the metadata template returned from the server. -537 */ -538 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -539 String scope, int limit, BoxAPIConnection api, String... fields) { -540 QueryStringBuilder builder = new QueryStringBuilder(); -541 if (fields.length > 0) { -542 builder.appendParam("fields", fields); -543 } -544 return new BoxResourceIterable<MetadataTemplate>( -545 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( -546 api.getBaseURL(), builder.toString(), scope), limit) { -547 -548 @Override -549 protected MetadataTemplate factory(JsonObject jsonObject) { -550 return new MetadataTemplate(jsonObject); -551 } -552 }; -553 } -554 -555 /** -556 * Determines the metadata scope based on type. -557 * -558 * @param typeName type of the metadata. -559 * @return scope of the metadata. -560 */ -561 private static String scopeBasedOnType(String typeName) { -562 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +456 * @param api the API connection to be used. +457 * @return the metadata template returned from the server. +458 */ +459 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { +460 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +461 } +462 +463 /** +464 * Gets the metadata template of specified template type. +465 * +466 * @param api the API connection to be used. +467 * @param templateName the metadata template type name. +468 * @return the metadata template returned from the server. +469 */ +470 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { +471 String scope = scopeBasedOnType(templateName); +472 return getMetadataTemplate(api, templateName, scope); +473 } +474 +475 /** +476 * Gets the metadata template of specified template type. +477 * +478 * @param api the API connection to be used. +479 * @param templateName the metadata template type name. +480 * @param scope the metadata template scope (global or enterprise). +481 * @param fields the fields to retrieve. +482 * @return the metadata template returned from the server. +483 */ +484 public static MetadataTemplate getMetadataTemplate( +485 BoxAPIConnection api, String templateName, String scope, String... fields) { +486 QueryStringBuilder builder = new QueryStringBuilder(); +487 if (fields.length > 0) { +488 builder.appendParam("fields", fields); +489 } +490 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( +491 api.getBaseURL(), builder.toString(), scope, templateName); +492 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +493 try (BoxJSONResponse response = request.send()) { +494 return new MetadataTemplate(response.getJSON()); +495 } +496 } +497 +498 /** +499 * Geta the specified metadata template by its ID. +500 * +501 * @param api the API connection to be used. +502 * @param templateID the ID of the template to get. +503 * @return the metadata template object. +504 */ +505 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { +506 +507 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); +508 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +509 try (BoxJSONResponse response = request.send()) { +510 return new MetadataTemplate(response.getJSON()); +511 } +512 } +513 +514 /** +515 * Returns all metadata templates within a user's enterprise. +516 * +517 * @param api the API connection to be used. +518 * @param fields the fields to retrieve. +519 * @return the metadata template returned from the server. +520 */ +521 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { +522 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); +523 } +524 +525 /** +526 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +527 * +528 * @param scope the scope of the metadata templates. +529 * @param api the API connection to be used. +530 * @param fields the fields to retrieve. +531 * @return the metadata template returned from the server. +532 */ +533 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +534 String scope, BoxAPIConnection api, String... fields +535 ) { +536 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); +537 } +538 +539 /** +540 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +541 * +542 * @param scope the scope of the metadata templates. +543 * @param limit maximum number of entries per response. +544 * @param api the API connection to be used. +545 * @param fields the fields to retrieve. +546 * @return the metadata template returned from the server. +547 */ +548 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +549 String scope, int limit, BoxAPIConnection api, String... fields) { +550 QueryStringBuilder builder = new QueryStringBuilder(); +551 if (fields.length > 0) { +552 builder.appendParam("fields", fields); +553 } +554 return new BoxResourceIterable<MetadataTemplate>( +555 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( +556 api.getBaseURL(), builder.toString(), scope), limit) { +557 +558 @Override +559 protected MetadataTemplate factory(JsonObject jsonObject) { +560 return new MetadataTemplate(jsonObject); +561 } +562 };563 }564565 /** -566 * Gets the ID of the template. +566 * Determines the metadata scope based on type.567 * -568 * @return the template ID. -569 */ -570 public String getID() { -571 return this.id; -572 } -573 -574 /** -575 * Gets the unique template key to identify the metadata template. -576 * -577 * @return the unique template key to identify the metadata template. -578 */ -579 public String getTemplateKey() { -580 return this.templateKey; -581 } -582 -583 /** -584 * Gets the metadata template scope. -585 * -586 * @return the metadata template scope. -587 */ -588 public String getScope() { -589 return this.scope; -590 } -591 -592 /** -593 * Gets the displayed metadata template name. -594 * -595 * @return the displayed metadata template name. -596 */ -597 public String getDisplayName() { -598 return this.displayName; -599 } -600 -601 /** -602 * Gets is the metadata template hidden. -603 * -604 * @return is the metadata template hidden. -605 */ -606 public Boolean getIsHidden() { -607 return this.isHidden; -608 } -609 -610 /** -611 * Gets the iterable with all fields the metadata template contains. -612 * -613 * @return the iterable with all fields the metadata template contains. -614 */ -615 public List<Field> getFields() { -616 return this.fields; -617 } -618 -619 /** -620 * Gets whether the copy operation should copy the metadata along with the item. -621 * -622 * @return whether the copy operation should copy the metadata along with the item. -623 */ -624 public Boolean getCopyInstanceOnItemCopy() { -625 return this.copyInstanceOnItemCopy; -626 } -627 -628 /** -629 * {@inheritDoc} -630 */ -631 @Override -632 void parseJSONMember(JsonObject.Member member) { -633 JsonValue value = member.getValue(); -634 String memberName = member.getName(); -635 switch (memberName) { -636 case "templateKey": -637 this.templateKey = value.asString(); -638 break; -639 case "scope": -640 this.scope = value.asString(); -641 break; -642 case "displayName": -643 this.displayName = value.asString(); -644 break; -645 case "hidden": -646 this.isHidden = value.asBoolean(); -647 break; -648 case "fields": -649 this.fields = new ArrayList<>(); -650 for (JsonValue field : value.asArray()) { -651 this.fields.add(new Field(field.asObject())); -652 } -653 break; -654 case "id": -655 this.id = value.asString(); -656 break; -657 case "copyInstanceOnItemCopy": -658 this.copyInstanceOnItemCopy = value.asBoolean(); -659 break; -660 default: -661 break; -662 } -663 } -664 -665 /** -666 * Possible template operations. -667 */ -668 public enum Operation { -669 -670 /** -671 * Adds an enum option at the end of the enum option list for the specified field. -672 */ -673 addEnumOption, +568 * @param typeName type of the metadata. +569 * @return scope of the metadata. +570 */ +571 private static String scopeBasedOnType(String typeName) { +572 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +573 } +574 +575 /** +576 * Gets the ID of the template. +577 * +578 * @return the template ID. +579 */ +580 public String getID() { +581 return this.id; +582 } +583 +584 /** +585 * Gets the unique template key to identify the metadata template. +586 * +587 * @return the unique template key to identify the metadata template. +588 */ +589 public String getTemplateKey() { +590 return this.templateKey; +591 } +592 +593 /** +594 * Gets the metadata template scope. +595 * +596 * @return the metadata template scope. +597 */ +598 public String getScope() { +599 return this.scope; +600 } +601 +602 /** +603 * Gets the displayed metadata template name. +604 * +605 * @return the displayed metadata template name. +606 */ +607 public String getDisplayName() { +608 return this.displayName; +609 } +610 +611 /** +612 * Gets is the metadata template hidden. +613 * +614 * @return is the metadata template hidden. +615 */ +616 public Boolean getIsHidden() { +617 return this.isHidden; +618 } +619 +620 /** +621 * Gets the iterable with all fields the metadata template contains. +622 * +623 * @return the iterable with all fields the metadata template contains. +624 */ +625 public List<Field> getFields() { +626 return this.fields; +627 } +628 +629 /** +630 * Gets whether the copy operation should copy the metadata along with the item. +631 * +632 * @return whether the copy operation should copy the metadata along with the item. +633 */ +634 public Boolean getCopyInstanceOnItemCopy() { +635 return this.copyInstanceOnItemCopy; +636 } +637 +638 /** +639 * {@inheritDoc} +640 */ +641 @Override +642 void parseJSONMember(JsonObject.Member member) { +643 JsonValue value = member.getValue(); +644 String memberName = member.getName(); +645 switch (memberName) { +646 case "templateKey": +647 this.templateKey = value.asString(); +648 break; +649 case "scope": +650 this.scope = value.asString(); +651 break; +652 case "displayName": +653 this.displayName = value.asString(); +654 break; +655 case "hidden": +656 this.isHidden = value.asBoolean(); +657 break; +658 case "fields": +659 this.fields = new ArrayList<>(); +660 for (JsonValue field : value.asArray()) { +661 this.fields.add(new Field(field.asObject())); +662 } +663 break; +664 case "id": +665 this.id = value.asString(); +666 break; +667 case "copyInstanceOnItemCopy": +668 this.copyInstanceOnItemCopy = value.asBoolean(); +669 break; +670 default: +671 break; +672 } +673 }674 -675 /** -676 * Edits the enum option. -677 */ -678 editEnumOption, +675 /** +676 * Possible template operations. +677 */ +678 public enum Operation {679680 /** -681 * Removes the specified enum option from the specified enum field. +681 * Adds an enum option at the end of the enum option list for the specified field.682 */ -683 removeEnumOption, +683 addEnumOption,684685 /** -686 * Adds a field at the end of the field list for the template. +686 * Edits the enum option.687 */ -688 addField, +688 editEnumOption,689690 /** -691 * Edits any number of the base properties of a field: displayName, hidden, description. +691 * Removes the specified enum option from the specified enum field.692 */ -693 editField, +693 removeEnumOption,694695 /** -696 * Removes the specified field from the template. +696 * Adds a field at the end of the field list for the template.697 */ -698 removeField, +698 addField,699700 /** -701 * Edits any number of the base properties of a template: displayName, hidden. +701 * Edits any number of the base properties of a field: displayName, hidden, description.702 */ -703 editTemplate, +703 editField,704705 /** -706 * Reorders the enum option list to match the requested enum option list. +706 * Removes the specified field from the template.707 */ -708 reorderEnumOptions, +708 removeField,709710 /** -711 * Reorders the field list to match the requested field list. +711 * Edits any number of the base properties of a template: displayName, hidden.712 */ -713 reorderFields, +713 editTemplate,714715 /** -716 * Adds a new option to a multiselect field. +716 * Reorders the enum option list to match the requested enum option list.717 */ -718 addMultiSelectOption, +718 reorderEnumOptions,719720 /** -721 * Edits an existing option in a multiselect field. +721 * Reorders the field list to match the requested field list.722 */ -723 editMultiSelectOption, +723 reorderFields,724725 /** -726 * Removes an option from a multiselect field. +726 * Adds a new option to a multiselect field.727 */ -728 removeMultiSelectOption, +728 addMultiSelectOption,729730 /** -731 * Changes the display order of options in a multiselect field. +731 * Edits an existing option in a multiselect field.732 */ -733 reorderMultiSelectOptions -734 } -735 -736 /** -737 * Class contains information about the metadata template field. -738 */ -739 public static class Field extends BoxJSONObject { -740 -741 /** -742 * @see #getID() -743 */ -744 private String id; +733 editMultiSelectOption, +734 +735 /** +736 * Removes an option from a multiselect field. +737 */ +738 removeMultiSelectOption, +739 +740 /** +741 * Changes the display order of options in a multiselect field. +742 */ +743 reorderMultiSelectOptions +744 }745 -746 /** -747 * @see #getType() -748 */ -749 private String type; -750 -751 /** -752 * @see #getKey() -753 */ -754 private String key; -755 -756 /** -757 * @see #getDisplayName() -758 */ -759 private String displayName; -760 -761 /** -762 * @see #getIsHidden() +746 /** +747 * Class contains information about the static configuration for the classification. +748 */ +749 public static class StaticConfig extends BoxJSONObject { +750 private JsonObject classification; +751 +752 /** +753 * Constructs an empty static configuration. +754 */ +755 public StaticConfig() { +756 super(); +757 } +758 +759 /** +760 * Constructs a static configuration from a JSON string. +761 * +762 * @param json the json encoded metadate template field.763 */ -764 private Boolean isHidden; -765 -766 /** -767 * @see #getDescription() -768 */ -769 private String description; -770 -771 /** -772 * @see #getOptionsObjects() -773 */ -774 private List<Option> options; +764 public StaticConfig(String json) { +765 super(json); +766 } +767 +768 /** Constructs a static configuration from a JSON object. +769 * +770 * @param jsonObject the json encoded metadate template field. +771 */ +772 StaticConfig(JsonObject jsonObject) { +773 super(jsonObject); +774 }775776 /** -777 * @see #getCopyInstanceOnItemCopy() -778 */ -779 private Boolean copyInstanceOnItemCopy; -780 -781 /** -782 * Constructs an empty metadata template. -783 */ -784 public Field() { -785 super(); -786 } -787 -788 /** -789 * Constructs a metadate template field from a JSON string. -790 * -791 * @param json the json encoded metadate template field. -792 */ -793 public Field(String json) { -794 super(json); -795 } -796 -797 /** -798 * Constructs a metadate template field from a JSON object. -799 * -800 * @param jsonObject the json encoded metadate template field. -801 */ -802 Field(JsonObject jsonObject) { -803 super(jsonObject); -804 } -805 -806 /** -807 * Gets the ID of the template field. -808 * -809 * @return the template field ID. -810 */ -811 public String getID() { -812 return this.id; -813 } -814 -815 /** -816 * Gets the data type of the field's value. -817 * -818 * @return the data type of the field's value. -819 */ -820 public String getType() { -821 return this.type; -822 } -823 -824 /** -825 * Sets the data type of the field's value. -826 * -827 * @param type the data type of the field's value. +777 * Gets the classification of the static configuration. +778 * +779 * @return the classification of the static configuration. +780 */ +781 public JsonObject getClassification() { +782 return this.classification; +783 } +784 +785 /** +786 * Sets the classification of the static configuration. +787 * +788 * @param classification the classification of the static configuration. +789 */ +790 public void setClassification(JsonObject classification) { +791 this.classification = classification; +792 } +793 +794 /** +795 * {@inheritDoc} +796 */ +797 @Override +798 void parseJSONMember(JsonObject.Member member) { +799 JsonValue value = member.getValue(); +800 String memberName = member.getName(); +801 switch (memberName) { +802 case "classification": +803 this.classification = value.asObject(); +804 break; +805 default: +806 break; +807 } +808 } +809 } +810 +811 /** +812 * Class contains information about the metadata template field. +813 */ +814 public static class Field extends BoxJSONObject { +815 +816 /** +817 * @see #getID() +818 */ +819 private String id; +820 +821 /** +822 * @see #getType() +823 */ +824 private String type; +825 +826 /** +827 * @see #getKey()828 */ -829 public void setType(String type) { -830 this.type = type; -831 } -832 -833 /** -834 * Gets the key of the field. -835 * -836 * @return the key of the field. -837 */ -838 public String getKey() { -839 return this.key; -840 } -841 -842 /** -843 * Sets the key of the field. -844 * -845 * @param key the key of the field. -846 */ -847 public void setKey(String key) { -848 this.key = key; -849 } +829 private String key; +830 +831 /** +832 * @see #getDisplayName() +833 */ +834 private String displayName; +835 +836 /** +837 * @see #getIsHidden() +838 */ +839 private Boolean isHidden; +840 +841 /** +842 * @see #getDescription() +843 */ +844 private String description; +845 +846 /** +847 * @see #getOptionsObjects() +848 */ +849 private List<Option> options;850851 /** -852 * Gets the display name of the field. -853 * -854 * @return the display name of the field. -855 */ -856 public String getDisplayName() { -857 return this.displayName; -858 } -859 -860 /** -861 * Sets the display name of the field. -862 * -863 * @param displayName the display name of the field. -864 */ -865 public void setDisplayName(String displayName) { -866 this.displayName = displayName; -867 } -868 -869 /** -870 * Gets is metadata template field hidden. -871 * -872 * @return is metadata template field hidden. -873 */ -874 public Boolean getIsHidden() { -875 return this.isHidden; -876 } -877 -878 /** -879 * Sets is metadata template field hidden. -880 * -881 * @param isHidden is metadata template field hidden? -882 */ -883 public void setIsHidden(boolean isHidden) { -884 this.isHidden = isHidden; -885 } -886 -887 /** -888 * Gets the description of the field. -889 * -890 * @return the description of the field. -891 */ -892 public String getDescription() { -893 return this.description; -894 } -895 -896 /** -897 * Sets the description of the field. -898 * -899 * @param description the description of the field. -900 */ -901 public void setDescription(String description) { -902 this.description = description; -903 } -904 -905 /** -906 * Gets list of possible options for enum type of the field. -907 * -908 * @return list of possible options for enum type of the field. -909 */ -910 public List<String> getOptions() { -911 if (this.options == null) { -912 return null; -913 } -914 List<String> optionsList = new ArrayList<>(); -915 for (Option option : this.options) { -916 optionsList.add(option.getKey()); -917 } -918 return optionsList; -919 } -920 -921 /** -922 * Sets list of possible options for enum type of the field. -923 * -924 * @param options list of possible options for enum type of the field. -925 */ -926 public void setOptions(List<String> options) { -927 if (options == null) { -928 this.options = null; -929 return; -930 } -931 List<Option> optionList = new ArrayList<>(); -932 for (String key : options) { -933 JsonObject optionObject = new JsonObject(); -934 optionObject.add("key", key); -935 Option newOption = new Option(optionObject); -936 optionList.add(newOption); -937 } -938 this.options = optionList; -939 } -940 -941 /** -942 * Gets list of possible options for options type of the field. -943 * -944 * @return list of possible options for option type of the field. -945 */ -946 public List<Option> getOptionsObjects() { -947 return this.options; -948 } -949 -950 /** -951 * Gets whether the copy operation should copy the metadata along with the item. -952 * -953 * @return whether the copy operation should copy the metadata along with the item. -954 */ -955 public Boolean getCopyInstanceOnItemCopy() { -956 return this.copyInstanceOnItemCopy; -957 } -958 -959 /** -960 * Sets whether the copy operation should copy the metadata along with the item. -961 * -962 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. -963 */ -964 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { -965 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; -966 } -967 -968 /** -969 * {@inheritDoc} -970 */ -971 @Override -972 void parseJSONMember(JsonObject.Member member) { -973 JsonValue value = member.getValue(); -974 String memberName = member.getName(); -975 switch (memberName) { -976 case "type": -977 this.type = value.asString(); -978 break; -979 case "key": -980 this.key = value.asString(); -981 break; -982 case "displayName": -983 this.displayName = value.asString(); -984 break; -985 case "hidden": -986 this.isHidden = value.asBoolean(); -987 break; -988 case "description": -989 this.description = value.asString(); -990 break; -991 case "options": -992 this.options = new ArrayList<>(); -993 for (JsonValue option : value.asArray()) { -994 this.options.add(new Option(option.asObject())); -995 } -996 break; -997 case "id": -998 this.id = value.asString(); -999 break; -1000 case "copyInstanceOnItemCopy": -1001 this.copyInstanceOnItemCopy = value.asBoolean(); -1002 break; -1003 default: -1004 break; -1005 } -1006 } -1007 } -1008 -1009 /** -1010 * Class contains information about the metadata template option. -1011 */ -1012 public static class Option extends BoxJSONObject { -1013 /** -1014 * @see #getID() -1015 */ -1016 private String id; -1017 /** -1018 * @see #getKey() -1019 */ -1020 private String key; -1021 -1022 /** -1023 * Constructs an empty metadata template. -1024 */ -1025 public Option() { -1026 super(); -1027 } -1028 -1029 /** -1030 * Constructs a metadate template option from a JSON string. -1031 * -1032 * @param json the json encoded metadata template option. -1033 */ -1034 public Option(String json) { -1035 super(json); -1036 } -1037 -1038 /** -1039 * Constructs a metadate template option from a JSON object. -1040 * -1041 * @param jsonObject the json encoded metadate template option. -1042 */ -1043 Option(JsonObject jsonObject) { -1044 super(jsonObject); -1045 } -1046 -1047 /** -1048 * Gets the ID of the template field. -1049 * -1050 * @return the template field ID. -1051 */ -1052 public String getID() { -1053 return this.id; -1054 } -1055 -1056 /** -1057 * Gets the key of the field. -1058 * -1059 * @return the key of the field. -1060 */ -1061 public String getKey() { -1062 return this.key; -1063 } -1064 -1065 /** -1066 * {@inheritDoc} -1067 */ -1068 @Override -1069 void parseJSONMember(JsonObject.Member member) { -1070 JsonValue value = member.getValue(); -1071 String memberName = member.getName(); -1072 if (memberName.equals("id")) { -1073 this.id = value.asString(); -1074 } else if (memberName.equals("key")) { -1075 this.key = value.asString(); -1076 } -1077 } -1078 } -1079 -1080 /** -1081 * Posssible operations that can be performed in a Metadata template. -1082 * <ul> -1083 * <li>Add an enum option</li> -1084 * <li>Edit an enum option</li> -1085 * <li>Remove an enum option</li> -1086 * <li>Add a field</li> -1087 * <li>Edit a field</li> -1088 * <li>Remove a field</li> -1089 * <li>Edit template</li> -1090 * <li>Reorder the enum option</li> -1091 * <li>Reorder the field list</li> -1092 * </ul> -1093 */ -1094 public static class FieldOperation extends BoxJSONObject { -1095 -1096 private Operation op; -1097 private Field data; -1098 private String fieldKey; -1099 private List<String> fieldKeys; -1100 private List<String> enumOptionKeys; -1101 private String enumOptionKey; -1102 private String multiSelectOptionKey; -1103 private List<String> multiSelectOptionKeys; -1104 -1105 /** -1106 * Constructs an empty FieldOperation. -1107 */ -1108 public FieldOperation() { -1109 super(); -1110 } -1111 -1112 /** -1113 * Constructs a Field operation from a JSON string. -1114 * -1115 * @param json the json encoded metadate template field. +852 * @see #getCopyInstanceOnItemCopy() +853 */ +854 private Boolean copyInstanceOnItemCopy; +855 +856 /** +857 * @see #getStaticConfig() +858 */ +859 private StaticConfig staticConfig; +860 +861 /** +862 * Constructs an empty metadata template. +863 */ +864 public Field() { +865 super(); +866 } +867 +868 /** +869 * Constructs a metadate template field from a JSON string. +870 * +871 * @param json the json encoded metadate template field. +872 */ +873 public Field(String json) { +874 super(json); +875 } +876 +877 /** +878 * Constructs a metadate template field from a JSON object. +879 * +880 * @param jsonObject the json encoded metadate template field. +881 */ +882 Field(JsonObject jsonObject) { +883 super(jsonObject); +884 } +885 +886 /** +887 * Gets the ID of the template field. +888 * +889 * @return the template field ID. +890 */ +891 public String getID() { +892 return this.id; +893 } +894 +895 /** +896 * Gets the data type of the field's value. +897 * +898 * @return the data type of the field's value. +899 */ +900 public String getType() { +901 return this.type; +902 } +903 +904 /** +905 * Sets the data type of the field's value. +906 * +907 * @param type the data type of the field's value. +908 */ +909 public void setType(String type) { +910 this.type = type; +911 } +912 +913 /** +914 * Gets the key of the field. +915 * +916 * @return the key of the field. +917 */ +918 public String getKey() { +919 return this.key; +920 } +921 +922 /** +923 * Sets the key of the field. +924 * +925 * @param key the key of the field. +926 */ +927 public void setKey(String key) { +928 this.key = key; +929 } +930 +931 /** +932 * Gets the display name of the field. +933 * +934 * @return the display name of the field. +935 */ +936 public String getDisplayName() { +937 return this.displayName; +938 } +939 +940 /** +941 * Sets the display name of the field. +942 * +943 * @param displayName the display name of the field. +944 */ +945 public void setDisplayName(String displayName) { +946 this.displayName = displayName; +947 } +948 +949 /** +950 * Gets is metadata template field hidden. +951 * +952 * @return is metadata template field hidden. +953 */ +954 public Boolean getIsHidden() { +955 return this.isHidden; +956 } +957 +958 /** +959 * Sets is metadata template field hidden. +960 * +961 * @param isHidden is metadata template field hidden? +962 */ +963 public void setIsHidden(boolean isHidden) { +964 this.isHidden = isHidden; +965 } +966 +967 /** +968 * Gets the description of the field. +969 * +970 * @return the description of the field. +971 */ +972 public String getDescription() { +973 return this.description; +974 } +975 +976 /** +977 * Sets the description of the field. +978 * +979 * @param description the description of the field. +980 */ +981 public void setDescription(String description) { +982 this.description = description; +983 } +984 +985 /** +986 * Gets list of possible options for enum type of the field. +987 * +988 * @return list of possible options for enum type of the field. +989 */ +990 public List<String> getOptions() { +991 if (this.options == null) { +992 return null; +993 } +994 List<String> optionsList = new ArrayList<>(); +995 for (Option option : this.options) { +996 optionsList.add(option.getKey()); +997 } +998 return optionsList; +999 } +1000 +1001 /** +1002 * Sets list of possible options for enum type of the field. +1003 * +1004 * @param options list of possible options for enum type of the field. +1005 */ +1006 public void setOptions(List<String> options) { +1007 if (options == null) { +1008 this.options = null; +1009 return; +1010 } +1011 List<Option> optionList = new ArrayList<>(); +1012 for (String key : options) { +1013 JsonObject optionObject = new JsonObject(); +1014 optionObject.add("key", key); +1015 Option newOption = new Option(optionObject); +1016 optionList.add(newOption); +1017 } +1018 this.options = optionList; +1019 } +1020 +1021 /** +1022 * Gets list of possible options for options type of the field. +1023 * +1024 * @return list of possible options for option type of the field. +1025 */ +1026 public List<Option> getOptionsObjects() { +1027 return this.options; +1028 } +1029 +1030 /** +1031 * Gets whether the copy operation should copy the metadata along with the item. +1032 * +1033 * @return whether the copy operation should copy the metadata along with the item. +1034 */ +1035 public Boolean getCopyInstanceOnItemCopy() { +1036 return this.copyInstanceOnItemCopy; +1037 } +1038 +1039 /** +1040 * Sets whether the copy operation should copy the metadata along with the item. +1041 * +1042 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. +1043 */ +1044 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { +1045 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; +1046 } +1047 +1048 /** +1049 * Gets static configuration for the classification. +1050 * +1051 * @return static configuration for the classification. +1052 */ +1053 public StaticConfig getStaticConfig() { +1054 return this.staticConfig; +1055 } +1056 +1057 /** +1058 * Sets static configuration for the classification. +1059 * +1060 * @param staticConfig static configuration for the classification. +1061 */ +1062 public void setStaticConfig(StaticConfig staticConfig) { +1063 this.staticConfig = staticConfig; +1064 } +1065 +1066 /** +1067 * {@inheritDoc} +1068 */ +1069 @Override +1070 void parseJSONMember(JsonObject.Member member) { +1071 JsonValue value = member.getValue(); +1072 String memberName = member.getName(); +1073 switch (memberName) { +1074 case "type": +1075 this.type = value.asString(); +1076 break; +1077 case "key": +1078 this.key = value.asString(); +1079 break; +1080 case "displayName": +1081 this.displayName = value.asString(); +1082 break; +1083 case "hidden": +1084 this.isHidden = value.asBoolean(); +1085 break; +1086 case "description": +1087 this.description = value.asString(); +1088 break; +1089 case "options": +1090 this.options = new ArrayList<>(); +1091 for (JsonValue option : value.asArray()) { +1092 this.options.add(new Option(option.asObject())); +1093 } +1094 break; +1095 case "id": +1096 this.id = value.asString(); +1097 break; +1098 case "copyInstanceOnItemCopy": +1099 this.copyInstanceOnItemCopy = value.asBoolean(); +1100 break; +1101 case "staticConfig": +1102 this.staticConfig = new StaticConfig(value.asObject()); +1103 break; +1104 default: +1105 break; +1106 } +1107 } +1108 } +1109 +1110 /** +1111 * Class contains information about the metadata template option. +1112 */ +1113 public static class Option extends BoxJSONObject { +1114 /** +1115 * @see #getID()1116 */ -1117 public FieldOperation(String json) { -1118 super(json); -1119 } -1120 -1121 /** -1122 * Constructs a Field operation from a JSON object. -1123 * -1124 * @param jsonObject the json encoded metadate template field. -1125 */ -1126 FieldOperation(JsonObject jsonObject) { -1127 super(jsonObject); -1128 } -1129 -1130 /** -1131 * Gets the operation. -1132 * -1133 * @return the operation -1134 */ -1135 public Operation getOp() { -1136 return this.op; -1137 } -1138 -1139 /** -1140 * Sets the operation. -1141 * -1142 * @param op the operation -1143 */ -1144 public void setOp(Operation op) { -1145 this.op = op; -1146 } -1147 -1148 /** -1149 * Gets the data associated with the operation. -1150 * -1151 * @return the field object representing the data -1152 */ -1153 public Field getData() { -1154 return this.data; -1155 } -1156 -1157 /** -1158 * Sets the data. -1159 * -1160 * @param data the Field object representing the data -1161 */ -1162 public void setData(Field data) { -1163 this.data = data; -1164 } -1165 -1166 /** -1167 * Gets the field key. -1168 * -1169 * @return the field key -1170 */ -1171 public String getFieldKey() { -1172 return this.fieldKey; -1173 } -1174 -1175 /** -1176 * Sets the field key. -1177 * -1178 * @param fieldKey the key of the field -1179 */ -1180 public void setFieldKey(String fieldKey) { -1181 this.fieldKey = fieldKey; -1182 } -1183 -1184 /** -1185 * Gets the list of field keys. -1186 * -1187 * @return the list of Strings -1188 */ -1189 public List<String> getFieldKeys() { -1190 return this.fieldKeys; -1191 } -1192 -1193 /** -1194 * Sets the list of the field keys. -1195 * -1196 * @param fieldKeys the list of strings -1197 */ -1198 public void setFieldKeys(List<String> fieldKeys) { -1199 this.fieldKeys = fieldKeys; -1200 } +1117 private String id; +1118 /** +1119 * @see #getKey() +1120 */ +1121 private String key; +1122 /** +1123 * @see #getStaticConfig() +1124 */ +1125 private StaticConfig staticConfig; +1126 +1127 /** +1128 * Constructs an empty metadata template. +1129 */ +1130 public Option() { +1131 super(); +1132 } +1133 +1134 /** +1135 * Constructs a metadate template option from a JSON string. +1136 * +1137 * @param json the json encoded metadata template option. +1138 */ +1139 public Option(String json) { +1140 super(json); +1141 } +1142 +1143 /** +1144 * Constructs a metadate template option from a JSON object. +1145 * +1146 * @param jsonObject the json encoded metadate template option. +1147 */ +1148 Option(JsonObject jsonObject) { +1149 super(jsonObject); +1150 } +1151 +1152 /** +1153 * Gets the ID of the template field. +1154 * +1155 * @return the template field ID. +1156 */ +1157 public String getID() { +1158 return this.id; +1159 } +1160 +1161 /** +1162 * Gets the key of the field. +1163 * +1164 * @return the key of the field. +1165 */ +1166 public String getKey() { +1167 return this.key; +1168 } +1169 +1170 /** +1171 * Gets static configuration for the classification. +1172 * +1173 * @return static configuration for the classification. +1174 */ +1175 public StaticConfig getStaticConfig() { +1176 return this.staticConfig; +1177 } +1178 +1179 /** +1180 * {@inheritDoc} +1181 */ +1182 @Override +1183 void parseJSONMember(JsonObject.Member member) { +1184 JsonValue value = member.getValue(); +1185 String memberName = member.getName(); +1186 switch (memberName) { +1187 case "id": +1188 this.id = value.asString(); +1189 break; +1190 case "key": +1191 this.key = value.asString(); +1192 break; +1193 case "staticConfig": +1194 this.staticConfig = new StaticConfig(value.asObject()); +1195 break; +1196 default: +1197 break; +1198 } +1199 } +1200 }1201 -1202 /** -1203 * Gets the list of keys of the Enum options. -1204 * -1205 * @return the list of Strings -1206 */ -1207 public List<String> getEnumOptionKeys() { -1208 return this.enumOptionKeys; -1209 } -1210 -1211 /** -1212 * Sets the list of the enum option keys. -1213 * -1214 * @param enumOptionKeys the list of Strings -1215 */ -1216 public void setEnumOptionKeys(List<String> enumOptionKeys) { -1217 this.enumOptionKeys = enumOptionKeys; -1218 } -1219 -1220 /** -1221 * Gets the enum option key. -1222 * -1223 * @return the enum option key -1224 */ -1225 public String getEnumOptionKey() { -1226 return this.enumOptionKey; -1227 } -1228 -1229 /** -1230 * Sets the enum option key. -1231 * -1232 * @param enumOptionKey the enum option key -1233 */ -1234 public void setEnumOptionKey(String enumOptionKey) { -1235 this.enumOptionKey = enumOptionKey; -1236 } -1237 -1238 /** -1239 * Gets the multi-select option key. -1240 * -1241 * @return the key. -1242 */ -1243 public String getMultiSelectOptionKey() { -1244 return this.multiSelectOptionKey; -1245 } -1246 -1247 /** -1248 * Sets the multi-select option key. -1249 * -1250 * @param key the key. -1251 */ -1252 public void setMultiSelectOptionKey(String key) { -1253 this.multiSelectOptionKey = key; -1254 } -1255 -1256 /** -1257 * Gets the list of multiselect option keys. -1258 * -1259 * @return the list of keys. -1260 */ -1261 public List<String> getMultiSelectOptionKeys() { -1262 return this.multiSelectOptionKeys; -1263 } -1264 -1265 /** -1266 * Sets the multi-select option keys. -1267 * -1268 * @param keys the list of keys. -1269 */ -1270 public void setMultiSelectOptionKeys(List<String> keys) { -1271 this.multiSelectOptionKeys = keys; -1272 } -1273 -1274 @Override -1275 public void clearPendingChanges() { -1276 super.clearPendingChanges(); +1202 /** +1203 * Posssible operations that can be performed in a Metadata template. +1204 * <ul> +1205 * <li>Add an enum option</li> +1206 * <li>Edit an enum option</li> +1207 * <li>Remove an enum option</li> +1208 * <li>Add a field</li> +1209 * <li>Edit a field</li> +1210 * <li>Remove a field</li> +1211 * <li>Edit template</li> +1212 * <li>Reorder the enum option</li> +1213 * <li>Reorder the field list</li> +1214 * </ul> +1215 */ +1216 public static class FieldOperation extends BoxJSONObject { +1217 +1218 private Operation op; +1219 private Field data; +1220 private String fieldKey; +1221 private List<String> fieldKeys; +1222 private List<String> enumOptionKeys; +1223 private String enumOptionKey; +1224 private String multiSelectOptionKey; +1225 private List<String> multiSelectOptionKeys; +1226 +1227 /** +1228 * Constructs an empty FieldOperation. +1229 */ +1230 public FieldOperation() { +1231 super(); +1232 } +1233 +1234 /** +1235 * Constructs a Field operation from a JSON string. +1236 * +1237 * @param json the json encoded metadate template field. +1238 */ +1239 public FieldOperation(String json) { +1240 super(json); +1241 } +1242 +1243 /** +1244 * Constructs a Field operation from a JSON object. +1245 * +1246 * @param jsonObject the json encoded metadate template field. +1247 */ +1248 FieldOperation(JsonObject jsonObject) { +1249 super(jsonObject); +1250 } +1251 +1252 /** +1253 * Gets the operation. +1254 * +1255 * @return the operation +1256 */ +1257 public Operation getOp() { +1258 return this.op; +1259 } +1260 +1261 /** +1262 * Sets the operation. +1263 * +1264 * @param op the operation +1265 */ +1266 public void setOp(Operation op) { +1267 this.op = op; +1268 } +1269 +1270 /** +1271 * Gets the data associated with the operation. +1272 * +1273 * @return the field object representing the data +1274 */ +1275 public Field getData() { +1276 return this.data;1277 }12781279 /** -1280 * {@inheritDoc} -1281 */ -1282 @Override -1283 void parseJSONMember(JsonObject.Member member) { -1284 JsonValue value = member.getValue(); -1285 String memberName = member.getName(); -1286 switch (memberName) { -1287 case "op": -1288 this.op = Operation.valueOf(value.asString()); -1289 break; -1290 case "data": -1291 this.data = new Field(value.asObject()); -1292 break; -1293 case "fieldKey": -1294 this.fieldKey = value.asString(); -1295 break; -1296 case "fieldKeys": -1297 if (this.fieldKeys == null) { -1298 this.fieldKeys = new ArrayList<>(); -1299 } else { -1300 this.fieldKeys.clear(); -1301 } -1302 for (JsonValue jsonValue : value.asArray()) { -1303 this.fieldKeys.add(jsonValue.asString()); -1304 } -1305 break; -1306 case "enumOptionKeys": -1307 if (this.enumOptionKeys == null) { -1308 this.enumOptionKeys = new ArrayList<>(); -1309 } else { -1310 this.enumOptionKeys.clear(); -1311 } -1312 -1313 for (JsonValue jsonValue : value.asArray()) { -1314 this.enumOptionKeys.add(jsonValue.asString()); -1315 } -1316 break; -1317 case "enumOptionKey": -1318 this.enumOptionKey = value.asString(); -1319 break; -1320 case "multiSelectOptionKey": -1321 this.multiSelectOptionKey = value.asString(); -1322 break; -1323 case "multiSelectOptionKeys": -1324 this.multiSelectOptionKeys = new ArrayList<>(); -1325 for (JsonValue key : value.asArray()) { -1326 this.multiSelectOptionKeys.add(key.asString()); -1327 } -1328 break; -1329 default: -1330 break; -1331 } -1332 } -1333 } -1334} +1280 * Sets the data. +1281 * +1282 * @param data the Field object representing the data +1283 */ +1284 public void setData(Field data) { +1285 this.data = data; +1286 } +1287 +1288 /** +1289 * Gets the field key. +1290 * +1291 * @return the field key +1292 */ +1293 public String getFieldKey() { +1294 return this.fieldKey; +1295 } +1296 +1297 /** +1298 * Sets the field key. +1299 * +1300 * @param fieldKey the key of the field +1301 */ +1302 public void setFieldKey(String fieldKey) { +1303 this.fieldKey = fieldKey; +1304 } +1305 +1306 /** +1307 * Gets the list of field keys. +1308 * +1309 * @return the list of Strings +1310 */ +1311 public List<String> getFieldKeys() { +1312 return this.fieldKeys; +1313 } +1314 +1315 /** +1316 * Sets the list of the field keys. +1317 * +1318 * @param fieldKeys the list of strings +1319 */ +1320 public void setFieldKeys(List<String> fieldKeys) { +1321 this.fieldKeys = fieldKeys; +1322 } +1323 +1324 /** +1325 * Gets the list of keys of the Enum options. +1326 * +1327 * @return the list of Strings +1328 */ +1329 public List<String> getEnumOptionKeys() { +1330 return this.enumOptionKeys; +1331 } +1332 +1333 /** +1334 * Sets the list of the enum option keys. +1335 * +1336 * @param enumOptionKeys the list of Strings +1337 */ +1338 public void setEnumOptionKeys(List<String> enumOptionKeys) { +1339 this.enumOptionKeys = enumOptionKeys; +1340 } +1341 +1342 /** +1343 * Gets the enum option key. +1344 * +1345 * @return the enum option key +1346 */ +1347 public String getEnumOptionKey() { +1348 return this.enumOptionKey; +1349 } +1350 +1351 /** +1352 * Sets the enum option key. +1353 * +1354 * @param enumOptionKey the enum option key +1355 */ +1356 public void setEnumOptionKey(String enumOptionKey) { +1357 this.enumOptionKey = enumOptionKey; +1358 } +1359 +1360 /** +1361 * Gets the multi-select option key. +1362 * +1363 * @return the key. +1364 */ +1365 public String getMultiSelectOptionKey() { +1366 return this.multiSelectOptionKey; +1367 } +1368 +1369 /** +1370 * Sets the multi-select option key. +1371 * +1372 * @param key the key. +1373 */ +1374 public void setMultiSelectOptionKey(String key) { +1375 this.multiSelectOptionKey = key; +1376 } +1377 +1378 /** +1379 * Gets the list of multiselect option keys. +1380 * +1381 * @return the list of keys. +1382 */ +1383 public List<String> getMultiSelectOptionKeys() { +1384 return this.multiSelectOptionKeys; +1385 } +1386 +1387 /** +1388 * Sets the multi-select option keys. +1389 * +1390 * @param keys the list of keys. +1391 */ +1392 public void setMultiSelectOptionKeys(List<String> keys) { +1393 this.multiSelectOptionKeys = keys; +1394 } +1395 +1396 @Override +1397 public void clearPendingChanges() { +1398 super.clearPendingChanges(); +1399 } +1400 +1401 /** +1402 * {@inheritDoc} +1403 */ +1404 @Override +1405 void parseJSONMember(JsonObject.Member member) { +1406 JsonValue value = member.getValue(); +1407 String memberName = member.getName(); +1408 switch (memberName) { +1409 case "op": +1410 this.op = Operation.valueOf(value.asString()); +1411 break; +1412 case "data": +1413 this.data = new Field(value.asObject()); +1414 break; +1415 case "fieldKey": +1416 this.fieldKey = value.asString(); +1417 break; +1418 case "fieldKeys": +1419 if (this.fieldKeys == null) { +1420 this.fieldKeys = new ArrayList<>(); +1421 } else { +1422 this.fieldKeys.clear(); +1423 } +1424 for (JsonValue jsonValue : value.asArray()) { +1425 this.fieldKeys.add(jsonValue.asString()); +1426 } +1427 break; +1428 case "enumOptionKeys": +1429 if (this.enumOptionKeys == null) { +1430 this.enumOptionKeys = new ArrayList<>(); +1431 } else { +1432 this.enumOptionKeys.clear(); +1433 } +1434 +1435 for (JsonValue jsonValue : value.asArray()) { +1436 this.enumOptionKeys.add(jsonValue.asString()); +1437 } +1438 break; +1439 case "enumOptionKey": +1440 this.enumOptionKey = value.asString(); +1441 break; +1442 case "multiSelectOptionKey": +1443 this.multiSelectOptionKey = value.asString(); +1444 break; +1445 case "multiSelectOptionKeys": +1446 this.multiSelectOptionKeys = new ArrayList<>(); +1447 for (JsonValue key : value.asArray()) { +1448 this.multiSelectOptionKeys.add(key.asString()); +1449 } +1450 break; +1451 default: +1452 break; +1453 } +1454 } +1455 } +1456} diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.StaticConfig.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.StaticConfig.html new file mode 100644 index 000000000..494a461b2 --- /dev/null +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.StaticConfig.html @@ -0,0 +1,1528 @@ + + + +Source code + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        001package com.box.sdk;
                                                                                                                                                                                                                                                        +002
                                                                                                                                                                                                                                                        +003import com.eclipsesource.json.Json;
                                                                                                                                                                                                                                                        +004import com.eclipsesource.json.JsonArray;
                                                                                                                                                                                                                                                        +005import com.eclipsesource.json.JsonObject;
                                                                                                                                                                                                                                                        +006import com.eclipsesource.json.JsonValue;
                                                                                                                                                                                                                                                        +007import java.net.URL;
                                                                                                                                                                                                                                                        +008import java.util.ArrayList;
                                                                                                                                                                                                                                                        +009import java.util.List;
                                                                                                                                                                                                                                                        +010
                                                                                                                                                                                                                                                        +011/**
                                                                                                                                                                                                                                                        +012 * The MetadataTemplate class represents the Box metadata template object.
                                                                                                                                                                                                                                                        +013 * Templates allow the metadata service to provide a multitude of services,
                                                                                                                                                                                                                                                        +014 * such as pre-defining sets of key:value pairs or schema enforcement on specific fields.
                                                                                                                                                                                                                                                        +015 *
                                                                                                                                                                                                                                                        +016 * @see <a href="https://developer.box.com/reference/resources/metadata-templates/">Box metadata templates</a>
                                                                                                                                                                                                                                                        +017 */
                                                                                                                                                                                                                                                        +018public class MetadataTemplate extends BoxJSONObject {
                                                                                                                                                                                                                                                        +019
                                                                                                                                                                                                                                                        +020    /**
                                                                                                                                                                                                                                                        +021     * @see #getMetadataTemplate(BoxAPIConnection)
                                                                                                                                                                                                                                                        +022     */
                                                                                                                                                                                                                                                        +023    public static final URLTemplate METADATA_TEMPLATE_URL_TEMPLATE
                                                                                                                                                                                                                                                        +024        = new URLTemplate("metadata_templates/%s/%s/schema");
                                                                                                                                                                                                                                                        +025
                                                                                                                                                                                                                                                        +026    /**
                                                                                                                                                                                                                                                        +027     * @see #getMetadataTemplateByID(BoxAPIConnection, String)
                                                                                                                                                                                                                                                        +028     */
                                                                                                                                                                                                                                                        +029    public static final URLTemplate METADATA_TEMPLATE_BY_ID_URL_TEMPLATE = new URLTemplate("metadata_templates/%s");
                                                                                                                                                                                                                                                        +030
                                                                                                                                                                                                                                                        +031    /**
                                                                                                                                                                                                                                                        +032     * @see #createMetadataTemplate(BoxAPIConnection, String, String, String, boolean, List)
                                                                                                                                                                                                                                                        +033     */
                                                                                                                                                                                                                                                        +034    public static final URLTemplate METADATA_TEMPLATE_SCHEMA_URL_TEMPLATE
                                                                                                                                                                                                                                                        +035        = new URLTemplate("metadata_templates/schema");
                                                                                                                                                                                                                                                        +036
                                                                                                                                                                                                                                                        +037    /**
                                                                                                                                                                                                                                                        +038     * @see #getEnterpriseMetadataTemplates(String, int, BoxAPIConnection, String...)
                                                                                                                                                                                                                                                        +039     */
                                                                                                                                                                                                                                                        +040    public static final URLTemplate ENTERPRISE_METADATA_URL_TEMPLATE = new URLTemplate("metadata_templates/%s");
                                                                                                                                                                                                                                                        +041
                                                                                                                                                                                                                                                        +042    /**
                                                                                                                                                                                                                                                        +043     *
                                                                                                                                                                                                                                                        +044     */
                                                                                                                                                                                                                                                        +045    private static final URLTemplate METADATA_QUERIES_URL_TEMPLATE = new URLTemplate("metadata_queries/execute_read");
                                                                                                                                                                                                                                                        +046
                                                                                                                                                                                                                                                        +047    /**
                                                                                                                                                                                                                                                        +048     * Default metadata type to be used in query.
                                                                                                                                                                                                                                                        +049     */
                                                                                                                                                                                                                                                        +050    private static final String DEFAULT_METADATA_TYPE = "properties";
                                                                                                                                                                                                                                                        +051
                                                                                                                                                                                                                                                        +052    /**
                                                                                                                                                                                                                                                        +053     * Global metadata scope. Used by default if the metadata type is "properties".
                                                                                                                                                                                                                                                        +054     */
                                                                                                                                                                                                                                                        +055    private static final String GLOBAL_METADATA_SCOPE = "global";
                                                                                                                                                                                                                                                        +056
                                                                                                                                                                                                                                                        +057    /**
                                                                                                                                                                                                                                                        +058     * Enterprise metadata scope. Used by default if the metadata type is not "properties".
                                                                                                                                                                                                                                                        +059     */
                                                                                                                                                                                                                                                        +060    private static final String ENTERPRISE_METADATA_SCOPE = "enterprise";
                                                                                                                                                                                                                                                        +061
                                                                                                                                                                                                                                                        +062    /**
                                                                                                                                                                                                                                                        +063     * Default number of entries per page.
                                                                                                                                                                                                                                                        +064     */
                                                                                                                                                                                                                                                        +065    private static final int DEFAULT_ENTRIES_LIMIT = 100;
                                                                                                                                                                                                                                                        +066
                                                                                                                                                                                                                                                        +067    /**
                                                                                                                                                                                                                                                        +068     * @see #getID()
                                                                                                                                                                                                                                                        +069     */
                                                                                                                                                                                                                                                        +070    private String id;
                                                                                                                                                                                                                                                        +071
                                                                                                                                                                                                                                                        +072    /**
                                                                                                                                                                                                                                                        +073     * @see #getTemplateKey()
                                                                                                                                                                                                                                                        +074     */
                                                                                                                                                                                                                                                        +075    private String templateKey;
                                                                                                                                                                                                                                                        +076
                                                                                                                                                                                                                                                        +077    /**
                                                                                                                                                                                                                                                        +078     * @see #getScope()
                                                                                                                                                                                                                                                        +079     */
                                                                                                                                                                                                                                                        +080    private String scope;
                                                                                                                                                                                                                                                        +081
                                                                                                                                                                                                                                                        +082    /**
                                                                                                                                                                                                                                                        +083     * @see #getDisplayName()
                                                                                                                                                                                                                                                        +084     */
                                                                                                                                                                                                                                                        +085    private String displayName;
                                                                                                                                                                                                                                                        +086
                                                                                                                                                                                                                                                        +087    /**
                                                                                                                                                                                                                                                        +088     * @see #getIsHidden()
                                                                                                                                                                                                                                                        +089     */
                                                                                                                                                                                                                                                        +090    private Boolean isHidden;
                                                                                                                                                                                                                                                        +091
                                                                                                                                                                                                                                                        +092    /**
                                                                                                                                                                                                                                                        +093     * @see #getFields()
                                                                                                                                                                                                                                                        +094     */
                                                                                                                                                                                                                                                        +095    private List<Field> fields;
                                                                                                                                                                                                                                                        +096
                                                                                                                                                                                                                                                        +097    /**
                                                                                                                                                                                                                                                        +098     * @see #getCopyInstanceOnItemCopy()
                                                                                                                                                                                                                                                        +099     */
                                                                                                                                                                                                                                                        +100    private Boolean copyInstanceOnItemCopy;
                                                                                                                                                                                                                                                        +101
                                                                                                                                                                                                                                                        +102    /**
                                                                                                                                                                                                                                                        +103     * Constructs an empty metadata template.
                                                                                                                                                                                                                                                        +104     */
                                                                                                                                                                                                                                                        +105    public MetadataTemplate() {
                                                                                                                                                                                                                                                        +106        super();
                                                                                                                                                                                                                                                        +107    }
                                                                                                                                                                                                                                                        +108
                                                                                                                                                                                                                                                        +109    /**
                                                                                                                                                                                                                                                        +110     * Constructs a metadata template from a JSON string.
                                                                                                                                                                                                                                                        +111     *
                                                                                                                                                                                                                                                        +112     * @param json the json encoded metadate template.
                                                                                                                                                                                                                                                        +113     */
                                                                                                                                                                                                                                                        +114    public MetadataTemplate(String json) {
                                                                                                                                                                                                                                                        +115        super(json);
                                                                                                                                                                                                                                                        +116    }
                                                                                                                                                                                                                                                        +117
                                                                                                                                                                                                                                                        +118    /**
                                                                                                                                                                                                                                                        +119     * Constructs a metadate template from a JSON object.
                                                                                                                                                                                                                                                        +120     *
                                                                                                                                                                                                                                                        +121     * @param jsonObject the json encoded metadate template.
                                                                                                                                                                                                                                                        +122     */
                                                                                                                                                                                                                                                        +123    MetadataTemplate(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +124        super(jsonObject);
                                                                                                                                                                                                                                                        +125    }
                                                                                                                                                                                                                                                        +126
                                                                                                                                                                                                                                                        +127    /**
                                                                                                                                                                                                                                                        +128     * Creates new metadata template.
                                                                                                                                                                                                                                                        +129     *
                                                                                                                                                                                                                                                        +130     * @param api         the API connection to be used.
                                                                                                                                                                                                                                                        +131     * @param scope       the scope of the object.
                                                                                                                                                                                                                                                        +132     * @param templateKey a unique identifier for the template.
                                                                                                                                                                                                                                                        +133     * @param displayName the display name of the field.
                                                                                                                                                                                                                                                        +134     * @param hidden      whether this template is hidden in the UI.
                                                                                                                                                                                                                                                        +135     * @param fields      the ordered set of fields for the template
                                                                                                                                                                                                                                                        +136     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +137     */
                                                                                                                                                                                                                                                        +138    public static MetadataTemplate createMetadataTemplate(
                                                                                                                                                                                                                                                        +139        BoxAPIConnection api,
                                                                                                                                                                                                                                                        +140        String scope,
                                                                                                                                                                                                                                                        +141        String templateKey,
                                                                                                                                                                                                                                                        +142        String displayName,
                                                                                                                                                                                                                                                        +143        boolean hidden,
                                                                                                                                                                                                                                                        +144        List<Field> fields
                                                                                                                                                                                                                                                        +145    ) {
                                                                                                                                                                                                                                                        +146        return createMetadataTemplate(api, scope, templateKey, displayName, hidden, fields, null);
                                                                                                                                                                                                                                                        +147    }
                                                                                                                                                                                                                                                        +148
                                                                                                                                                                                                                                                        +149    /**
                                                                                                                                                                                                                                                        +150     * Creates new metadata template.
                                                                                                                                                                                                                                                        +151     *
                                                                                                                                                                                                                                                        +152     * @param api                    the API connection to be used.
                                                                                                                                                                                                                                                        +153     * @param scope                  the scope of the object.
                                                                                                                                                                                                                                                        +154     * @param templateKey            a unique identifier for the template.
                                                                                                                                                                                                                                                        +155     * @param displayName            the display name of the field.
                                                                                                                                                                                                                                                        +156     * @param hidden                 whether this template is hidden in the UI.
                                                                                                                                                                                                                                                        +157     * @param fields                 the ordered set of fields for the template
                                                                                                                                                                                                                                                        +158     * @param copyInstanceOnItemCopy determines whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +159     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +160     */
                                                                                                                                                                                                                                                        +161    public static MetadataTemplate createMetadataTemplate(
                                                                                                                                                                                                                                                        +162        BoxAPIConnection api,
                                                                                                                                                                                                                                                        +163        String scope,
                                                                                                                                                                                                                                                        +164        String templateKey,
                                                                                                                                                                                                                                                        +165        String displayName,
                                                                                                                                                                                                                                                        +166        Boolean hidden,
                                                                                                                                                                                                                                                        +167        List<Field> fields,
                                                                                                                                                                                                                                                        +168        Boolean copyInstanceOnItemCopy
                                                                                                                                                                                                                                                        +169    ) {
                                                                                                                                                                                                                                                        +170
                                                                                                                                                                                                                                                        +171        JsonObject jsonObject = new JsonObject();
                                                                                                                                                                                                                                                        +172        jsonObject.add("scope", scope);
                                                                                                                                                                                                                                                        +173        jsonObject.add("displayName", displayName);
                                                                                                                                                                                                                                                        +174
                                                                                                                                                                                                                                                        +175        if (hidden != null) {
                                                                                                                                                                                                                                                        +176            jsonObject.add("hidden", hidden);
                                                                                                                                                                                                                                                        +177        }
                                                                                                                                                                                                                                                        +178
                                                                                                                                                                                                                                                        +179        if (copyInstanceOnItemCopy != null) {
                                                                                                                                                                                                                                                        +180            jsonObject.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);
                                                                                                                                                                                                                                                        +181        }
                                                                                                                                                                                                                                                        +182
                                                                                                                                                                                                                                                        +183        if (templateKey != null) {
                                                                                                                                                                                                                                                        +184            jsonObject.add("templateKey", templateKey);
                                                                                                                                                                                                                                                        +185        }
                                                                                                                                                                                                                                                        +186
                                                                                                                                                                                                                                                        +187        JsonArray fieldsArray = new JsonArray();
                                                                                                                                                                                                                                                        +188        if (fields != null && !fields.isEmpty()) {
                                                                                                                                                                                                                                                        +189            for (Field field : fields) {
                                                                                                                                                                                                                                                        +190                JsonObject fieldObj = getFieldJsonObject(field);
                                                                                                                                                                                                                                                        +191
                                                                                                                                                                                                                                                        +192                fieldsArray.add(fieldObj);
                                                                                                                                                                                                                                                        +193            }
                                                                                                                                                                                                                                                        +194
                                                                                                                                                                                                                                                        +195            jsonObject.add("fields", fieldsArray);
                                                                                                                                                                                                                                                        +196        }
                                                                                                                                                                                                                                                        +197
                                                                                                                                                                                                                                                        +198        URL url = METADATA_TEMPLATE_SCHEMA_URL_TEMPLATE.build(api.getBaseURL());
                                                                                                                                                                                                                                                        +199        BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
                                                                                                                                                                                                                                                        +200        request.setBody(jsonObject.toString());
                                                                                                                                                                                                                                                        +201
                                                                                                                                                                                                                                                        +202        try (BoxJSONResponse response = request.send()) {
                                                                                                                                                                                                                                                        +203            JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
                                                                                                                                                                                                                                                        +204
                                                                                                                                                                                                                                                        +205            return new MetadataTemplate(responseJSON);
                                                                                                                                                                                                                                                        +206        }
                                                                                                                                                                                                                                                        +207    }
                                                                                                                                                                                                                                                        +208
                                                                                                                                                                                                                                                        +209    /**
                                                                                                                                                                                                                                                        +210     * Gets the JsonObject representation of the given field object.
                                                                                                                                                                                                                                                        +211     *
                                                                                                                                                                                                                                                        +212     * @param field represents a template field
                                                                                                                                                                                                                                                        +213     * @return the json object
                                                                                                                                                                                                                                                        +214     */
                                                                                                                                                                                                                                                        +215    private static JsonObject getFieldJsonObject(Field field) {
                                                                                                                                                                                                                                                        +216        JsonObject fieldObj = new JsonObject();
                                                                                                                                                                                                                                                        +217        fieldObj.add("type", field.getType());
                                                                                                                                                                                                                                                        +218        fieldObj.add("key", field.getKey());
                                                                                                                                                                                                                                                        +219        fieldObj.add("displayName", field.getDisplayName());
                                                                                                                                                                                                                                                        +220
                                                                                                                                                                                                                                                        +221        String fieldDesc = field.getDescription();
                                                                                                                                                                                                                                                        +222        if (fieldDesc != null) {
                                                                                                                                                                                                                                                        +223            fieldObj.add("description", field.getDescription());
                                                                                                                                                                                                                                                        +224        }
                                                                                                                                                                                                                                                        +225
                                                                                                                                                                                                                                                        +226        Boolean fieldIsHidden = field.getIsHidden();
                                                                                                                                                                                                                                                        +227        if (fieldIsHidden != null) {
                                                                                                                                                                                                                                                        +228            fieldObj.add("hidden", field.getIsHidden());
                                                                                                                                                                                                                                                        +229        }
                                                                                                                                                                                                                                                        +230
                                                                                                                                                                                                                                                        +231        JsonArray array = new JsonArray();
                                                                                                                                                                                                                                                        +232        List<String> options = field.getOptions();
                                                                                                                                                                                                                                                        +233        if (options != null && !options.isEmpty()) {
                                                                                                                                                                                                                                                        +234            for (String option : options) {
                                                                                                                                                                                                                                                        +235                JsonObject optionObj = new JsonObject();
                                                                                                                                                                                                                                                        +236                optionObj.add("key", option);
                                                                                                                                                                                                                                                        +237
                                                                                                                                                                                                                                                        +238                array.add(optionObj);
                                                                                                                                                                                                                                                        +239            }
                                                                                                                                                                                                                                                        +240            fieldObj.add("options", array);
                                                                                                                                                                                                                                                        +241        }
                                                                                                                                                                                                                                                        +242
                                                                                                                                                                                                                                                        +243        return fieldObj;
                                                                                                                                                                                                                                                        +244    }
                                                                                                                                                                                                                                                        +245
                                                                                                                                                                                                                                                        +246    /**
                                                                                                                                                                                                                                                        +247     * Updates the schema of an existing metadata template.
                                                                                                                                                                                                                                                        +248     *
                                                                                                                                                                                                                                                        +249     * @param api             the API connection to be used
                                                                                                                                                                                                                                                        +250     * @param scope           the scope of the object
                                                                                                                                                                                                                                                        +251     * @param template        Unique identifier of the template
                                                                                                                                                                                                                                                        +252     * @param fieldOperations the fields that needs to be updated / added in the template
                                                                                                                                                                                                                                                        +253     * @return the updated metadata template
                                                                                                                                                                                                                                                        +254     */
                                                                                                                                                                                                                                                        +255    public static MetadataTemplate updateMetadataTemplate(BoxAPIConnection api, String scope, String template,
                                                                                                                                                                                                                                                        +256                                                          List<FieldOperation> fieldOperations) {
                                                                                                                                                                                                                                                        +257
                                                                                                                                                                                                                                                        +258        JsonArray array = new JsonArray();
                                                                                                                                                                                                                                                        +259
                                                                                                                                                                                                                                                        +260        for (FieldOperation fieldOperation : fieldOperations) {
                                                                                                                                                                                                                                                        +261            JsonObject jsonObject = getFieldOperationJsonObject(fieldOperation);
                                                                                                                                                                                                                                                        +262            array.add(jsonObject);
                                                                                                                                                                                                                                                        +263        }
                                                                                                                                                                                                                                                        +264
                                                                                                                                                                                                                                                        +265        URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlpha(api.getBaseURL(), scope, template);
                                                                                                                                                                                                                                                        +266        BoxJSONRequest request = new BoxJSONRequest(api, url, "PUT");
                                                                                                                                                                                                                                                        +267        request.setBody(array.toString());
                                                                                                                                                                                                                                                        +268
                                                                                                                                                                                                                                                        +269        try (BoxJSONResponse response = request.send()) {
                                                                                                                                                                                                                                                        +270            JsonObject responseJson = Json.parse(response.getJSON()).asObject();
                                                                                                                                                                                                                                                        +271
                                                                                                                                                                                                                                                        +272            return new MetadataTemplate(responseJson);
                                                                                                                                                                                                                                                        +273        }
                                                                                                                                                                                                                                                        +274    }
                                                                                                                                                                                                                                                        +275
                                                                                                                                                                                                                                                        +276    /**
                                                                                                                                                                                                                                                        +277     * Deletes the schema of an existing metadata template.
                                                                                                                                                                                                                                                        +278     *
                                                                                                                                                                                                                                                        +279     * @param api      the API connection to be used
                                                                                                                                                                                                                                                        +280     * @param scope    the scope of the object
                                                                                                                                                                                                                                                        +281     * @param template Unique identifier of the template
                                                                                                                                                                                                                                                        +282     */
                                                                                                                                                                                                                                                        +283    public static void deleteMetadataTemplate(BoxAPIConnection api, String scope, String template) {
                                                                                                                                                                                                                                                        +284        URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlpha(api.getBaseURL(), scope, template);
                                                                                                                                                                                                                                                        +285        BoxAPIRequest request = new BoxAPIRequest(api, url, "DELETE");
                                                                                                                                                                                                                                                        +286        request.send().close();
                                                                                                                                                                                                                                                        +287    }
                                                                                                                                                                                                                                                        +288
                                                                                                                                                                                                                                                        +289    /**
                                                                                                                                                                                                                                                        +290     * Executes a metadata query.
                                                                                                                                                                                                                                                        +291     *
                                                                                                                                                                                                                                                        +292     * @param api       The API connection to be used
                                                                                                                                                                                                                                                        +293     * @param queryBody The query
                                                                                                                                                                                                                                                        +294     * @return An iterable of BoxItem.Info search results
                                                                                                                                                                                                                                                        +295     */
                                                                                                                                                                                                                                                        +296    public static BoxResourceIterable<BoxItem.Info> executeMetadataQuery(
                                                                                                                                                                                                                                                        +297        final BoxAPIConnection api,
                                                                                                                                                                                                                                                        +298        final MetadataQuery queryBody
                                                                                                                                                                                                                                                        +299    ) {
                                                                                                                                                                                                                                                        +300
                                                                                                                                                                                                                                                        +301        URL url = METADATA_QUERIES_URL_TEMPLATE.build(api.getBaseURL());
                                                                                                                                                                                                                                                        +302        return new BoxResourceIterable<BoxItem.Info>(
                                                                                                                                                                                                                                                        +303            api, url, queryBody.getLimit(), queryBody.toJsonObject(), queryBody.getMarker()
                                                                                                                                                                                                                                                        +304        ) {
                                                                                                                                                                                                                                                        +305
                                                                                                                                                                                                                                                        +306            @Override
                                                                                                                                                                                                                                                        +307            protected BoxItem.Info factory(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +308                String type = jsonObject.get("type").asString();
                                                                                                                                                                                                                                                        +309                String id = jsonObject.get("id").asString();
                                                                                                                                                                                                                                                        +310
                                                                                                                                                                                                                                                        +311                BoxItem.Info nextItemInfo;
                                                                                                                                                                                                                                                        +312                switch (type) {
                                                                                                                                                                                                                                                        +313                    case "folder":
                                                                                                                                                                                                                                                        +314                        BoxFolder folder = new BoxFolder(api, id);
                                                                                                                                                                                                                                                        +315                        nextItemInfo = folder.new Info(jsonObject);
                                                                                                                                                                                                                                                        +316                        break;
                                                                                                                                                                                                                                                        +317                    case "file":
                                                                                                                                                                                                                                                        +318                        BoxFile file = new BoxFile(api, id);
                                                                                                                                                                                                                                                        +319                        nextItemInfo = file.new Info(jsonObject);
                                                                                                                                                                                                                                                        +320                        break;
                                                                                                                                                                                                                                                        +321                    case "web_link":
                                                                                                                                                                                                                                                        +322                        BoxWebLink link = new BoxWebLink(api, id);
                                                                                                                                                                                                                                                        +323                        nextItemInfo = link.new Info(jsonObject);
                                                                                                                                                                                                                                                        +324                        break;
                                                                                                                                                                                                                                                        +325                    default:
                                                                                                                                                                                                                                                        +326                        assert false : "Unsupported item type: " + type;
                                                                                                                                                                                                                                                        +327                        throw new BoxAPIException("Unsupported item type: " + type);
                                                                                                                                                                                                                                                        +328                }
                                                                                                                                                                                                                                                        +329
                                                                                                                                                                                                                                                        +330                return nextItemInfo;
                                                                                                                                                                                                                                                        +331            }
                                                                                                                                                                                                                                                        +332        };
                                                                                                                                                                                                                                                        +333    }
                                                                                                                                                                                                                                                        +334
                                                                                                                                                                                                                                                        +335    /**
                                                                                                                                                                                                                                                        +336     * Gets the JsonObject representation of the Field Operation.
                                                                                                                                                                                                                                                        +337     *
                                                                                                                                                                                                                                                        +338     * @param fieldOperation represents the template update operation
                                                                                                                                                                                                                                                        +339     * @return the json object
                                                                                                                                                                                                                                                        +340     */
                                                                                                                                                                                                                                                        +341    private static JsonObject getFieldOperationJsonObject(FieldOperation fieldOperation) {
                                                                                                                                                                                                                                                        +342        JsonObject jsonObject = new JsonObject();
                                                                                                                                                                                                                                                        +343        jsonObject.add("op", fieldOperation.getOp().toString());
                                                                                                                                                                                                                                                        +344
                                                                                                                                                                                                                                                        +345        String fieldKey = fieldOperation.getFieldKey();
                                                                                                                                                                                                                                                        +346        if (fieldKey != null) {
                                                                                                                                                                                                                                                        +347            jsonObject.add("fieldKey", fieldKey);
                                                                                                                                                                                                                                                        +348        }
                                                                                                                                                                                                                                                        +349
                                                                                                                                                                                                                                                        +350        Field field = fieldOperation.getData();
                                                                                                                                                                                                                                                        +351        if (field != null) {
                                                                                                                                                                                                                                                        +352            JsonObject fieldObj = new JsonObject();
                                                                                                                                                                                                                                                        +353
                                                                                                                                                                                                                                                        +354            String type = field.getType();
                                                                                                                                                                                                                                                        +355            if (type != null) {
                                                                                                                                                                                                                                                        +356                fieldObj.add("type", type);
                                                                                                                                                                                                                                                        +357            }
                                                                                                                                                                                                                                                        +358
                                                                                                                                                                                                                                                        +359            String key = field.getKey();
                                                                                                                                                                                                                                                        +360            if (key != null) {
                                                                                                                                                                                                                                                        +361                fieldObj.add("key", key);
                                                                                                                                                                                                                                                        +362            }
                                                                                                                                                                                                                                                        +363
                                                                                                                                                                                                                                                        +364            String displayName = field.getDisplayName();
                                                                                                                                                                                                                                                        +365            if (displayName != null) {
                                                                                                                                                                                                                                                        +366                fieldObj.add("displayName", displayName);
                                                                                                                                                                                                                                                        +367            }
                                                                                                                                                                                                                                                        +368
                                                                                                                                                                                                                                                        +369            String description = field.getDescription();
                                                                                                                                                                                                                                                        +370            if (description != null) {
                                                                                                                                                                                                                                                        +371                fieldObj.add("description", description);
                                                                                                                                                                                                                                                        +372            }
                                                                                                                                                                                                                                                        +373
                                                                                                                                                                                                                                                        +374            Boolean hidden = field.getIsHidden();
                                                                                                                                                                                                                                                        +375            if (hidden != null) {
                                                                                                                                                                                                                                                        +376                fieldObj.add("hidden", hidden);
                                                                                                                                                                                                                                                        +377            }
                                                                                                                                                                                                                                                        +378
                                                                                                                                                                                                                                                        +379            List<String> options = field.getOptions();
                                                                                                                                                                                                                                                        +380            if (options != null) {
                                                                                                                                                                                                                                                        +381                JsonArray array = new JsonArray();
                                                                                                                                                                                                                                                        +382                for (String option : options) {
                                                                                                                                                                                                                                                        +383                    JsonObject optionObj = new JsonObject();
                                                                                                                                                                                                                                                        +384                    optionObj.add("key", option);
                                                                                                                                                                                                                                                        +385
                                                                                                                                                                                                                                                        +386                    array.add(optionObj);
                                                                                                                                                                                                                                                        +387                }
                                                                                                                                                                                                                                                        +388
                                                                                                                                                                                                                                                        +389                fieldObj.add("options", array);
                                                                                                                                                                                                                                                        +390            }
                                                                                                                                                                                                                                                        +391
                                                                                                                                                                                                                                                        +392            Boolean copyInstanceOnItemCopy = field.getCopyInstanceOnItemCopy();
                                                                                                                                                                                                                                                        +393            if (copyInstanceOnItemCopy != null) {
                                                                                                                                                                                                                                                        +394                fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);
                                                                                                                                                                                                                                                        +395            }
                                                                                                                                                                                                                                                        +396
                                                                                                                                                                                                                                                        +397            StaticConfig staticConfig = field.getStaticConfig();
                                                                                                                                                                                                                                                        +398            if (staticConfig != null) {
                                                                                                                                                                                                                                                        +399                JsonObject staticConfigObj = new JsonObject();
                                                                                                                                                                                                                                                        +400                JsonObject classification = staticConfig.getClassification();
                                                                                                                                                                                                                                                        +401                if (classification != null) {
                                                                                                                                                                                                                                                        +402                    staticConfigObj.add("classification", classification);
                                                                                                                                                                                                                                                        +403                }
                                                                                                                                                                                                                                                        +404                fieldObj.add("staticConfig", staticConfigObj);
                                                                                                                                                                                                                                                        +405            }
                                                                                                                                                                                                                                                        +406
                                                                                                                                                                                                                                                        +407            jsonObject.add("data", fieldObj);
                                                                                                                                                                                                                                                        +408        }
                                                                                                                                                                                                                                                        +409
                                                                                                                                                                                                                                                        +410        List<String> fieldKeys = fieldOperation.getFieldKeys();
                                                                                                                                                                                                                                                        +411        if (fieldKeys != null) {
                                                                                                                                                                                                                                                        +412            jsonObject.add("fieldKeys", getJsonArray(fieldKeys));
                                                                                                                                                                                                                                                        +413        }
                                                                                                                                                                                                                                                        +414
                                                                                                                                                                                                                                                        +415        List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys();
                                                                                                                                                                                                                                                        +416        if (enumOptionKeys != null) {
                                                                                                                                                                                                                                                        +417            jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));
                                                                                                                                                                                                                                                        +418        }
                                                                                                                                                                                                                                                        +419
                                                                                                                                                                                                                                                        +420        String enumOptionKey = fieldOperation.getEnumOptionKey();
                                                                                                                                                                                                                                                        +421        if (enumOptionKey != null) {
                                                                                                                                                                                                                                                        +422            jsonObject.add("enumOptionKey", enumOptionKey);
                                                                                                                                                                                                                                                        +423        }
                                                                                                                                                                                                                                                        +424
                                                                                                                                                                                                                                                        +425        String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey();
                                                                                                                                                                                                                                                        +426        if (multiSelectOptionKey != null) {
                                                                                                                                                                                                                                                        +427            jsonObject.add("multiSelectOptionKey", multiSelectOptionKey);
                                                                                                                                                                                                                                                        +428        }
                                                                                                                                                                                                                                                        +429
                                                                                                                                                                                                                                                        +430        List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys();
                                                                                                                                                                                                                                                        +431        if (multiSelectOptionKeys != null) {
                                                                                                                                                                                                                                                        +432            jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys));
                                                                                                                                                                                                                                                        +433        }
                                                                                                                                                                                                                                                        +434
                                                                                                                                                                                                                                                        +435        return jsonObject;
                                                                                                                                                                                                                                                        +436    }
                                                                                                                                                                                                                                                        +437
                                                                                                                                                                                                                                                        +438    /**
                                                                                                                                                                                                                                                        +439     * Gets the Json Array representation of the given list of strings.
                                                                                                                                                                                                                                                        +440     *
                                                                                                                                                                                                                                                        +441     * @param keys List of strings
                                                                                                                                                                                                                                                        +442     * @return the JsonArray represents the list of keys
                                                                                                                                                                                                                                                        +443     */
                                                                                                                                                                                                                                                        +444    private static JsonArray getJsonArray(List<String> keys) {
                                                                                                                                                                                                                                                        +445        JsonArray array = new JsonArray();
                                                                                                                                                                                                                                                        +446        for (String key : keys) {
                                                                                                                                                                                                                                                        +447            array.add(key);
                                                                                                                                                                                                                                                        +448        }
                                                                                                                                                                                                                                                        +449
                                                                                                                                                                                                                                                        +450        return array;
                                                                                                                                                                                                                                                        +451    }
                                                                                                                                                                                                                                                        +452
                                                                                                                                                                                                                                                        +453    /**
                                                                                                                                                                                                                                                        +454     * Gets the metadata template of properties.
                                                                                                                                                                                                                                                        +455     *
                                                                                                                                                                                                                                                        +456     * @param api the API connection to be used.
                                                                                                                                                                                                                                                        +457     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +458     */
                                                                                                                                                                                                                                                        +459    public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) {
                                                                                                                                                                                                                                                        +460        return getMetadataTemplate(api, DEFAULT_METADATA_TYPE);
                                                                                                                                                                                                                                                        +461    }
                                                                                                                                                                                                                                                        +462
                                                                                                                                                                                                                                                        +463    /**
                                                                                                                                                                                                                                                        +464     * Gets the metadata template of specified template type.
                                                                                                                                                                                                                                                        +465     *
                                                                                                                                                                                                                                                        +466     * @param api          the API connection to be used.
                                                                                                                                                                                                                                                        +467     * @param templateName the metadata template type name.
                                                                                                                                                                                                                                                        +468     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +469     */
                                                                                                                                                                                                                                                        +470    public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) {
                                                                                                                                                                                                                                                        +471        String scope = scopeBasedOnType(templateName);
                                                                                                                                                                                                                                                        +472        return getMetadataTemplate(api, templateName, scope);
                                                                                                                                                                                                                                                        +473    }
                                                                                                                                                                                                                                                        +474
                                                                                                                                                                                                                                                        +475    /**
                                                                                                                                                                                                                                                        +476     * Gets the metadata template of specified template type.
                                                                                                                                                                                                                                                        +477     *
                                                                                                                                                                                                                                                        +478     * @param api          the API connection to be used.
                                                                                                                                                                                                                                                        +479     * @param templateName the metadata template type name.
                                                                                                                                                                                                                                                        +480     * @param scope        the metadata template scope (global or enterprise).
                                                                                                                                                                                                                                                        +481     * @param fields       the fields to retrieve.
                                                                                                                                                                                                                                                        +482     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +483     */
                                                                                                                                                                                                                                                        +484    public static MetadataTemplate getMetadataTemplate(
                                                                                                                                                                                                                                                        +485        BoxAPIConnection api, String templateName, String scope, String... fields) {
                                                                                                                                                                                                                                                        +486        QueryStringBuilder builder = new QueryStringBuilder();
                                                                                                                                                                                                                                                        +487        if (fields.length > 0) {
                                                                                                                                                                                                                                                        +488            builder.appendParam("fields", fields);
                                                                                                                                                                                                                                                        +489        }
                                                                                                                                                                                                                                                        +490        URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery(
                                                                                                                                                                                                                                                        +491            api.getBaseURL(), builder.toString(), scope, templateName);
                                                                                                                                                                                                                                                        +492        BoxJSONRequest request = new BoxJSONRequest(api, url, "GET");
                                                                                                                                                                                                                                                        +493        try (BoxJSONResponse response = request.send()) {
                                                                                                                                                                                                                                                        +494            return new MetadataTemplate(response.getJSON());
                                                                                                                                                                                                                                                        +495        }
                                                                                                                                                                                                                                                        +496    }
                                                                                                                                                                                                                                                        +497
                                                                                                                                                                                                                                                        +498    /**
                                                                                                                                                                                                                                                        +499     * Geta the specified metadata template by its ID.
                                                                                                                                                                                                                                                        +500     *
                                                                                                                                                                                                                                                        +501     * @param api        the API connection to be used.
                                                                                                                                                                                                                                                        +502     * @param templateID the ID of the template to get.
                                                                                                                                                                                                                                                        +503     * @return the metadata template object.
                                                                                                                                                                                                                                                        +504     */
                                                                                                                                                                                                                                                        +505    public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) {
                                                                                                                                                                                                                                                        +506
                                                                                                                                                                                                                                                        +507        URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID);
                                                                                                                                                                                                                                                        +508        BoxJSONRequest request = new BoxJSONRequest(api, url, "GET");
                                                                                                                                                                                                                                                        +509        try (BoxJSONResponse response = request.send()) {
                                                                                                                                                                                                                                                        +510            return new MetadataTemplate(response.getJSON());
                                                                                                                                                                                                                                                        +511        }
                                                                                                                                                                                                                                                        +512    }
                                                                                                                                                                                                                                                        +513
                                                                                                                                                                                                                                                        +514    /**
                                                                                                                                                                                                                                                        +515     * Returns all metadata templates within a user's enterprise.
                                                                                                                                                                                                                                                        +516     *
                                                                                                                                                                                                                                                        +517     * @param api    the API connection to be used.
                                                                                                                                                                                                                                                        +518     * @param fields the fields to retrieve.
                                                                                                                                                                                                                                                        +519     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +520     */
                                                                                                                                                                                                                                                        +521    public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) {
                                                                                                                                                                                                                                                        +522        return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields);
                                                                                                                                                                                                                                                        +523    }
                                                                                                                                                                                                                                                        +524
                                                                                                                                                                                                                                                        +525    /**
                                                                                                                                                                                                                                                        +526     * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported.
                                                                                                                                                                                                                                                        +527     *
                                                                                                                                                                                                                                                        +528     * @param scope  the scope of the metadata templates.
                                                                                                                                                                                                                                                        +529     * @param api    the API connection to be used.
                                                                                                                                                                                                                                                        +530     * @param fields the fields to retrieve.
                                                                                                                                                                                                                                                        +531     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +532     */
                                                                                                                                                                                                                                                        +533    public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(
                                                                                                                                                                                                                                                        +534        String scope, BoxAPIConnection api, String... fields
                                                                                                                                                                                                                                                        +535    ) {
                                                                                                                                                                                                                                                        +536        return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields);
                                                                                                                                                                                                                                                        +537    }
                                                                                                                                                                                                                                                        +538
                                                                                                                                                                                                                                                        +539    /**
                                                                                                                                                                                                                                                        +540     * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported.
                                                                                                                                                                                                                                                        +541     *
                                                                                                                                                                                                                                                        +542     * @param scope  the scope of the metadata templates.
                                                                                                                                                                                                                                                        +543     * @param limit  maximum number of entries per response.
                                                                                                                                                                                                                                                        +544     * @param api    the API connection to be used.
                                                                                                                                                                                                                                                        +545     * @param fields the fields to retrieve.
                                                                                                                                                                                                                                                        +546     * @return the metadata template returned from the server.
                                                                                                                                                                                                                                                        +547     */
                                                                                                                                                                                                                                                        +548    public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(
                                                                                                                                                                                                                                                        +549        String scope, int limit, BoxAPIConnection api, String... fields) {
                                                                                                                                                                                                                                                        +550        QueryStringBuilder builder = new QueryStringBuilder();
                                                                                                                                                                                                                                                        +551        if (fields.length > 0) {
                                                                                                                                                                                                                                                        +552            builder.appendParam("fields", fields);
                                                                                                                                                                                                                                                        +553        }
                                                                                                                                                                                                                                                        +554        return new BoxResourceIterable<MetadataTemplate>(
                                                                                                                                                                                                                                                        +555            api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery(
                                                                                                                                                                                                                                                        +556            api.getBaseURL(), builder.toString(), scope), limit) {
                                                                                                                                                                                                                                                        +557
                                                                                                                                                                                                                                                        +558            @Override
                                                                                                                                                                                                                                                        +559            protected MetadataTemplate factory(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +560                return new MetadataTemplate(jsonObject);
                                                                                                                                                                                                                                                        +561            }
                                                                                                                                                                                                                                                        +562        };
                                                                                                                                                                                                                                                        +563    }
                                                                                                                                                                                                                                                        +564
                                                                                                                                                                                                                                                        +565    /**
                                                                                                                                                                                                                                                        +566     * Determines the metadata scope based on type.
                                                                                                                                                                                                                                                        +567     *
                                                                                                                                                                                                                                                        +568     * @param typeName type of the metadata.
                                                                                                                                                                                                                                                        +569     * @return scope of the metadata.
                                                                                                                                                                                                                                                        +570     */
                                                                                                                                                                                                                                                        +571    private static String scopeBasedOnType(String typeName) {
                                                                                                                                                                                                                                                        +572        return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE;
                                                                                                                                                                                                                                                        +573    }
                                                                                                                                                                                                                                                        +574
                                                                                                                                                                                                                                                        +575    /**
                                                                                                                                                                                                                                                        +576     * Gets the ID of the template.
                                                                                                                                                                                                                                                        +577     *
                                                                                                                                                                                                                                                        +578     * @return the template ID.
                                                                                                                                                                                                                                                        +579     */
                                                                                                                                                                                                                                                        +580    public String getID() {
                                                                                                                                                                                                                                                        +581        return this.id;
                                                                                                                                                                                                                                                        +582    }
                                                                                                                                                                                                                                                        +583
                                                                                                                                                                                                                                                        +584    /**
                                                                                                                                                                                                                                                        +585     * Gets the unique template key to identify the metadata template.
                                                                                                                                                                                                                                                        +586     *
                                                                                                                                                                                                                                                        +587     * @return the unique template key to identify the metadata template.
                                                                                                                                                                                                                                                        +588     */
                                                                                                                                                                                                                                                        +589    public String getTemplateKey() {
                                                                                                                                                                                                                                                        +590        return this.templateKey;
                                                                                                                                                                                                                                                        +591    }
                                                                                                                                                                                                                                                        +592
                                                                                                                                                                                                                                                        +593    /**
                                                                                                                                                                                                                                                        +594     * Gets the metadata template scope.
                                                                                                                                                                                                                                                        +595     *
                                                                                                                                                                                                                                                        +596     * @return the metadata template scope.
                                                                                                                                                                                                                                                        +597     */
                                                                                                                                                                                                                                                        +598    public String getScope() {
                                                                                                                                                                                                                                                        +599        return this.scope;
                                                                                                                                                                                                                                                        +600    }
                                                                                                                                                                                                                                                        +601
                                                                                                                                                                                                                                                        +602    /**
                                                                                                                                                                                                                                                        +603     * Gets the displayed metadata template name.
                                                                                                                                                                                                                                                        +604     *
                                                                                                                                                                                                                                                        +605     * @return the displayed metadata template name.
                                                                                                                                                                                                                                                        +606     */
                                                                                                                                                                                                                                                        +607    public String getDisplayName() {
                                                                                                                                                                                                                                                        +608        return this.displayName;
                                                                                                                                                                                                                                                        +609    }
                                                                                                                                                                                                                                                        +610
                                                                                                                                                                                                                                                        +611    /**
                                                                                                                                                                                                                                                        +612     * Gets is the metadata template hidden.
                                                                                                                                                                                                                                                        +613     *
                                                                                                                                                                                                                                                        +614     * @return is the metadata template hidden.
                                                                                                                                                                                                                                                        +615     */
                                                                                                                                                                                                                                                        +616    public Boolean getIsHidden() {
                                                                                                                                                                                                                                                        +617        return this.isHidden;
                                                                                                                                                                                                                                                        +618    }
                                                                                                                                                                                                                                                        +619
                                                                                                                                                                                                                                                        +620    /**
                                                                                                                                                                                                                                                        +621     * Gets the iterable with all fields the metadata template contains.
                                                                                                                                                                                                                                                        +622     *
                                                                                                                                                                                                                                                        +623     * @return the iterable with all fields the metadata template contains.
                                                                                                                                                                                                                                                        +624     */
                                                                                                                                                                                                                                                        +625    public List<Field> getFields() {
                                                                                                                                                                                                                                                        +626        return this.fields;
                                                                                                                                                                                                                                                        +627    }
                                                                                                                                                                                                                                                        +628
                                                                                                                                                                                                                                                        +629    /**
                                                                                                                                                                                                                                                        +630     * Gets whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +631     *
                                                                                                                                                                                                                                                        +632     * @return whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +633     */
                                                                                                                                                                                                                                                        +634    public Boolean getCopyInstanceOnItemCopy() {
                                                                                                                                                                                                                                                        +635        return this.copyInstanceOnItemCopy;
                                                                                                                                                                                                                                                        +636    }
                                                                                                                                                                                                                                                        +637
                                                                                                                                                                                                                                                        +638    /**
                                                                                                                                                                                                                                                        +639     * {@inheritDoc}
                                                                                                                                                                                                                                                        +640     */
                                                                                                                                                                                                                                                        +641    @Override
                                                                                                                                                                                                                                                        +642    void parseJSONMember(JsonObject.Member member) {
                                                                                                                                                                                                                                                        +643        JsonValue value = member.getValue();
                                                                                                                                                                                                                                                        +644        String memberName = member.getName();
                                                                                                                                                                                                                                                        +645        switch (memberName) {
                                                                                                                                                                                                                                                        +646            case "templateKey":
                                                                                                                                                                                                                                                        +647                this.templateKey = value.asString();
                                                                                                                                                                                                                                                        +648                break;
                                                                                                                                                                                                                                                        +649            case "scope":
                                                                                                                                                                                                                                                        +650                this.scope = value.asString();
                                                                                                                                                                                                                                                        +651                break;
                                                                                                                                                                                                                                                        +652            case "displayName":
                                                                                                                                                                                                                                                        +653                this.displayName = value.asString();
                                                                                                                                                                                                                                                        +654                break;
                                                                                                                                                                                                                                                        +655            case "hidden":
                                                                                                                                                                                                                                                        +656                this.isHidden = value.asBoolean();
                                                                                                                                                                                                                                                        +657                break;
                                                                                                                                                                                                                                                        +658            case "fields":
                                                                                                                                                                                                                                                        +659                this.fields = new ArrayList<>();
                                                                                                                                                                                                                                                        +660                for (JsonValue field : value.asArray()) {
                                                                                                                                                                                                                                                        +661                    this.fields.add(new Field(field.asObject()));
                                                                                                                                                                                                                                                        +662                }
                                                                                                                                                                                                                                                        +663                break;
                                                                                                                                                                                                                                                        +664            case "id":
                                                                                                                                                                                                                                                        +665                this.id = value.asString();
                                                                                                                                                                                                                                                        +666                break;
                                                                                                                                                                                                                                                        +667            case "copyInstanceOnItemCopy":
                                                                                                                                                                                                                                                        +668                this.copyInstanceOnItemCopy = value.asBoolean();
                                                                                                                                                                                                                                                        +669                break;
                                                                                                                                                                                                                                                        +670            default:
                                                                                                                                                                                                                                                        +671                break;
                                                                                                                                                                                                                                                        +672        }
                                                                                                                                                                                                                                                        +673    }
                                                                                                                                                                                                                                                        +674
                                                                                                                                                                                                                                                        +675    /**
                                                                                                                                                                                                                                                        +676     * Possible template operations.
                                                                                                                                                                                                                                                        +677     */
                                                                                                                                                                                                                                                        +678    public enum Operation {
                                                                                                                                                                                                                                                        +679
                                                                                                                                                                                                                                                        +680        /**
                                                                                                                                                                                                                                                        +681         * Adds an enum option at the end of the enum option list for the specified field.
                                                                                                                                                                                                                                                        +682         */
                                                                                                                                                                                                                                                        +683        addEnumOption,
                                                                                                                                                                                                                                                        +684
                                                                                                                                                                                                                                                        +685        /**
                                                                                                                                                                                                                                                        +686         * Edits the enum option.
                                                                                                                                                                                                                                                        +687         */
                                                                                                                                                                                                                                                        +688        editEnumOption,
                                                                                                                                                                                                                                                        +689
                                                                                                                                                                                                                                                        +690        /**
                                                                                                                                                                                                                                                        +691         * Removes the specified enum option from the specified enum field.
                                                                                                                                                                                                                                                        +692         */
                                                                                                                                                                                                                                                        +693        removeEnumOption,
                                                                                                                                                                                                                                                        +694
                                                                                                                                                                                                                                                        +695        /**
                                                                                                                                                                                                                                                        +696         * Adds a field at the end of the field list for the template.
                                                                                                                                                                                                                                                        +697         */
                                                                                                                                                                                                                                                        +698        addField,
                                                                                                                                                                                                                                                        +699
                                                                                                                                                                                                                                                        +700        /**
                                                                                                                                                                                                                                                        +701         * Edits any number of the base properties of a field: displayName, hidden, description.
                                                                                                                                                                                                                                                        +702         */
                                                                                                                                                                                                                                                        +703        editField,
                                                                                                                                                                                                                                                        +704
                                                                                                                                                                                                                                                        +705        /**
                                                                                                                                                                                                                                                        +706         * Removes the specified field from the template.
                                                                                                                                                                                                                                                        +707         */
                                                                                                                                                                                                                                                        +708        removeField,
                                                                                                                                                                                                                                                        +709
                                                                                                                                                                                                                                                        +710        /**
                                                                                                                                                                                                                                                        +711         * Edits any number of the base properties of a template: displayName, hidden.
                                                                                                                                                                                                                                                        +712         */
                                                                                                                                                                                                                                                        +713        editTemplate,
                                                                                                                                                                                                                                                        +714
                                                                                                                                                                                                                                                        +715        /**
                                                                                                                                                                                                                                                        +716         * Reorders the enum option list to match the requested enum option list.
                                                                                                                                                                                                                                                        +717         */
                                                                                                                                                                                                                                                        +718        reorderEnumOptions,
                                                                                                                                                                                                                                                        +719
                                                                                                                                                                                                                                                        +720        /**
                                                                                                                                                                                                                                                        +721         * Reorders the field list to match the requested field list.
                                                                                                                                                                                                                                                        +722         */
                                                                                                                                                                                                                                                        +723        reorderFields,
                                                                                                                                                                                                                                                        +724
                                                                                                                                                                                                                                                        +725        /**
                                                                                                                                                                                                                                                        +726         * Adds a new option to a multiselect field.
                                                                                                                                                                                                                                                        +727         */
                                                                                                                                                                                                                                                        +728        addMultiSelectOption,
                                                                                                                                                                                                                                                        +729
                                                                                                                                                                                                                                                        +730        /**
                                                                                                                                                                                                                                                        +731         * Edits an existing option in a multiselect field.
                                                                                                                                                                                                                                                        +732         */
                                                                                                                                                                                                                                                        +733        editMultiSelectOption,
                                                                                                                                                                                                                                                        +734
                                                                                                                                                                                                                                                        +735        /**
                                                                                                                                                                                                                                                        +736         * Removes an option from a multiselect field.
                                                                                                                                                                                                                                                        +737         */
                                                                                                                                                                                                                                                        +738        removeMultiSelectOption,
                                                                                                                                                                                                                                                        +739
                                                                                                                                                                                                                                                        +740        /**
                                                                                                                                                                                                                                                        +741         * Changes the display order of options in a multiselect field.
                                                                                                                                                                                                                                                        +742         */
                                                                                                                                                                                                                                                        +743        reorderMultiSelectOptions
                                                                                                                                                                                                                                                        +744    }
                                                                                                                                                                                                                                                        +745
                                                                                                                                                                                                                                                        +746    /**
                                                                                                                                                                                                                                                        +747     * Class contains information about the static configuration for the classification.
                                                                                                                                                                                                                                                        +748     */
                                                                                                                                                                                                                                                        +749    public static class StaticConfig extends BoxJSONObject {
                                                                                                                                                                                                                                                        +750        private JsonObject classification;
                                                                                                                                                                                                                                                        +751
                                                                                                                                                                                                                                                        +752        /**
                                                                                                                                                                                                                                                        +753         * Constructs an empty static configuration.
                                                                                                                                                                                                                                                        +754         */
                                                                                                                                                                                                                                                        +755        public StaticConfig() {
                                                                                                                                                                                                                                                        +756            super();
                                                                                                                                                                                                                                                        +757        }
                                                                                                                                                                                                                                                        +758
                                                                                                                                                                                                                                                        +759        /**
                                                                                                                                                                                                                                                        +760         * Constructs a static configuration from a JSON string.
                                                                                                                                                                                                                                                        +761         *
                                                                                                                                                                                                                                                        +762         * @param json the json encoded metadate template field.
                                                                                                                                                                                                                                                        +763         */
                                                                                                                                                                                                                                                        +764        public StaticConfig(String json) {
                                                                                                                                                                                                                                                        +765            super(json);
                                                                                                                                                                                                                                                        +766        }
                                                                                                                                                                                                                                                        +767
                                                                                                                                                                                                                                                        +768        /** Constructs a static configuration from a JSON object.
                                                                                                                                                                                                                                                        +769         *
                                                                                                                                                                                                                                                        +770         * @param jsonObject the json encoded metadate template field.
                                                                                                                                                                                                                                                        +771         */
                                                                                                                                                                                                                                                        +772        StaticConfig(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +773            super(jsonObject);
                                                                                                                                                                                                                                                        +774        }
                                                                                                                                                                                                                                                        +775
                                                                                                                                                                                                                                                        +776        /**
                                                                                                                                                                                                                                                        +777         * Gets the classification of the static configuration.
                                                                                                                                                                                                                                                        +778         *
                                                                                                                                                                                                                                                        +779         * @return the classification of the static configuration.
                                                                                                                                                                                                                                                        +780         */
                                                                                                                                                                                                                                                        +781        public JsonObject getClassification() {
                                                                                                                                                                                                                                                        +782            return this.classification;
                                                                                                                                                                                                                                                        +783        }
                                                                                                                                                                                                                                                        +784
                                                                                                                                                                                                                                                        +785        /**
                                                                                                                                                                                                                                                        +786         * Sets the classification of the static configuration.
                                                                                                                                                                                                                                                        +787         *
                                                                                                                                                                                                                                                        +788         * @param classification the classification of the static configuration.
                                                                                                                                                                                                                                                        +789         */
                                                                                                                                                                                                                                                        +790        public void setClassification(JsonObject classification) {
                                                                                                                                                                                                                                                        +791            this.classification = classification;
                                                                                                                                                                                                                                                        +792        }
                                                                                                                                                                                                                                                        +793
                                                                                                                                                                                                                                                        +794        /**
                                                                                                                                                                                                                                                        +795         * {@inheritDoc}
                                                                                                                                                                                                                                                        +796         */
                                                                                                                                                                                                                                                        +797        @Override
                                                                                                                                                                                                                                                        +798        void parseJSONMember(JsonObject.Member member) {
                                                                                                                                                                                                                                                        +799            JsonValue value = member.getValue();
                                                                                                                                                                                                                                                        +800            String memberName = member.getName();
                                                                                                                                                                                                                                                        +801            switch (memberName) {
                                                                                                                                                                                                                                                        +802                case "classification":
                                                                                                                                                                                                                                                        +803                    this.classification = value.asObject();
                                                                                                                                                                                                                                                        +804                    break;
                                                                                                                                                                                                                                                        +805                default:
                                                                                                                                                                                                                                                        +806                    break;
                                                                                                                                                                                                                                                        +807            }
                                                                                                                                                                                                                                                        +808        }
                                                                                                                                                                                                                                                        +809    }
                                                                                                                                                                                                                                                        +810
                                                                                                                                                                                                                                                        +811    /**
                                                                                                                                                                                                                                                        +812     * Class contains information about the metadata template field.
                                                                                                                                                                                                                                                        +813     */
                                                                                                                                                                                                                                                        +814    public static class Field extends BoxJSONObject {
                                                                                                                                                                                                                                                        +815
                                                                                                                                                                                                                                                        +816        /**
                                                                                                                                                                                                                                                        +817         * @see #getID()
                                                                                                                                                                                                                                                        +818         */
                                                                                                                                                                                                                                                        +819        private String id;
                                                                                                                                                                                                                                                        +820
                                                                                                                                                                                                                                                        +821        /**
                                                                                                                                                                                                                                                        +822         * @see #getType()
                                                                                                                                                                                                                                                        +823         */
                                                                                                                                                                                                                                                        +824        private String type;
                                                                                                                                                                                                                                                        +825
                                                                                                                                                                                                                                                        +826        /**
                                                                                                                                                                                                                                                        +827         * @see #getKey()
                                                                                                                                                                                                                                                        +828         */
                                                                                                                                                                                                                                                        +829        private String key;
                                                                                                                                                                                                                                                        +830
                                                                                                                                                                                                                                                        +831        /**
                                                                                                                                                                                                                                                        +832         * @see #getDisplayName()
                                                                                                                                                                                                                                                        +833         */
                                                                                                                                                                                                                                                        +834        private String displayName;
                                                                                                                                                                                                                                                        +835
                                                                                                                                                                                                                                                        +836        /**
                                                                                                                                                                                                                                                        +837         * @see #getIsHidden()
                                                                                                                                                                                                                                                        +838         */
                                                                                                                                                                                                                                                        +839        private Boolean isHidden;
                                                                                                                                                                                                                                                        +840
                                                                                                                                                                                                                                                        +841        /**
                                                                                                                                                                                                                                                        +842         * @see #getDescription()
                                                                                                                                                                                                                                                        +843         */
                                                                                                                                                                                                                                                        +844        private String description;
                                                                                                                                                                                                                                                        +845
                                                                                                                                                                                                                                                        +846        /**
                                                                                                                                                                                                                                                        +847         * @see #getOptionsObjects()
                                                                                                                                                                                                                                                        +848         */
                                                                                                                                                                                                                                                        +849        private List<Option> options;
                                                                                                                                                                                                                                                        +850
                                                                                                                                                                                                                                                        +851        /**
                                                                                                                                                                                                                                                        +852         * @see #getCopyInstanceOnItemCopy()
                                                                                                                                                                                                                                                        +853         */
                                                                                                                                                                                                                                                        +854        private Boolean copyInstanceOnItemCopy;
                                                                                                                                                                                                                                                        +855
                                                                                                                                                                                                                                                        +856        /**
                                                                                                                                                                                                                                                        +857         * @see #getStaticConfig()
                                                                                                                                                                                                                                                        +858         */
                                                                                                                                                                                                                                                        +859        private StaticConfig staticConfig;
                                                                                                                                                                                                                                                        +860
                                                                                                                                                                                                                                                        +861        /**
                                                                                                                                                                                                                                                        +862         * Constructs an empty metadata template.
                                                                                                                                                                                                                                                        +863         */
                                                                                                                                                                                                                                                        +864        public Field() {
                                                                                                                                                                                                                                                        +865            super();
                                                                                                                                                                                                                                                        +866        }
                                                                                                                                                                                                                                                        +867
                                                                                                                                                                                                                                                        +868        /**
                                                                                                                                                                                                                                                        +869         * Constructs a metadate template field from a JSON string.
                                                                                                                                                                                                                                                        +870         *
                                                                                                                                                                                                                                                        +871         * @param json the json encoded metadate template field.
                                                                                                                                                                                                                                                        +872         */
                                                                                                                                                                                                                                                        +873        public Field(String json) {
                                                                                                                                                                                                                                                        +874            super(json);
                                                                                                                                                                                                                                                        +875        }
                                                                                                                                                                                                                                                        +876
                                                                                                                                                                                                                                                        +877        /**
                                                                                                                                                                                                                                                        +878         * Constructs a metadate template field from a JSON object.
                                                                                                                                                                                                                                                        +879         *
                                                                                                                                                                                                                                                        +880         * @param jsonObject the json encoded metadate template field.
                                                                                                                                                                                                                                                        +881         */
                                                                                                                                                                                                                                                        +882        Field(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +883            super(jsonObject);
                                                                                                                                                                                                                                                        +884        }
                                                                                                                                                                                                                                                        +885
                                                                                                                                                                                                                                                        +886        /**
                                                                                                                                                                                                                                                        +887         * Gets the ID of the template field.
                                                                                                                                                                                                                                                        +888         *
                                                                                                                                                                                                                                                        +889         * @return the template field ID.
                                                                                                                                                                                                                                                        +890         */
                                                                                                                                                                                                                                                        +891        public String getID() {
                                                                                                                                                                                                                                                        +892            return this.id;
                                                                                                                                                                                                                                                        +893        }
                                                                                                                                                                                                                                                        +894
                                                                                                                                                                                                                                                        +895        /**
                                                                                                                                                                                                                                                        +896         * Gets the data type of the field's value.
                                                                                                                                                                                                                                                        +897         *
                                                                                                                                                                                                                                                        +898         * @return the data type of the field's value.
                                                                                                                                                                                                                                                        +899         */
                                                                                                                                                                                                                                                        +900        public String getType() {
                                                                                                                                                                                                                                                        +901            return this.type;
                                                                                                                                                                                                                                                        +902        }
                                                                                                                                                                                                                                                        +903
                                                                                                                                                                                                                                                        +904        /**
                                                                                                                                                                                                                                                        +905         * Sets the data type of the field's value.
                                                                                                                                                                                                                                                        +906         *
                                                                                                                                                                                                                                                        +907         * @param type the data type of the field's value.
                                                                                                                                                                                                                                                        +908         */
                                                                                                                                                                                                                                                        +909        public void setType(String type) {
                                                                                                                                                                                                                                                        +910            this.type = type;
                                                                                                                                                                                                                                                        +911        }
                                                                                                                                                                                                                                                        +912
                                                                                                                                                                                                                                                        +913        /**
                                                                                                                                                                                                                                                        +914         * Gets the key of the field.
                                                                                                                                                                                                                                                        +915         *
                                                                                                                                                                                                                                                        +916         * @return the key of the field.
                                                                                                                                                                                                                                                        +917         */
                                                                                                                                                                                                                                                        +918        public String getKey() {
                                                                                                                                                                                                                                                        +919            return this.key;
                                                                                                                                                                                                                                                        +920        }
                                                                                                                                                                                                                                                        +921
                                                                                                                                                                                                                                                        +922        /**
                                                                                                                                                                                                                                                        +923         * Sets the key of the field.
                                                                                                                                                                                                                                                        +924         *
                                                                                                                                                                                                                                                        +925         * @param key the key of the field.
                                                                                                                                                                                                                                                        +926         */
                                                                                                                                                                                                                                                        +927        public void setKey(String key) {
                                                                                                                                                                                                                                                        +928            this.key = key;
                                                                                                                                                                                                                                                        +929        }
                                                                                                                                                                                                                                                        +930
                                                                                                                                                                                                                                                        +931        /**
                                                                                                                                                                                                                                                        +932         * Gets the display name of the field.
                                                                                                                                                                                                                                                        +933         *
                                                                                                                                                                                                                                                        +934         * @return the display name of the field.
                                                                                                                                                                                                                                                        +935         */
                                                                                                                                                                                                                                                        +936        public String getDisplayName() {
                                                                                                                                                                                                                                                        +937            return this.displayName;
                                                                                                                                                                                                                                                        +938        }
                                                                                                                                                                                                                                                        +939
                                                                                                                                                                                                                                                        +940        /**
                                                                                                                                                                                                                                                        +941         * Sets the display name of the field.
                                                                                                                                                                                                                                                        +942         *
                                                                                                                                                                                                                                                        +943         * @param displayName the display name of the field.
                                                                                                                                                                                                                                                        +944         */
                                                                                                                                                                                                                                                        +945        public void setDisplayName(String displayName) {
                                                                                                                                                                                                                                                        +946            this.displayName = displayName;
                                                                                                                                                                                                                                                        +947        }
                                                                                                                                                                                                                                                        +948
                                                                                                                                                                                                                                                        +949        /**
                                                                                                                                                                                                                                                        +950         * Gets is metadata template field hidden.
                                                                                                                                                                                                                                                        +951         *
                                                                                                                                                                                                                                                        +952         * @return is metadata template field hidden.
                                                                                                                                                                                                                                                        +953         */
                                                                                                                                                                                                                                                        +954        public Boolean getIsHidden() {
                                                                                                                                                                                                                                                        +955            return this.isHidden;
                                                                                                                                                                                                                                                        +956        }
                                                                                                                                                                                                                                                        +957
                                                                                                                                                                                                                                                        +958        /**
                                                                                                                                                                                                                                                        +959         * Sets is metadata template field hidden.
                                                                                                                                                                                                                                                        +960         *
                                                                                                                                                                                                                                                        +961         * @param isHidden is metadata template field hidden?
                                                                                                                                                                                                                                                        +962         */
                                                                                                                                                                                                                                                        +963        public void setIsHidden(boolean isHidden) {
                                                                                                                                                                                                                                                        +964            this.isHidden = isHidden;
                                                                                                                                                                                                                                                        +965        }
                                                                                                                                                                                                                                                        +966
                                                                                                                                                                                                                                                        +967        /**
                                                                                                                                                                                                                                                        +968         * Gets the description of the field.
                                                                                                                                                                                                                                                        +969         *
                                                                                                                                                                                                                                                        +970         * @return the description of the field.
                                                                                                                                                                                                                                                        +971         */
                                                                                                                                                                                                                                                        +972        public String getDescription() {
                                                                                                                                                                                                                                                        +973            return this.description;
                                                                                                                                                                                                                                                        +974        }
                                                                                                                                                                                                                                                        +975
                                                                                                                                                                                                                                                        +976        /**
                                                                                                                                                                                                                                                        +977         * Sets the description of the field.
                                                                                                                                                                                                                                                        +978         *
                                                                                                                                                                                                                                                        +979         * @param description the description of the field.
                                                                                                                                                                                                                                                        +980         */
                                                                                                                                                                                                                                                        +981        public void setDescription(String description) {
                                                                                                                                                                                                                                                        +982            this.description = description;
                                                                                                                                                                                                                                                        +983        }
                                                                                                                                                                                                                                                        +984
                                                                                                                                                                                                                                                        +985        /**
                                                                                                                                                                                                                                                        +986         * Gets list of possible options for enum type of the field.
                                                                                                                                                                                                                                                        +987         *
                                                                                                                                                                                                                                                        +988         * @return list of possible options for enum type of the field.
                                                                                                                                                                                                                                                        +989         */
                                                                                                                                                                                                                                                        +990        public List<String> getOptions() {
                                                                                                                                                                                                                                                        +991            if (this.options == null) {
                                                                                                                                                                                                                                                        +992                return null;
                                                                                                                                                                                                                                                        +993            }
                                                                                                                                                                                                                                                        +994            List<String> optionsList = new ArrayList<>();
                                                                                                                                                                                                                                                        +995            for (Option option : this.options) {
                                                                                                                                                                                                                                                        +996                optionsList.add(option.getKey());
                                                                                                                                                                                                                                                        +997            }
                                                                                                                                                                                                                                                        +998            return optionsList;
                                                                                                                                                                                                                                                        +999        }
                                                                                                                                                                                                                                                        +1000
                                                                                                                                                                                                                                                        +1001        /**
                                                                                                                                                                                                                                                        +1002         * Sets list of possible options for enum type of the field.
                                                                                                                                                                                                                                                        +1003         *
                                                                                                                                                                                                                                                        +1004         * @param options list of possible options for enum type of the field.
                                                                                                                                                                                                                                                        +1005         */
                                                                                                                                                                                                                                                        +1006        public void setOptions(List<String> options) {
                                                                                                                                                                                                                                                        +1007            if (options == null) {
                                                                                                                                                                                                                                                        +1008                this.options = null;
                                                                                                                                                                                                                                                        +1009                return;
                                                                                                                                                                                                                                                        +1010            }
                                                                                                                                                                                                                                                        +1011            List<Option> optionList = new ArrayList<>();
                                                                                                                                                                                                                                                        +1012            for (String key : options) {
                                                                                                                                                                                                                                                        +1013                JsonObject optionObject = new JsonObject();
                                                                                                                                                                                                                                                        +1014                optionObject.add("key", key);
                                                                                                                                                                                                                                                        +1015                Option newOption = new Option(optionObject);
                                                                                                                                                                                                                                                        +1016                optionList.add(newOption);
                                                                                                                                                                                                                                                        +1017            }
                                                                                                                                                                                                                                                        +1018            this.options = optionList;
                                                                                                                                                                                                                                                        +1019        }
                                                                                                                                                                                                                                                        +1020
                                                                                                                                                                                                                                                        +1021        /**
                                                                                                                                                                                                                                                        +1022         * Gets list of possible options for options type of the field.
                                                                                                                                                                                                                                                        +1023         *
                                                                                                                                                                                                                                                        +1024         * @return list of possible options for option type of the field.
                                                                                                                                                                                                                                                        +1025         */
                                                                                                                                                                                                                                                        +1026        public List<Option> getOptionsObjects() {
                                                                                                                                                                                                                                                        +1027            return this.options;
                                                                                                                                                                                                                                                        +1028        }
                                                                                                                                                                                                                                                        +1029
                                                                                                                                                                                                                                                        +1030        /**
                                                                                                                                                                                                                                                        +1031         * Gets whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +1032         *
                                                                                                                                                                                                                                                        +1033         * @return whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +1034         */
                                                                                                                                                                                                                                                        +1035        public Boolean getCopyInstanceOnItemCopy() {
                                                                                                                                                                                                                                                        +1036            return this.copyInstanceOnItemCopy;
                                                                                                                                                                                                                                                        +1037        }
                                                                                                                                                                                                                                                        +1038
                                                                                                                                                                                                                                                        +1039        /**
                                                                                                                                                                                                                                                        +1040         * Sets whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +1041         *
                                                                                                                                                                                                                                                        +1042         * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item.
                                                                                                                                                                                                                                                        +1043         */
                                                                                                                                                                                                                                                        +1044        public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) {
                                                                                                                                                                                                                                                        +1045            this.copyInstanceOnItemCopy = copyInstanceOnItemCopy;
                                                                                                                                                                                                                                                        +1046        }
                                                                                                                                                                                                                                                        +1047
                                                                                                                                                                                                                                                        +1048        /**
                                                                                                                                                                                                                                                        +1049         * Gets static configuration for the classification.
                                                                                                                                                                                                                                                        +1050         *
                                                                                                                                                                                                                                                        +1051         * @return static configuration for the classification.
                                                                                                                                                                                                                                                        +1052         */
                                                                                                                                                                                                                                                        +1053        public StaticConfig getStaticConfig() {
                                                                                                                                                                                                                                                        +1054            return this.staticConfig;
                                                                                                                                                                                                                                                        +1055        }
                                                                                                                                                                                                                                                        +1056
                                                                                                                                                                                                                                                        +1057        /**
                                                                                                                                                                                                                                                        +1058         * Sets static configuration for the classification.
                                                                                                                                                                                                                                                        +1059         *
                                                                                                                                                                                                                                                        +1060         * @param staticConfig static configuration for the classification.
                                                                                                                                                                                                                                                        +1061         */
                                                                                                                                                                                                                                                        +1062        public void setStaticConfig(StaticConfig staticConfig) {
                                                                                                                                                                                                                                                        +1063            this.staticConfig = staticConfig;
                                                                                                                                                                                                                                                        +1064        }
                                                                                                                                                                                                                                                        +1065
                                                                                                                                                                                                                                                        +1066        /**
                                                                                                                                                                                                                                                        +1067         * {@inheritDoc}
                                                                                                                                                                                                                                                        +1068         */
                                                                                                                                                                                                                                                        +1069        @Override
                                                                                                                                                                                                                                                        +1070        void parseJSONMember(JsonObject.Member member) {
                                                                                                                                                                                                                                                        +1071            JsonValue value = member.getValue();
                                                                                                                                                                                                                                                        +1072            String memberName = member.getName();
                                                                                                                                                                                                                                                        +1073            switch (memberName) {
                                                                                                                                                                                                                                                        +1074                case "type":
                                                                                                                                                                                                                                                        +1075                    this.type = value.asString();
                                                                                                                                                                                                                                                        +1076                    break;
                                                                                                                                                                                                                                                        +1077                case "key":
                                                                                                                                                                                                                                                        +1078                    this.key = value.asString();
                                                                                                                                                                                                                                                        +1079                    break;
                                                                                                                                                                                                                                                        +1080                case "displayName":
                                                                                                                                                                                                                                                        +1081                    this.displayName = value.asString();
                                                                                                                                                                                                                                                        +1082                    break;
                                                                                                                                                                                                                                                        +1083                case "hidden":
                                                                                                                                                                                                                                                        +1084                    this.isHidden = value.asBoolean();
                                                                                                                                                                                                                                                        +1085                    break;
                                                                                                                                                                                                                                                        +1086                case "description":
                                                                                                                                                                                                                                                        +1087                    this.description = value.asString();
                                                                                                                                                                                                                                                        +1088                    break;
                                                                                                                                                                                                                                                        +1089                case "options":
                                                                                                                                                                                                                                                        +1090                    this.options = new ArrayList<>();
                                                                                                                                                                                                                                                        +1091                    for (JsonValue option : value.asArray()) {
                                                                                                                                                                                                                                                        +1092                        this.options.add(new Option(option.asObject()));
                                                                                                                                                                                                                                                        +1093                    }
                                                                                                                                                                                                                                                        +1094                    break;
                                                                                                                                                                                                                                                        +1095                case "id":
                                                                                                                                                                                                                                                        +1096                    this.id = value.asString();
                                                                                                                                                                                                                                                        +1097                    break;
                                                                                                                                                                                                                                                        +1098                case "copyInstanceOnItemCopy":
                                                                                                                                                                                                                                                        +1099                    this.copyInstanceOnItemCopy = value.asBoolean();
                                                                                                                                                                                                                                                        +1100                    break;
                                                                                                                                                                                                                                                        +1101                case "staticConfig":
                                                                                                                                                                                                                                                        +1102                    this.staticConfig = new StaticConfig(value.asObject());
                                                                                                                                                                                                                                                        +1103                    break;
                                                                                                                                                                                                                                                        +1104                default:
                                                                                                                                                                                                                                                        +1105                    break;
                                                                                                                                                                                                                                                        +1106            }
                                                                                                                                                                                                                                                        +1107        }
                                                                                                                                                                                                                                                        +1108    }
                                                                                                                                                                                                                                                        +1109
                                                                                                                                                                                                                                                        +1110    /**
                                                                                                                                                                                                                                                        +1111     * Class contains information about the metadata template option.
                                                                                                                                                                                                                                                        +1112     */
                                                                                                                                                                                                                                                        +1113    public static class Option extends BoxJSONObject {
                                                                                                                                                                                                                                                        +1114        /**
                                                                                                                                                                                                                                                        +1115         * @see #getID()
                                                                                                                                                                                                                                                        +1116         */
                                                                                                                                                                                                                                                        +1117        private String id;
                                                                                                                                                                                                                                                        +1118        /**
                                                                                                                                                                                                                                                        +1119         * @see #getKey()
                                                                                                                                                                                                                                                        +1120         */
                                                                                                                                                                                                                                                        +1121        private String key;
                                                                                                                                                                                                                                                        +1122        /**
                                                                                                                                                                                                                                                        +1123         * @see #getStaticConfig()
                                                                                                                                                                                                                                                        +1124         */
                                                                                                                                                                                                                                                        +1125        private StaticConfig staticConfig;
                                                                                                                                                                                                                                                        +1126
                                                                                                                                                                                                                                                        +1127        /**
                                                                                                                                                                                                                                                        +1128         * Constructs an empty metadata template.
                                                                                                                                                                                                                                                        +1129         */
                                                                                                                                                                                                                                                        +1130        public Option() {
                                                                                                                                                                                                                                                        +1131            super();
                                                                                                                                                                                                                                                        +1132        }
                                                                                                                                                                                                                                                        +1133
                                                                                                                                                                                                                                                        +1134        /**
                                                                                                                                                                                                                                                        +1135         * Constructs a metadate template option from a JSON string.
                                                                                                                                                                                                                                                        +1136         *
                                                                                                                                                                                                                                                        +1137         * @param json the json encoded metadata template option.
                                                                                                                                                                                                                                                        +1138         */
                                                                                                                                                                                                                                                        +1139        public Option(String json) {
                                                                                                                                                                                                                                                        +1140            super(json);
                                                                                                                                                                                                                                                        +1141        }
                                                                                                                                                                                                                                                        +1142
                                                                                                                                                                                                                                                        +1143        /**
                                                                                                                                                                                                                                                        +1144         * Constructs a metadate template option from a JSON object.
                                                                                                                                                                                                                                                        +1145         *
                                                                                                                                                                                                                                                        +1146         * @param jsonObject the json encoded metadate template option.
                                                                                                                                                                                                                                                        +1147         */
                                                                                                                                                                                                                                                        +1148        Option(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +1149            super(jsonObject);
                                                                                                                                                                                                                                                        +1150        }
                                                                                                                                                                                                                                                        +1151
                                                                                                                                                                                                                                                        +1152        /**
                                                                                                                                                                                                                                                        +1153         * Gets the ID of the template field.
                                                                                                                                                                                                                                                        +1154         *
                                                                                                                                                                                                                                                        +1155         * @return the template field ID.
                                                                                                                                                                                                                                                        +1156         */
                                                                                                                                                                                                                                                        +1157        public String getID() {
                                                                                                                                                                                                                                                        +1158            return this.id;
                                                                                                                                                                                                                                                        +1159        }
                                                                                                                                                                                                                                                        +1160
                                                                                                                                                                                                                                                        +1161        /**
                                                                                                                                                                                                                                                        +1162         * Gets the key of the field.
                                                                                                                                                                                                                                                        +1163         *
                                                                                                                                                                                                                                                        +1164         * @return the key of the field.
                                                                                                                                                                                                                                                        +1165         */
                                                                                                                                                                                                                                                        +1166        public String getKey() {
                                                                                                                                                                                                                                                        +1167            return this.key;
                                                                                                                                                                                                                                                        +1168        }
                                                                                                                                                                                                                                                        +1169
                                                                                                                                                                                                                                                        +1170        /**
                                                                                                                                                                                                                                                        +1171         * Gets static configuration for the classification.
                                                                                                                                                                                                                                                        +1172         *
                                                                                                                                                                                                                                                        +1173         * @return static configuration for the classification.
                                                                                                                                                                                                                                                        +1174         */
                                                                                                                                                                                                                                                        +1175        public StaticConfig getStaticConfig() {
                                                                                                                                                                                                                                                        +1176            return this.staticConfig;
                                                                                                                                                                                                                                                        +1177        }
                                                                                                                                                                                                                                                        +1178
                                                                                                                                                                                                                                                        +1179        /**
                                                                                                                                                                                                                                                        +1180         * {@inheritDoc}
                                                                                                                                                                                                                                                        +1181         */
                                                                                                                                                                                                                                                        +1182        @Override
                                                                                                                                                                                                                                                        +1183        void parseJSONMember(JsonObject.Member member) {
                                                                                                                                                                                                                                                        +1184            JsonValue value = member.getValue();
                                                                                                                                                                                                                                                        +1185            String memberName = member.getName();
                                                                                                                                                                                                                                                        +1186            switch (memberName) {
                                                                                                                                                                                                                                                        +1187                case "id":
                                                                                                                                                                                                                                                        +1188                    this.id = value.asString();
                                                                                                                                                                                                                                                        +1189                    break;
                                                                                                                                                                                                                                                        +1190                case "key":
                                                                                                                                                                                                                                                        +1191                    this.key = value.asString();
                                                                                                                                                                                                                                                        +1192                    break;
                                                                                                                                                                                                                                                        +1193                case "staticConfig":
                                                                                                                                                                                                                                                        +1194                    this.staticConfig = new StaticConfig(value.asObject());
                                                                                                                                                                                                                                                        +1195                    break;
                                                                                                                                                                                                                                                        +1196                default:
                                                                                                                                                                                                                                                        +1197                    break;
                                                                                                                                                                                                                                                        +1198            }
                                                                                                                                                                                                                                                        +1199        }
                                                                                                                                                                                                                                                        +1200    }
                                                                                                                                                                                                                                                        +1201
                                                                                                                                                                                                                                                        +1202    /**
                                                                                                                                                                                                                                                        +1203     * Posssible operations that can be performed in a Metadata template.
                                                                                                                                                                                                                                                        +1204     * <ul>
                                                                                                                                                                                                                                                        +1205     *     <li>Add an enum option</li>
                                                                                                                                                                                                                                                        +1206     *     <li>Edit an enum option</li>
                                                                                                                                                                                                                                                        +1207     *     <li>Remove an enum option</li>
                                                                                                                                                                                                                                                        +1208     *     <li>Add a field</li>
                                                                                                                                                                                                                                                        +1209     *     <li>Edit a field</li>
                                                                                                                                                                                                                                                        +1210     *     <li>Remove a field</li>
                                                                                                                                                                                                                                                        +1211     *     <li>Edit template</li>
                                                                                                                                                                                                                                                        +1212     *     <li>Reorder the enum option</li>
                                                                                                                                                                                                                                                        +1213     *     <li>Reorder the field list</li>
                                                                                                                                                                                                                                                        +1214     * </ul>
                                                                                                                                                                                                                                                        +1215     */
                                                                                                                                                                                                                                                        +1216    public static class FieldOperation extends BoxJSONObject {
                                                                                                                                                                                                                                                        +1217
                                                                                                                                                                                                                                                        +1218        private Operation op;
                                                                                                                                                                                                                                                        +1219        private Field data;
                                                                                                                                                                                                                                                        +1220        private String fieldKey;
                                                                                                                                                                                                                                                        +1221        private List<String> fieldKeys;
                                                                                                                                                                                                                                                        +1222        private List<String> enumOptionKeys;
                                                                                                                                                                                                                                                        +1223        private String enumOptionKey;
                                                                                                                                                                                                                                                        +1224        private String multiSelectOptionKey;
                                                                                                                                                                                                                                                        +1225        private List<String> multiSelectOptionKeys;
                                                                                                                                                                                                                                                        +1226
                                                                                                                                                                                                                                                        +1227        /**
                                                                                                                                                                                                                                                        +1228         * Constructs an empty FieldOperation.
                                                                                                                                                                                                                                                        +1229         */
                                                                                                                                                                                                                                                        +1230        public FieldOperation() {
                                                                                                                                                                                                                                                        +1231            super();
                                                                                                                                                                                                                                                        +1232        }
                                                                                                                                                                                                                                                        +1233
                                                                                                                                                                                                                                                        +1234        /**
                                                                                                                                                                                                                                                        +1235         * Constructs a Field operation from a JSON string.
                                                                                                                                                                                                                                                        +1236         *
                                                                                                                                                                                                                                                        +1237         * @param json the json encoded metadate template field.
                                                                                                                                                                                                                                                        +1238         */
                                                                                                                                                                                                                                                        +1239        public FieldOperation(String json) {
                                                                                                                                                                                                                                                        +1240            super(json);
                                                                                                                                                                                                                                                        +1241        }
                                                                                                                                                                                                                                                        +1242
                                                                                                                                                                                                                                                        +1243        /**
                                                                                                                                                                                                                                                        +1244         * Constructs a Field operation from a JSON object.
                                                                                                                                                                                                                                                        +1245         *
                                                                                                                                                                                                                                                        +1246         * @param jsonObject the json encoded metadate template field.
                                                                                                                                                                                                                                                        +1247         */
                                                                                                                                                                                                                                                        +1248        FieldOperation(JsonObject jsonObject) {
                                                                                                                                                                                                                                                        +1249            super(jsonObject);
                                                                                                                                                                                                                                                        +1250        }
                                                                                                                                                                                                                                                        +1251
                                                                                                                                                                                                                                                        +1252        /**
                                                                                                                                                                                                                                                        +1253         * Gets the operation.
                                                                                                                                                                                                                                                        +1254         *
                                                                                                                                                                                                                                                        +1255         * @return the operation
                                                                                                                                                                                                                                                        +1256         */
                                                                                                                                                                                                                                                        +1257        public Operation getOp() {
                                                                                                                                                                                                                                                        +1258            return this.op;
                                                                                                                                                                                                                                                        +1259        }
                                                                                                                                                                                                                                                        +1260
                                                                                                                                                                                                                                                        +1261        /**
                                                                                                                                                                                                                                                        +1262         * Sets the operation.
                                                                                                                                                                                                                                                        +1263         *
                                                                                                                                                                                                                                                        +1264         * @param op the operation
                                                                                                                                                                                                                                                        +1265         */
                                                                                                                                                                                                                                                        +1266        public void setOp(Operation op) {
                                                                                                                                                                                                                                                        +1267            this.op = op;
                                                                                                                                                                                                                                                        +1268        }
                                                                                                                                                                                                                                                        +1269
                                                                                                                                                                                                                                                        +1270        /**
                                                                                                                                                                                                                                                        +1271         * Gets the data associated with the operation.
                                                                                                                                                                                                                                                        +1272         *
                                                                                                                                                                                                                                                        +1273         * @return the field object representing the data
                                                                                                                                                                                                                                                        +1274         */
                                                                                                                                                                                                                                                        +1275        public Field getData() {
                                                                                                                                                                                                                                                        +1276            return this.data;
                                                                                                                                                                                                                                                        +1277        }
                                                                                                                                                                                                                                                        +1278
                                                                                                                                                                                                                                                        +1279        /**
                                                                                                                                                                                                                                                        +1280         * Sets the data.
                                                                                                                                                                                                                                                        +1281         *
                                                                                                                                                                                                                                                        +1282         * @param data the Field object representing the data
                                                                                                                                                                                                                                                        +1283         */
                                                                                                                                                                                                                                                        +1284        public void setData(Field data) {
                                                                                                                                                                                                                                                        +1285            this.data = data;
                                                                                                                                                                                                                                                        +1286        }
                                                                                                                                                                                                                                                        +1287
                                                                                                                                                                                                                                                        +1288        /**
                                                                                                                                                                                                                                                        +1289         * Gets the field key.
                                                                                                                                                                                                                                                        +1290         *
                                                                                                                                                                                                                                                        +1291         * @return the field key
                                                                                                                                                                                                                                                        +1292         */
                                                                                                                                                                                                                                                        +1293        public String getFieldKey() {
                                                                                                                                                                                                                                                        +1294            return this.fieldKey;
                                                                                                                                                                                                                                                        +1295        }
                                                                                                                                                                                                                                                        +1296
                                                                                                                                                                                                                                                        +1297        /**
                                                                                                                                                                                                                                                        +1298         * Sets the field key.
                                                                                                                                                                                                                                                        +1299         *
                                                                                                                                                                                                                                                        +1300         * @param fieldKey the key of the field
                                                                                                                                                                                                                                                        +1301         */
                                                                                                                                                                                                                                                        +1302        public void setFieldKey(String fieldKey) {
                                                                                                                                                                                                                                                        +1303            this.fieldKey = fieldKey;
                                                                                                                                                                                                                                                        +1304        }
                                                                                                                                                                                                                                                        +1305
                                                                                                                                                                                                                                                        +1306        /**
                                                                                                                                                                                                                                                        +1307         * Gets the list of field keys.
                                                                                                                                                                                                                                                        +1308         *
                                                                                                                                                                                                                                                        +1309         * @return the list of Strings
                                                                                                                                                                                                                                                        +1310         */
                                                                                                                                                                                                                                                        +1311        public List<String> getFieldKeys() {
                                                                                                                                                                                                                                                        +1312            return this.fieldKeys;
                                                                                                                                                                                                                                                        +1313        }
                                                                                                                                                                                                                                                        +1314
                                                                                                                                                                                                                                                        +1315        /**
                                                                                                                                                                                                                                                        +1316         * Sets the list of the field keys.
                                                                                                                                                                                                                                                        +1317         *
                                                                                                                                                                                                                                                        +1318         * @param fieldKeys the list of strings
                                                                                                                                                                                                                                                        +1319         */
                                                                                                                                                                                                                                                        +1320        public void setFieldKeys(List<String> fieldKeys) {
                                                                                                                                                                                                                                                        +1321            this.fieldKeys = fieldKeys;
                                                                                                                                                                                                                                                        +1322        }
                                                                                                                                                                                                                                                        +1323
                                                                                                                                                                                                                                                        +1324        /**
                                                                                                                                                                                                                                                        +1325         * Gets the list of keys of the Enum options.
                                                                                                                                                                                                                                                        +1326         *
                                                                                                                                                                                                                                                        +1327         * @return the list of Strings
                                                                                                                                                                                                                                                        +1328         */
                                                                                                                                                                                                                                                        +1329        public List<String> getEnumOptionKeys() {
                                                                                                                                                                                                                                                        +1330            return this.enumOptionKeys;
                                                                                                                                                                                                                                                        +1331        }
                                                                                                                                                                                                                                                        +1332
                                                                                                                                                                                                                                                        +1333        /**
                                                                                                                                                                                                                                                        +1334         * Sets the list of the enum option keys.
                                                                                                                                                                                                                                                        +1335         *
                                                                                                                                                                                                                                                        +1336         * @param enumOptionKeys the list of Strings
                                                                                                                                                                                                                                                        +1337         */
                                                                                                                                                                                                                                                        +1338        public void setEnumOptionKeys(List<String> enumOptionKeys) {
                                                                                                                                                                                                                                                        +1339            this.enumOptionKeys = enumOptionKeys;
                                                                                                                                                                                                                                                        +1340        }
                                                                                                                                                                                                                                                        +1341
                                                                                                                                                                                                                                                        +1342        /**
                                                                                                                                                                                                                                                        +1343         * Gets the enum option key.
                                                                                                                                                                                                                                                        +1344         *
                                                                                                                                                                                                                                                        +1345         * @return the enum option key
                                                                                                                                                                                                                                                        +1346         */
                                                                                                                                                                                                                                                        +1347        public String getEnumOptionKey() {
                                                                                                                                                                                                                                                        +1348            return this.enumOptionKey;
                                                                                                                                                                                                                                                        +1349        }
                                                                                                                                                                                                                                                        +1350
                                                                                                                                                                                                                                                        +1351        /**
                                                                                                                                                                                                                                                        +1352         * Sets the enum option key.
                                                                                                                                                                                                                                                        +1353         *
                                                                                                                                                                                                                                                        +1354         * @param enumOptionKey the enum option key
                                                                                                                                                                                                                                                        +1355         */
                                                                                                                                                                                                                                                        +1356        public void setEnumOptionKey(String enumOptionKey) {
                                                                                                                                                                                                                                                        +1357            this.enumOptionKey = enumOptionKey;
                                                                                                                                                                                                                                                        +1358        }
                                                                                                                                                                                                                                                        +1359
                                                                                                                                                                                                                                                        +1360        /**
                                                                                                                                                                                                                                                        +1361         * Gets the multi-select option key.
                                                                                                                                                                                                                                                        +1362         *
                                                                                                                                                                                                                                                        +1363         * @return the key.
                                                                                                                                                                                                                                                        +1364         */
                                                                                                                                                                                                                                                        +1365        public String getMultiSelectOptionKey() {
                                                                                                                                                                                                                                                        +1366            return this.multiSelectOptionKey;
                                                                                                                                                                                                                                                        +1367        }
                                                                                                                                                                                                                                                        +1368
                                                                                                                                                                                                                                                        +1369        /**
                                                                                                                                                                                                                                                        +1370         * Sets the multi-select option key.
                                                                                                                                                                                                                                                        +1371         *
                                                                                                                                                                                                                                                        +1372         * @param key the key.
                                                                                                                                                                                                                                                        +1373         */
                                                                                                                                                                                                                                                        +1374        public void setMultiSelectOptionKey(String key) {
                                                                                                                                                                                                                                                        +1375            this.multiSelectOptionKey = key;
                                                                                                                                                                                                                                                        +1376        }
                                                                                                                                                                                                                                                        +1377
                                                                                                                                                                                                                                                        +1378        /**
                                                                                                                                                                                                                                                        +1379         * Gets the list of multiselect option keys.
                                                                                                                                                                                                                                                        +1380         *
                                                                                                                                                                                                                                                        +1381         * @return the list of keys.
                                                                                                                                                                                                                                                        +1382         */
                                                                                                                                                                                                                                                        +1383        public List<String> getMultiSelectOptionKeys() {
                                                                                                                                                                                                                                                        +1384            return this.multiSelectOptionKeys;
                                                                                                                                                                                                                                                        +1385        }
                                                                                                                                                                                                                                                        +1386
                                                                                                                                                                                                                                                        +1387        /**
                                                                                                                                                                                                                                                        +1388         * Sets the multi-select option keys.
                                                                                                                                                                                                                                                        +1389         *
                                                                                                                                                                                                                                                        +1390         * @param keys the list of keys.
                                                                                                                                                                                                                                                        +1391         */
                                                                                                                                                                                                                                                        +1392        public void setMultiSelectOptionKeys(List<String> keys) {
                                                                                                                                                                                                                                                        +1393            this.multiSelectOptionKeys = keys;
                                                                                                                                                                                                                                                        +1394        }
                                                                                                                                                                                                                                                        +1395
                                                                                                                                                                                                                                                        +1396        @Override
                                                                                                                                                                                                                                                        +1397        public void clearPendingChanges() {
                                                                                                                                                                                                                                                        +1398            super.clearPendingChanges();
                                                                                                                                                                                                                                                        +1399        }
                                                                                                                                                                                                                                                        +1400
                                                                                                                                                                                                                                                        +1401        /**
                                                                                                                                                                                                                                                        +1402         * {@inheritDoc}
                                                                                                                                                                                                                                                        +1403         */
                                                                                                                                                                                                                                                        +1404        @Override
                                                                                                                                                                                                                                                        +1405        void parseJSONMember(JsonObject.Member member) {
                                                                                                                                                                                                                                                        +1406            JsonValue value = member.getValue();
                                                                                                                                                                                                                                                        +1407            String memberName = member.getName();
                                                                                                                                                                                                                                                        +1408            switch (memberName) {
                                                                                                                                                                                                                                                        +1409                case "op":
                                                                                                                                                                                                                                                        +1410                    this.op = Operation.valueOf(value.asString());
                                                                                                                                                                                                                                                        +1411                    break;
                                                                                                                                                                                                                                                        +1412                case "data":
                                                                                                                                                                                                                                                        +1413                    this.data = new Field(value.asObject());
                                                                                                                                                                                                                                                        +1414                    break;
                                                                                                                                                                                                                                                        +1415                case "fieldKey":
                                                                                                                                                                                                                                                        +1416                    this.fieldKey = value.asString();
                                                                                                                                                                                                                                                        +1417                    break;
                                                                                                                                                                                                                                                        +1418                case "fieldKeys":
                                                                                                                                                                                                                                                        +1419                    if (this.fieldKeys == null) {
                                                                                                                                                                                                                                                        +1420                        this.fieldKeys = new ArrayList<>();
                                                                                                                                                                                                                                                        +1421                    } else {
                                                                                                                                                                                                                                                        +1422                        this.fieldKeys.clear();
                                                                                                                                                                                                                                                        +1423                    }
                                                                                                                                                                                                                                                        +1424                    for (JsonValue jsonValue : value.asArray()) {
                                                                                                                                                                                                                                                        +1425                        this.fieldKeys.add(jsonValue.asString());
                                                                                                                                                                                                                                                        +1426                    }
                                                                                                                                                                                                                                                        +1427                    break;
                                                                                                                                                                                                                                                        +1428                case "enumOptionKeys":
                                                                                                                                                                                                                                                        +1429                    if (this.enumOptionKeys == null) {
                                                                                                                                                                                                                                                        +1430                        this.enumOptionKeys = new ArrayList<>();
                                                                                                                                                                                                                                                        +1431                    } else {
                                                                                                                                                                                                                                                        +1432                        this.enumOptionKeys.clear();
                                                                                                                                                                                                                                                        +1433                    }
                                                                                                                                                                                                                                                        +1434
                                                                                                                                                                                                                                                        +1435                    for (JsonValue jsonValue : value.asArray()) {
                                                                                                                                                                                                                                                        +1436                        this.enumOptionKeys.add(jsonValue.asString());
                                                                                                                                                                                                                                                        +1437                    }
                                                                                                                                                                                                                                                        +1438                    break;
                                                                                                                                                                                                                                                        +1439                case "enumOptionKey":
                                                                                                                                                                                                                                                        +1440                    this.enumOptionKey = value.asString();
                                                                                                                                                                                                                                                        +1441                    break;
                                                                                                                                                                                                                                                        +1442                case "multiSelectOptionKey":
                                                                                                                                                                                                                                                        +1443                    this.multiSelectOptionKey = value.asString();
                                                                                                                                                                                                                                                        +1444                    break;
                                                                                                                                                                                                                                                        +1445                case "multiSelectOptionKeys":
                                                                                                                                                                                                                                                        +1446                    this.multiSelectOptionKeys = new ArrayList<>();
                                                                                                                                                                                                                                                        +1447                    for (JsonValue key : value.asArray()) {
                                                                                                                                                                                                                                                        +1448                        this.multiSelectOptionKeys.add(key.asString());
                                                                                                                                                                                                                                                        +1449                    }
                                                                                                                                                                                                                                                        +1450                    break;
                                                                                                                                                                                                                                                        +1451                default:
                                                                                                                                                                                                                                                        +1452                    break;
                                                                                                                                                                                                                                                        +1453            }
                                                                                                                                                                                                                                                        +1454        }
                                                                                                                                                                                                                                                        +1455    }
                                                                                                                                                                                                                                                        +1456}
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + diff --git a/javadoc/src-html/com/box/sdk/MetadataTemplate.html b/javadoc/src-html/com/box/sdk/MetadataTemplate.html index 76e3722aa..494a461b2 100644 --- a/javadoc/src-html/com/box/sdk/MetadataTemplate.html +++ b/javadoc/src-html/com/box/sdk/MetadataTemplate.html @@ -402,944 +402,1066 @@ 394 fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);395 }396 -397 jsonObject.add("data", fieldObj); -398 } -399 -400 List<String> fieldKeys = fieldOperation.getFieldKeys(); -401 if (fieldKeys != null) { -402 jsonObject.add("fieldKeys", getJsonArray(fieldKeys)); -403 } -404 -405 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); -406 if (enumOptionKeys != null) { -407 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys)); +397 StaticConfig staticConfig = field.getStaticConfig(); +398 if (staticConfig != null) { +399 JsonObject staticConfigObj = new JsonObject(); +400 JsonObject classification = staticConfig.getClassification(); +401 if (classification != null) { +402 staticConfigObj.add("classification", classification); +403 } +404 fieldObj.add("staticConfig", staticConfigObj); +405 } +406 +407 jsonObject.add("data", fieldObj);408 }409 -410 String enumOptionKey = fieldOperation.getEnumOptionKey(); -411 if (enumOptionKey != null) { -412 jsonObject.add("enumOptionKey", enumOptionKey); +410 List<String> fieldKeys = fieldOperation.getFieldKeys(); +411 if (fieldKeys != null) { +412 jsonObject.add("fieldKeys", getJsonArray(fieldKeys));413 }414 -415 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); -416 if (multiSelectOptionKey != null) { -417 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +415 List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys(); +416 if (enumOptionKeys != null) { +417 jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));418 }419 -420 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); -421 if (multiSelectOptionKeys != null) { -422 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +420 String enumOptionKey = fieldOperation.getEnumOptionKey(); +421 if (enumOptionKey != null) { +422 jsonObject.add("enumOptionKey", enumOptionKey);423 }424 -425 return jsonObject; -426 } -427 -428 /** -429 * Gets the Json Array representation of the given list of strings. -430 * -431 * @param keys List of strings -432 * @return the JsonArray represents the list of keys -433 */ -434 private static JsonArray getJsonArray(List<String> keys) { -435 JsonArray array = new JsonArray(); -436 for (String key : keys) { -437 array.add(key); -438 } -439 -440 return array; -441 } -442 -443 /** -444 * Gets the metadata template of properties. -445 * -446 * @param api the API connection to be used. -447 * @return the metadata template returned from the server. -448 */ -449 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { -450 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +425 String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey(); +426 if (multiSelectOptionKey != null) { +427 jsonObject.add("multiSelectOptionKey", multiSelectOptionKey); +428 } +429 +430 List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys(); +431 if (multiSelectOptionKeys != null) { +432 jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys)); +433 } +434 +435 return jsonObject; +436 } +437 +438 /** +439 * Gets the Json Array representation of the given list of strings. +440 * +441 * @param keys List of strings +442 * @return the JsonArray represents the list of keys +443 */ +444 private static JsonArray getJsonArray(List<String> keys) { +445 JsonArray array = new JsonArray(); +446 for (String key : keys) { +447 array.add(key); +448 } +449 +450 return array;451 }452453 /** -454 * Gets the metadata template of specified template type. +454 * Gets the metadata template of properties.455 * -456 * @param api the API connection to be used. -457 * @param templateName the metadata template type name. -458 * @return the metadata template returned from the server. -459 */ -460 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { -461 String scope = scopeBasedOnType(templateName); -462 return getMetadataTemplate(api, templateName, scope); -463 } -464 -465 /** -466 * Gets the metadata template of specified template type. -467 * -468 * @param api the API connection to be used. -469 * @param templateName the metadata template type name. -470 * @param scope the metadata template scope (global or enterprise). -471 * @param fields the fields to retrieve. -472 * @return the metadata template returned from the server. -473 */ -474 public static MetadataTemplate getMetadataTemplate( -475 BoxAPIConnection api, String templateName, String scope, String... fields) { -476 QueryStringBuilder builder = new QueryStringBuilder(); -477 if (fields.length > 0) { -478 builder.appendParam("fields", fields); -479 } -480 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( -481 api.getBaseURL(), builder.toString(), scope, templateName); -482 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -483 try (BoxJSONResponse response = request.send()) { -484 return new MetadataTemplate(response.getJSON()); -485 } -486 } -487 -488 /** -489 * Geta the specified metadata template by its ID. -490 * -491 * @param api the API connection to be used. -492 * @param templateID the ID of the template to get. -493 * @return the metadata template object. -494 */ -495 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { -496 -497 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); -498 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); -499 try (BoxJSONResponse response = request.send()) { -500 return new MetadataTemplate(response.getJSON()); -501 } -502 } -503 -504 /** -505 * Returns all metadata templates within a user's enterprise. -506 * -507 * @param api the API connection to be used. -508 * @param fields the fields to retrieve. -509 * @return the metadata template returned from the server. -510 */ -511 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { -512 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); -513 } -514 -515 /** -516 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -517 * -518 * @param scope the scope of the metadata templates. -519 * @param api the API connection to be used. -520 * @param fields the fields to retrieve. -521 * @return the metadata template returned from the server. -522 */ -523 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -524 String scope, BoxAPIConnection api, String... fields -525 ) { -526 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); -527 } -528 -529 /** -530 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. -531 * -532 * @param scope the scope of the metadata templates. -533 * @param limit maximum number of entries per response. -534 * @param api the API connection to be used. -535 * @param fields the fields to retrieve. -536 * @return the metadata template returned from the server. -537 */ -538 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( -539 String scope, int limit, BoxAPIConnection api, String... fields) { -540 QueryStringBuilder builder = new QueryStringBuilder(); -541 if (fields.length > 0) { -542 builder.appendParam("fields", fields); -543 } -544 return new BoxResourceIterable<MetadataTemplate>( -545 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( -546 api.getBaseURL(), builder.toString(), scope), limit) { -547 -548 @Override -549 protected MetadataTemplate factory(JsonObject jsonObject) { -550 return new MetadataTemplate(jsonObject); -551 } -552 }; -553 } -554 -555 /** -556 * Determines the metadata scope based on type. -557 * -558 * @param typeName type of the metadata. -559 * @return scope of the metadata. -560 */ -561 private static String scopeBasedOnType(String typeName) { -562 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +456 * @param api the API connection to be used. +457 * @return the metadata template returned from the server. +458 */ +459 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api) { +460 return getMetadataTemplate(api, DEFAULT_METADATA_TYPE); +461 } +462 +463 /** +464 * Gets the metadata template of specified template type. +465 * +466 * @param api the API connection to be used. +467 * @param templateName the metadata template type name. +468 * @return the metadata template returned from the server. +469 */ +470 public static MetadataTemplate getMetadataTemplate(BoxAPIConnection api, String templateName) { +471 String scope = scopeBasedOnType(templateName); +472 return getMetadataTemplate(api, templateName, scope); +473 } +474 +475 /** +476 * Gets the metadata template of specified template type. +477 * +478 * @param api the API connection to be used. +479 * @param templateName the metadata template type name. +480 * @param scope the metadata template scope (global or enterprise). +481 * @param fields the fields to retrieve. +482 * @return the metadata template returned from the server. +483 */ +484 public static MetadataTemplate getMetadataTemplate( +485 BoxAPIConnection api, String templateName, String scope, String... fields) { +486 QueryStringBuilder builder = new QueryStringBuilder(); +487 if (fields.length > 0) { +488 builder.appendParam("fields", fields); +489 } +490 URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlphaWithQuery( +491 api.getBaseURL(), builder.toString(), scope, templateName); +492 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +493 try (BoxJSONResponse response = request.send()) { +494 return new MetadataTemplate(response.getJSON()); +495 } +496 } +497 +498 /** +499 * Geta the specified metadata template by its ID. +500 * +501 * @param api the API connection to be used. +502 * @param templateID the ID of the template to get. +503 * @return the metadata template object. +504 */ +505 public static MetadataTemplate getMetadataTemplateByID(BoxAPIConnection api, String templateID) { +506 +507 URL url = METADATA_TEMPLATE_BY_ID_URL_TEMPLATE.buildAlpha(api.getBaseURL(), templateID); +508 BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); +509 try (BoxJSONResponse response = request.send()) { +510 return new MetadataTemplate(response.getJSON()); +511 } +512 } +513 +514 /** +515 * Returns all metadata templates within a user's enterprise. +516 * +517 * @param api the API connection to be used. +518 * @param fields the fields to retrieve. +519 * @return the metadata template returned from the server. +520 */ +521 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates(BoxAPIConnection api, String... fields) { +522 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, api, fields); +523 } +524 +525 /** +526 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +527 * +528 * @param scope the scope of the metadata templates. +529 * @param api the API connection to be used. +530 * @param fields the fields to retrieve. +531 * @return the metadata template returned from the server. +532 */ +533 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +534 String scope, BoxAPIConnection api, String... fields +535 ) { +536 return getEnterpriseMetadataTemplates(ENTERPRISE_METADATA_SCOPE, DEFAULT_ENTRIES_LIMIT, api, fields); +537 } +538 +539 /** +540 * Returns all metadata templates within a user's scope. Currently only the enterprise scope is supported. +541 * +542 * @param scope the scope of the metadata templates. +543 * @param limit maximum number of entries per response. +544 * @param api the API connection to be used. +545 * @param fields the fields to retrieve. +546 * @return the metadata template returned from the server. +547 */ +548 public static Iterable<MetadataTemplate> getEnterpriseMetadataTemplates( +549 String scope, int limit, BoxAPIConnection api, String... fields) { +550 QueryStringBuilder builder = new QueryStringBuilder(); +551 if (fields.length > 0) { +552 builder.appendParam("fields", fields); +553 } +554 return new BoxResourceIterable<MetadataTemplate>( +555 api, ENTERPRISE_METADATA_URL_TEMPLATE.buildAlphaWithQuery( +556 api.getBaseURL(), builder.toString(), scope), limit) { +557 +558 @Override +559 protected MetadataTemplate factory(JsonObject jsonObject) { +560 return new MetadataTemplate(jsonObject); +561 } +562 };563 }564565 /** -566 * Gets the ID of the template. +566 * Determines the metadata scope based on type.567 * -568 * @return the template ID. -569 */ -570 public String getID() { -571 return this.id; -572 } -573 -574 /** -575 * Gets the unique template key to identify the metadata template. -576 * -577 * @return the unique template key to identify the metadata template. -578 */ -579 public String getTemplateKey() { -580 return this.templateKey; -581 } -582 -583 /** -584 * Gets the metadata template scope. -585 * -586 * @return the metadata template scope. -587 */ -588 public String getScope() { -589 return this.scope; -590 } -591 -592 /** -593 * Gets the displayed metadata template name. -594 * -595 * @return the displayed metadata template name. -596 */ -597 public String getDisplayName() { -598 return this.displayName; -599 } -600 -601 /** -602 * Gets is the metadata template hidden. -603 * -604 * @return is the metadata template hidden. -605 */ -606 public Boolean getIsHidden() { -607 return this.isHidden; -608 } -609 -610 /** -611 * Gets the iterable with all fields the metadata template contains. -612 * -613 * @return the iterable with all fields the metadata template contains. -614 */ -615 public List<Field> getFields() { -616 return this.fields; -617 } -618 -619 /** -620 * Gets whether the copy operation should copy the metadata along with the item. -621 * -622 * @return whether the copy operation should copy the metadata along with the item. -623 */ -624 public Boolean getCopyInstanceOnItemCopy() { -625 return this.copyInstanceOnItemCopy; -626 } -627 -628 /** -629 * {@inheritDoc} -630 */ -631 @Override -632 void parseJSONMember(JsonObject.Member member) { -633 JsonValue value = member.getValue(); -634 String memberName = member.getName(); -635 switch (memberName) { -636 case "templateKey": -637 this.templateKey = value.asString(); -638 break; -639 case "scope": -640 this.scope = value.asString(); -641 break; -642 case "displayName": -643 this.displayName = value.asString(); -644 break; -645 case "hidden": -646 this.isHidden = value.asBoolean(); -647 break; -648 case "fields": -649 this.fields = new ArrayList<>(); -650 for (JsonValue field : value.asArray()) { -651 this.fields.add(new Field(field.asObject())); -652 } -653 break; -654 case "id": -655 this.id = value.asString(); -656 break; -657 case "copyInstanceOnItemCopy": -658 this.copyInstanceOnItemCopy = value.asBoolean(); -659 break; -660 default: -661 break; -662 } -663 } -664 -665 /** -666 * Possible template operations. -667 */ -668 public enum Operation { -669 -670 /** -671 * Adds an enum option at the end of the enum option list for the specified field. -672 */ -673 addEnumOption, +568 * @param typeName type of the metadata. +569 * @return scope of the metadata. +570 */ +571 private static String scopeBasedOnType(String typeName) { +572 return typeName.equals(DEFAULT_METADATA_TYPE) ? GLOBAL_METADATA_SCOPE : ENTERPRISE_METADATA_SCOPE; +573 } +574 +575 /** +576 * Gets the ID of the template. +577 * +578 * @return the template ID. +579 */ +580 public String getID() { +581 return this.id; +582 } +583 +584 /** +585 * Gets the unique template key to identify the metadata template. +586 * +587 * @return the unique template key to identify the metadata template. +588 */ +589 public String getTemplateKey() { +590 return this.templateKey; +591 } +592 +593 /** +594 * Gets the metadata template scope. +595 * +596 * @return the metadata template scope. +597 */ +598 public String getScope() { +599 return this.scope; +600 } +601 +602 /** +603 * Gets the displayed metadata template name. +604 * +605 * @return the displayed metadata template name. +606 */ +607 public String getDisplayName() { +608 return this.displayName; +609 } +610 +611 /** +612 * Gets is the metadata template hidden. +613 * +614 * @return is the metadata template hidden. +615 */ +616 public Boolean getIsHidden() { +617 return this.isHidden; +618 } +619 +620 /** +621 * Gets the iterable with all fields the metadata template contains. +622 * +623 * @return the iterable with all fields the metadata template contains. +624 */ +625 public List<Field> getFields() { +626 return this.fields; +627 } +628 +629 /** +630 * Gets whether the copy operation should copy the metadata along with the item. +631 * +632 * @return whether the copy operation should copy the metadata along with the item. +633 */ +634 public Boolean getCopyInstanceOnItemCopy() { +635 return this.copyInstanceOnItemCopy; +636 } +637 +638 /** +639 * {@inheritDoc} +640 */ +641 @Override +642 void parseJSONMember(JsonObject.Member member) { +643 JsonValue value = member.getValue(); +644 String memberName = member.getName(); +645 switch (memberName) { +646 case "templateKey": +647 this.templateKey = value.asString(); +648 break; +649 case "scope": +650 this.scope = value.asString(); +651 break; +652 case "displayName": +653 this.displayName = value.asString(); +654 break; +655 case "hidden": +656 this.isHidden = value.asBoolean(); +657 break; +658 case "fields": +659 this.fields = new ArrayList<>(); +660 for (JsonValue field : value.asArray()) { +661 this.fields.add(new Field(field.asObject())); +662 } +663 break; +664 case "id": +665 this.id = value.asString(); +666 break; +667 case "copyInstanceOnItemCopy": +668 this.copyInstanceOnItemCopy = value.asBoolean(); +669 break; +670 default: +671 break; +672 } +673 }674 -675 /** -676 * Edits the enum option. -677 */ -678 editEnumOption, +675 /** +676 * Possible template operations. +677 */ +678 public enum Operation {679680 /** -681 * Removes the specified enum option from the specified enum field. +681 * Adds an enum option at the end of the enum option list for the specified field.682 */ -683 removeEnumOption, +683 addEnumOption,684685 /** -686 * Adds a field at the end of the field list for the template. +686 * Edits the enum option.687 */ -688 addField, +688 editEnumOption,689690 /** -691 * Edits any number of the base properties of a field: displayName, hidden, description. +691 * Removes the specified enum option from the specified enum field.692 */ -693 editField, +693 removeEnumOption,694695 /** -696 * Removes the specified field from the template. +696 * Adds a field at the end of the field list for the template.697 */ -698 removeField, +698 addField,699700 /** -701 * Edits any number of the base properties of a template: displayName, hidden. +701 * Edits any number of the base properties of a field: displayName, hidden, description.702 */ -703 editTemplate, +703 editField,704705 /** -706 * Reorders the enum option list to match the requested enum option list. +706 * Removes the specified field from the template.707 */ -708 reorderEnumOptions, +708 removeField,709710 /** -711 * Reorders the field list to match the requested field list. +711 * Edits any number of the base properties of a template: displayName, hidden.712 */ -713 reorderFields, +713 editTemplate,714715 /** -716 * Adds a new option to a multiselect field. +716 * Reorders the enum option list to match the requested enum option list.717 */ -718 addMultiSelectOption, +718 reorderEnumOptions,719720 /** -721 * Edits an existing option in a multiselect field. +721 * Reorders the field list to match the requested field list.722 */ -723 editMultiSelectOption, +723 reorderFields,724725 /** -726 * Removes an option from a multiselect field. +726 * Adds a new option to a multiselect field.727 */ -728 removeMultiSelectOption, +728 addMultiSelectOption,729730 /** -731 * Changes the display order of options in a multiselect field. +731 * Edits an existing option in a multiselect field.732 */ -733 reorderMultiSelectOptions -734 } -735 -736 /** -737 * Class contains information about the metadata template field. -738 */ -739 public static class Field extends BoxJSONObject { -740 -741 /** -742 * @see #getID() -743 */ -744 private String id; +733 editMultiSelectOption, +734 +735 /** +736 * Removes an option from a multiselect field. +737 */ +738 removeMultiSelectOption, +739 +740 /** +741 * Changes the display order of options in a multiselect field. +742 */ +743 reorderMultiSelectOptions +744 }745 -746 /** -747 * @see #getType() -748 */ -749 private String type; -750 -751 /** -752 * @see #getKey() -753 */ -754 private String key; -755 -756 /** -757 * @see #getDisplayName() -758 */ -759 private String displayName; -760 -761 /** -762 * @see #getIsHidden() +746 /** +747 * Class contains information about the static configuration for the classification. +748 */ +749 public static class StaticConfig extends BoxJSONObject { +750 private JsonObject classification; +751 +752 /** +753 * Constructs an empty static configuration. +754 */ +755 public StaticConfig() { +756 super(); +757 } +758 +759 /** +760 * Constructs a static configuration from a JSON string. +761 * +762 * @param json the json encoded metadate template field.763 */ -764 private Boolean isHidden; -765 -766 /** -767 * @see #getDescription() -768 */ -769 private String description; -770 -771 /** -772 * @see #getOptionsObjects() -773 */ -774 private List<Option> options; +764 public StaticConfig(String json) { +765 super(json); +766 } +767 +768 /** Constructs a static configuration from a JSON object. +769 * +770 * @param jsonObject the json encoded metadate template field. +771 */ +772 StaticConfig(JsonObject jsonObject) { +773 super(jsonObject); +774 }775776 /** -777 * @see #getCopyInstanceOnItemCopy() -778 */ -779 private Boolean copyInstanceOnItemCopy; -780 -781 /** -782 * Constructs an empty metadata template. -783 */ -784 public Field() { -785 super(); -786 } -787 -788 /** -789 * Constructs a metadate template field from a JSON string. -790 * -791 * @param json the json encoded metadate template field. -792 */ -793 public Field(String json) { -794 super(json); -795 } -796 -797 /** -798 * Constructs a metadate template field from a JSON object. -799 * -800 * @param jsonObject the json encoded metadate template field. -801 */ -802 Field(JsonObject jsonObject) { -803 super(jsonObject); -804 } -805 -806 /** -807 * Gets the ID of the template field. -808 * -809 * @return the template field ID. -810 */ -811 public String getID() { -812 return this.id; -813 } -814 -815 /** -816 * Gets the data type of the field's value. -817 * -818 * @return the data type of the field's value. -819 */ -820 public String getType() { -821 return this.type; -822 } -823 -824 /** -825 * Sets the data type of the field's value. -826 * -827 * @param type the data type of the field's value. +777 * Gets the classification of the static configuration. +778 * +779 * @return the classification of the static configuration. +780 */ +781 public JsonObject getClassification() { +782 return this.classification; +783 } +784 +785 /** +786 * Sets the classification of the static configuration. +787 * +788 * @param classification the classification of the static configuration. +789 */ +790 public void setClassification(JsonObject classification) { +791 this.classification = classification; +792 } +793 +794 /** +795 * {@inheritDoc} +796 */ +797 @Override +798 void parseJSONMember(JsonObject.Member member) { +799 JsonValue value = member.getValue(); +800 String memberName = member.getName(); +801 switch (memberName) { +802 case "classification": +803 this.classification = value.asObject(); +804 break; +805 default: +806 break; +807 } +808 } +809 } +810 +811 /** +812 * Class contains information about the metadata template field. +813 */ +814 public static class Field extends BoxJSONObject { +815 +816 /** +817 * @see #getID() +818 */ +819 private String id; +820 +821 /** +822 * @see #getType() +823 */ +824 private String type; +825 +826 /** +827 * @see #getKey()828 */ -829 public void setType(String type) { -830 this.type = type; -831 } -832 -833 /** -834 * Gets the key of the field. -835 * -836 * @return the key of the field. -837 */ -838 public String getKey() { -839 return this.key; -840 } -841 -842 /** -843 * Sets the key of the field. -844 * -845 * @param key the key of the field. -846 */ -847 public void setKey(String key) { -848 this.key = key; -849 } +829 private String key; +830 +831 /** +832 * @see #getDisplayName() +833 */ +834 private String displayName; +835 +836 /** +837 * @see #getIsHidden() +838 */ +839 private Boolean isHidden; +840 +841 /** +842 * @see #getDescription() +843 */ +844 private String description; +845 +846 /** +847 * @see #getOptionsObjects() +848 */ +849 private List<Option> options;850851 /** -852 * Gets the display name of the field. -853 * -854 * @return the display name of the field. -855 */ -856 public String getDisplayName() { -857 return this.displayName; -858 } -859 -860 /** -861 * Sets the display name of the field. -862 * -863 * @param displayName the display name of the field. -864 */ -865 public void setDisplayName(String displayName) { -866 this.displayName = displayName; -867 } -868 -869 /** -870 * Gets is metadata template field hidden. -871 * -872 * @return is metadata template field hidden. -873 */ -874 public Boolean getIsHidden() { -875 return this.isHidden; -876 } -877 -878 /** -879 * Sets is metadata template field hidden. -880 * -881 * @param isHidden is metadata template field hidden? -882 */ -883 public void setIsHidden(boolean isHidden) { -884 this.isHidden = isHidden; -885 } -886 -887 /** -888 * Gets the description of the field. -889 * -890 * @return the description of the field. -891 */ -892 public String getDescription() { -893 return this.description; -894 } -895 -896 /** -897 * Sets the description of the field. -898 * -899 * @param description the description of the field. -900 */ -901 public void setDescription(String description) { -902 this.description = description; -903 } -904 -905 /** -906 * Gets list of possible options for enum type of the field. -907 * -908 * @return list of possible options for enum type of the field. -909 */ -910 public List<String> getOptions() { -911 if (this.options == null) { -912 return null; -913 } -914 List<String> optionsList = new ArrayList<>(); -915 for (Option option : this.options) { -916 optionsList.add(option.getKey()); -917 } -918 return optionsList; -919 } -920 -921 /** -922 * Sets list of possible options for enum type of the field. -923 * -924 * @param options list of possible options for enum type of the field. -925 */ -926 public void setOptions(List<String> options) { -927 if (options == null) { -928 this.options = null; -929 return; -930 } -931 List<Option> optionList = new ArrayList<>(); -932 for (String key : options) { -933 JsonObject optionObject = new JsonObject(); -934 optionObject.add("key", key); -935 Option newOption = new Option(optionObject); -936 optionList.add(newOption); -937 } -938 this.options = optionList; -939 } -940 -941 /** -942 * Gets list of possible options for options type of the field. -943 * -944 * @return list of possible options for option type of the field. -945 */ -946 public List<Option> getOptionsObjects() { -947 return this.options; -948 } -949 -950 /** -951 * Gets whether the copy operation should copy the metadata along with the item. -952 * -953 * @return whether the copy operation should copy the metadata along with the item. -954 */ -955 public Boolean getCopyInstanceOnItemCopy() { -956 return this.copyInstanceOnItemCopy; -957 } -958 -959 /** -960 * Sets whether the copy operation should copy the metadata along with the item. -961 * -962 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. -963 */ -964 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { -965 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; -966 } -967 -968 /** -969 * {@inheritDoc} -970 */ -971 @Override -972 void parseJSONMember(JsonObject.Member member) { -973 JsonValue value = member.getValue(); -974 String memberName = member.getName(); -975 switch (memberName) { -976 case "type": -977 this.type = value.asString(); -978 break; -979 case "key": -980 this.key = value.asString(); -981 break; -982 case "displayName": -983 this.displayName = value.asString(); -984 break; -985 case "hidden": -986 this.isHidden = value.asBoolean(); -987 break; -988 case "description": -989 this.description = value.asString(); -990 break; -991 case "options": -992 this.options = new ArrayList<>(); -993 for (JsonValue option : value.asArray()) { -994 this.options.add(new Option(option.asObject())); -995 } -996 break; -997 case "id": -998 this.id = value.asString(); -999 break; -1000 case "copyInstanceOnItemCopy": -1001 this.copyInstanceOnItemCopy = value.asBoolean(); -1002 break; -1003 default: -1004 break; -1005 } -1006 } -1007 } -1008 -1009 /** -1010 * Class contains information about the metadata template option. -1011 */ -1012 public static class Option extends BoxJSONObject { -1013 /** -1014 * @see #getID() -1015 */ -1016 private String id; -1017 /** -1018 * @see #getKey() -1019 */ -1020 private String key; -1021 -1022 /** -1023 * Constructs an empty metadata template. -1024 */ -1025 public Option() { -1026 super(); -1027 } -1028 -1029 /** -1030 * Constructs a metadate template option from a JSON string. -1031 * -1032 * @param json the json encoded metadata template option. -1033 */ -1034 public Option(String json) { -1035 super(json); -1036 } -1037 -1038 /** -1039 * Constructs a metadate template option from a JSON object. -1040 * -1041 * @param jsonObject the json encoded metadate template option. -1042 */ -1043 Option(JsonObject jsonObject) { -1044 super(jsonObject); -1045 } -1046 -1047 /** -1048 * Gets the ID of the template field. -1049 * -1050 * @return the template field ID. -1051 */ -1052 public String getID() { -1053 return this.id; -1054 } -1055 -1056 /** -1057 * Gets the key of the field. -1058 * -1059 * @return the key of the field. -1060 */ -1061 public String getKey() { -1062 return this.key; -1063 } -1064 -1065 /** -1066 * {@inheritDoc} -1067 */ -1068 @Override -1069 void parseJSONMember(JsonObject.Member member) { -1070 JsonValue value = member.getValue(); -1071 String memberName = member.getName(); -1072 if (memberName.equals("id")) { -1073 this.id = value.asString(); -1074 } else if (memberName.equals("key")) { -1075 this.key = value.asString(); -1076 } -1077 } -1078 } -1079 -1080 /** -1081 * Posssible operations that can be performed in a Metadata template. -1082 * <ul> -1083 * <li>Add an enum option</li> -1084 * <li>Edit an enum option</li> -1085 * <li>Remove an enum option</li> -1086 * <li>Add a field</li> -1087 * <li>Edit a field</li> -1088 * <li>Remove a field</li> -1089 * <li>Edit template</li> -1090 * <li>Reorder the enum option</li> -1091 * <li>Reorder the field list</li> -1092 * </ul> -1093 */ -1094 public static class FieldOperation extends BoxJSONObject { -1095 -1096 private Operation op; -1097 private Field data; -1098 private String fieldKey; -1099 private List<String> fieldKeys; -1100 private List<String> enumOptionKeys; -1101 private String enumOptionKey; -1102 private String multiSelectOptionKey; -1103 private List<String> multiSelectOptionKeys; -1104 -1105 /** -1106 * Constructs an empty FieldOperation. -1107 */ -1108 public FieldOperation() { -1109 super(); -1110 } -1111 -1112 /** -1113 * Constructs a Field operation from a JSON string. -1114 * -1115 * @param json the json encoded metadate template field. +852 * @see #getCopyInstanceOnItemCopy() +853 */ +854 private Boolean copyInstanceOnItemCopy; +855 +856 /** +857 * @see #getStaticConfig() +858 */ +859 private StaticConfig staticConfig; +860 +861 /** +862 * Constructs an empty metadata template. +863 */ +864 public Field() { +865 super(); +866 } +867 +868 /** +869 * Constructs a metadate template field from a JSON string. +870 * +871 * @param json the json encoded metadate template field. +872 */ +873 public Field(String json) { +874 super(json); +875 } +876 +877 /** +878 * Constructs a metadate template field from a JSON object. +879 * +880 * @param jsonObject the json encoded metadate template field. +881 */ +882 Field(JsonObject jsonObject) { +883 super(jsonObject); +884 } +885 +886 /** +887 * Gets the ID of the template field. +888 * +889 * @return the template field ID. +890 */ +891 public String getID() { +892 return this.id; +893 } +894 +895 /** +896 * Gets the data type of the field's value. +897 * +898 * @return the data type of the field's value. +899 */ +900 public String getType() { +901 return this.type; +902 } +903 +904 /** +905 * Sets the data type of the field's value. +906 * +907 * @param type the data type of the field's value. +908 */ +909 public void setType(String type) { +910 this.type = type; +911 } +912 +913 /** +914 * Gets the key of the field. +915 * +916 * @return the key of the field. +917 */ +918 public String getKey() { +919 return this.key; +920 } +921 +922 /** +923 * Sets the key of the field. +924 * +925 * @param key the key of the field. +926 */ +927 public void setKey(String key) { +928 this.key = key; +929 } +930 +931 /** +932 * Gets the display name of the field. +933 * +934 * @return the display name of the field. +935 */ +936 public String getDisplayName() { +937 return this.displayName; +938 } +939 +940 /** +941 * Sets the display name of the field. +942 * +943 * @param displayName the display name of the field. +944 */ +945 public void setDisplayName(String displayName) { +946 this.displayName = displayName; +947 } +948 +949 /** +950 * Gets is metadata template field hidden. +951 * +952 * @return is metadata template field hidden. +953 */ +954 public Boolean getIsHidden() { +955 return this.isHidden; +956 } +957 +958 /** +959 * Sets is metadata template field hidden. +960 * +961 * @param isHidden is metadata template field hidden? +962 */ +963 public void setIsHidden(boolean isHidden) { +964 this.isHidden = isHidden; +965 } +966 +967 /** +968 * Gets the description of the field. +969 * +970 * @return the description of the field. +971 */ +972 public String getDescription() { +973 return this.description; +974 } +975 +976 /** +977 * Sets the description of the field. +978 * +979 * @param description the description of the field. +980 */ +981 public void setDescription(String description) { +982 this.description = description; +983 } +984 +985 /** +986 * Gets list of possible options for enum type of the field. +987 * +988 * @return list of possible options for enum type of the field. +989 */ +990 public List<String> getOptions() { +991 if (this.options == null) { +992 return null; +993 } +994 List<String> optionsList = new ArrayList<>(); +995 for (Option option : this.options) { +996 optionsList.add(option.getKey()); +997 } +998 return optionsList; +999 } +1000 +1001 /** +1002 * Sets list of possible options for enum type of the field. +1003 * +1004 * @param options list of possible options for enum type of the field. +1005 */ +1006 public void setOptions(List<String> options) { +1007 if (options == null) { +1008 this.options = null; +1009 return; +1010 } +1011 List<Option> optionList = new ArrayList<>(); +1012 for (String key : options) { +1013 JsonObject optionObject = new JsonObject(); +1014 optionObject.add("key", key); +1015 Option newOption = new Option(optionObject); +1016 optionList.add(newOption); +1017 } +1018 this.options = optionList; +1019 } +1020 +1021 /** +1022 * Gets list of possible options for options type of the field. +1023 * +1024 * @return list of possible options for option type of the field. +1025 */ +1026 public List<Option> getOptionsObjects() { +1027 return this.options; +1028 } +1029 +1030 /** +1031 * Gets whether the copy operation should copy the metadata along with the item. +1032 * +1033 * @return whether the copy operation should copy the metadata along with the item. +1034 */ +1035 public Boolean getCopyInstanceOnItemCopy() { +1036 return this.copyInstanceOnItemCopy; +1037 } +1038 +1039 /** +1040 * Sets whether the copy operation should copy the metadata along with the item. +1041 * +1042 * @param copyInstanceOnItemCopy whether the copy operation should copy the metadata along with the item. +1043 */ +1044 public void setCopyInstanceOnItemCopy(Boolean copyInstanceOnItemCopy) { +1045 this.copyInstanceOnItemCopy = copyInstanceOnItemCopy; +1046 } +1047 +1048 /** +1049 * Gets static configuration for the classification. +1050 * +1051 * @return static configuration for the classification. +1052 */ +1053 public StaticConfig getStaticConfig() { +1054 return this.staticConfig; +1055 } +1056 +1057 /** +1058 * Sets static configuration for the classification. +1059 * +1060 * @param staticConfig static configuration for the classification. +1061 */ +1062 public void setStaticConfig(StaticConfig staticConfig) { +1063 this.staticConfig = staticConfig; +1064 } +1065 +1066 /** +1067 * {@inheritDoc} +1068 */ +1069 @Override +1070 void parseJSONMember(JsonObject.Member member) { +1071 JsonValue value = member.getValue(); +1072 String memberName = member.getName(); +1073 switch (memberName) { +1074 case "type": +1075 this.type = value.asString(); +1076 break; +1077 case "key": +1078 this.key = value.asString(); +1079 break; +1080 case "displayName": +1081 this.displayName = value.asString(); +1082 break; +1083 case "hidden": +1084 this.isHidden = value.asBoolean(); +1085 break; +1086 case "description": +1087 this.description = value.asString(); +1088 break; +1089 case "options": +1090 this.options = new ArrayList<>(); +1091 for (JsonValue option : value.asArray()) { +1092 this.options.add(new Option(option.asObject())); +1093 } +1094 break; +1095 case "id": +1096 this.id = value.asString(); +1097 break; +1098 case "copyInstanceOnItemCopy": +1099 this.copyInstanceOnItemCopy = value.asBoolean(); +1100 break; +1101 case "staticConfig": +1102 this.staticConfig = new StaticConfig(value.asObject()); +1103 break; +1104 default: +1105 break; +1106 } +1107 } +1108 } +1109 +1110 /** +1111 * Class contains information about the metadata template option. +1112 */ +1113 public static class Option extends BoxJSONObject { +1114 /** +1115 * @see #getID()1116 */ -1117 public FieldOperation(String json) { -1118 super(json); -1119 } -1120 -1121 /** -1122 * Constructs a Field operation from a JSON object. -1123 * -1124 * @param jsonObject the json encoded metadate template field. -1125 */ -1126 FieldOperation(JsonObject jsonObject) { -1127 super(jsonObject); -1128 } -1129 -1130 /** -1131 * Gets the operation. -1132 * -1133 * @return the operation -1134 */ -1135 public Operation getOp() { -1136 return this.op; -1137 } -1138 -1139 /** -1140 * Sets the operation. -1141 * -1142 * @param op the operation -1143 */ -1144 public void setOp(Operation op) { -1145 this.op = op; -1146 } -1147 -1148 /** -1149 * Gets the data associated with the operation. -1150 * -1151 * @return the field object representing the data -1152 */ -1153 public Field getData() { -1154 return this.data; -1155 } -1156 -1157 /** -1158 * Sets the data. -1159 * -1160 * @param data the Field object representing the data -1161 */ -1162 public void setData(Field data) { -1163 this.data = data; -1164 } -1165 -1166 /** -1167 * Gets the field key. -1168 * -1169 * @return the field key -1170 */ -1171 public String getFieldKey() { -1172 return this.fieldKey; -1173 } -1174 -1175 /** -1176 * Sets the field key. -1177 * -1178 * @param fieldKey the key of the field -1179 */ -1180 public void setFieldKey(String fieldKey) { -1181 this.fieldKey = fieldKey; -1182 } -1183 -1184 /** -1185 * Gets the list of field keys. -1186 * -1187 * @return the list of Strings -1188 */ -1189 public List<String> getFieldKeys() { -1190 return this.fieldKeys; -1191 } -1192 -1193 /** -1194 * Sets the list of the field keys. -1195 * -1196 * @param fieldKeys the list of strings -1197 */ -1198 public void setFieldKeys(List<String> fieldKeys) { -1199 this.fieldKeys = fieldKeys; -1200 } +1117 private String id; +1118 /** +1119 * @see #getKey() +1120 */ +1121 private String key; +1122 /** +1123 * @see #getStaticConfig() +1124 */ +1125 private StaticConfig staticConfig; +1126 +1127 /** +1128 * Constructs an empty metadata template. +1129 */ +1130 public Option() { +1131 super(); +1132 } +1133 +1134 /** +1135 * Constructs a metadate template option from a JSON string. +1136 * +1137 * @param json the json encoded metadata template option. +1138 */ +1139 public Option(String json) { +1140 super(json); +1141 } +1142 +1143 /** +1144 * Constructs a metadate template option from a JSON object. +1145 * +1146 * @param jsonObject the json encoded metadate template option. +1147 */ +1148 Option(JsonObject jsonObject) { +1149 super(jsonObject); +1150 } +1151 +1152 /** +1153 * Gets the ID of the template field. +1154 * +1155 * @return the template field ID. +1156 */ +1157 public String getID() { +1158 return this.id; +1159 } +1160 +1161 /** +1162 * Gets the key of the field. +1163 * +1164 * @return the key of the field. +1165 */ +1166 public String getKey() { +1167 return this.key; +1168 } +1169 +1170 /** +1171 * Gets static configuration for the classification. +1172 * +1173 * @return static configuration for the classification. +1174 */ +1175 public StaticConfig getStaticConfig() { +1176 return this.staticConfig; +1177 } +1178 +1179 /** +1180 * {@inheritDoc} +1181 */ +1182 @Override +1183 void parseJSONMember(JsonObject.Member member) { +1184 JsonValue value = member.getValue(); +1185 String memberName = member.getName(); +1186 switch (memberName) { +1187 case "id": +1188 this.id = value.asString(); +1189 break; +1190 case "key": +1191 this.key = value.asString(); +1192 break; +1193 case "staticConfig": +1194 this.staticConfig = new StaticConfig(value.asObject()); +1195 break; +1196 default: +1197 break; +1198 } +1199 } +1200 }1201 -1202 /** -1203 * Gets the list of keys of the Enum options. -1204 * -1205 * @return the list of Strings -1206 */ -1207 public List<String> getEnumOptionKeys() { -1208 return this.enumOptionKeys; -1209 } -1210 -1211 /** -1212 * Sets the list of the enum option keys. -1213 * -1214 * @param enumOptionKeys the list of Strings -1215 */ -1216 public void setEnumOptionKeys(List<String> enumOptionKeys) { -1217 this.enumOptionKeys = enumOptionKeys; -1218 } -1219 -1220 /** -1221 * Gets the enum option key. -1222 * -1223 * @return the enum option key -1224 */ -1225 public String getEnumOptionKey() { -1226 return this.enumOptionKey; -1227 } -1228 -1229 /** -1230 * Sets the enum option key. -1231 * -1232 * @param enumOptionKey the enum option key -1233 */ -1234 public void setEnumOptionKey(String enumOptionKey) { -1235 this.enumOptionKey = enumOptionKey; -1236 } -1237 -1238 /** -1239 * Gets the multi-select option key. -1240 * -1241 * @return the key. -1242 */ -1243 public String getMultiSelectOptionKey() { -1244 return this.multiSelectOptionKey; -1245 } -1246 -1247 /** -1248 * Sets the multi-select option key. -1249 * -1250 * @param key the key. -1251 */ -1252 public void setMultiSelectOptionKey(String key) { -1253 this.multiSelectOptionKey = key; -1254 } -1255 -1256 /** -1257 * Gets the list of multiselect option keys. -1258 * -1259 * @return the list of keys. -1260 */ -1261 public List<String> getMultiSelectOptionKeys() { -1262 return this.multiSelectOptionKeys; -1263 } -1264 -1265 /** -1266 * Sets the multi-select option keys. -1267 * -1268 * @param keys the list of keys. -1269 */ -1270 public void setMultiSelectOptionKeys(List<String> keys) { -1271 this.multiSelectOptionKeys = keys; -1272 } -1273 -1274 @Override -1275 public void clearPendingChanges() { -1276 super.clearPendingChanges(); +1202 /** +1203 * Posssible operations that can be performed in a Metadata template. +1204 * <ul> +1205 * <li>Add an enum option</li> +1206 * <li>Edit an enum option</li> +1207 * <li>Remove an enum option</li> +1208 * <li>Add a field</li> +1209 * <li>Edit a field</li> +1210 * <li>Remove a field</li> +1211 * <li>Edit template</li> +1212 * <li>Reorder the enum option</li> +1213 * <li>Reorder the field list</li> +1214 * </ul> +1215 */ +1216 public static class FieldOperation extends BoxJSONObject { +1217 +1218 private Operation op; +1219 private Field data; +1220 private String fieldKey; +1221 private List<String> fieldKeys; +1222 private List<String> enumOptionKeys; +1223 private String enumOptionKey; +1224 private String multiSelectOptionKey; +1225 private List<String> multiSelectOptionKeys; +1226 +1227 /** +1228 * Constructs an empty FieldOperation. +1229 */ +1230 public FieldOperation() { +1231 super(); +1232 } +1233 +1234 /** +1235 * Constructs a Field operation from a JSON string. +1236 * +1237 * @param json the json encoded metadate template field. +1238 */ +1239 public FieldOperation(String json) { +1240 super(json); +1241 } +1242 +1243 /** +1244 * Constructs a Field operation from a JSON object. +1245 * +1246 * @param jsonObject the json encoded metadate template field. +1247 */ +1248 FieldOperation(JsonObject jsonObject) { +1249 super(jsonObject); +1250 } +1251 +1252 /** +1253 * Gets the operation. +1254 * +1255 * @return the operation +1256 */ +1257 public Operation getOp() { +1258 return this.op; +1259 } +1260 +1261 /** +1262 * Sets the operation. +1263 * +1264 * @param op the operation +1265 */ +1266 public void setOp(Operation op) { +1267 this.op = op; +1268 } +1269 +1270 /** +1271 * Gets the data associated with the operation. +1272 * +1273 * @return the field object representing the data +1274 */ +1275 public Field getData() { +1276 return this.data;1277 }12781279 /** -1280 * {@inheritDoc} -1281 */ -1282 @Override -1283 void parseJSONMember(JsonObject.Member member) { -1284 JsonValue value = member.getValue(); -1285 String memberName = member.getName(); -1286 switch (memberName) { -1287 case "op": -1288 this.op = Operation.valueOf(value.asString()); -1289 break; -1290 case "data": -1291 this.data = new Field(value.asObject()); -1292 break; -1293 case "fieldKey": -1294 this.fieldKey = value.asString(); -1295 break; -1296 case "fieldKeys": -1297 if (this.fieldKeys == null) { -1298 this.fieldKeys = new ArrayList<>(); -1299 } else { -1300 this.fieldKeys.clear(); -1301 } -1302 for (JsonValue jsonValue : value.asArray()) { -1303 this.fieldKeys.add(jsonValue.asString()); -1304 } -1305 break; -1306 case "enumOptionKeys": -1307 if (this.enumOptionKeys == null) { -1308 this.enumOptionKeys = new ArrayList<>(); -1309 } else { -1310 this.enumOptionKeys.clear(); -1311 } -1312 -1313 for (JsonValue jsonValue : value.asArray()) { -1314 this.enumOptionKeys.add(jsonValue.asString()); -1315 } -1316 break; -1317 case "enumOptionKey": -1318 this.enumOptionKey = value.asString(); -1319 break; -1320 case "multiSelectOptionKey": -1321 this.multiSelectOptionKey = value.asString(); -1322 break; -1323 case "multiSelectOptionKeys": -1324 this.multiSelectOptionKeys = new ArrayList<>(); -1325 for (JsonValue key : value.asArray()) { -1326 this.multiSelectOptionKeys.add(key.asString()); -1327 } -1328 break; -1329 default: -1330 break; -1331 } -1332 } -1333 } -1334} +1280 * Sets the data. +1281 * +1282 * @param data the Field object representing the data +1283 */ +1284 public void setData(Field data) { +1285 this.data = data; +1286 } +1287 +1288 /** +1289 * Gets the field key. +1290 * +1291 * @return the field key +1292 */ +1293 public String getFieldKey() { +1294 return this.fieldKey; +1295 } +1296 +1297 /** +1298 * Sets the field key. +1299 * +1300 * @param fieldKey the key of the field +1301 */ +1302 public void setFieldKey(String fieldKey) { +1303 this.fieldKey = fieldKey; +1304 } +1305 +1306 /** +1307 * Gets the list of field keys. +1308 * +1309 * @return the list of Strings +1310 */ +1311 public List<String> getFieldKeys() { +1312 return this.fieldKeys; +1313 } +1314 +1315 /** +1316 * Sets the list of the field keys. +1317 * +1318 * @param fieldKeys the list of strings +1319 */ +1320 public void setFieldKeys(List<String> fieldKeys) { +1321 this.fieldKeys = fieldKeys; +1322 } +1323 +1324 /** +1325 * Gets the list of keys of the Enum options. +1326 * +1327 * @return the list of Strings +1328 */ +1329 public List<String> getEnumOptionKeys() { +1330 return this.enumOptionKeys; +1331 } +1332 +1333 /** +1334 * Sets the list of the enum option keys. +1335 * +1336 * @param enumOptionKeys the list of Strings +1337 */ +1338 public void setEnumOptionKeys(List<String> enumOptionKeys) { +1339 this.enumOptionKeys = enumOptionKeys; +1340 } +1341 +1342 /** +1343 * Gets the enum option key. +1344 * +1345 * @return the enum option key +1346 */ +1347 public String getEnumOptionKey() { +1348 return this.enumOptionKey; +1349 } +1350 +1351 /** +1352 * Sets the enum option key. +1353 * +1354 * @param enumOptionKey the enum option key +1355 */ +1356 public void setEnumOptionKey(String enumOptionKey) { +1357 this.enumOptionKey = enumOptionKey; +1358 } +1359 +1360 /** +1361 * Gets the multi-select option key. +1362 * +1363 * @return the key. +1364 */ +1365 public String getMultiSelectOptionKey() { +1366 return this.multiSelectOptionKey; +1367 } +1368 +1369 /** +1370 * Sets the multi-select option key. +1371 * +1372 * @param key the key. +1373 */ +1374 public void setMultiSelectOptionKey(String key) { +1375 this.multiSelectOptionKey = key; +1376 } +1377 +1378 /** +1379 * Gets the list of multiselect option keys. +1380 * +1381 * @return the list of keys. +1382 */ +1383 public List<String> getMultiSelectOptionKeys() { +1384 return this.multiSelectOptionKeys; +1385 } +1386 +1387 /** +1388 * Sets the multi-select option keys. +1389 * +1390 * @param keys the list of keys. +1391 */ +1392 public void setMultiSelectOptionKeys(List<String> keys) { +1393 this.multiSelectOptionKeys = keys; +1394 } +1395 +1396 @Override +1397 public void clearPendingChanges() { +1398 super.clearPendingChanges(); +1399 } +1400 +1401 /** +1402 * {@inheritDoc} +1403 */ +1404 @Override +1405 void parseJSONMember(JsonObject.Member member) { +1406 JsonValue value = member.getValue(); +1407 String memberName = member.getName(); +1408 switch (memberName) { +1409 case "op": +1410 this.op = Operation.valueOf(value.asString()); +1411 break; +1412 case "data": +1413 this.data = new Field(value.asObject()); +1414 break; +1415 case "fieldKey": +1416 this.fieldKey = value.asString(); +1417 break; +1418 case "fieldKeys": +1419 if (this.fieldKeys == null) { +1420 this.fieldKeys = new ArrayList<>(); +1421 } else { +1422 this.fieldKeys.clear(); +1423 } +1424 for (JsonValue jsonValue : value.asArray()) { +1425 this.fieldKeys.add(jsonValue.asString()); +1426 } +1427 break; +1428 case "enumOptionKeys": +1429 if (this.enumOptionKeys == null) { +1430 this.enumOptionKeys = new ArrayList<>(); +1431 } else { +1432 this.enumOptionKeys.clear(); +1433 } +1434 +1435 for (JsonValue jsonValue : value.asArray()) { +1436 this.enumOptionKeys.add(jsonValue.asString()); +1437 } +1438 break; +1439 case "enumOptionKey": +1440 this.enumOptionKey = value.asString(); +1441 break; +1442 case "multiSelectOptionKey": +1443 this.multiSelectOptionKey = value.asString(); +1444 break; +1445 case "multiSelectOptionKeys": +1446 this.multiSelectOptionKeys = new ArrayList<>(); +1447 for (JsonValue key : value.asArray()) { +1448 this.multiSelectOptionKeys.add(key.asString()); +1449 } +1450 break; +1451 default: +1452 break; +1453 } +1454 } +1455 } +1456}