Skip to content

Commit

Permalink
Added review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush-shukla03_infosys committed Jun 27, 2023
1 parent 98d9d4f commit bb047a3
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ app.*.map.json
# Android Pigeon generated files
/android/app/src/main/java/io/mosip/registration_client/model

# IOS Pigeon generated files
/ios/pigeon.h
/ios/pigeon.m

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Application;
import android.content.Context;


import androidx.annotation.NonNull;

import javax.inject.Singleton;
Expand All @@ -15,15 +14,13 @@
import io.mosip.registration.clientmanager.repository.IdentitySchemaRepository;
import io.mosip.registration.clientmanager.repository.RegistrationCenterRepository;
import io.mosip.registration.clientmanager.service.LoginService;

import io.mosip.registration.clientmanager.spi.AuditManagerService;
import io.mosip.registration.clientmanager.spi.MasterDataService;
import io.mosip.registration.clientmanager.spi.SyncRestService;
import io.mosip.registration.clientmanager.util.SyncRestUtil;
import io.mosip.registration.keymanager.spi.ClientCryptoManagerService;
import io.mosip.registration_client.api_services.AuthenticationApi;

import io.mosip.registration_client.api_services.CommonApiImpl;
import io.mosip.registration_client.api_services.CommonDetailsApi;
import io.mosip.registration_client.api_services.MachineDetailsApi;
import io.mosip.registration_client.api_services.ProcessSpecDetailsApi;
import io.mosip.registration_client.api_services.UserDetailsApi;
Expand Down Expand Up @@ -78,8 +75,8 @@ AuthenticationApi getAuthenticationApi(SyncRestService syncRestService,

@Provides
@Singleton
CommonApiImpl getCommonApiImpl(MasterDataService masterDataService){
return new CommonApiImpl(masterDataService);
CommonDetailsApi getCommonApiImpl(MasterDataService masterDataService){
return new CommonDetailsApi(masterDataService);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@
import io.mosip.registration.clientmanager.spi.SyncRestService;
import io.mosip.registration.clientmanager.util.SyncRestUtil;
import io.mosip.registration.keymanager.spi.ClientCryptoManagerService;

import io.mosip.registration_client.api_services.CommonApiImpl;

import io.mosip.registration_client.api_services.AuthenticationApi;

import io.mosip.registration_client.api_services.CommonDetailsApi;
import io.mosip.registration_client.api_services.MachineDetailsApi;
import io.mosip.registration_client.api_services.ProcessSpecDetailsApi;
import io.mosip.registration_client.api_services.UserDetailsApi;

import io.mosip.registration_client.model.CommonApiPigeon;

import io.mosip.registration_client.model.AuthResponsePigeon;

import io.mosip.registration_client.model.CommonDetailsPigeon;
import io.mosip.registration_client.model.MachinePigeon;
import io.mosip.registration_client.model.ProcessSpecPigeon;
import io.mosip.registration_client.model.UserPigeon;
Expand Down Expand Up @@ -94,7 +88,7 @@ public class MainActivity extends FlutterActivity {
UserDetailsApi userDetailsApi;

@Inject
CommonApiImpl commonApiImpl;
CommonDetailsApi commonDetailsApi;

@Inject
AuthenticationApi authenticationApi;
Expand Down Expand Up @@ -127,7 +121,7 @@ public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
initializeAppComponent();
MachinePigeon.MachineApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), machineDetailsApi);
UserPigeon.UserApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), userDetailsApi);
CommonApiPigeon.CommonApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(),commonApiImpl);
CommonDetailsPigeon.CommonDetailsApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(),commonDetailsApi);
AuthResponsePigeon.AuthResponseApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), authenticationApi);
ProcessSpecPigeon.ProcessSpecApi.setup(flutterEngine.getDartExecutor().getBinaryMessenger(), processSpecDetailsApi);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public AuthenticationApi(Context context, SyncRestService syncRestService, SyncR
Context.MODE_PRIVATE);
}

private AuthResponsePigeon.AuthResponse getAuthErrorResponse(String errorCode) {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode(errorCode)
.build();

return authResponse;
}

