idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
35,800
private String getAuthHeader ( ) { String base64ClientIdSec = DatatypeConverter . printBase64Binary ( ( oauth2Config . getClientId ( ) + ":" + oauth2Config . getClientSecret ( ) ) . getBytes ( ) ) ; return "Basic " + base64ClientIdSec ; }
Method to generate auth header based on client ID and Client Secret
35,801
public UserInfoResponse getUserInfo ( String accessToken ) throws OpenIdException { logger . debug ( "Enter OAuth2PlatformClient::getUserInfo" ) ; try { HttpRequestClient client = new HttpRequestClient ( oauth2Config . getProxyConfig ( ) ) ; Request request = new Request . RequestBuilder ( MethodType . GET , oauth2Config . getUserProfileEndpoint ( ) ) . requiresAuthentication ( true ) . authString ( "Bearer " + accessToken ) . build ( ) ; Response response = client . makeRequest ( request ) ; logger . debug ( "Response Code : " + response . getStatusCode ( ) ) ; if ( response . getStatusCode ( ) == 200 ) { ObjectReader reader = mapper . readerFor ( UserInfoResponse . class ) ; UserInfoResponse userInfoResponse = reader . readValue ( response . getContent ( ) ) ; return userInfoResponse ; } else { logger . debug ( "failed getting user info" ) ; throw new OpenIdException ( "failed getting user info" , response . getStatusCode ( ) + "" ) ; } } catch ( Exception ex ) { logger . error ( "Exception while retrieving user info " , ex ) ; throw new OpenIdException ( ex . getMessage ( ) , ex ) ; } }
Method to retrieve UserInfo data associated with the accessToken generated The response depends on the Scope supplied during openId
35,802
public boolean validateIDToken ( String idToken ) throws OpenIdException { logger . debug ( "Enter OAuth2PlatformClient::validateIDToken" ) ; String [ ] idTokenParts = idToken . split ( "\\." ) ; if ( idTokenParts . length < 3 ) { logger . debug ( "invalid idTokenParts length" ) ; return false ; } String idTokenHeader = base64UrlDecode ( idTokenParts [ 0 ] ) ; String idTokenPayload = base64UrlDecode ( idTokenParts [ 1 ] ) ; byte [ ] idTokenSignature = base64UrlDecodeToBytes ( idTokenParts [ 2 ] ) ; JSONObject idTokenHeaderJson = new JSONObject ( idTokenHeader ) ; JSONObject idTokenHeaderPayload = new JSONObject ( idTokenPayload ) ; String issuer = idTokenHeaderPayload . getString ( "iss" ) ; if ( ! issuer . equalsIgnoreCase ( oauth2Config . getIntuitIdTokenIssuer ( ) ) ) { logger . debug ( "issuer value mismtach" ) ; return false ; } JSONArray jsonaud = idTokenHeaderPayload . getJSONArray ( "aud" ) ; String aud = jsonaud . getString ( 0 ) ; if ( ! aud . equalsIgnoreCase ( oauth2Config . getClientId ( ) ) ) { logger . debug ( "incorrect client id" ) ; return false ; } Long expirationTimestamp = idTokenHeaderPayload . getLong ( "exp" ) ; Long currentTime = System . currentTimeMillis ( ) / 1000 ; if ( ( expirationTimestamp - currentTime ) <= 0 ) { logger . debug ( "expirationTimestamp has elapsed" ) ; return false ; } HashMap < String , JSONObject > keyMap = getKeyMapFromJWKSUri ( ) ; if ( keyMap == null || keyMap . isEmpty ( ) ) { logger . debug ( "unable to retrive keyMap from JWKS url" ) ; return false ; } String keyId = idTokenHeaderJson . getString ( "kid" ) ; JSONObject keyDetails = keyMap . get ( keyId ) ; String exponent = keyDetails . getString ( "e" ) ; String modulo = keyDetails . getString ( "n" ) ; PublicKey publicKey = getPublicKey ( modulo , exponent ) ; byte [ ] data = ( idTokenParts [ 0 ] + "." + idTokenParts [ 1 ] ) . getBytes ( StandardCharsets . UTF_8 ) ; try { boolean isSignatureValid = verifyUsingPublicKey ( data , idTokenSignature , publicKey ) ; logger . debug ( "isSignatureValid: " + isSignatureValid ) ; return isSignatureValid ; } catch ( GeneralSecurityException e ) { logger . error ( "Exception while validating ID token " , e ) ; throw new OpenIdException ( e . getMessage ( ) , e ) ; } }
Method to validate IDToken
35,803
private HashMap < String , JSONObject > getKeyMapFromJWKSUri ( ) throws OpenIdException { logger . debug ( "Enter OAuth2PlatformClient::getKeyMapFromJWKSUri" ) ; try { HttpRequestClient client = new HttpRequestClient ( oauth2Config . getProxyConfig ( ) ) ; Request request = new Request . RequestBuilder ( MethodType . GET , oauth2Config . getIntuitJwksURI ( ) ) . requiresAuthentication ( false ) . build ( ) ; Response response = client . makeRequest ( request ) ; logger . debug ( "Response Code : " + response . getStatusCode ( ) ) ; if ( response . getStatusCode ( ) != 200 ) { logger . debug ( "failed JWKS URI" ) ; throw new OpenIdException ( "failed JWKS URI" , response . getStatusCode ( ) + "" ) ; } return buildKeyMap ( response . getContent ( ) ) ; } catch ( Exception ex ) { logger . error ( "Exception while retrieving jwks " , ex ) ; throw new OpenIdException ( ex . getMessage ( ) , ex ) ; } }
Build JWKS keymap
35,804
private PublicKey getPublicKey ( String MODULUS , String EXPONENT ) { byte [ ] nb = base64UrlDecodeToBytes ( MODULUS ) ; byte [ ] eb = base64UrlDecodeToBytes ( EXPONENT ) ; BigInteger n = new BigInteger ( 1 , nb ) ; BigInteger e = new BigInteger ( 1 , eb ) ; RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec ( n , e ) ; try { PublicKey publicKey = KeyFactory . getInstance ( "RSA" ) . generatePublic ( rsaPublicKeySpec ) ; return publicKey ; } catch ( Exception ex ) { logger . error ( "Exception while getting public key " , ex ) ; throw new RuntimeException ( "Cant create public key" , ex ) ; } }
Build public key
35,805
private HashMap < String , JSONObject > buildKeyMap ( String content ) throws ConnectionException { HashMap < String , JSONObject > retMap = new HashMap < String , JSONObject > ( ) ; JSONObject jwksPayload = new JSONObject ( content ) ; JSONArray keysArray = jwksPayload . getJSONArray ( "keys" ) ; for ( int i = 0 ; i < keysArray . length ( ) ; i ++ ) { JSONObject object = keysArray . getJSONObject ( i ) ; String keyId = object . getString ( "kid" ) ; retMap . put ( keyId , object ) ; } return retMap ; }
Build Map from response
35,806
public Expression < String > eq ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . eq , valueString ) ; }
Method to construct the equals expression for string
35,807
public Expression < String > neq ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . neq , valueString ) ; }
Method to construct the not equals expression for string
35,808
public Expression < String > lt ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . lt , valueString ) ; }
Method to construct the less than expression for string
35,809
public Expression < String > lte ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . lte , valueString ) ; }
Method to construct the less than or equals expression for string
35,810
public Expression < String > gt ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . gt , valueString ) ; }
Method to construct the greater than expression for string
35,811
public Expression < String > gte ( String value ) { String valueString = "'" + value + "'" ; return new Expression < String > ( this , Operation . gte , valueString ) ; }
Method to construct the greater than or equals expression for string
35,812
public Expression < String > in ( String [ ] value ) { String listString = "" ; Boolean firstString = true ; for ( String v : value ) { if ( firstString ) { listString = listString . concat ( "('" ) . concat ( v ) . concat ( "'" ) ; firstString = false ; } else { listString = listString . concat ( ", '" ) . concat ( v ) . concat ( "'" ) ; } } listString = listString . concat ( ")" ) ; return new Expression < String > ( this , Operation . in , listString ) ; }
Method to construct the in expression for string
35,813
public Expression < String > startsWith ( String value ) { String valueString = "'" + value + "%'" ; return new Expression < String > ( this , Operation . like , valueString ) ; }
Method to construct the like expression for string starts with
35,814
public Expression < String > endsWith ( String value ) { String valueString = "'%" + value + "'" ; return new Expression < String > ( this , Operation . like , valueString ) ; }
Method to construct the like expression for string ends with
35,815
public Expression < String > contains ( String value ) { String valueString = "'%" + value + "%'" ; return new Expression < String > ( this , Operation . like , valueString ) ; }
Method to construct the like expression for string contains
35,816
public Expression < String > between ( String startValue , String endValue ) { String valueString = "'" + startValue + "' AND '" + endValue + "'" ; return new Expression < String > ( this , Operation . between , valueString ) ; }
Method to construct the between expression for string
35,817
public String getContent ( ) throws ConnectionException { logger . debug ( "Enter Response::getContent" ) ; if ( content != null ) { logger . debug ( "content already available " ) ; return content ; } BufferedReader rd = new BufferedReader ( new InputStreamReader ( stream ) ) ; StringBuffer result = new StringBuffer ( ) ; String line = "" ; try { while ( ( line = rd . readLine ( ) ) != null ) { result . append ( line ) ; } } catch ( IOException e ) { logger . error ( "Exception while retrieving content" , e ) ; throw new ConnectionException ( e . getMessage ( ) ) ; } content = result . toString ( ) ; logger . debug ( "End Response::getContent" ) ; return content ; }
Returns the json content from http response
35,818
public static void setProperty ( String key , String value ) { local . get ( ) . cc . setProperty ( key , value ) ; }
Sets the property to the configuration
35,819
public static Boolean getBooleanProperty ( String key , Boolean defaultValue ) { String value = getProperty ( key ) ; if ( ( null == value ) || value . isEmpty ( ) ) { return ( null == defaultValue ) ? false : defaultValue ; } if ( "null" . equals ( value . toLowerCase ( ) ) && ( null != defaultValue ) ) { return defaultValue ; } return Boolean . parseBoolean ( value ) ; }
Returns boolean value for specified property and default value
35,820
private SimpleDateFormat getDateTimeFormatter ( ) { SimpleDateFormat formatter = new SimpleDateFormat ( ) ; formatter . applyPattern ( "yyyy-MM-dd'T'HH:mm:ss" ) ; formatter . setTimeZone ( TimeZone . getTimeZone ( "GMT" ) ) ; return formatter ; }
Method to get simple date format
35,821
private String getCalendarAsString ( Calendar cal ) { SimpleDateFormat formatter = getDateTimeFormatter ( ) ; Date date = cal . getTime ( ) ; return formatter . format ( date ) . concat ( "Z" ) ; }
Method to get string value of date from Calendar
35,822
public Expression < Calendar > eq ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . eq , valueString ) ; }
Method to construct the equals expression for Calendar
35,823
public Expression < Calendar > neq ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . neq , valueString ) ; }
Method to construct the not equals expression for Calendar
35,824
public Expression < Calendar > lt ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . lt , valueString ) ; }
Method to construct the less than expression for calendar
35,825
public Expression < Calendar > lte ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . lte , valueString ) ; }
Method to construct the less than or equals expression for calendar
35,826
public Expression < java . sql . Date > lte ( java . sql . Date value ) { SimpleDateFormat formatter = getDateFormatter ( ) ; String valueString = "'" + formatter . format ( value ) + "'" ; return new Expression < java . sql . Date > ( this , Operation . lte , valueString ) ; }
Method to construct the less than or equals expression for date
35,827
public Expression < Calendar > gt ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . gt , valueString ) ; }
Method to construct the greater than expression for calendar
35,828
public Expression < java . util . Date > gt ( java . util . Date value ) { SimpleDateFormat formatter = getDateTimeFormatter ( ) ; String valueString = "'" + formatter . format ( value ) . concat ( "Z" ) + "'" ; return new Expression < java . util . Date > ( this , Operation . gt , valueString ) ; }
Method to construct the greater than expression for date
35,829
public Expression < Calendar > gte ( Calendar value ) { String valueString = "'" + getCalendarAsString ( value ) + "'" ; return new Expression < Calendar > ( this , Operation . gte , valueString ) ; }
Method to construct the greater than or equals expression for calendar
35,830
public Expression < Calendar > in ( Calendar [ ] value ) { String valueString = "" ; Boolean firstCalendar = true ; for ( Calendar v : value ) { if ( firstCalendar ) { valueString = valueString . concat ( "('" ) . concat ( getCalendarAsString ( v ) ) . concat ( "'" ) ; firstCalendar = false ; } else { valueString = valueString . concat ( ", '" ) . concat ( getCalendarAsString ( v ) ) . concat ( "'" ) ; } } valueString = valueString . concat ( ")" ) ; return new Expression < Calendar > ( this , Operation . in , valueString ) ; }
Method to construct the in expression for calendar
35,831
public Expression < java . util . Date > in ( java . util . Date [ ] value ) { SimpleDateFormat formatter = getDateTimeFormatter ( ) ; String valueString = "" ; Boolean firstCalendar = true ; for ( Date v : value ) { if ( firstCalendar ) { valueString = valueString . concat ( "('" ) . concat ( formatter . format ( v ) . concat ( "Z" ) ) . concat ( "'" ) ; firstCalendar = false ; } else { valueString = valueString . concat ( ", '" ) . concat ( formatter . format ( v ) . concat ( "Z" ) ) . concat ( "'" ) ; } } valueString = valueString . concat ( ")" ) ; return new Expression < java . util . Date > ( this , Operation . in , valueString ) ; }
Method to construct the in expression for date
35,832
public Expression < Calendar > between ( Calendar startValue , Calendar endValue ) { String valueString = "'" + getCalendarAsString ( startValue ) . concat ( "Z" ) + "' AND '" + getCalendarAsString ( endValue ) + "'" ; return new Expression < Calendar > ( this , Operation . between , valueString ) ; }
Method to construct the between expression for calendar
35,833
private void setResponseElements ( IntuitMessage intuitMessage , HttpURLConnection httpUrlConnection ) throws FMSException { LOG . debug ( "Response headers:" + httpUrlConnection . getHeaderFields ( ) ) ; ResponseElements responseElements = intuitMessage . getResponseElements ( ) ; responseElements . setEncodingHeader ( httpUrlConnection . getContentEncoding ( ) ) ; responseElements . setContentTypeHeader ( httpUrlConnection . getContentType ( ) ) ; try { responseElements . setStatusCode ( httpUrlConnection . getResponseCode ( ) ) ; InputStream responseStream ; try { responseStream = httpUrlConnection . getInputStream ( ) ; } catch ( IOException ioe ) { responseStream = httpUrlConnection . getErrorStream ( ) ; } responseElements . setResponseContent ( getCopyOfResponseContent ( responseStream ) ) ; } catch ( IllegalStateException e ) { LOG . error ( "IllegalStateException while get the content from HttpRespose." , e ) ; throw new FMSException ( e ) ; } catch ( Exception e ) { LOG . error ( "IOException in HTTPURLConnectionInterceptor while reading the entity from HttpResponse." , e ) ; throw new FMSException ( e ) ; } }
Method to set the response elements by reading the values from the response
35,834
private InputStream getCopyOfResponseContent ( InputStream is ) throws FMSException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; InputStream copyIs = null ; try { byte [ ] bbuf = new byte [ LENGTH_256 ] ; while ( true ) { int r = is . read ( bbuf ) ; if ( r < 0 ) { break ; } baos . write ( bbuf , 0 , r ) ; } copyIs = new ByteArrayInputStream ( baos . toByteArray ( ) ) ; return copyIs ; } catch ( IOException ioe ) { LOG . error ( "IOException while decompress the data using GZIP compression." , ioe ) ; throw new CompressionException ( ioe ) ; } finally { if ( baos != null ) { try { baos . close ( ) ; } catch ( IOException e ) { LOG . error ( "Unable to close ByteArrayOutputStream." ) ; } } } }
Method to create the copy of the input stream of response body . This is required while decompress the original content
35,835
private void setTimeout ( HttpURLConnection httpUrlConnection ) { String connTimeout = Config . getProperty ( Config . TIMEOUT_CONNECTION ) ; if ( StringUtils . hasText ( connTimeout ) ) { httpUrlConnection . setReadTimeout ( new Integer ( connTimeout . trim ( ) ) ) ; } String reqTimeout = Config . getProperty ( Config . TIMEOUT_REQUEST ) ; if ( StringUtils . hasText ( reqTimeout ) ) { httpUrlConnection . setConnectTimeout ( new Integer ( reqTimeout . trim ( ) ) ) ; } }
Method to set the connection and request timeouts by reading from the configuration file
35,836
public PlatformResponse disconnect ( String consumerKey , String consumerSecret , String accessToken , String accessTokenSecret ) throws ConnectionException { httpClient = new PlatformHttpClient ( consumerKey , consumerSecret , accessToken , accessTokenSecret ) ; return this . httpClient . disconnect ( ) ; }
Disconnects the user from quickbooks
35,837
public User getcurrentUser ( String consumerKey , String consumerSecret , String accessToken , String accessTokenSecret ) throws ConnectionException { httpClient = new PlatformHttpClient ( consumerKey , consumerSecret , accessToken , accessTokenSecret ) ; User user = null ; ; try { user = this . httpClient . getCurrentUser ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return user ; }
getCurrentUser the user from quickbooks
35,838
public List < String > getAppMenu ( String consumerKey , String consumerSecret , String accessToken , String accessTokenSecret ) throws ConnectionException { try { List < String > menulist ; httpClient = new PlatformHttpClient ( consumerKey , consumerSecret , accessToken , accessTokenSecret ) ; menulist = this . httpClient . getAppMenu ( ) ; return menulist ; } catch ( ConnectionException conEx ) { throw conEx ; } catch ( Exception e ) { throw new ConnectionException ( "Failed to fetch appmenu: " + e . getMessage ( ) ) ; } }
Get App Menu returns list of all the applications that are linked with the selected company
35,839
private void swapRequestInterceptor ( Class < ? extends Interceptor > target , Interceptor interceptor ) { List < Interceptor > list = this . getRequestInterceptors ( ) ; for ( Interceptor object : list ) { if ( object . getClass ( ) == target ) { list . set ( list . indexOf ( object ) , interceptor ) ; } } this . setRequestInterceptors ( list ) ; }
Swap one interceptor with new one
35,840
private SyncObject getSyncObject ( JsonNode jsonNode ) { String name = null ; JsonNode jn1 = null ; SyncObject syncObject = new SyncObject ( ) ; Iterator < String > ite = jsonNode . fieldNames ( ) ; while ( ite . hasNext ( ) ) { String key = ite . next ( ) ; if ( JsonResourceTypeLocator . lookupType ( key ) != null ) { jn1 = jsonNode . get ( key ) ; LOG . debug ( "Query response entity Key :" + key ) ; try { Object intuitType = mapper . treeToValue ( jn1 , JsonResourceTypeLocator . lookupType ( key ) ) ; if ( intuitType instanceof IntuitEntity ) { JAXBElement < ? extends IntuitEntity > intuitObject = objFactory . createIntuitObject ( ( IntuitEntity ) intuitType ) ; syncObject . setIntuitObject ( intuitObject ) ; } } catch ( JsonParseException e ) { e . printStackTrace ( ) ; } catch ( JsonMappingException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } return syncObject ; }
Method to Object Intuitobject
35,841
public ECheck create ( ECheck eCheck ) throws BaseException { logger . debug ( "Enter ECheckService::create" ) ; String apiUrl = requestContext . getBaseUrl ( ) + "echecks" . replaceAll ( "\\{format\\}" , "json" ) ; logger . info ( "apiUrl - " + apiUrl ) ; TypeReference < ECheck > typeReference = new TypeReference < ECheck > ( ) { } ; Request request = new Request . RequestBuilder ( MethodType . POST , apiUrl ) . requestObject ( eCheck ) . typeReference ( typeReference ) . context ( requestContext ) . build ( ) ; Response response = sendRequest ( request ) ; ECheck eCheckResponse = ( ECheck ) response . getResponseObject ( ) ; prepareResponse ( request , response , eCheckResponse ) ; return eCheckResponse ; }
Method to create ECheck
35,842
public ECheck retrieve ( String eCheckId ) throws BaseException { logger . debug ( "Enter ECheckService::retrieve" ) ; if ( StringUtils . isBlank ( eCheckId ) ) { logger . error ( "IllegalArgumentException {}" , eCheckId ) ; throw new IllegalArgumentException ( "eCheckId cannot be empty or null" ) ; } String apiUrl = requestContext . getBaseUrl ( ) + "echecks/{id}" . replaceAll ( "\\{format\\}" , "json" ) . replaceAll ( "\\{" + "id" + "\\}" , eCheckId . toString ( ) ) ; logger . info ( "apiUrl - " + apiUrl ) ; TypeReference < ECheck > typeReference = new TypeReference < ECheck > ( ) { } ; Request request = new Request . RequestBuilder ( MethodType . GET , apiUrl ) . typeReference ( typeReference ) . context ( requestContext ) . build ( ) ; Response response = sendRequest ( request ) ; ECheck eCheckResponse = ( ECheck ) response . getResponseObject ( ) ; prepareResponse ( request , response , eCheckResponse ) ; return eCheckResponse ; }
Method to retrieve ECheck
35,843
public Refund refund ( String eCheckId , Refund refund ) throws BaseException { logger . debug ( "Enter ECheckService::refund" ) ; if ( StringUtils . isBlank ( eCheckId ) ) { logger . error ( "IllegalArgumentException {}" , eCheckId ) ; throw new IllegalArgumentException ( "eCheckId cannot be empty or null" ) ; } String apiUrl = requestContext . getBaseUrl ( ) + "echecks/{id}/refunds" . replaceAll ( "\\{format\\}" , "json" ) . replaceAll ( "\\{" + "id" + "\\}" , eCheckId . toString ( ) ) ; logger . info ( "apiUrl - " + apiUrl ) ; TypeReference < Refund > typeReference = new TypeReference < Refund > ( ) { } ; Request request = new Request . RequestBuilder ( MethodType . POST , apiUrl ) . requestObject ( refund ) . typeReference ( typeReference ) . context ( requestContext ) . build ( ) ; Response response = sendRequest ( request ) ; Refund refundResponse = ( Refund ) response . getResponseObject ( ) ; prepareResponse ( request , response , refundResponse ) ; return refundResponse ; }
Method to refund or void ECheck
35,844
private CustomFieldDefinition getCustomFieldDefinitionType ( JsonNode jn ) throws IOException { if ( jn . isArray ( ) ) { JsonNode jn1 = jn . get ( 0 ) ; String type = jn1 . get ( TYPE ) . textValue ( ) ; try { return ( CustomFieldDefinition ) Class . forName ( "com.intuit.ipp.data." + type + "CustomFieldDefinition" ) . newInstance ( ) ; } catch ( Exception e ) { throw new IOException ( "Exception while deserializing CustomFieldDefinition" , e ) ; } } return null ; }
Method to get the CustomFieldDefinition implementation type object
35,845
private BatchItemResponse getBatchItemResponse ( JsonNode jsonNode ) throws IOException { ObjectMapper mapper = new ObjectMapper ( ) ; SimpleModule simpleModule = new SimpleModule ( "BatchItemResponseDeserializer" , new Version ( 1 , 0 , 0 , null ) ) ; simpleModule . addDeserializer ( BatchItemResponse . class , new BatchItemResponseDeserializer ( ) ) ; mapper . registerModule ( simpleModule ) ; mapper . configure ( DeserializationFeature . FAIL_ON_UNKNOWN_PROPERTIES , false ) ; return mapper . treeToValue ( jsonNode , BatchItemResponse . class ) ; }
Method to deserialize the BatchItemResponse object
35,846
public void execute ( List < IntuitMessage > intuitMessages ) throws FMSException { LOG . debug ( "Enter HTTPBatchClientConnectionInterceptor - batch..." ) ; RequestElements intuitRequest = getFirst ( intuitMessages ) . getRequestElements ( ) ; IntuitRetryPolicyHandler handler = getRetryHandler ( ) ; HttpClientBuilder hcBuilder = HttpClients . custom ( ) . setRetryHandler ( handler ) . setDefaultRequestConfig ( setTimeout ( intuitRequest . getContext ( ) ) ) . setDefaultCredentialsProvider ( setProxyAuthentication ( ) ) . setSSLSocketFactory ( prepareClientSSL ( ) ) ; entitiesManager . reset ( ) ; HttpHost proxy = getProxy ( ) ; if ( proxy != null ) { hcBuilder . setProxy ( proxy ) ; } CloseableHttpClient client = hcBuilder . build ( ) ; HttpRequestBase httpRequest = prepareHttpRequest ( intuitRequest ) ; if ( httpRequest instanceof HttpPost ) { for ( IntuitMessage intuitMessage : intuitMessages ) { execute ( intuitMessage ) ; } try { ( ( HttpPost ) httpRequest ) . setEntity ( entitiesManager . asSingleEntity ( ) ) ; } catch ( IOException ex ) { LOG . debug ( "HTTPBatchClientConnectionInterceptor was unable to convert input into single HTTP entity" ) ; throw new FMSException ( "Unable to prepare http entity" + ex . getMessage ( ) + "\n" + ex . getStackTrace ( ) ) ; } finally { entitiesManager . reset ( ) ; } } IntuitMessage intuitMessage = executeHttpRequest ( httpRequest , client ) ; for ( IntuitMessage originalMessage : intuitMessages ) { ResponseElements originalResponseElements = originalMessage . getResponseElements ( ) ; ResponseElements receivedResponseElements = intuitMessage . getResponseElements ( ) ; originalResponseElements . setResponseContent ( receivedResponseElements . getResponseContent ( ) ) ; originalResponseElements . setEncodingHeader ( receivedResponseElements . getEncodingHeader ( ) ) ; originalResponseElements . setContentTypeHeader ( receivedResponseElements . getContentTypeHeader ( ) ) ; originalResponseElements . setStatusLine ( receivedResponseElements . getStatusLine ( ) ) ; originalResponseElements . setStatusCode ( receivedResponseElements . getStatusCode ( ) ) ; } LOG . debug ( "Exit HTTPBatchClientConnectionInterceptor." ) ; }
Major executor . It is not part of interface
35,847
private IntuitMessage getFirst ( List < IntuitMessage > intuitMessages ) throws FMSException { if ( intuitMessages . isEmpty ( ) ) { throw new FMSException ( "IntuitMessages list is empty. Nothing to upload." ) ; } return intuitMessages . get ( 0 ) ; }
Returns first item from the list
35,848
public SSLConnectionSocketFactory prepareClientSSL ( ) { try { String path = Config . getProperty ( Config . PROXY_KEYSTORE_PATH ) ; String pass = Config . getProperty ( Config . PROXY_KEYSTORE_PASSWORD ) ; KeyStore trustStore = null ; if ( path != null && pass != null ) { trustStore = KeyStore . getInstance ( KeyStore . getDefaultType ( ) ) ; FileInputStream instream = new FileInputStream ( new File ( path ) ) ; try { trustStore . load ( instream , pass . toCharArray ( ) ) ; } finally { instream . close ( ) ; } } SSLContext sslContext = SSLContexts . custom ( ) . loadTrustMaterial ( trustStore , new TrustSelfSignedStrategy ( ) ) . build ( ) ; String tlsVersion = Config . getProperty ( Config . TLS_VERSION ) ; SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory ( sslContext , new String [ ] { tlsVersion } , null , new NoopHostnameVerifier ( ) ) ; return sslConnectionFactory ; } catch ( Exception ex ) { LOG . error ( "couldn't create httpClient!! {}" , ex . getMessage ( ) , ex ) ; return null ; } }
Configures proxy if this is applicable to connection
35,849
private < T extends CloseableHttpClient > HttpRequestBase prepareHttpRequest ( RequestElements intuitRequest ) throws FMSException { HttpRequestBase httpRequest = extractMethod ( intuitRequest , extractURI ( intuitRequest ) ) ; populateRequestHeaders ( httpRequest , intuitRequest . getRequestHeaders ( ) ) ; authorizeRequest ( intuitRequest . getContext ( ) , httpRequest ) ; LOG . debug ( "Request URI : " + httpRequest . getURI ( ) ) ; LOG . debug ( "Http Method : " + httpRequest . getMethod ( ) ) ; return httpRequest ; }
Returns httpRequest instance with configured fields
35,850
private URI extractURI ( RequestElements intuitRequest ) throws FMSException { URI uri = null ; try { uri = new URI ( intuitRequest . getRequestParameters ( ) . get ( RequestElements . REQ_PARAM_RESOURCE_URL ) ) ; } catch ( URISyntaxException e ) { throw new FMSException ( "URISyntaxException" , e ) ; } return uri ; }
Returns URI instance which will be used as a connection source
35,851
private HttpRequestBase extractMethod ( RequestElements intuitRequest , URI uri ) throws FMSException { String method = intuitRequest . getRequestParameters ( ) . get ( RequestElements . REQ_PARAM_METHOD_TYPE ) ; if ( method . equals ( MethodType . GET . toString ( ) ) ) { return new HttpGet ( uri ) ; } else if ( method . equals ( MethodType . POST . toString ( ) ) ) { return new HttpPost ( uri ) ; } throw new FMSException ( "Unexpected HTTP method" ) ; }
Returns instance of HttpGet or HttpPost type depends from request parameters
35,852
private IntuitMessage executeHttpRequest ( HttpRequestBase httpRequest , CloseableHttpClient client ) throws FMSException { CloseableHttpResponse httpResponse = null ; IntuitMessage intuitMessage = new IntuitMessage ( ) ; try { HttpHost target = new HttpHost ( httpRequest . getURI ( ) . getHost ( ) , - 1 , httpRequest . getURI ( ) . getScheme ( ) ) ; httpResponse = client . execute ( target , httpRequest ) ; LOG . debug ( "Connection status : " + httpResponse . getStatusLine ( ) ) ; setResponseElements ( intuitMessage , httpResponse ) ; return intuitMessage ; } catch ( ClientProtocolException e ) { throw new ConfigurationException ( "Error in Http Protocol definition" , e ) ; } catch ( IOException e ) { throw new FMSException ( e ) ; } finally { if ( httpResponse != null ) { try { httpResponse . close ( ) ; } catch ( IOException e ) { LOG . warn ( "Unable to close CloseableHttpResponse ." , e ) ; } } if ( client != null ) { try { client . close ( ) ; } catch ( Exception e ) { LOG . warn ( "Unable to close CloseableHttpClient connection." , e ) ; } } } }
Executes communication with remote host
35,853
private void authorizeRequest ( Context context , HttpRequestBase httpRequest ) throws FMSException { context . getAuthorizer ( ) . authorize ( httpRequest ) ; }
Method to authorize the given HttpRequest
35,854
private IntuitRetryPolicyHandler getRetryHandler ( ) throws FMSException { IntuitRetryPolicyHandler handler = null ; String policy = Config . getProperty ( Config . RETRY_MODE ) ; if ( policy . equalsIgnoreCase ( "fixed" ) ) { String retryCountStr = Config . getProperty ( Config . RETRY_FIXED_COUNT ) ; String retryIntervalStr = Config . getProperty ( Config . RETRY_FIXED_INTERVAL ) ; try { handler = new IntuitRetryPolicyHandler ( Integer . parseInt ( retryCountStr ) , Integer . parseInt ( retryIntervalStr ) ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( e ) ; } } else if ( policy . equalsIgnoreCase ( "incremental" ) ) { String retryCountStr = Config . getProperty ( Config . RETRY_INCREMENTAL_COUNT ) ; String retryIntervalStr = Config . getProperty ( Config . RETRY_INCREMENTAL_INTERVAL ) ; String retryIncrementStr = Config . getProperty ( Config . RETRY_INCREMENTAL_INCREMENT ) ; try { handler = new IntuitRetryPolicyHandler ( Integer . parseInt ( retryCountStr ) , Integer . parseInt ( retryIntervalStr ) , Integer . parseInt ( retryIncrementStr ) ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( e ) ; } } else if ( policy . equalsIgnoreCase ( "exponential" ) ) { String retryCountStr = Config . getProperty ( Config . RETRY_EXPONENTIAL_COUNT ) ; String minBackoffStr = Config . getProperty ( Config . RETRY_EXPONENTIAL_MIN_BACKOFF ) ; String maxBackoffStr = Config . getProperty ( Config . RETRY_EXPONENTIAL_MAX_BACKOFF ) ; String deltaBackoffStr = Config . getProperty ( Config . RETRY_EXPONENTIAL_DELTA_BACKOFF ) ; try { handler = new IntuitRetryPolicyHandler ( Integer . parseInt ( retryCountStr ) , Integer . parseInt ( minBackoffStr ) , Integer . parseInt ( maxBackoffStr ) , Integer . parseInt ( deltaBackoffStr ) ) ; } catch ( NumberFormatException e ) { throw new ConfigurationException ( e ) ; } } return handler ; }
Method to get the retry handler which is used to retry to establish the HTTP connection
35,855
private void setResponseElements ( IntuitMessage intuitMessage , HttpResponse httpResponse ) throws FMSException { ResponseElements responseElements = intuitMessage . getResponseElements ( ) ; if ( httpResponse . getLastHeader ( RequestElements . HEADER_PARAM_CONTENT_ENCODING ) != null ) { responseElements . setEncodingHeader ( httpResponse . getLastHeader ( RequestElements . HEADER_PARAM_CONTENT_ENCODING ) . getValue ( ) ) ; } else { responseElements . setEncodingHeader ( null ) ; } if ( httpResponse . getLastHeader ( RequestElements . HEADER_PARAM_CONTENT_TYPE ) != null ) { responseElements . setContentTypeHeader ( httpResponse . getLastHeader ( RequestElements . HEADER_PARAM_CONTENT_TYPE ) . getValue ( ) ) ; } else { responseElements . setContentTypeHeader ( null ) ; } responseElements . setStatusLine ( httpResponse . getStatusLine ( ) ) ; responseElements . setStatusCode ( httpResponse . getStatusLine ( ) . getStatusCode ( ) ) ; try { responseElements . setResponseContent ( getCopyOfResponseContent ( httpResponse . getEntity ( ) . getContent ( ) ) ) ; } catch ( IllegalStateException e ) { LOG . error ( "IllegalStateException while get the content from HttpRespose." , e ) ; throw new FMSException ( e ) ; } catch ( Exception e ) { LOG . error ( "IOException in HTTPClientConnectionInterceptor while reading the entity from HttpResponse." , e ) ; throw new FMSException ( e ) ; } }
Method to set the response elements by reading the values from HttpResponse
35,856
private RequestConfig setTimeout ( Context context ) { int socketTimeout = 0 ; int connectionTimeout = 0 ; if ( context . getCustomerRequestTimeout ( ) != null ) { socketTimeout = context . getCustomerRequestTimeout ( ) ; } else { String reqTimeout = Config . getProperty ( Config . TIMEOUT_REQUEST ) ; if ( StringUtils . hasText ( reqTimeout ) ) { socketTimeout = new Integer ( reqTimeout . trim ( ) ) ; } } String connTimeout = Config . getProperty ( Config . TIMEOUT_CONNECTION ) ; if ( StringUtils . hasText ( connTimeout ) ) { connectionTimeout = new Integer ( connTimeout . trim ( ) ) ; } RequestConfig defaultRequestConfig = RequestConfig . custom ( ) . setSocketTimeout ( socketTimeout ) . setConnectTimeout ( connectionTimeout ) . setConnectionRequestTimeout ( connectionTimeout ) . setCookieSpec ( CookieSpecs . IGNORE_COOKIES ) . build ( ) ; return defaultRequestConfig ; }
Method to set the connection and request timeouts by reading from the configuration file or Context object
35,857
private HttpEntity populateEntity ( RequestElements intuitRequest ) throws FMSException { byte [ ] compressedData = intuitRequest . getCompressedData ( ) ; if ( null == compressedData ) { try { return new StringEntity ( intuitRequest . getPostString ( ) ) ; } catch ( UnsupportedEncodingException e ) { throw new FMSException ( "UnsupportedEncodingException" , e ) ; } } return new InputStreamEntity ( new ByteArrayInputStream ( compressedData ) , compressedData . length ) ; }
Creates HttpEntity depends from type of content
35,858
public static String serialize ( Object obj ) throws SerializationException { try { if ( obj != null ) { return mapper . writeValueAsString ( obj ) ; } else { return null ; } } catch ( Exception e ) { logger . error ( "SerializationException {}" , e . getMessage ( ) ) ; throw new SerializationException ( e . getMessage ( ) ) ; } }
Serialize object to String
35,859
public static Object deserialize ( String json , TypeReference < ? > typeReference ) throws SerializationException { try { logger . debug ( "Json string to deserialize {} " , json ) ; return mapper . readValue ( json , typeReference ) ; } catch ( IOException e ) { logger . error ( "SerializationException {}" , e . getMessage ( ) ) ; SerializationException serializationException = new SerializationException ( e ) ; throw serializationException ; } }
Deserialize String to object of TypeReference
35,860
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > List < T > findAll ( T entity ) throws FMSException { String intuitQuery = "SELECT * FROM " + entity . getClass ( ) . getSimpleName ( ) ; QueryResult result = executeQuery ( intuitQuery ) ; return ( List < T > ) result . getEntities ( ) ; }
Method to retrieve all records for the given entity Note without pagination this will return only 100 records Use query API to add pagintion and obtain additional records
35,861
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T add ( T entity ) throws FMSException { IntuitMessage intuitMessage = prepareAdd ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
Method to add the given entity
35,862
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T delete ( T entity ) throws FMSException { IntuitMessage intuitMessage = prepareDelete ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
Method to delete record for the given entity
35,863
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T update ( T entity ) throws FMSException { IntuitMessage intuitMessage = prepareUpdate ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
Method to update the record of the corresponding entity
35,864
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T updateAccountOnTxns ( T entity ) throws FMSException { IntuitMessage intuitMessage = prepareupdateAccountOnTxns ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
updateAccountOnTxns used for France Locale with Minor Version > = 5 .
35,865
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T donotUpdateAccountOnTxns ( T entity ) throws FMSException { IntuitMessage intuitMessage = preparedonotUpdateAccountOnTxns ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
donotUpdateAccountOnTxns used for France Locale with Minor Version > = 5 .
35,866
@ SuppressWarnings ( "unchecked" ) private < T extends IEntity > T retrieveEntity ( IntuitMessage intuitMessage ) { T returnEntity = null ; IntuitResponse intuitResponse = ( IntuitResponse ) intuitMessage . getResponseElements ( ) . getResponse ( ) ; if ( intuitResponse != null ) { JAXBElement < ? extends IntuitEntity > intuitObject = intuitResponse . getIntuitObject ( ) ; if ( intuitObject != null ) { returnEntity = ( ( T ) intuitObject . getValue ( ) ) ; } } return returnEntity ; }
Common method to retrieve result entity from IntuitMessage
35,867
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T voidRequest ( T entity ) throws FMSException { IntuitMessage intuitMessage = prepareVoidRequest ( entity ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
Method to cancel the operation for the corresponding entity
35,868
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T upload ( T entity , InputStream docContent ) throws FMSException { IntuitMessage intuitMessage = prepareUpload ( entity , docContent ) ; executeInterceptors ( intuitMessage ) ; return ( T ) getReturnEntity ( intuitMessage ) ; }
Method to upload the given document content for the corresponding entity
35,869
public < T extends IEntity > List < T > upload ( List < UploadEntry > entries ) throws FMSException { List < IntuitMessage > intuitMessages = prepareUpload ( entries ) ; if ( ! intuitMessages . isEmpty ( ) ) { executeInterceptors ( intuitMessages ) ; } return getResultEntities ( intuitMessages ) ; }
Method to upload entities with their correspond binary
35,870
@ SuppressWarnings ( "unchecked" ) private < T extends IEntity > List < T > getResultEntities ( List < IntuitMessage > intuitMessages ) { List < T > resultEntities = new ArrayList < T > ( ) ; int i = 0 ; for ( IntuitMessage intuitMessage : intuitMessages ) { if ( ! isContainResponse ( intuitMessage , i ) ) { LOG . warn ( "Response object with index=" + i + " was expected, got nothing." ) ; } else { resultEntities . add ( ( T ) getReturnEntity ( intuitMessage , i ) ) ; } i ++ ; } return resultEntities ; }
Processes list of intuitMessages and returns list of resultEntities
35,871
private List < IntuitMessage > prepareUpload ( List < UploadEntry > entries ) throws FMSException { List < IntuitMessage > intuitMessages = new ArrayList < IntuitMessage > ( ) ; String boundaryId = null ; for ( UploadEntry item : entries ) { if ( item . isEmpty ( ) ) { LOG . warn ( "UploadEntry instance (hash:" + System . identityHashCode ( item ) + ") has at least one null property. " + "It should have intuit entity and InputStream instances" ) ; } IntuitMessage intuitMessage = prepareUpload ( item . getEntity ( ) , item . getStream ( ) , boundaryId ) ; if ( null == boundaryId ) { boundaryId = intuitMessage . getRequestElements ( ) . getUploadRequestElements ( ) . getBoundaryId ( ) ; } intuitMessages . add ( intuitMessage ) ; } return intuitMessages ; }
Creates list of IntuitMessage instances based on list of entries
35,872
private boolean isContainResponse ( IntuitMessage intuitMessage , int idx ) { List < AttachableResponse > response = ( ( IntuitResponse ) intuitMessage . getResponseElements ( ) . getResponse ( ) ) . getAttachableResponse ( ) ; if ( null == response ) { return false ; } if ( 0 >= response . size ( ) ) { return false ; } if ( idx >= response . size ( ) ) { return false ; } return true ; }
verifies availability of an object in response
35,873
public < T extends IEntity > T sendEmail ( T entity ) throws FMSException { return sendEmail ( entity , null ) ; }
Send entity via email using address associated with this entity in the system
35,874
@ SuppressWarnings ( "unchecked" ) public < T extends IEntity > T sendEmail ( T entity , String email ) throws FMSException { if ( ! isAvailableToEmail ( entity ) ) { throw new FMSException ( "Following entity: " + entity . getClass ( ) . getSimpleName ( ) + " cannot be send as email" ) ; } IntuitMessage intuitMessage = prepareEmail ( entity , email ) ; executeInterceptors ( intuitMessage ) ; return ( T ) retrieveEntity ( intuitMessage ) ; }
Send entity via email using specified address
35,875
public List < CDCQueryResult > executeCDCQuery ( List < ? extends IEntity > entities , String changedSince ) throws FMSException { if ( entities == null || entities . isEmpty ( ) ) { throw new FMSException ( "Entities is required." ) ; } if ( ! StringUtils . hasText ( changedSince ) ) { throw new FMSException ( "changedSince is required." ) ; } IntuitMessage intuitMessage = prepareCDCQuery ( entities , changedSince ) ; executeInterceptors ( intuitMessage ) ; List < CDCQueryResult > cdcQueryResults = null ; IntuitResponse intuitResponse = ( IntuitResponse ) intuitMessage . getResponseElements ( ) . getResponse ( ) ; if ( intuitResponse != null ) { List < CDCResponse > cdcResponses = intuitResponse . getCDCResponse ( ) ; if ( cdcResponses != null ) { cdcQueryResults = getCDCQueryResult ( cdcResponses ) ; } } return cdcQueryResults ; }
Method to retrieve the list of records for the given entities whose last modified date is greater than the given changedSince date
35,876
public void executeBatch ( BatchOperation batchOperation ) throws FMSException { IntuitMessage intuitMessage = prepareBatch ( batchOperation ) ; executeInterceptors ( intuitMessage ) ; IntuitResponse intuitResponse = ( IntuitResponse ) intuitMessage . getResponseElements ( ) . getResponse ( ) ; if ( intuitResponse != null ) { List < BatchItemResponse > batchItemResponses = intuitResponse . getBatchItemResponse ( ) ; if ( batchItemResponses != null && ! batchItemResponses . isEmpty ( ) ) { int count = 0 ; Iterator < BatchItemResponse > itr = batchItemResponses . iterator ( ) ; while ( itr . hasNext ( ) ) { BatchItemResponse batchItemResponse = itr . next ( ) ; String bId = batchItemResponse . getBId ( ) ; if ( ! StringUtils . hasText ( bId ) ) { bId = batchOperation . getBatchItemRequests ( ) . get ( count ) . getBId ( ) ; } if ( batchItemResponse . getFault ( ) != null ) { batchOperation . getFaultResult ( ) . put ( bId , batchItemResponse . getFault ( ) ) ; } else if ( batchItemResponse . getReport ( ) != null ) { batchOperation . getReportResult ( ) . put ( bId , batchItemResponse . getReport ( ) ) ; } else if ( batchItemResponse . getIntuitObject ( ) != null ) { batchOperation . getEntityResult ( ) . put ( bId , ( IEntity ) batchItemResponse . getIntuitObject ( ) . getValue ( ) ) ; } else if ( batchItemResponse . getQueryResponse ( ) != null ) { QueryResult queryResult = getQueryResult ( batchItemResponse . getQueryResponse ( ) ) ; batchOperation . getQueryResult ( ) . put ( bId , queryResult ) ; } else if ( batchItemResponse . getCDCResponse ( ) != null ) { CDCQueryResult cdcQueryResult = getCDCQueryResult ( batchItemResponse . getCDCResponse ( ) ) ; batchOperation . getCDCQueryResult ( ) . put ( bId , cdcQueryResult ) ; } else { LOG . warn ( "BatchItemResponse is not Fault, Entity, Query and Report." ) ; } count ++ ; } } } }
Method to execute the batch operation
35,877
public < T extends IEntity > void findAllAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { String query = "SELECT * FROM " + entity . getClass ( ) . getSimpleName ( ) ; executeQueryAsync ( query , callbackHandler ) ; }
Method to retrieve all records for the given entity in asynchronous fashion Note without pagination this will return only 100 records Use query API to add pagintion and obtain additional records
35,878
public < T extends IEntity > void addAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { IntuitMessage intuitMessage = prepareAdd ( entity ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to add the given entity in asynchronous fashion
35,879
public < T extends IEntity > void deleteAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { IntuitMessage intuitMessage = prepareDelete ( entity ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to delete record for the given entity in asynchronous fashion
35,880
public < T extends IEntity > void updateAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { IntuitMessage intuitMessage = prepareUpdate ( entity ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to update the record of the corresponding entity in asynchronous fashion
35,881
public < T extends IEntity > void findByIdAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { IntuitMessage intuitMessage = prepareFindById ( entity ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to find the record for the given id for the corresponding entity in asynchronous fashion
35,882
public < T extends IEntity > void uploadAsync ( T entity , InputStream docContent , CallbackHandler callbackHandler ) throws FMSException { IntuitMessage intuitMessage = prepareUpload ( entity , docContent ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to upload the file for the given entity in asynchronous fashion
35,883
public < T extends IEntity > void sendEmailAsync ( T entity , CallbackHandler callbackHandler ) throws FMSException { sendEmailAsync ( entity , null , callbackHandler ) ; }
Method to send the entity to default email for the given id in asynchronous fashion
35,884
public < T extends IEntity > void sendEmailAsync ( T entity , String email , CallbackHandler callbackHandler ) throws FMSException { if ( ! isAvailableToEmail ( entity ) ) { throw new FMSException ( "Following entity: " + entity . getClass ( ) . getSimpleName ( ) + " cannot send as email (Async) " ) ; } IntuitMessage intuitMessage = prepareEmail ( entity , email ) ; intuitMessage . getRequestElements ( ) . setCallbackHandler ( callbackHandler ) ; executeAsyncInterceptors ( intuitMessage ) ; }
Method to send the entity to email for the given id in asynchronous fashion
35,885
private < T extends IEntity > IntuitMessage prepareVoidRequest ( T entity ) throws FMSException { IntuitMessage intuitMessage = new IntuitMessage ( ) ; RequestElements requestElements = intuitMessage . getRequestElements ( ) ; Map < String , String > requestParameters = requestElements . getRequestParameters ( ) ; requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . POST . toString ( ) ) ; requestParameters . put ( RequestElements . REQ_PARAM_INCLUDE , OperationType . VOID . toString ( ) ) ; requestElements . setContext ( context ) ; requestElements . setEntity ( entity ) ; requestElements . setObjectToSerialize ( getSerializableObject ( entity ) ) ; return intuitMessage ; }
Common method to prepare the request params for voidRequest operation for both sync and async calls
35,886
private < T extends IEntity > IntuitMessage prepareUpload ( T entity , InputStream docContent , String boundaryId ) throws FMSException { IntuitMessage intuitMessage = new IntuitMessage ( ) ; RequestElements requestElements = intuitMessage . getRequestElements ( ) ; Map < String , String > requestParameters = requestElements . getRequestParameters ( ) ; requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . POST . toString ( ) ) ; UploadRequestElements uploadRequestElements = requestElements . getUploadRequestElements ( ) ; uploadRequestElements . setDocContent ( docContent ) ; uploadRequestElements . setBoundaryId ( utilizeIf ( boundaryId ) ) ; uploadRequestElements . setElementsId ( generateId ( ) . substring ( 0 , 5 ) ) ; requestElements . setAction ( OperationType . UPLOAD . toString ( ) ) ; requestElements . setContext ( context ) ; requestElements . setEntity ( entity ) ; requestElements . setObjectToSerialize ( getSerializableObject ( entity ) ) ; return intuitMessage ; }
Common method to prepare the request params for upload operation for both sync and async calls
35,887
private < T extends IEntity > Object verifyEntityId ( T entity ) throws FMSException { Class < ? > objectClass = entity . getClass ( ) ; Object rid = null ; Method m ; try { m = objectClass . getMethod ( "getId" ) ; rid = m . invoke ( entity ) ; } catch ( Exception e ) { throw new FMSException ( "Unable to read the method getId" , e ) ; } if ( rid == null ) { throw new FMSException ( "Id is required." ) ; } return rid ; }
Verifies that entity has getID method which can be invoked to retrieve entity id
35,888
private < T extends IEntity > IntuitMessage prepareQuery ( String query ) throws FMSException { IntuitMessage intuitMessage = new IntuitMessage ( ) ; RequestElements requestElements = intuitMessage . getRequestElements ( ) ; Map < String , String > requestParameters = requestElements . getRequestParameters ( ) ; if ( query . length ( ) > LENGTH_200 ) { requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . POST . toString ( ) ) ; requestElements . setPostString ( query ) ; } else { requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . GET . toString ( ) ) ; requestParameters . put ( RequestElements . REQ_PARAM_QUERY , query ) ; } requestElements . setAction ( OperationType . QUERY . toString ( ) ) ; requestElements . setContext ( context ) ; return intuitMessage ; }
Common method to prepare the request params for query operation for both sync and async calls
35,889
private < T extends IEntity > IntuitMessage prepareCDCQuery ( List < ? extends IEntity > entities , String changedSince ) throws FMSException { IntuitMessage intuitMessage = new IntuitMessage ( ) ; RequestElements requestElements = intuitMessage . getRequestElements ( ) ; Map < String , String > requestParameters = requestElements . getRequestParameters ( ) ; requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . GET . toString ( ) ) ; if ( entities != null ) { StringBuffer entityParam = new StringBuffer ( ) ; for ( IEntity entity : entities ) { entityParam . append ( entity . getClass ( ) . getSimpleName ( ) ) . append ( "," ) ; } entityParam . delete ( entityParam . length ( ) - 1 , entityParam . length ( ) ) ; requestParameters . put ( RequestElements . REQ_PARAM_ENTITIES , entityParam . toString ( ) ) ; } String cdcChangedSinceParam = null ; String cdcAction = null ; cdcChangedSinceParam = RequestElements . REQ_PARAM_CHANGED_SINCE ; cdcAction = OperationType . CDCQUERY . toString ( ) ; if ( StringUtils . hasText ( changedSince ) ) { requestParameters . put ( cdcChangedSinceParam , changedSince ) ; } requestElements . setAction ( cdcAction ) ; requestElements . setContext ( context ) ; return intuitMessage ; }
Common method to prepare the request params for CDC query operation for both sync and async calls
35,890
private < T extends IEntity > IntuitMessage prepareBatch ( BatchOperation batchOperation ) throws FMSException { IntuitMessage intuitMessage = new IntuitMessage ( ) ; RequestElements requestElements = intuitMessage . getRequestElements ( ) ; Map < String , String > requestParameters = requestElements . getRequestParameters ( ) ; requestParameters . put ( RequestElements . REQ_PARAM_METHOD_TYPE , MethodType . POST . toString ( ) ) ; IntuitBatchRequest intuitBatchRequest = new IntuitBatchRequest ( ) ; intuitBatchRequest . setBatchItemRequest ( batchOperation . getBatchItemRequests ( ) ) ; requestElements . setAction ( OperationType . BATCH . toString ( ) ) ; requestElements . setContext ( context ) ; requestElements . setObjectToSerialize ( getSerializableRequestObject ( intuitBatchRequest ) ) ; requestElements . setBatchOperation ( batchOperation ) ; return intuitMessage ; }
Common method to prepare the request params for batch operation for both sync and async calls
35,891
@ SuppressWarnings ( "unchecked" ) protected < T extends IEntity > Object getSerializableObject ( T object ) throws FMSException { Class < ? > objectClass = object . getClass ( ) ; String methodName = "create" . concat ( objectClass . getSimpleName ( ) ) ; ObjectFactory objectEntity = new ObjectFactory ( ) ; Class < ? > objectEntityClass = objectEntity . getClass ( ) ; Method method = null ; try { method = objectEntityClass . getMethod ( methodName , Class . forName ( objectClass . getName ( ) ) ) ; } catch ( Exception e ) { LOG . error ( "Exception while prepare the method signature using reflection to generate JAXBElement" , e ) ; throw new FMSException ( "Exception while prepare the method signature using reflection to generate JAXBElement" , e ) ; } JAXBElement < ? extends IEntity > jaxbElement = null ; try { jaxbElement = ( JAXBElement < ? extends IEntity > ) method . invoke ( objectEntity , object ) ; } catch ( Exception e ) { LOG . error ( "Exception while invoking the method using reflection to generate JAXBElement" , e ) ; throw new FMSException ( "Exception while prepare the method signature using reflection to generate JAXBElement" , e ) ; } return jaxbElement ; }
Method to get the serializable object for the given entity
35,892
protected QueryResult getQueryResult ( QueryResponse queryResponse ) { QueryResult queryResult = null ; if ( queryResponse != null ) { queryResult = new QueryResult ( ) ; queryResult . setEntities ( getEntities ( queryResponse ) ) ; queryResult . setFault ( queryResponse . getFault ( ) ) ; queryResult . setMaxResults ( queryResponse . getMaxResults ( ) ) ; queryResult . setStartPosition ( queryResponse . getStartPosition ( ) ) ; queryResult . setTotalCount ( queryResponse . getTotalCount ( ) ) ; } return queryResult ; }
Method to read the query response from QueryResponse and set into QueryResult
35,893
protected List < CDCQueryResult > getCDCQueryResult ( List < CDCResponse > cdcResponses ) { List < CDCQueryResult > cdcQueryResults = null ; if ( cdcResponses != null ) { Iterator < CDCResponse > cdcResponseItr = cdcResponses . iterator ( ) ; while ( cdcResponseItr . hasNext ( ) ) { cdcQueryResults = new ArrayList < CDCQueryResult > ( ) ; CDCQueryResult cdcQueryResult = getCDCQueryResult ( cdcResponseItr . next ( ) ) ; cdcQueryResults . add ( cdcQueryResult ) ; } } return cdcQueryResults ; }
Method to get the list of CDCQueryResult object from list of CDCResponse
35,894
protected CDCQueryResult getCDCQueryResult ( CDCResponse cdcResponse ) { CDCQueryResult cdcQueryResult = new CDCQueryResult ( ) ; List < QueryResponse > queryResponses = cdcResponse . getQueryResponse ( ) ; if ( queryResponses != null ) { Map < String , QueryResult > queryResults = new HashMap < String , QueryResult > ( ) ; Iterator < QueryResponse > queryResponseItr = queryResponses . iterator ( ) ; while ( queryResponseItr . hasNext ( ) ) { QueryResponse queryResponse = queryResponseItr . next ( ) ; QueryResult queryResult = getQueryResult ( queryResponse ) ; populateQueryResultsInCDC ( queryResults , queryResult ) ; populateFaultInCDC ( cdcQueryResult , queryResult ) ; } if ( queryResults != null && ! queryResults . isEmpty ( ) ) { cdcQueryResult . setQueryResults ( queryResults ) ; cdcQueryResult . setSize ( cdcResponse . getSize ( ) ) ; } } else if ( cdcResponse . getFault ( ) != null ) { cdcQueryResult . setFalut ( cdcResponse . getFault ( ) ) ; } return cdcQueryResult ; }
Method to construct and return the CDCQueryResult object from CDCResponse
35,895
private void populateQueryResultsInCDC ( Map < String , QueryResult > queryResults , QueryResult queryResult ) { if ( queryResult != null ) { List < ? extends IEntity > entities = queryResult . getEntities ( ) ; if ( entities != null && ! entities . isEmpty ( ) ) { IEntity entity = entities . get ( 0 ) ; String entityName = entity . getClass ( ) . getSimpleName ( ) ; queryResults . put ( entityName , queryResult ) ; } } }
Method to populate the QueryResults hash map by reading the key from QueryResult entities
35,896
private void populateFaultInCDC ( CDCQueryResult cdcQueryResult , QueryResult queryResult ) { if ( queryResult != null ) { Fault fault = queryResult . getFault ( ) ; if ( fault != null ) { cdcQueryResult . setFalut ( fault ) ; } } }
Method to populate the fault in CDCQueryResult if any
35,897
private void readProperties ( ) { InputStream input = null ; try { input = getClass ( ) . getClassLoader ( ) . getResourceAsStream ( PROP_FILE_NAME ) ; if ( input == null ) { logger . info ( "Unnable to find " + PROP_FILE_NAME ) ; return ; } prop . load ( input ) ; } catch ( Exception e ) { logger . info ( "exception in PropertiesConfig readProperties" ) ; } finally { if ( input != null ) { try { input . close ( ) ; } catch ( Exception e ) { logger . info ( "exception in PropertiesConfig readProperties finally" ) ; } } } }
Method to read propeties file and store the data
35,898
private byte [ ] getUploadFileContent ( RequestElements requestElements ) throws FMSException { Attachable attachable = ( Attachable ) requestElements . getEntity ( ) ; InputStream docContent = requestElements . getUploadRequestElements ( ) . getDocContent ( ) ; String mime = getMime ( attachable . getFileName ( ) , "." ) ; mime = ( mime != null ) ? mime : getMime ( attachable . getContentType ( ) , "/" ) ; if ( isImageType ( mime ) ) { return getImageContent ( docContent , mime ) ; } else { return getContent ( docContent ) ; } }
Method to get the file content of the upload file based on the mime type
35,899
private boolean isImageType ( String mime ) { if ( StringUtils . hasText ( mime ) ) { for ( String imageMime : IMAGE_MIMES ) { if ( mime . equalsIgnoreCase ( imageMime ) ) { return true ; } } } return false ; }
Method to validate whether the given mime is an image file