-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logging): extend logs with isDebugMode field
SDK-226 Co-authored-by: davidSchuppa <[email protected]> Co-authored-by: LasOri <[email protected]> Co-authored-by: megamegax <[email protected]> Co-authored-by: matusekma <[email protected]>
- Loading branch information
1 parent
4d3bc1b
commit a6d59bd
Showing
2 changed files
with
51 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 49 additions & 71 deletions
120
core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,59 @@ | ||
package com.emarsys.core.util.log; | ||
|
||
import com.emarsys.core.Mapper; | ||
import com.emarsys.core.device.DeviceInfo; | ||
import com.emarsys.core.endpoint.Endpoint; | ||
import com.emarsys.core.provider.timestamp.TimestampProvider; | ||
import com.emarsys.core.provider.uuid.UUIDProvider; | ||
import com.emarsys.core.request.model.RequestMethod; | ||
import com.emarsys.core.request.model.RequestModel; | ||
import com.emarsys.core.shard.ShardModel; | ||
import com.emarsys.core.util.Assert; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LogShardListMerger implements Mapper<List<ShardModel>, RequestModel> { | ||
|
||
|
||
private final TimestampProvider timestampProvider; | ||
private final UUIDProvider uuidProvider; | ||
private final DeviceInfo deviceInfo; | ||
private final String applicationCode; | ||
private final String merchantId; | ||
|
||
public LogShardListMerger(TimestampProvider timestampProvider, UUIDProvider uuidProvider, DeviceInfo deviceInfo, String applicationCode, String merchantId) { | ||
Assert.notNull(timestampProvider, "TimestampProvider must not be null!"); | ||
Assert.notNull(uuidProvider, "UuidProvider must not be null!"); | ||
Assert.notNull(deviceInfo, "DeviceInfo must not be null!"); | ||
|
||
this.timestampProvider = timestampProvider; | ||
this.uuidProvider = uuidProvider; | ||
this.deviceInfo = deviceInfo; | ||
this.applicationCode = applicationCode; | ||
this.merchantId = merchantId; | ||
} | ||
|
||
@Override | ||
public RequestModel map(List<ShardModel> shards) { | ||
Assert.notNull(shards, "Shards must not be null!"); | ||
Assert.notEmpty(shards, "Shards must not be empty!"); | ||
Assert.elementsNotNull(shards, "Shard elements must not be null!"); | ||
|
||
return new RequestModel.Builder(timestampProvider, uuidProvider) | ||
package com.emarsys.core.util.log | ||
|
||
import com.emarsys.core.Mapper | ||
import com.emarsys.core.device.DeviceInfo | ||
import com.emarsys.core.endpoint.Endpoint | ||
import com.emarsys.core.provider.timestamp.TimestampProvider | ||
import com.emarsys.core.provider.uuid.UUIDProvider | ||
import com.emarsys.core.request.model.RequestMethod | ||
import com.emarsys.core.request.model.RequestModel | ||
import com.emarsys.core.shard.ShardModel | ||
|
||
class LogShardListMerger( | ||
private val timestampProvider: TimestampProvider, | ||
private val uuidProvider: UUIDProvider, | ||
private val deviceInfo: DeviceInfo, | ||
private val applicationCode: String?, | ||
private val merchantId: String? | ||
) : Mapper<List<ShardModel>, RequestModel> { | ||
|
||
override fun map(value: List<ShardModel>): RequestModel { | ||
return if (value.isNotEmpty()) { | ||
RequestModel.Builder(timestampProvider, uuidProvider) | ||
.url(Endpoint.LOG_URL) | ||
.method(RequestMethod.POST) | ||
.payload(createPayload(shards)) | ||
.build(); | ||
.payload(createPayload(value)) | ||
.build() | ||
} else throw IllegalArgumentException("Shards must not be empty!") | ||
} | ||
|
||
private Map<String, Object> createPayload(List<ShardModel> shards) { | ||
Map<String, Object> result = new HashMap<>(); | ||
List<Map<String, Object>> datas = new ArrayList<>(shards.size()); | ||
Map<String, String> deviceInfo = createDeviceInfo(); | ||
for (ShardModel shard : shards) { | ||
Map<String, Object> data = new HashMap<>(); | ||
data.put("type", shard.getType()); | ||
data.put("deviceInfo", deviceInfo); | ||
data.putAll(shard.getData()); | ||
datas.add(data); | ||
private fun createPayload(shards: List<ShardModel>): Map<String, Any?> { | ||
val result: MutableMap<String, Any?> = mutableMapOf() | ||
val dataList: MutableList<Map<String, Any>> = mutableListOf() | ||
val deviceInfo = createDeviceInfo() | ||
shards.forEach { shard -> | ||
val data: MutableMap<String, Any> = mutableMapOf() | ||
data["type"] = shard.type | ||
data["deviceInfo"] = deviceInfo | ||
data.putAll(shard.data) | ||
dataList.add(data) | ||
} | ||
|
||
result.put("logs", datas); | ||
return result; | ||
result["logs"] = dataList | ||
return result | ||
} | ||
|
||
private Map<String, String> createDeviceInfo() { | ||
Map<String, String> data = new HashMap<>(); | ||
data.put("platform", deviceInfo.getPlatform()); | ||
data.put("appVersion", deviceInfo.getApplicationVersion()); | ||
data.put("sdkVersion", deviceInfo.getSdkVersion()); | ||
data.put("osVersion", deviceInfo.getOsVersion()); | ||
data.put("model", deviceInfo.getModel()); | ||
data.put("hwId", deviceInfo.getClientId()); | ||
data.put("applicationCode", applicationCode); | ||
data.put("merchantId", merchantId); | ||
return data; | ||
private fun createDeviceInfo(): Map<String, String?> { | ||
val data: MutableMap<String, String?> = mutableMapOf() | ||
data["platform"] = deviceInfo.platform | ||
data["appVersion"] = deviceInfo.applicationVersion | ||
data["sdkVersion"] = deviceInfo.sdkVersion | ||
data["osVersion"] = deviceInfo.osVersion | ||
data["model"] = deviceInfo.model | ||
data["hwId"] = deviceInfo.clientId | ||
data["isDebugMode"] = deviceInfo.isDebugMode.toString() | ||
data["applicationCode"] = applicationCode | ||
data["merchantId"] = merchantId | ||
return data | ||
} | ||
|
||
} |