Skip to content

Commit

Permalink
Merge pull request #36 from nidp/Merging_from_document_scanner
Browse files Browse the repository at this point in the history
Merging from document scanner
  • Loading branch information
Piyush7034 authored Aug 1, 2023
2 parents b94cdae + d83f252 commit 3b86e9c
Show file tree
Hide file tree
Showing 28 changed files with 1,714 additions and 132 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import io.mosip.registration_client.api_services.BiometricsDetailsApi;
import io.mosip.registration_client.api_services.CommonDetailsApi;
import io.mosip.registration_client.api_services.DemographicsDetailsApi;
import io.mosip.registration_client.api_services.DocumentDetailsApi;

import io.mosip.registration_client.api_services.DynamicDetailsApi;
import io.mosip.registration_client.api_services.MachineDetailsApi;
import io.mosip.registration_client.api_services.PacketAuthenticationApi;
Expand Down Expand Up @@ -131,4 +133,10 @@ DemographicsDetailsApi getDemographicsDetailsApi(RegistrationService registratio
DynamicDetailsApi getDynamicDetailsApi(MasterDataService masterDataService) {
return new DynamicDetailsApi(masterDataService);
}

@Provides
@Singleton
DocumentDetailsApi getDocumentDetailsApi(RegistrationService registrationService) {
return new DocumentDetailsApi(registrationService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.mosip.registration_client.api_services.BiometricsDetailsApi;
import io.mosip.registration_client.api_services.CommonDetailsApi;
import io.mosip.registration_client.api_services.DemographicsDetailsApi;
import io.mosip.registration_client.api_services.DocumentDetailsApi;
import io.mosip.registration_client.api_services.DynamicDetailsApi;
import io.mosip.registration_client.api_services.MachineDetailsApi;
import io.mosip.registration_client.api_services.PacketAuthenticationApi;
Expand All @@ -58,6 +59,7 @@
import io.mosip.registration_client.model.ProcessSpecPigeon;
import io.mosip.registration_client.model.RegistrationDataPigeon;
import io.mosip.registration_client.model.UserPigeon;
import io.mosip.registration_client.model.DocumentDataPigeon;

public class MainActivity extends FlutterActivity {
private static final String REG_CLIENT_CHANNEL = "com.flutter.dev/io.mosip.get-package-instance";
Expand Down Expand Up @@ -121,6 +123,10 @@ public class MainActivity extends FlutterActivity {
@Inject
DemographicsDetailsApi demographicsDetailsApi;

@Inject
DocumentDetailsApi documentDetailsApi;


@Inject
DynamicDetailsApi dynamicDetailsApi;

Expand Down Expand Up @@ -157,6 +163,8 @@ public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
RegistrationDataPigeon.RegistrationDataApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), registrationApi);
PacketAuthPigeon.PacketAuthApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), packetAuthenticationApi);
DemographicsDataPigeon.DemographicsApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), demographicsDetailsApi);
DocumentDataPigeon.DocumentApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), documentDetailsApi);

DynamicResponsePigeon.DynamicResponseApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), dynamicDetailsApi);

new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), REG_CLIENT_CHANNEL)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.mosip.registration_client.api_services;

import android.util.Log;

import androidx.annotation.NonNull;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import io.mosip.registration.clientmanager.spi.RegistrationService;
import io.mosip.registration_client.model.DocumentDataPigeon;

import org.apache.commons.lang3.ArrayUtils;

