Commit b613c708 by Kang Donghun

#73114 作業同期 ContentRefresher修正

parent 56511aac
package jp.agentec.abook.abv.bl.download; package jp.agentec.abook.abv.bl.download;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient; import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
...@@ -312,18 +316,21 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -312,18 +316,21 @@ import jp.agentec.adf.util.DateTimeUtil;
// sppDeviceDtoを登録 // sppDeviceDtoを登録
List<SppDeviceDto> sppDeviceDtoList = json.sppDeviceDtoList; List<SppDeviceDto> sppDeviceDtoList = json.sppDeviceDtoList;
if (CollectionUtil.isNotEmpty(sppDeviceDtoList)) { if (CollectionUtil.isNotEmpty(sppDeviceDtoList)) {
// ローカルに保存されてるIDリストを取得(登録・更新の判定のため // ローカルに保存されてるID(contains/remove を O(1) に
List<Integer> localSppDeviceIdList = sppDeviceDao.getSppDeviceIdList(); List<Integer> localSppDeviceIdList = sppDeviceDao.getSppDeviceIdList();
Set<Integer> localSppDeviceIds = new HashSet<Integer>();
if (CollectionUtil.isNotEmpty(localSppDeviceIdList)) {
localSppDeviceIds.addAll(localSppDeviceIdList);
}
for (SppDeviceDto sppDeviceDto : sppDeviceDtoList) { for (SppDeviceDto sppDeviceDto : sppDeviceDtoList) {
if (CollectionUtil.isNotEmpty(localSppDeviceIdList) && localSppDeviceIdList.contains(sppDeviceDto.sppDeviceId)) { if (localSppDeviceIds.contains(sppDeviceDto.sppDeviceId)) {
SppDeviceDto localSppDevice = sppDeviceDao.getSppDeviceById(sppDeviceDto.sppDeviceId); SppDeviceDto localSppDevice = sppDeviceDao.getSppDeviceById(sppDeviceDto.sppDeviceId);
// ペアリング情報だけローカルから取得して、更新する // ペアリング情報だけローカルから取得して、更新する
sppDeviceDto.pairingDeviceName = localSppDevice.pairingDeviceName; sppDeviceDto.pairingDeviceName = localSppDevice.pairingDeviceName;
sppDeviceDto.pairingDeviceAddress = localSppDevice.pairingDeviceAddress; sppDeviceDto.pairingDeviceAddress = localSppDevice.pairingDeviceAddress;
sppDeviceDao.updateSppDevice(sppDeviceDto); sppDeviceDao.updateSppDevice(sppDeviceDto);
// 削除のため、更新したら該当するIDを削除する localSppDeviceIds.remove(sppDeviceDto.sppDeviceId);
localSppDeviceIdList.remove(localSppDeviceIdList.indexOf(sppDeviceDto.sppDeviceId));
} else { } else {
// 取得したSPP通信端末のデータベースへ登録 // 取得したSPP通信端末のデータベースへ登録
sppDeviceDao.insert(sppDeviceDto); sppDeviceDao.insert(sppDeviceDto);
...@@ -331,15 +338,25 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -331,15 +338,25 @@ import jp.agentec.adf.util.DateTimeUtil;
} }
// ローカル情報削除(サーバーと端末データの差分) // ローカル情報削除(サーバーと端末データの差分)
if (CollectionUtil.isNotEmpty(localSppDeviceIdList)) { for (Integer deleteSppDeviceId : localSppDeviceIds) {
for (Integer deleteSppDeviceId : localSppDeviceIdList) {
sppDeviceDao.deleteById(deleteSppDeviceId); sppDeviceDao.deleteById(deleteSppDeviceId);
} }
} }
}
List<ContentDto> serverContents = json.contentVersions; List<ContentDto> serverContents = json.contentVersions;
// DTO Info:contentId, metaVersion, resourceVersion, contentNameKana, readerShareFlg // DTO Info:contentId, metaVersion, resourceVersion, contentNameKana, readerShareFlg
// AbstractDto#equals は getKeyValues()(ContentDto は contentId のみ)のため、従来の indexOf(serverDto) は contentId 一致と同値。
// indexOf は先頭一致を採用するため、同一 contentId が複数ある場合も先頭のみマップへ入れる。残りリストの順序は元リストの部分列として再現する。
ArrayList<ContentDto> localContentsInitialOrder = null;
HashMap<Long, ContentDto> localByContentId = new HashMap<Long, ContentDto>();
if (localContents != null) {
localContentsInitialOrder = new ArrayList<ContentDto>(localContents);
for (ContentDto c : localContentsInitialOrder) {
if (!localByContentId.containsKey(c.contentId)) {
localByContentId.put(c.contentId, c);
}
}
}
for (ContentDto serverContentDto : serverContents) { for (ContentDto serverContentDto : serverContents) {
while (isBusyRefreshingContent()) { while (isBusyRefreshingContent()) {
...@@ -357,9 +374,8 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -357,9 +374,8 @@ import jp.agentec.adf.util.DateTimeUtil;
} }
if (localContents != null) { if (localContents != null) {
int localContentIndex = localContents.indexOf(serverContentDto); ContentDto localDto = localByContentId.remove(serverContentDto.contentId);
if (localContentIndex >= 0) { if (localDto != null) {
ContentDto localDto = localContents.get(localContentIndex);
if (!serverContentDto.equalsVersion(localDto)) { // 更新 ContentInfo.zipをダウンロードする。 if (!serverContentDto.equalsVersion(localDto)) { // 更新 ContentInfo.zipをダウンロードする。
contentDownloader.downloadContentInfo(serverContentDto.contentId); contentDownloader.downloadContentInfo(serverContentDto.contentId);
if (serverContentDto.isLinkType() && localDto.isDownloadable(true)) { if (serverContentDto.isLinkType() && localDto.isDownloadable(true)) {
...@@ -369,8 +385,6 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -369,8 +385,6 @@ import jp.agentec.adf.util.DateTimeUtil;
else if (!localDto.downloadedFlg && serverContentDto.isLinkType() && localDto.isDownloadable(true)) { // ダウンロード未完了も追加 else if (!localDto.downloadedFlg && serverContentDto.isLinkType() && localDto.isDownloadable(true)) { // ダウンロード未完了も追加
contentDownloader.addAutoDownload(serverContentDto.contentId); contentDownloader.addAutoDownload(serverContentDto.contentId);
} }
localContents.remove(localDto); // 既に存在するコンテンツはローカルのリストからはずしておく。
} else { } else {
// 新規 ContentInfo.zipをダウンロードする。 // 新規 ContentInfo.zipをダウンロードする。
contentDownloader.downloadContentInfo(serverContentDto.contentId); contentDownloader.downloadContentInfo(serverContentDto.contentId);
...@@ -380,6 +394,19 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -380,6 +394,19 @@ import jp.agentec.adf.util.DateTimeUtil;
} }
} }
} }
if (localContents != null && localContentsInitialOrder != null) {
localContents.clear();
for (ContentDto c : localContentsInitialOrder) {
Long id = c.contentId;
if (localByContentId.containsKey(id)) {
ContentDto still = localByContentId.get(id);
if (still == c) {
localContents.add(c);
localByContentId.remove(id);
}
}
}
}
return true; return true;
} }
} }
...@@ -464,9 +491,10 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -464,9 +491,10 @@ import jp.agentec.adf.util.DateTimeUtil;
} }
try { try {
List<ContentDto> list = contentDao.getSendLog(); List<ContentDto> list = contentDao.getSendLog();
if (list == null || list.size() == 0) {
return;
}
AcmsClient acms = AcmsClient.getInstance(cache.getUrlPath(), ABVEnvironment.getInstance().networkAdapter); AcmsClient acms = AcmsClient.getInstance(cache.getUrlPath(), ABVEnvironment.getInstance().networkAdapter);
if (list != null && list.size() > 0) {
for (ContentDto dto : list) { // FIXME: Readerがここに来るかどうか for (ContentDto dto : list) { // FIXME: Readerがここに来るかどうか
ContentDownloadLogParameters downloadParam = new ContentDownloadLogParameters(cache.getMemberInfo().sid ContentDownloadLogParameters downloadParam = new ContentDownloadLogParameters(cache.getMemberInfo().sid
, dto.contentId, DateTimeUtil.dateToTimestamp(dto.downloadStartDate) , dto.contentId, DateTimeUtil.dateToTimestamp(dto.downloadStartDate)
...@@ -479,7 +507,6 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -479,7 +507,6 @@ import jp.agentec.adf.util.DateTimeUtil;
contentDao.updateLogSendFlg(dto); contentDao.updateLogSendFlg(dto);
} }
} }
}
} catch (Exception e) { } catch (Exception e) {
Logger.e("batchSendDownloadLog failed.", e); // 例外は上にあげない。失敗したら次送られるはず(要確認) Logger.e("batchSendDownloadLog failed.", e); // 例外は上にあげない。失敗したら次送られるはず(要確認)
} }
......
package jp.agentec.abook.abv.bl.logic; package jp.agentec.abook.abv.bl.logic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient; import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
...@@ -51,6 +54,10 @@ public class ContractLogic extends AbstractLogic { ...@@ -51,6 +54,10 @@ public class ContractLogic extends AbstractLogic {
List<ServiceOptionDto> list = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).serviceOption(param); List<ServiceOptionDto> list = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).serviceOption(param);
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
if (isSameServiceOptionListAsDb(list)) {
Logger.d(TAG, "service options unchanged, skip delete/insert");
return;
}
try { try {
serviceOptionDao.beginTransaction(); serviceOptionDao.beginTransaction();
...@@ -68,6 +75,54 @@ public class ContractLogic extends AbstractLogic { ...@@ -68,6 +75,54 @@ public class ContractLogic extends AbstractLogic {
} }
/** /**
* サーバ取得のサービスオプションとローカルDBの内容が同一なら、削除・再挿入を省略する。
*/
private boolean isSameServiceOptionListAsDb(List<ServiceOptionDto> serverList) {
List<ServiceOptionDto> localList = serviceOptionDao.getServiceOptions();
if (localList == null || localList.size() != serverList.size()) {
return false;
}
ArrayList<ServiceOptionDto> s = new ArrayList<ServiceOptionDto>(serverList);
ArrayList<ServiceOptionDto> l = new ArrayList<ServiceOptionDto>(localList);
Comparator<ServiceOptionDto> byId = new Comparator<ServiceOptionDto>() {
@Override
public int compare(ServiceOptionDto a, ServiceOptionDto b) {
return Integer.valueOf(a.serviceOptionId).compareTo(b.serviceOptionId);
}
};
Collections.sort(s, byId);
Collections.sort(l, byId);
for (int i = 0; i < s.size(); i++) {
if (!serviceOptionRowEquals(s.get(i), l.get(i))) {
return false;
}
}
return true;
}
private static boolean serviceOptionRowEquals(ServiceOptionDto a, ServiceOptionDto b) {
if (a.serviceOptionId != b.serviceOptionId) {
return false;
}
if (!safeStrEq(a.val, b.val)) {
return false;
}
if (!safeStrEq(a.serviceOptionName, b.serviceOptionName)) {
return false;
}
if (!safeStrEq(a.serviceOptionDispName, b.serviceOptionDispName)) {
return false;
}
return true;
}
private static boolean safeStrEq(String x, String y) {
String xs = x == null ? "" : x;
String ys = y == null ? "" : y;
return xs.equals(ys);
}
/**
* 権限喪失,非公開,削除時のDL済コンテンツ強制削除するかどうかを示します。 * 権限喪失,非公開,削除時のDL済コンテンツ強制削除するかどうかを示します。
* @return 権限喪失,非公開,削除時のDL済コンテンツ強制削除する場合、trueを返します。 * @return 権限喪失,非公開,削除時のDL済コンテンツ強制削除する場合、trueを返します。
* @since 1.0.0 * @since 1.0.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment