public abstract class CommonUtil
extends Object
Modifier and Type | Field and Description |
---|---|
static String |
HOST_ENVIRONMENT |
Constructor and Description |
---|
CommonUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
checkUserSetup(String clientId,
String clientSecret,
String tenant)
Verifies if mandatory user details available before requesting for token.
|
static String |
encodeFilter(String filter) |
static byte[] |
fileToByteArray(File file)
Converts the given file to byte stream.
|
static MindsphereCredentials |
getCredentialFromEnv(MindsphereCredentials creds)
Method to fetch credentials from sytem's environment variable if it has not
been provided
|
static String |
getCredentials(RestClientConfig config,
MindsphereCredentials creds)
Returns bearer token for the requested client.
|
static String |
getEnvironmentSpecificGateWayUrl(RestClientConfig config)
Returns gate way URL specific to the configured environment
|
static Timestamp |
getTimestamp(String timeString)
Converts time stamp in string to java Timestamp object.
|
static String |
getURL(String urlKey,
RestClientConfig config) |
static String |
getURL(String baseUrlKey,
String apiUrlKey,
RestClientConfig config)
Method to get fully qualified Url for the requested resource
|
static ErrorObject |
parseException(String inp)
Reads the error message received from requested Api and parses to representable format.
|
void |
wrapperFetchTechnicalToken(MindsphereCredentials credentialFromEnv,
RestClientConfig config,
HttpHeaders header) |
String |
wrapperGetEnvironmentVarValue(String envKey) |
void |
wrapperNonStaticAddCredential(RestClientConfig config,
MindsphereCredentials creds,
HttpHeaders header) |
MindsphereCredentials |
wrapperNonStaticGetCredentialFromEnv(MindsphereCredentials creds) |
String |
wrapperNonStaticGetCredentialFromEnv(String envKey) |
public static String getURL(String baseUrlKey, String apiUrlKey, RestClientConfig config)
baseUrlKey
- base url for a set of operation on same resourceapiUrlKey
- Http operation specific end pointconfig
- RestClientConfig instancepublic static String getEnvironmentSpecificGateWayUrl(RestClientConfig config)
config
- RestClientConfig instance to get the host environment (region) valuepublic static String getURL(String urlKey, RestClientConfig config)
public static String getCredentials(RestClientConfig config, MindsphereCredentials creds) throws MindsphereException
config
- RestClientConfig having client configuration such as proxy settings.creds
- Credentials object used by the client to set credentials.MindsphereException
- thrown if some error occurs while fetching the token.public static MindsphereCredentials getCredentialFromEnv(MindsphereCredentials creds) throws MindsphereForbiddenAccessException
creds
- Credentials object used by the client to set credentialsMindsphereForbiddenAccessException
- thrown if clientId, clientSecret and tenant details are not setpublic void wrapperFetchTechnicalToken(MindsphereCredentials credentialFromEnv, RestClientConfig config, HttpHeaders header) throws MindsphereException
MindsphereException
public String wrapperGetEnvironmentVarValue(String envKey)
public String wrapperNonStaticGetCredentialFromEnv(String envKey)
public MindsphereCredentials wrapperNonStaticGetCredentialFromEnv(MindsphereCredentials creds) throws MindsphereForbiddenAccessException
public void wrapperNonStaticAddCredential(RestClientConfig config, MindsphereCredentials creds, HttpHeaders header) throws MindsphereException
MindsphereException
public static byte[] fileToByteArray(File file)
file
- input filepublic static Timestamp getTimestamp(String timeString) throws ParseException
timeString
- time stamp in stringParseException
- thrown if an error is encountered when converting String to Timestamppublic static ErrorObject parseException(String inp)
inp
- error message.public static void checkUserSetup(String clientId, String clientSecret, String tenant) throws MindsphereForbiddenAccessException
clientId
- Client id for authorization.clientSecret
- clientSecret for authorization.tenant
- tenant Id for authorization.MindsphereForbiddenAccessException
- thrown if any of the mandatory parameters is missing.public static String encodeFilter(String filter)