private void doLogin(final String username, final String password, AuthResponsePigeon.Result<AuthResponsePigeon.AuthResponse> result) {
Call<ResponseWrapper<String>> call = syncRestService.login(syncRestFactory.getAuthRequest(username, password));
call.enqueue(new Callback<ResponseWrapper<String>>() {
Expand Down Expand Up @@ -92,67 +105,32 @@ public void onResponse(Call call, Response response) {
} else {
errorCode = error.getMessage();
}
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode(errorCode)
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse(errorCode);
result.success(authResponse);
return;
}
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_TRY_AGAIN")
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse("REG_TRY_AGAIN");
result.success(authResponse);
}

@Override
public void onFailure(Call call, Throwable t) {
Log.e(getClass().getSimpleName(), "Login Failure! ");
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_NETWORK_ERROR")
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse("REG_NETWORK_ERROR");
result.success(authResponse);
}
});
}

private void offlineLogin(final String username, final String password, AuthResponsePigeon.Result<AuthResponsePigeon.AuthResponse> result) {
if(!loginService.isPasswordPresent(username)) {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_CRED_EXPIRED")
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse("REG_CRED_EXPIRED");
result.success(authResponse);
return;
}

if(!loginService.validatePassword(username, password)) {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_INVALID_REQUEST")
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse("REG_INVALID_REQUEST");
result.success(authResponse);
return;
}
Expand All @@ -169,26 +147,11 @@ private void offlineLogin(final String username, final String password, AuthResp
.build();
result.success(authResponse);
} else {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_CRED_EXPIRED")
.build();
AuthResponsePigeon.AuthResponse authResponse = getAuthErrorResponse("REG_CRED_EXPIRED");
result.success(authResponse);
}
} catch (Exception ex) {
Log.e(getClass().getSimpleName(), "Some error occurred!");
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_CRED_EXPIRED")
.build();
result.error(ex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@

import io.mosip.registration.clientmanager.dto.registration.GenericValueDto;
import io.mosip.registration.clientmanager.spi.MasterDataService;
import io.mosip.registration_client.model.CommonApiPigeon;
import io.mosip.registration_client.model.CommonDetailsPigeon;

@Singleton
public class CommonApiImpl implements CommonApiPigeon.CommonApi {
public class CommonDetailsApi implements CommonDetailsPigeon.CommonDetailsApi {

MasterDataService masterDataService;

@Inject
public CommonApiImpl(MasterDataService masterDataService){
public CommonDetailsApi(MasterDataService masterDataService){
this.masterDataService=masterDataService;
}

@Override
public void getTemplateContent(@NonNull String templateName, @NonNull String langCode, @NonNull CommonApiPigeon.Result<String> result) {
public void getTemplateContent(@NonNull String templateName, @NonNull String langCode, @NonNull CommonDetailsPigeon.Result<String> result) {
String response=masterDataService.getTemplateContent(templateName,langCode);
result.success(response);
}

@Override
public void getPreviewTemplateContent(@NonNull String templateTypeCode, @NonNull String langCode, @NonNull CommonApiPigeon.Result<String> result) {
public void getPreviewTemplateContent(@NonNull String templateTypeCode, @NonNull String langCode, @NonNull CommonDetailsPigeon.Result<String> result) {
String response=masterDataService.getPreviewTemplateContent(templateTypeCode,langCode);
result.success(response);
}

@Override
public void getDocumentTypes(@NonNull String categoryCode, @NonNull String applicantType, @NonNull String langCode, @NonNull CommonApiPigeon.Result<List<String>> result) {
public void getDocumentTypes(@NonNull String categoryCode, @NonNull String applicantType, @NonNull String langCode, @NonNull CommonDetailsPigeon.Result<List<String>> result) {
List<String> response=masterDataService.getDocumentTypes(categoryCode,applicantType,langCode);
result.success(response);
}

@Override
public void getFieldValues(@NonNull String fieldName, @NonNull String langCode, @NonNull CommonApiPigeon.Result<List<String>> result) {
public void getFieldValues(@NonNull String fieldName, @NonNull String langCode, @NonNull CommonDetailsPigeon.Result<List<String>> result) {
List<GenericValueDto> output=masterDataService.getFieldValues(fieldName,langCode);
List<String> response=new ArrayList<>();
output.forEach((value)->{response.add(value.toString());});
Expand Down
17 changes: 9 additions & 8 deletions ios/Runner/pigeon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
NS_ASSUME_NONNULL_BEGIN


/// The codec used by ProcessSpecApi.
NSObject<FlutterMessageCodec> *ProcessSpecApiGetCodec(void);

@protocol ProcessSpecApi
- (void)getUISchemaWithCompletion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)getStringValueGlobalParamKey:(NSString *)key completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)getNewProcessSpecWithCompletion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
/// The codec used by CommonDetailsApi.
NSObject<FlutterMessageCodec> *CommonDetailsApiGetCodec(void);

@protocol CommonDetailsApi
- (void)getTemplateContentTemplateName:(NSString *)templateName langCode:(NSString *)langCode completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)getPreviewTemplateContentTemplateTypeCode:(NSString *)templateTypeCode langCode:(NSString *)langCode completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion;
- (void)getDocumentTypesCategoryCode:(NSString *)categoryCode applicantType:(NSString *)applicantType langCode:(NSString *)langCode completion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
- (void)getFieldValuesFieldName:(NSString *)fieldName langCode:(NSString *)langCode completion:(void (^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
@end

extern void ProcessSpecApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<ProcessSpecApi> *_Nullable api);
extern void CommonDetailsApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CommonDetailsApi> *_Nullable api);

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

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

void ProcessSpecApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<ProcessSpecApi> *api) {
void CommonDetailsApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CommonDetailsApi> *api) {
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.ProcessSpecApi.getUISchema"
initWithName:@"dev.flutter.pigeon.CommonDetailsApi.getTemplateContent"
binaryMessenger:binaryMessenger
codec:ProcessSpecApiGetCodec()];
codec:CommonDetailsApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getUISchemaWithCompletion:)], @"ProcessSpecApi api (%@) doesn't respond to @selector(getUISchemaWithCompletion:)", api);
NSCAssert([api respondsToSelector:@selector(getTemplateContentTemplateName:langCode:completion:)], @"CommonDetailsApi api (%@) doesn't respond to @selector(getTemplateContentTemplateName:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
[api getUISchemaWithCompletion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
NSArray *args = message;
NSString *arg_templateName = GetNullableObjectAtIndex(args, 0);
NSString *arg_langCode = GetNullableObjectAtIndex(args, 1);
[api getTemplateContentTemplateName:arg_templateName langCode:arg_langCode completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.CommonDetailsApi.getPreviewTemplateContent"
binaryMessenger:binaryMessenger
codec:CommonDetailsApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getPreviewTemplateContentTemplateTypeCode:langCode:completion:)], @"CommonDetailsApi api (%@) doesn't respond to @selector(getPreviewTemplateContentTemplateTypeCode:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSString *arg_templateTypeCode = GetNullableObjectAtIndex(args, 0);
NSString *arg_langCode = GetNullableObjectAtIndex(args, 1);
[api getPreviewTemplateContentTemplateTypeCode:arg_templateTypeCode langCode:arg_langCode completion:^(NSString *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand All @@ -48,15 +71,17 @@ void ProcessSpecApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<Pr
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.ProcessSpecApi.getStringValueGlobalParam"
initWithName:@"dev.flutter.pigeon.CommonDetailsApi.getDocumentTypes"
binaryMessenger:binaryMessenger
codec:ProcessSpecApiGetCodec()];
codec:CommonDetailsApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getStringValueGlobalParamKey:completion:)], @"ProcessSpecApi api (%@) doesn't respond to @selector(getStringValueGlobalParamKey:completion:)", api);
NSCAssert([api respondsToSelector:@selector(getDocumentTypesCategoryCode:applicantType:langCode:completion:)], @"CommonDetailsApi api (%@) doesn't respond to @selector(getDocumentTypesCategoryCode:applicantType:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSString *arg_key = GetNullableObjectAtIndex(args, 0);
[api getStringValueGlobalParamKey:arg_key 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 getDocumentTypesCategoryCode:arg_categoryCode applicantType:arg_applicantType langCode:arg_langCode completion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
Expand All @@ -67,13 +92,16 @@ void ProcessSpecApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<Pr
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.ProcessSpecApi.getNewProcessSpec"
initWithName:@"dev.flutter.pigeon.CommonDetailsApi.getFieldValues"
binaryMessenger:binaryMessenger
codec:ProcessSpecApiGetCodec()];
codec:CommonDetailsApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getNewProcessSpecWithCompletion:)], @"ProcessSpecApi api (%@) doesn't respond to @selector(getNewProcessSpecWithCompletion:)", api);
NSCAssert([api respondsToSelector:@selector(getFieldValuesFieldName:langCode:completion:)], @"CommonDetailsApi api (%@) doesn't respond to @selector(getFieldValuesFieldName:langCode:completion:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
[api getNewProcessSpecWithCompletion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
NSArray *args = message;
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 Down
Loading

0 comments on commit bb047a3

Please sign in to comment.