Search in sources :

Example 1 with Hardware

use of org.flyve.inventory.categories.Hardware in project android-mdm-agent by flyve-mdm.

the class EnrollmentModel method enroll.

@Override
public void enroll(final Activity activity, final List<UserData.EmailsData> arrEmails, final String firstName, final String lastName, final String phone, final String phone2, final String mobilePhone, final String inventory, final String photo, final String language, final String administrativeNumber) {
    StringBuilder errMsg = new StringBuilder(activity.getResources().getString(R.string.validate_error));
    boolean allow = true;
    Helpers.hideKeyboard(activity);
    if (arrEmails.isEmpty() || arrEmails.get(0).getEmail().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_email_at_least_one));
        allow = false;
    }
    if (firstName.trim().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_first_name));
        allow = false;
    }
    if (lastName.trim().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_last_name));
        allow = false;
    }
    if (inventory.contains("fail")) {
        errMsg.append(activity.getResources().getString(R.string.validate_inventory));
        allow = false;
    }
    // inventory running
    if (inventory.equals("")) {
        errMsg.append(activity.getResources().getString(R.string.inventory_not_exists));
        allow = false;
    }
    if (!allow) {
        presenter.showSnackError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, activity.getResources().getString(R.string.validate_check_details));
        presenter.showDetailError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, errMsg.toString());
        return;
    }
    try {
        AndroidCryptoProvider csr = new AndroidCryptoProvider(activity);
        String requestCSR = "";
        if (csr.getlCsr() != null) {
            requestCSR = URLEncoder.encode(csr.getlCsr(), "UTF-8");
        }
        MqttData cache = new MqttData(activity);
        String invitationToken = cache.getInvitationToken();
        JSONObject payload = new JSONObject();
        String mInventory = Helpers.base64encode(inventory.trim());
        // get first email
        payload.put("_email", arrEmails.get(0).getEmail());
        payload.put("_invitation_token", invitationToken);
        payload.put("_serial", Helpers.getDeviceSerial());
        payload.put("_uuid", new Hardware(activity).getUUID());
        payload.put("csr", requestCSR);
        payload.put("firstname", firstName);
        payload.put("lastname", lastName);
        payload.put("phone", phone);
        payload.put("version", BuildConfig.VERSION_NAME);
        payload.put("type", "android");
        payload.put("has_system_permission", Helpers.isSystemApp(activity));
        payload.put("inventory", mInventory);
        // could be mqtt or fcm
        payload.put("notification_type", "mqtt");
        // this is the token get from fcm register
        payload.put("notification_token", "");
        FlyveLog.d(mInventory);
        EnrollmentHelper enroll = new EnrollmentHelper(activity);
        enroll.enrollment(payload, new EnrollmentHelper.EnrollCallBack() {

            @Override
            public void onSuccess(String data) {
                // -------------------------------
                // Store user information
                // -------------------------------
                UserData userData = new UserData(activity);
                userData.setFirstName(firstName);
                userData.setLastName(lastName);
                userData.setEmails(arrEmails);
                userData.setPicture(photo);
                userData.setLanguage(language);
                userData.setAdministrativeNumber(administrativeNumber);
                // -------------------------------
                // Remove Deeplink information
                // -------------------------------
                MqttData cache = new MqttData(activity);
                cache.setInvitationToken("");
                presenter.enrollSuccess();
            }

            @Override
            public void onError(int type, String error) {
                presenter.showSnackError(type, error);
            }
        });
    } catch (Exception ex) {
        presenter.showSnackError(CommonErrorType.ENROLLMENT_REQUEST_EXCEPTION, ex.getMessage());
    }
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) UserData(org.flyve.mdm.agent.data.localstorage.UserData) AndroidCryptoProvider(org.flyve.mdm.agent.security.AndroidCryptoProvider) JSONObject(org.json.JSONObject) Hardware(org.flyve.inventory.categories.Hardware)

Example 2 with Hardware

use of org.flyve.inventory.categories.Hardware in project android-mdm-agent by flyve-mdm.