@Singleton
public class DocumentDetailsApi implements DocumentDataPigeon.DocumentApi {
private final RegistrationService registrationService;

@Inject
public DocumentDetailsApi(RegistrationService registrationService) {
this.registrationService = registrationService;
}


@Override
public void addDocument(@NonNull String fieldId, @NonNull String docType, @NonNull String reference, @NonNull List<String> bytes, @NonNull DocumentDataPigeon.Result<Void> result) {
byte[] byteArray = new byte[0];
for (String str : bytes) {
byteArray = ArrayUtils.addAll(byteArray, str.getBytes());
}
try {

this.registrationService.getRegistrationDto().addDocument(fieldId, docType,reference,byteArray);
Log.e(getClass().getSimpleName(), "Document Added!"+this.registrationService.getRegistrationDto().getDocuments() );
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Add Document failed!" + Arrays.toString(e.getStackTrace()));
}
}

@Override
public void removeDocument(@NonNull String fieldId, @NonNull Long pageIndex, @NonNull DocumentDataPigeon.Result<Void> result) {

}

@Override
public void getScannedPages(@NonNull String fieldId, @NonNull DocumentDataPigeon.Result<List<String>> result) {

}

@Override
public void hasDocument(@NonNull String fieldId, @NonNull DocumentDataPigeon.Result<Boolean> result) {

}

@Override
public void removeDocumentField(@NonNull String fieldId, @NonNull DocumentDataPigeon.Result<Void> result) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ public void getLocationValues(@NonNull String hierarchyLevelName, @NonNull Strin
}
result.success(locationResponse);
}
@Override
public void getDocumentValues(@NonNull String categoryCode, String applicantType,@NonNull String langCode,@NonNull DynamicResponsePigeon.Result<List<String>> result){

List<String> documentResponse=new ArrayList<>();
try{
documentResponse=this.masterDataService.getDocumentTypes(categoryCode,applicantType,langCode);
Log.e(getClass().getSimpleName(), "Fetch Document values: " + documentResponse);
}catch(Exception e){
Log.e(getClass().getSimpleName(), "Fetch document values: " + Arrays.toString(e.getStackTrace()));
}
result.success(documentResponse);

}
}
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
17 changes: 8 additions & 9 deletions ios/Runner/pigeon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
NS_ASSUME_NONNULL_BEGIN


/// The codec used by RegistrationDataApi.
NSObject<FlutterMessageCodec> *RegistrationDataApiGetCodec(void);

@protocol RegistrationDataApi
- (void)startRegistrationLanguages:(NSArray<NSString *> *)languages completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)evaluateMVELFieldData:(NSString *)fieldData expression:(NSString *)expression completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion;
- (void)getPreviewTemplateIsPreview:(NSNumber *)isPreview completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)submitRegistrationDtoMakerName:(NSString *)makerName completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
/// The codec used by DynamicResponseApi.
NSObject<FlutterMessageCodec> *DynamicResponseApiGetCodec(void);

@protocol DynamicResponseApi
- (void)getFieldValuesFieldName:(NSString *)fieldName langCode:(NSString *)langCode completion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
- (void)getLocationValuesHierarchyLevelName:(NSString *)hierarchyLevelName langCode:(NSString *)langCode completion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
- (void)getDocumentValuesCategoryCode:(NSString *)categoryCode applicantType:(nullable NSString *)applicantType langCode:(NSString *)langCode completion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
@end

extern void RegistrationDataApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<RegistrationDataApi> *_Nullable api);
extern void DynamicResponseApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<DynamicResponseApi> *_Nullable api);

NS_ASSUME_NONNULL_END
58 changes: 21 additions & 37 deletions ios/Runner/pigeon.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
return (result == [NSNull null]) ? nil : result;
}

