Skip to content

Commit

Permalink
Add: #183 - Data sharing UI and data agreement policy
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan authored and georgepadayatti committed Nov 13, 2023
1 parent 7fe1674 commit c7911bf
Show file tree
Hide file tree
Showing 30 changed files with 1,592 additions and 14 deletions.
4 changes: 4 additions & 0 deletions PrivacyDashboard/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".modules.userRequestStatus.BBConsentUserRequestStatusActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"/>
<activity android:name=".modules.dataSharing.BBConsentDataSharingActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"/>
<activity android:name=".modules.dataAgreementPolicy.BBConsentDataAgreementPolicyActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package com.github.privacyDashboard

import android.app.Activity
import android.content.Context
import android.content.Intent
import com.github.privacyDashboard.modules.dataSharing.BBConsentDataSharingActivity
import com.github.privacyDashboard.modules.home.BBConsentDashboardActivity
import com.github.privacyDashboard.utils.BBConsentDataUtils
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ACCESS_TOKEN
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_BASE_URL
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_DATA_AGREEMENT_ID
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_ASK_ME
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_ATTRIBUTE_LEVEL_CONSENT
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_USER_REQUEST
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ORG_ID
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_TOKEN
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_USERID
import com.github.privacyDashboard.utils.BBConsentLocaleHelper

object DataSharingUI {

private var mUserId: String? = null
private var mApiKey: String? = null
private var mAccessToken: String? = null
private var mDataAgreementId: String? = null
private var mBaseUrl: String? = ""
private var mLocale: String? = ""

private var mDataSharingUIIntent: Intent? = null

fun showDataSharingUI(): DataSharingUI {
mDataSharingUIIntent = Intent()
return this
}

/**
* Set user id for igrant sdk.
*
* @param userId
*/
fun withUserId(userId: String?): DataSharingUI {
this.mUserId = if (userId == "") null else userId
return this
}

/**
* Set Api key for the iGrant Sdk.
*
* @param apiKey
*/
fun withApiKey(apiKey: String?): DataSharingUI {
this.mApiKey = if (apiKey == "") null else apiKey
return this
}

/**
* Set Access token for the iGrant Sdk.
*
* @param accessToken
*/
fun withAccessToken(accessToken: String?): DataSharingUI {
this.mAccessToken = if (accessToken == "") null else accessToken
return this
}

/**
* Set data agreement id id for the iGrant Sdk.
*
* @param dataAgreementId
*/
fun withDataAgreementId(dataAgreementId: String?): DataSharingUI {
this.mDataAgreementId = dataAgreementId
return this
}

/**
* Set base url for the iGrant Sdk.
*
* @param baseUrl
*/
fun withBaseUrl(baseUrl: String?): DataSharingUI {
this.mBaseUrl = baseUrl
return this
}

/**
* Set other application details for the iGrant Sdk.
*
* @param applicationName
* @param logoUrl
*/
fun withOtherApplication(applicationName: String?, logoUrl: String?): DataSharingUI {
mDataSharingUIIntent?.putExtra(
BBConsentDataSharingActivity.TAG_EXTRA_OTHER_APPLICATION_NAME,
applicationName
)
mDataSharingUIIntent?.putExtra(
BBConsentDataSharingActivity.TAG_EXTRA_OTHER_APPLICATION_LOGO,
logoUrl
)
return this
}

/**
* Set secondaryButtonText for the iGrant Sdk.
*
* @param text
*/
fun secondaryButtonText(text: String?): DataSharingUI {
mDataSharingUIIntent?.putExtra(
BBConsentDataSharingActivity.TAG_EXTRA_SECONDARY_BUTTON_TEXT,
text
)
return this
}

/**
* Set Language code for the iGrant Sdk.
*
* @param languageCode
*/
fun withLocale(languageCode: String): DataSharingUI {
this.mLocale = languageCode
return this
}

/**
* Send the Intent from an Activity
*
* @param activity Activity to start activity
*/
fun get(activity: Activity): Intent? {
if (mAccessToken != null || (mApiKey != null && mUserId != null))
if (mDataAgreementId != null) {
return getIntent(activity)
}

return null
}

/**
* Send the Intent from an Activity with a custom request code
*
* @param context Context to start activity
*/
fun get(context: Context): Intent? {
if (mAccessToken != null || (mApiKey != null && mUserId != null))
if (mDataAgreementId != null) {
return getIntent(context)
}

return null
}

/**
* Get Intent to start [BBConsentDashboardActivity]
*
* @return Intent for [BBConsentDashboardActivity]
*/
private fun getIntent(context: Context): Intent? {
mDataSharingUIIntent?.setClass(context, BBConsentDataSharingActivity::class.java)
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_BASE_URL, this.mBaseUrl)
BBConsentDataUtils.saveStringValues(
context,
EXTRA_TAG_DATA_AGREEMENT_ID,
this.mDataAgreementId
)
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_USERID, this.mUserId)
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_TOKEN, this.mApiKey)
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_ACCESS_TOKEN, this.mAccessToken)
BBConsentLocaleHelper.setLocale(context, mLocale ?: "en")
return mDataSharingUIIntent
}

