List of usage examples for com.facebook.react.bridge ReadableMap hasKey
boolean hasKey(@NonNull String name);
From source file:com.amazonaws.reactnative.core.AWSRNCognitoCredentials.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) throws IllegalArgumentException { if (!options.hasKey(IDENTITY_POOL_ID) || !options.hasKey(REGION)) { throw new IllegalArgumentException("identity_pool_id and/or region not supplied"); } else {//from w ww . j a v a2 s . c o m credentialsProvider = new CognitoCachingCredentialsProvider(getReactApplicationContext(), options.getString(IDENTITY_POOL_ID), Regions.fromName(options.getString(REGION)), new AWSRNClientConfiguration().withUserAgent(SERVICE_NAME)); credentialsProvider.registerIdentityChangedListener(new IdentityChangedListener() { @Override public void identityChanged(final String oldidentityid, final String newidentityid) { final WritableMap params = Arguments.createMap(); params.putString(CURRENT, newidentityid); params.putString(PREVIOUS, oldidentityid); sendEvent(getReactApplicationContext(), IDENTITYCHANGE, params); } }); } }
From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) { if (!options.hasKey("region")) { throw new IllegalArgumentException("expected region key"); }/*from w ww . j a va 2s. c om*/ final AWSRNCognitoCredentials credentials = this.getReactApplicationContext() .getNativeModule(AWSRNCognitoCredentials.class); if (credentials.getCredentialsProvider() == null) { throw new IllegalArgumentException("AWSCognitoCredentials is not initialized"); } gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer()) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create(); dynamodbClient = new AmazonDynamoDBClient(credentials.getCredentialsProvider(), new AWSRNClientConfiguration().withUserAgent("DynamoDB")); dynamodbClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region")))); }
From source file:com.amazonaws.reactnative.lambda.AWSRNLambdaClient.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) { if (!options.hasKey("region")) { throw new IllegalArgumentException("expected region key"); }//from w w w . j a v a 2 s .c o m final AWSRNCognitoCredentials credentials = this.getReactApplicationContext() .getNativeModule(AWSRNCognitoCredentials.class); if (credentials.getCredentialsProvider() == null) { throw new IllegalArgumentException("AWSCognitoCredentials is not initialized"); } gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer()) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create(); lambdaClient = new AWSLambdaClient(credentials.getCredentialsProvider(), new AWSRNClientConfiguration().withUserAgent("Lambda")); lambdaClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region")))); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) { if (!options.hasKey(REGION)) { throw new IllegalArgumentException("region not supplied"); }/* w ww . j ava2 s . co m*/ final AWSRNCognitoCredentials credentials = this.getReactApplicationContext() .getNativeModule(AWSRNCognitoCredentials.class); if (credentials.getCredentialsProvider() == null) { throw new IllegalArgumentException("AWSCognitoCredentials is not initialized"); } final AmazonS3 s3 = new AmazonS3Client(credentials.getCredentialsProvider(), new AWSRNClientConfiguration().withUserAgent("AWSS3TransferUtility")); s3.setRegion(Region.getRegion(Regions.fromName(options.getString(REGION)))); transferUtility = new TransferUtility(s3, getReactApplicationContext()); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void createDownloadRequest(final ReadableMap options, final Callback callback) { if (requestMap == null) { callback.invoke("Error: AWSS3TransferUtility is not initialized", null); return;//w w w . j ava 2s. c o m } final String[] params = { BUCKET, KEY, PATH, SUBSCRIBE, COMPLETIONHANDLER }; for (int i = 0; i < params.length; i++) { if (!options.hasKey(params[i])) { callback.invoke(params[i] + " is not supplied", null); return; } } final Map<String, Object> map = new ConcurrentHashMap<>(); map.put(BUCKET, options.getString(BUCKET)); map.put(KEY, options.getString(KEY)); map.put(PATH, Environment.getExternalStorageDirectory() + options.getString(PATH)); map.put(TYPE, DOWNLOAD); map.put(SUBSCRIBE, options.getBoolean(SUBSCRIBE)); map.put(COMPLETIONHANDLER, options.getBoolean(COMPLETIONHANDLER)); final UUID uuid = UUID.randomUUID(); requestMap.put(uuid.toString(), map); callback.invoke(null, uuid.toString()); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void download(final ReadableMap options, final Promise promise) { if (!options.hasKey(REQUESTID)) { throw new IllegalArgumentException("requestid is not supplied"); }//from w w w .ja va 2 s .co m final String requestID = options.getString(REQUESTID); final Map<String, Object> map = requestMap.get(requestID); if (map == null) { throw new IllegalArgumentException("requestid is invalid"); } final TransferObserver observer; try { observer = transferUtility.download((String) map.get(BUCKET), (String) map.get(KEY), new File((String) map.get(PATH))); } catch (final AmazonServiceException e) { promise.reject(e.getErrorCode(), e.getErrorMessage(), e); return; } catch (final AmazonClientException e) { promise.reject("", e.getMessage(), e); return; } transferIDMap.put(observer.getId(), requestID); map.put(TRANSFERID, observer.getId()); if ((Boolean) map.get(SUBSCRIBE)) { this.subscribe(observer); } promise.resolve("success"); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void createUploadRequest(final ReadableMap options, final Callback callback) { if (requestMap == null) { callback.invoke("Error: AWSS3TransferUtility is not initialized", null); return;/* ww w . ja v a 2s .c om*/ } final String[] params = { BUCKET, KEY, PATH, SUBSCRIBE, COMPLETIONHANDLER }; for (int i = 0; i < params.length; i++) { if (!options.hasKey(params[i])) { callback.invoke(params[i] + " is not supplied", null); return; } } final Map<String, Object> map = new ConcurrentHashMap<>(); map.put(BUCKET, options.getString(BUCKET)); map.put(KEY, options.getString(KEY)); map.put(PATH, options.getString(PATH)); map.put(SUBSCRIBE, options.getBoolean(SUBSCRIBE)); map.put(COMPLETIONHANDLER, options.getBoolean(COMPLETIONHANDLER)); map.put(TYPE, UPLOAD); final UUID uuid = UUID.randomUUID(); requestMap.put(uuid.toString(), map); callback.invoke(null, uuid.toString()); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void upload(final ReadableMap options, final Promise promise) { if (!options.hasKey(REQUESTID)) { throw new IllegalArgumentException("requestid is not supplied"); }//from www . j a va 2 s .c om final String requestID = options.getString(REQUESTID); final Map<String, Object> map = requestMap.get(requestID); if (map == null) { throw new IllegalArgumentException("requestid is invalid"); } final TransferObserver observer; try { observer = transferUtility.upload((String) map.get(BUCKET), (String) map.get(KEY), new File((String) map.get(PATH))); } catch (final AmazonServiceException e) { promise.reject(e.getErrorCode(), e.getErrorMessage(), e); return; } catch (final AmazonClientException e) { promise.reject("", e.getMessage(), e); return; } transferIDMap.put(observer.getId(), requestID); map.put(TRANSFERID, observer.getId()); if ((Boolean) map.get(SUBSCRIBE)) { this.subscribe(observer); } promise.resolve("success"); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void editRequest(final ReadableMap options) { if (!options.hasKey(CONFIG)) { throw new IllegalArgumentException("config not supplied"); }/*from ww w . j ava 2 s. co m*/ final String config = options.getString(CONFIG); String option = null; if (options.hasKey(OPTION)) { option = options.getString(OPTION); } String request = null; if (options.hasKey(REQUEST)) { request = options.getString(REQUEST); } if (option == null && request == null) { throw new IllegalArgumentException("request and option not supplied. Please supply one"); } if (option != null && request != null) { throw new IllegalArgumentException("request and option are both supplied. Please only supply one"); } if (config.contentEquals(PAUSE)) { this.pause(request, option); } else if (config.contentEquals(RESUME)) { this.resume(request, option); } else if (config.contentEquals(CANCEL)) { this.cancel(request, option); } }
From source file:com.amazonaws.reactnative.sns.AWSRNSNSClient.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) { if (!options.hasKey("region")) { throw new IllegalArgumentException("expected region key"); }//from w w w.ja v a2s .co m final AWSRNCognitoCredentials credentials = this.getReactApplicationContext() .getNativeModule(AWSRNCognitoCredentials.class); if (credentials.getCredentialsProvider() == null) { throw new IllegalArgumentException("AWSCognitoCredentials is not initialized"); } gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer()) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create(); snsClient = new AmazonSNSClient(credentials.getCredentialsProvider(), new AWSRNClientConfiguration().withUserAgent("SNS")); snsClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region")))); }