NSObject<FlutterMessageCodec> *RegistrationDataApiGetCodec(void) {
NSObject<FlutterMessageCodec> *DynamicResponseApiGetCodec(void) {
static FlutterStandardMessageCodec *sSharedObject = nil;
sSharedObject = [FlutterStandardMessageCodec sharedInstance];
return sSharedObject;
}

void RegistrationDataApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<RegistrationDataApi> *api) {
void DynamicResponseApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<DynamicResponseApi> *api) {
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.RegistrationDataApi.startRegistration"
initWithName:@"dev.flutter.pigeon.DynamicResponseApi.getFieldValues"
binaryMessenger:binaryMessenger
codec:RegistrationDataApiGetCodec()];
codec:DynamicResponseApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(startRegistrationLanguages:completion:)], @"RegistrationDataApi api (%@) doesn't respond to @selector(startRegistrationLanguages:completion:)", api);
NSCAssert([api respondsToSelector:@selector(getFieldValuesFieldName:langCode:completion:)], @"DynamicResponseApi api (%@) doesn't respond to @selector(getFieldValuesFieldName:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSArray<NSString *> *arg_languages = GetNullableObjectAtIndex(args, 0);
[api startRegistrationLanguages:arg_languages completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
NSString *arg_fieldName = GetNullableObjectAtIndex(args, 0);
NSString *arg_langCode = GetNullableObjectAtIndex(args, 1);
[api getFieldValuesFieldName:arg_fieldName langCode:arg_langCode completion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand All @@ -55,16 +56,16 @@ void RegistrationDataApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObje
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.RegistrationDataApi.evaluateMVEL"
initWithName:@"dev.flutter.pigeon.DynamicResponseApi.getLocationValues"
binaryMessenger:binaryMessenger
codec:RegistrationDataApiGetCodec()];
codec:DynamicResponseApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(evaluateMVELFieldData:expression:completion:)], @"RegistrationDataApi api (%@) doesn't respond to @selector(evaluateMVELFieldData:expression:completion:)", api);
NSCAssert([api respondsToSelector:@selector(getLocationValuesHierarchyLevelName:langCode:completion:)], @"DynamicResponseApi api (%@) doesn't respond to @selector(getLocationValuesHierarchyLevelName:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSString *arg_fieldData = GetNullableObjectAtIndex(args, 0);
NSString *arg_expression = GetNullableObjectAtIndex(args, 1);
[api evaluateMVELFieldData:arg_fieldData expression:arg_expression completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) {
NSString *arg_hierarchyLevelName = GetNullableObjectAtIndex(args, 0);
NSString *arg_langCode = GetNullableObjectAtIndex(args, 1);
[api getLocationValuesHierarchyLevelName:arg_hierarchyLevelName langCode:arg_langCode completion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand All @@ -75,34 +76,17 @@ void RegistrationDataApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObje
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.RegistrationDataApi.getPreviewTemplate"
initWithName:@"dev.flutter.pigeon.DynamicResponseApi.getDocumentValues"
binaryMessenger:binaryMessenger
codec:RegistrationDataApiGetCodec()];
codec:DynamicResponseApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getPreviewTemplateIsPreview:completion:)], @"RegistrationDataApi api (%@) doesn't respond to @selector(getPreviewTemplateIsPreview:completion:)", api);
NSCAssert([api respondsToSelector:@selector(getDocumentValuesCategoryCode:applicantType:langCode:completion:)], @"DynamicResponseApi api (%@) doesn't respond to @selector(getDocumentValuesCategoryCode:applicantType:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSNumber *arg_isPreview = GetNullableObjectAtIndex(args, 0);
[api getPreviewTemplateIsPreview:arg_isPreview completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.RegistrationDataApi.submitRegistrationDto"
binaryMessenger:binaryMessenger
codec:RegistrationDataApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(submitRegistrationDtoMakerName:completion:)], @"RegistrationDataApi api (%@) doesn't respond to @selector(submitRegistrationDtoMakerName:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSString *arg_makerName = GetNullableObjectAtIndex(args, 0);
[api submitRegistrationDtoMakerName:arg_makerName completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
NSString *arg_categoryCode = GetNullableObjectAtIndex(args, 0);
NSString *arg_applicantType = GetNullableObjectAtIndex(args, 1);
NSString *arg_langCode = GetNullableObjectAtIndex(args, 2);
[api getDocumentValuesCategoryCode:arg_categoryCode applicantType:arg_applicantType langCode:arg_langCode completion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand Down
71 changes: 71 additions & 0 deletions lib/platform_android/document_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:registration_client/pigeon/document_pigeon.dart';
import 'package:registration_client/platform_spi/document.dart';

class DocumentImpl implements Document {
@override
Future<void> addDocument(String fieldId, String docType, String reference,
List<String> bytes) async {
try {
await DocumentApi().addDocument(fieldId, docType, reference, bytes);
} on PlatformException {
debugPrint('DocumentApi call failed');
} catch (e) {
debugPrint('Document not added ${e.toString()}');
}
}

@override
Future<void> removeDocument(String fieldId, int pageIndex) async {
try {
await DocumentApi().removeDocument(fieldId, pageIndex);
} on PlatformException {
debugPrint('DocumentApi call failed');
} catch (e) {
debugPrint('Document not removed ${e.toString()}');
}
}

@override
Future<List<String?>> getScannedPages(String fieldId) async {
List<String?> scannedPages = [];
try {
scannedPages = await DocumentApi().getScannedPages(fieldId);
} on PlatformException {
debugPrint('DocumentApi call failed');
} catch (e) {
debugPrint('get scanned pages failed ${e.toString()}');
}
return scannedPages;
}

@override
Future<bool?> hasDocument(String fieldId) async {
bool hasdocument = false;
try {
hasdocument = await DocumentApi().hasDocument(fieldId);
} on PlatformException {
debugPrint('DocumentApi call failed');
} catch (e) {
debugPrint('has document call failed ${e.toString()}');
}
return hasdocument;
}

@override
Future<bool?> removeDocumentField(String fieldId) async {
bool removeDocument = false;
try {
await DocumentApi().removeDocumentField(fieldId);
} on PlatformException {
debugPrint('DocumentApi call failed');
} catch (e) {
debugPrint('remove document field failed ${e.toString()}');
}
}
}

Document getDocumentImpl() => DocumentImpl();
Loading

0 comments on commit 3b86e9c

Please sign in to comment.