fun setLocale(context: Context, languageCode: String) {
BBConsentLocaleHelper.setLocale(context, languageCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ interface BBConsentAPIServices {
@GET("v2/service/data-agreements")
suspend fun getDataAgreementsV2(
@Header("X-ConsentBB-IndividualId") userID: String?,
): Response<DataAgreementResponseV2>
): Response<DataAgreementsResponseV2>

@GET("v2/service/data-agreement/{dataAgreementId}")
suspend fun getDataAgreementV2(
@Header("X-ConsentBB-IndividualId") userID: String?,
@Path("dataAgreementId") dataAgreementId: String?
): Response<DataAgreementResponseV2?>?

@GET("v2/service/individual/record/consent-record")
suspend fun getDataAgreementRecordsV2(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.privacyDashboard.communication.repositories

import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementsResponseV2

class GetDataAgreementApiRepository(private val apiService: BBConsentAPIServices) {

suspend fun getDataAgreement(
userId: String?,
dataAgreementId: String?
): Result<DataAgreementResponseV2?> {
return try {
val dataAgreementRecord = apiService.getDataAgreementV2(userId, dataAgreementId)

if (dataAgreementRecord?.isSuccessful == true) {
val data = dataAgreementRecord.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${dataAgreementRecord?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.privacyDashboard.communication.repositories

import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.models.v2.consent.ConsentStatusRequestV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementLatestRecordResponseV2
import retrofit2.Response

class GetDataAgreementRecordApiRepository(private val apiService: BBConsentAPIServices) {

suspend fun getDataAgreementRecord(
userId: String?,
dataAgreementId: String?
): Result<DataAgreementLatestRecordResponseV2?> {
return try {
val dataAgreementRecord = apiService.getDataAgreementRecordV2(userId, dataAgreementId)

if (dataAgreementRecord?.isSuccessful == true) {
val data = dataAgreementRecord.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${dataAgreementRecord?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package com.github.privacyDashboard.communication.repositories

import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.models.*
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementsResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementRecordsResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementRecordsV2
import com.github.privacyDashboard.models.v2.dataAgreement.organization.OrganizationResponseV2
import retrofit2.Response

class GetDataAgreementsApiRepository(private val apiService: BBConsentAPIServices) {
Expand Down Expand Up @@ -42,7 +41,7 @@ class GetDataAgreementsApiRepository(private val apiService: BBConsentAPIService
}

private suspend fun convertV2toBaseModel(
dataAgreementsResponse: Response<DataAgreementResponseV2>,
dataAgreementsResponse: Response<DataAgreementsResponseV2>,
dataAgreementRecordResponseV2: Response<DataAgreementRecordsResponseV2>,
userId: String?
): OrganizationDetailResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package com.github.privacyDashboard.communication.repositories

import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.models.*
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementRecordsResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementRecordsV2
import com.github.privacyDashboard.models.v2.dataAgreement.organization.OrganizationResponseV2
import retrofit2.Response

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.privacyDashboard.models

class DataAgreementPolicyList : ArrayList<ArrayList<DataAgreementPolicyModel>>() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.privacyDashboard.models

import com.google.gson.annotations.SerializedName

data class DataAgreementPolicyModel(
@SerializedName("name")
var name: String? = null,
@SerializedName("value")
var value: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.github.privacyDashboard.models.v2.dataAgreement

import com.github.privacyDashboard.models.v2.PaginationV2
import com.google.gson.annotations.SerializedName

class DataAgreementResponseV2(
@SerializedName("dataAgreements") var dataAgreements: ArrayList<DataAgreementV2> = arrayListOf(),
@SerializedName("pagination") var pagination: PaginationV2? = PaginationV2()
)
class DataAgreementResponseV2 {
@SerializedName("dataAgreement")
var dataAgreement: DataAgreementV2? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class DataAgreementV2(
@SerializedName("policy") var policy: PolicyV2? = PolicyV2(),
@SerializedName("purpose") var purpose: String? = null,
@SerializedName("purposeDescription") var purposeDescription: String? = null,
@SerializedName("dataAttributes") var dataAttributes:ArrayList<DataAttributesV2>? =null,
@SerializedName("dataAttributes") var dataAttributes:ArrayList<DataAttributesV2?>? =null,
@SerializedName("lawfulBasis") var lawfulBasis: String? = null,
@SerializedName("methodOfUse") var methodOfUse: String? = null,
@SerializedName("dpiaDate") var dpiaDate: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.privacyDashboard.models.v2.dataAgreement

import com.github.privacyDashboard.models.v2.PaginationV2
import com.google.gson.annotations.SerializedName

class DataAgreementsResponseV2(
@SerializedName("dataAgreements") var dataAgreements: ArrayList<DataAgreementV2> = arrayListOf(),
@SerializedName("pagination") var pagination: PaginationV2? = PaginationV2()
)
Loading

0 comments on commit c7911bf

Please sign in to comment.