the class EnrollmentModel method enroll.

@Override
public void enroll(final Activity activity, final List<UserData.EmailsData> arrEmails, final String firstName, final String lastName, final String phone, final String phone2, final String mobilePhone, final String inventory, final String photo, final String language, final String administrativeNumber, final String notificationToken, Context context) {
    StringBuilder errMsg = new StringBuilder(activity.getResources().getString(R.string.validate_error));
    boolean allow = true;
    Helpers.hideKeyboard(activity);
    if (arrEmails.isEmpty() || arrEmails.get(0).getEmail().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_email_at_least_one));
        allow = false;
    }
    if (firstName.trim().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_first_name));
        allow = false;
    }
    if (lastName.trim().equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_last_name));
        allow = false;
    }
    if (notificationToken.equals("")) {
        errMsg.append(activity.getResources().getString(R.string.validate_fcm_token));
        allow = false;
    }
    if (inventory.contains("fail")) {
        errMsg.append(activity.getResources().getString(R.string.validate_inventory));
        allow = false;
    }
    // inventory running
    if (inventory.equals("")) {
        errMsg.append(activity.getResources().getString(R.string.inventory_not_exists));
        allow = false;
    }
    if (!allow) {
        presenter.showSnackError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, activity.getResources().getString(R.string.validate_check_details));
        presenter.showDetailError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, errMsg.toString());
        return;
    }
    try {
        MqttData cache = new MqttData(activity);
        String invitationToken = cache.getInvitationToken();
        JSONObject payload = new JSONObject();
        String mInventory = Helpers.base64encode(inventory.trim());
        // get first email
        payload.put("_email", arrEmails.get(0).getEmail());
        payload.put("_invitation_token", invitationToken);
        payload.put("_serial", Helpers.getDeviceSerial());
        payload.put("_uuid", new Hardware(activity).getUUID());
        payload.put("csr", "");
        payload.put("firstname", firstName);
        payload.put("lastname", lastName);
        payload.put("phone", phone);
        payload.put("version", BuildConfig.VERSION_NAME);
        payload.put("type", "android");
        payload.put("has_system_permission", Helpers.isSystemApp(activity));
        payload.put("inventory", mInventory);
        // could be mqtt or fcm
        payload.put("notification_type", "fcm");
        // this is the token get from fcm register
        payload.put("notification_token", notificationToken);
        FlyveLog.d(mInventory);
        EnrollmentHelper enroll = new EnrollmentHelper(activity);
        enroll.enrollment(payload, new EnrollmentHelper.EnrollCallBack() {

            @Override
            public void onSuccess(String data) {
                // -------------------------------
                // Store user information
                // -------------------------------
                UserData userData = new UserData(activity);
                userData.setFirstName(firstName);
                userData.setLastName(lastName);
                userData.setEmails(arrEmails);
                userData.setPicture(photo);
                userData.setLanguage(language);
                userData.setAdministrativeNumber(administrativeNumber);
                // -------------------------------
                // Remove Deeplink information
                // -------------------------------
                MqttData cache = new MqttData(activity);
                cache.setInvitationToken("");
                presenter.enrollSuccess();
            }

            @Override
            public void onError(int type, String error) {
                presenter.showSnackError(type, error);
            }
        });
    } catch (Exception ex) {
        presenter.showSnackError(CommonErrorType.ENROLLMENT_REQUEST_EXCEPTION, ex.getMessage());
    }
}
Also used : MqttData(org.flyve.mdm.agent.data.database.MqttData) JSONObject(org.json.JSONObject) UserData(org.flyve.mdm.agent.data.localstorage.UserData) Hardware(org.flyve.inventory.categories.Hardware)

Aggregations

Hardware (org.flyve.inventory.categories.Hardware)2 MqttData (org.flyve.mdm.agent.data.database.MqttData)2 UserData (org.flyve.mdm.agent.data.localstorage.UserData)2 JSONObject (org.json.JSONObject)2 AndroidCryptoProvider (org.flyve.mdm.agent.security.AndroidCryptoProvider)1