Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.5.5 #896

Open
wants to merge 4 commits into
base: 1.1.5.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import io.mosip.authentication.demo.util.ApplicationResourceContext;
import io.mosip.biometrics.util.ConvertRequestDto;
import io.mosip.biometrics.util.face.FaceDecoder;
import javafx.fxml.FXMLLoader;
Expand Down Expand Up @@ -180,6 +181,8 @@ public class IdaController {
@FXML
private GridPane previewGrid;

private ResourceBundle labelBundle;

@FXML
private void initialize() {
responsetextField.setText(null);
Expand Down Expand Up @@ -209,6 +212,7 @@ private void initialize() {
otpValue.textProperty().addListener((observable, oldValue, newValue) -> {
updateSendButton();
});
labelBundle = ApplicationResourceContext.getInstance().getLabelBundle();
}

@FXML
Expand Down Expand Up @@ -406,7 +410,7 @@ private String getCaptureRequestTemplate() {
}

private String captureFingerprint() throws Exception {
responsetextField.setText("Capturing Fingerprint...");
responsetextField.setText(labelBundle.getString("capturingBiometric"));
responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold");

String requestBody = getCaptureRequestTemplate();
Expand Down Expand Up @@ -452,7 +456,7 @@ private String getFaceDeviceSubId() {
}

private String captureIris() throws Exception {
responsetextField.setText("Capturing Iris...");
responsetextField.setText(labelBundle.getString("capturingIris"));
responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold");

String requestBody = getCaptureRequestTemplate();
Expand All @@ -475,7 +479,7 @@ private String captureIris() throws Exception {
}

private String captureFace() throws Exception {
responsetextField.setText("Capturing Face...");
responsetextField.setText(labelBundle.getString("capturingFace"));
responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold");

String requestBody = getCaptureRequestTemplate();
Expand Down Expand Up @@ -553,7 +557,7 @@ private String capturebiometrics(String requestBody) throws Exception {
}
bR.close();
} catch (IOException e) {
responsetextField.setText("Device connectivity failed....");
responsetextField.setText(labelBundle.getString("deviceConnectivityFailed"));
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
e.printStackTrace();
}
Expand All @@ -571,7 +575,7 @@ private String capturebiometrics(String requestBody) throws Exception {
Map errorMap = (Map) e.get("error");
error = errorMap.get("errorCode").toString();
if (error.equals(DEFAULT_SUBID) || error.equals("100")) {
responsetextField.setText("Capture Success");
responsetextField.setText(labelBundle.getString("captureSuccess"));
responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold");
ObjectMapper objectMapper = new ObjectMapper();
List dataList = (List) objectMapper.readValue(result.getBytes(), Map.class).get("biometrics");
Expand All @@ -583,7 +587,7 @@ private String capturebiometrics(String requestBody) throws Exception {
previousHash = (String) b.get("hash");
}
} else {
responsetextField.setText("Capture Failed");
responsetextField.setText(labelBundle.getString("captureFailed"));
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
break;
}
Expand Down Expand Up @@ -621,15 +625,15 @@ private void onRequestOtp() {
if (response.getStatusCode().is2xxSuccessful()) {
List errors = ((List) response.getBody().get("errors"));
boolean status = errors == null || errors.isEmpty();
String responseText = status ? "OTP Request Success" : "OTP Request Failed";
String responseText = status ? labelBundle.getString("otpRequestSuccess") : labelBundle.getString("otpRequestFail");
if (status) {
responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold");
} else {
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
}
responsetextField.setText(responseText);
} else {
responsetextField.setText("OTP Request Failed with Error");
responsetextField.setText(labelBundle.getString("otpRequestFailedwithError"));
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
}

Expand Down Expand Up @@ -684,7 +688,7 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp
private void onSendAuthRequest() throws Exception {
responsetextField.setText(null);
responsetextField.setStyle("-fx-text-fill: black; -fx-font-size: 20px; -fx-font-weight: bold");
responsetextField.setText("Preparing Auth Request...");
responsetextField.setText(labelBundle.getString("prepareAuthRequest"));
AuthRequestDTO authRequestDTO = new AuthRequestDTO();
// Set Auth Type
AuthTypeDTO authTypeDTO = new AuthTypeDTO();
Expand All @@ -709,7 +713,7 @@ private void onSendAuthRequest() throws Exception {
if (isBioAuthType()) {
identityBlock.put("biometrics", mapper.readValue(capture, Map.class).get("biometrics"));
}
responsetextField.setText("Encrypting Auth Request...");
responsetextField.setText(labelBundle.getString("encryptAuthRequest"));
System.out.println("******* Request before encryption ************ \n\n");
System.out.println(mapper.writeValueAsString(identityBlock));
EncryptionRequestDto encryptionRequestDto = new EncryptionRequestDto();
Expand All @@ -719,11 +723,11 @@ private void onSendAuthRequest() throws Exception {
kernelEncrypt = kernelEncrypt(encryptionRequestDto, false);
} catch (Exception e) {
e.printStackTrace();
responsetextField.setText("Encryption of Auth Request Failed");
responsetextField.setText(labelBundle.getString("encryptAuthRequestFailed"));
return;
}

responsetextField.setText("Authenticating...");
responsetextField.setText(labelBundle.getString("authenticate"));
// Set request block
authRequestDTO.setRequest(requestDTO);

Expand Down Expand Up @@ -757,17 +761,17 @@ private void onSendAuthRequest() throws Exception {
String response;

if(isKycRequired.isSelected()) {
status = (boolean) ((Map<String, Object>) authResponse.getBody().get("response")).get("kycStatus");
response = status ? objectMapper.writeValueAsString(authResponse.getBody().get("response")) : "KYC Request Failed";
status = authResponse.getBody().get("response") != null ? (boolean) ((Map<String, Object>) authResponse.getBody().get("response")).get("kycStatus") : false;
response = status ? objectMapper.writeValueAsString(authResponse.getBody().get("response")) : labelBundle.getString("kycRequestFailed");
if(status) {
loadKYCPreviewPage(response, status);
response = status ? "Authentication Success" : "Authentication Failed";
response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail");
} else {
response = status ? "Authentication Success" : "Authentication Failed";
response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail");
}
} else {
status = (boolean) ((Map<String, Object>) authResponse.getBody().get("response")).get("authStatus");
response = status ? "Authentication Success" : "Authentication Failed";
response = status ? labelBundle.getString("authenticationSuccess") : labelBundle.getString("authenticationFail");
}
if (status) {
responsetextField.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold; scroll-bar:horizontal:enabled");
Expand All @@ -776,15 +780,15 @@ private void onSendAuthRequest() throws Exception {
}
responsetextField.setText(response);
} else {
responsetextField.setText("Authentication Failed with Error");
responsetextField.setText(labelBundle.getString("authenticationFailWithError"));
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
}

System.out.println("Auth Response : \n" + new ObjectMapper().writeValueAsString(authResponse));
System.out.println(authResponse.getBody());
} catch (Exception e) {
e.printStackTrace();
responsetextField.setText("Authentication Failed with Error");
responsetextField.setText(labelBundle.getString("authenticationFailWithError"));
responsetextField.setStyle("-fx-text-fill: red; -fx-font-size: 20px; -fx-font-weight: bold");
}
}
Expand Down Expand Up @@ -960,10 +964,10 @@ public static String getTransactionID() {
@FXML
private void onReset() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Confirm Reset");
alert.setContentText("Are you sure to reset?");
ButtonType okButton = new ButtonType("Yes", ButtonBar.ButtonData.YES);
ButtonType noButton = new ButtonType("No", ButtonBar.ButtonData.NO);
alert.setTitle(labelBundle.getString("confirmreset"));
alert.setContentText(labelBundle.getString("resetComfirmMessage"));
ButtonType okButton = new ButtonType(labelBundle.getString("yes"), ButtonBar.ButtonData.YES);
ButtonType noButton = new ButtonType(labelBundle.getString("no"), ButtonBar.ButtonData.NO);
alert.getButtonTypes().setAll(okButton, noButton);
alert.showAndWait().ifPresent(type -> {
if (type.getButtonData().equals(ButtonType.YES.getButtonData())) {
Expand Down Expand Up @@ -1293,7 +1297,7 @@ private void renderView(JSONObject jsonObject, boolean status) throws Exception
statusLabel.setMaxHeight(100);
statusLabel.setPrefWidth(400);
statusLabel.setAlignment(Pos.CENTER);
statusLabel.setText("EKYC Preview");
statusLabel.setText(labelBundle.getString("ekycPreviewLabel"));
statusLabel.setStyle("-fx-text-fill: green; -fx-font-size: 20px; -fx-font-weight: bold; scroll-bar:horizontal:enabled");

HBox statusHBox1 = new HBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;

import io.mosip.authentication.demo.util.ApplicationResourceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -14,6 +16,7 @@
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import org.springframework.core.env.Environment;

/**
* The Class IdaStarter.
Expand All @@ -38,7 +41,10 @@ public void init() throws Exception {
context = builder.run(getParameters().getRaw().toArray(new String[0]));

loader.setControllerFactory(context::getBean);
ApplicationResourceContext.getInstance().setApplicatioLanguage(context.getEnvironment().getProperty("mosip.primary-language"));
loader.setResources(ApplicationResourceContext.getInstance().getLabelBundle());
root = loader.load(this.getClass().getClassLoader().getResourceAsStream("fxml/idaFXML.fxml"));

context.close();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.mosip.authentication.demo.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Locale;
import java.util.ResourceBundle;

public class ApplicationResourceContext {

String applicatioLanguage;
ResourceBundle labelBundle;

private static ApplicationResourceContext context;
private ApplicationResourceContext() {

}

private void loadResource(){
Locale applicationPrimaryLanguageLocale = new Locale(applicatioLanguage != null ? applicatioLanguage.substring(0, 2) : "en");
labelBundle = ResourceBundle.getBundle("labels", applicationPrimaryLanguageLocale);
}
public static ApplicationResourceContext getInstance() {
if(context == null) {
context = new ApplicationResourceContext();
return context;
} else {
return context;
}
}

public ResourceBundle getLabelBundle() {
return labelBundle;
}

public void setApplicatioLanguage(String applicatioLanguage) {
this.applicatioLanguage = applicatioLanguage;
loadResource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mosip.kernel.crypto.sign-algorithm-name=SHA512withRSA
logging.level.org.springframework=OFF
logging.level.root=OFF
spring.main.banner-mode=off

mosip.primary-language=eng

clientId=mosip-regproc-client
secretKey=abc123
Expand Down
Loading