Commit fb28ee85 by Jeong Gilmo

#33721 絞り検索のAPIとの連携

- 絞り検索のマスタデータを受信処理の修正
parent 09d4ce4c
......@@ -975,7 +975,6 @@ public class AcmsClient implements AcmsClientResponseListener {
*/
public ApertureMasterDataJSON getApertureMasterData(GetApertureMasterDataParameters param) throws NetworkDisconnectedException, AcmsException {
HttpResponse response = send(AcmsApis.ApiGetApertureMasterData, param);
ApertureMasterDataJSON json = new ApertureMasterDataJSON(response.httpResponseBody);
return json;
return new ApertureMasterDataJSON(response.httpResponseBody);
}
}
package jp.agentec.abook.abv.bl.acms.client.json;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.common.exception.AcmsException;
import jp.agentec.abook.abv.bl.common.exception.JSONValidationException;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.WorkerGroupDto;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil;
import org.json.adf.JSONArray;
import org.json.adf.JSONObject;
......@@ -22,10 +13,10 @@ import org.json.adf.JSONObject;
* @version 1.0.0
*/
public class ApertureMasterDataJSON extends AcmsCommonJSON {
public static final String operationLastEditDate = "operationLastEditDate";
public static final String ApertureData = "apertureData";
public Date lastEditDate;
public JSONObject apertureJson;
private static final String apertureLastEditDate = "apertureLastEditDate";
private static final String ApertureData = "apertureData";
public String lastEditDate;
public JSONObject apertureData;
public ApertureMasterDataJSON(String jsonString) throws AcmsException {
super(jsonString);
......@@ -34,16 +25,15 @@ public class ApertureMasterDataJSON extends AcmsCommonJSON {
@Override
protected void parse(JSONObject json) throws JSONValidationException {
// 絞り検索の日付を取得
if(json.has(operationLastEditDate)) {
lastEditDate = DateTimeUtil.toDate(json.getString(operationLastEditDate), "UTC", DateTimeFormat.yyyyMMddHHmmss_hyphen);
if(json.has(apertureLastEditDate)) {
lastEditDate = json.getString(apertureLastEditDate);
}
// 絞り検索のデータを取得
if (json.has(ApertureData)) {
JSONArray apertureList = json.getJSONArray(ApertureData);
for (int i = 0; i < apertureList.length(); i++) {
apertureJson = apertureList.getJSONObject(i);json.getJSONArray(ApertureData);
Logger.e(apertureJson.toString());
apertureData = apertureList.getJSONObject(i);
}
}
}
......
......@@ -6,15 +6,7 @@ package jp.agentec.abook.abv.bl.acms.client.parameters;
public class GetApertureMasterDataParameters extends AcmsParameters {
private long operationId;
public GetApertureMasterDataParameters(String sid, long operationId) {
public GetApertureMasterDataParameters(String sid) {
super(sid);
this.operationId = operationId;
}
public long getOperationId() {
return operationId;
}
}
\ No newline at end of file
......@@ -177,7 +177,14 @@ public class ABVEnvironment {
public static final boolean DebugContentDownload = false;
public boolean enableToastMessage = true;
// 絞り検索マスタ参照パス
public static final String OperationMasterDataDirFormat = "%s/ABook/operation/master";
// 絞り検索マスタファイル名
public static final String ApertureMasterDataFileName = "apertureMaster.json";
private ABVEnvironment() {
}
......@@ -766,4 +773,11 @@ public class ABVEnvironment {
return reportDate;
}
}
// MasterDataに対したJSONファイルの位置
// 経路:root/files/operation/master
public String getMasterFilePath() {
return String.format(OperationMasterDataDirFormat, rootDirectory);
}
}
......@@ -41,7 +41,7 @@ public class ABVDataCache {
private static final int SEVER_ALERT_INTERVAL = 30; //システム日付チェック前後期間(分)
// Serverから取得したapertureMasterDataのfetchDateを一時的に保存するための変数
public String tempApertureMasterDataFetchDate = null;
private String tempApertureMasterDataFetchDate = null;
/**
* 未指定ジャンルのID
......@@ -373,4 +373,20 @@ public class ABVDataCache {
}
return null;
}
/**
* tempApertureMasterDataFetchDateを更新する
* @param date
*/
public void setTempApertureMasterDataFetchDate(String date){
this.tempApertureMasterDataFetchDate = date;
}
/**
* tempApertureMasterDataFetchDateをreturn
* @return tempApertureMasterDataFetchDate
*/
public String getTempApertureMasterDataFetchDate(){
return tempApertureMasterDataFetchDate;
}
}
......@@ -23,6 +23,7 @@ import jp.agentec.abook.abv.bl.data.dao.ContentDao;
import jp.agentec.abook.abv.bl.dto.ContentDto;
import jp.agentec.abook.abv.bl.dto.EnqueteDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.ApertureMasterDataLogic;
import jp.agentec.abook.abv.bl.logic.CategoryLogic;
import jp.agentec.abook.abv.bl.logic.ContentLogic;
import jp.agentec.abook.abv.bl.logic.ContentReadingLogLogic;
......@@ -62,7 +63,12 @@ public class ContentRefresher {
private boolean initializingRefreshing = false;
private static final int refreshSleepInterval = 500;
private static final int maxRefreshWorker = 2;
// masterDataを取得するため登録
private ApertureMasterDataLogic apertureMasterDataLogic = AbstractLogic.getLogic(ApertureMasterDataLogic.class);
public static ContentRefresher getInstance() {
if (instance == null) {
synchronized (ContentRefresher.class) {
......@@ -156,6 +162,13 @@ public class ContentRefresher {
contractLogic.initializeContractServiceOption(); // サービスオプション関連処理
groupLogic.initializeGroups(); // グループ設定(グループ変更の場合、FetchDateをクリアする)
categoryLogic.initializeCategories(); // カテゴリ設定
// 絞り検索マスタデータの最新更新された時のFetchDateを一時に保存する。
Logger.d(TAG, "before fetchDate : " + ABVDataCache.getInstance().getTempApertureMasterDataFetchDate());
// CMSでメンテナンスされる絞り検索マスタデータをアプリから取得できるようにJSONファイルを生成する。
apertureMasterDataLogic.initializeApertureMasterData(ABVDataCache.getInstance().getTempApertureMasterDataFetchDate());
Logger.d(TAG, "after fetchDate : " + ABVDataCache.getInstance().getTempApertureMasterDataFetchDate());
if (interrupt) { // この時点で停止要求が来た場合先には進まない。(ServiceOption/Group/Categoryの更新は1セットで行う(トランザクションはそれぞれ別))
Logger.d(TAG, "stop refresh worker before content update.");
......
package jp.agentec.abook.abv.bl.logic;
import org.json.adf.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.ApertureMasterDataJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.GetApertureMasterDataParameters;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil;
import jp.agentec.adf.util.FileUtil;
public class ApertureMasterDataLogic extends AbstractLogic {
private static final java.lang.String TAG = "RefineMasterDataLogic";
/**
* グループ情報をサーバから受信し、ローカルに保存します。既存のデータは上書きされます。また、サーバにないグループがローカルにある場合、そのグループは削除されます。
* 絞り検索マスタデータ情報をサーバから受信し、ローカルにJSONで保存する。
* 日付を比べてサーバーからローカルのデータより最新のデータを受信した場合、受信した情報を保存する。
* ローカルの日付はない場合、受信した情報を保存する。
* @param lastFetchDateString
*/
public void initializeApertureMasterData(String lastFetchDateString) {
try {
GetApertureMasterDataParameters param = new GetApertureMasterDataParameters(cache.getMemberInfo().sid);
//サーバーから絞り検索マスタデータを取得
ApertureMasterDataJSON masterDataJson = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).getApertureMasterData(param);
//サーバーデータの日付
String lastEditDateString = masterDataJson.lastEditDate;
if(lastFetchDateString != null) {
Date lastFetchDate = DateTimeUtil.toDate(lastFetchDateString, "UTC", DateTimeFormat.yyyyMMddHHmmss_hyphen);
Date lastEditDate = DateTimeUtil.toDate(lastEditDateString, "UTC", DateTimeFormat.yyyyMMddHHmmss_hyphen);
if (lastFetchDate == null || lastEditDate.after(lastFetchDate)) {
createApertureMasterDataJson(masterDataJson.apertureData);
cache.setTempApertureMasterDataFetchDate(lastEditDateString);
}
}
else{
createApertureMasterDataJson(masterDataJson.apertureData);
cache.setTempApertureMasterDataFetchDate(lastEditDateString);
}
Logger.i(masterDataJson.toString());
} catch (Exception e) {
Logger.e(TAG, "apertureMasterDataSend error : ", e);
}
}
/**
* apertureMaster.jsonファイル作成
* @param json
* @throws IOException
*/
private void createApertureMasterDataJson(JSONObject json) throws IOException {
// マスタデータの保存されるパス
String masterDataJsonPath = ABVEnvironment.getInstance().getMasterFilePath() + File.separator + ABVEnvironment.getInstance().ApertureMasterDataFileName;
FileUtil.createFile(masterDataJsonPath, json.toString());
}
}
......@@ -798,6 +798,9 @@ public class OperationLogic extends AbstractLogic {
jsonObject.put("attachedPath", "../../../../files/ABook/operation/" + operationId);
jsonObject.put("attachedMoviePath", ABVEnvironment.getInstance().getAttachedMoviesFilePath(contentId));
// 絞り検索マスタデータのパス
jsonObject.put("masterPath",ABVEnvironment.getInstance().getMasterFilePath() + File.separator + ABVEnvironment.getInstance().ApertureMasterDataFileName);
FileUtil.createFile(contentPath + "/content.json", jsonObject.toString());
}
......@@ -1597,22 +1600,4 @@ public class OperationLogic extends AbstractLogic {
mTaskDao.insert(taskDto);
}
}
/**
* 絞り検索のjsonファイル
* apertureMaster.jsonを作成
*
* @param json
* @param contentPath
* @throws IOException
*/
public void createJsonForApertureData(JSONObject json, String contentPath) throws IOException {
try {
FileUtil.createFile(contentPath + "/apertureMaster.json", json.toString());
} catch (IOException e) {
Logger.e(TAG, "createJsonForapertureMaster error : ", e);
throw e;
}
}
}
......@@ -54,7 +54,7 @@ public class ABVApplication extends MultiDexApplication {
FileUtil.delete(ABVEnvironment.getInstance().getCacheTempAttachedImageDirPath());
// 絞り検索のfetchDateをローカルに保存された値を取得して設定する
ABVDataCache.getInstance().tempApertureMasterDataFetchDate = PreferenceUtil.getUserPref(this, AppDefType.UserPrefKey.APERTURE_MASTER_DATA_FETCH_DATE, null);
ABVDataCache.getInstance().setTempApertureMasterDataFetchDate(PreferenceUtil.getUserPref(this, AppDefType.UserPrefKey.APERTURE_MASTER_DATA_FETCH_DATE, null));
}
@Override
......
......@@ -2,7 +2,6 @@ package jp.agentec.abook.abv.ui.home.activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
......@@ -12,7 +11,6 @@ import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.speech.tts.TextToSpeech;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
import android.view.View;
......@@ -89,9 +87,9 @@ import jp.agentec.abook.abv.bl.dto.PushMessageDto;
import jp.agentec.abook.abv.bl.dto.TaskDto;
import jp.agentec.abook.abv.bl.dto.TaskReportDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.ApertureMasterDataLogic;
import jp.agentec.abook.abv.bl.logic.OperationLogic;
import jp.agentec.abook.abv.bl.logic.PushMessageLogic;
import jp.agentec.abook.abv.cl.util.AndroidStringUtil;
import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
......@@ -188,7 +186,9 @@ public class OperationListActivity extends ABVUIActivity {
private ArrayList<Integer> mAllOperationReportTypes;
// 絞り検索マスタデータ
private Date mApertureLastEditDate;
// private Date mApertureLastEditDate;
// 絞り検索マスタLogic
private ApertureMasterDataLogic mApertureMasterDataLogic = AbstractLogic.getLogic(ApertureMasterDataLogic.class);
// ビューの作成
private class ReloadHandler implements Runnable {
......@@ -397,6 +397,8 @@ public class OperationListActivity extends ABVUIActivity {
getABVUIDataCache().saveLastUpdateTime();
// リソースパターンを取得し、ローカルに保存する。
setResourcePattern();
// 絞り検索マスタデータ最新更新する時fetchDateをローカルに保存する。
setApertureMasterDataFetchDate();
refreshOperationList();
}
}
......@@ -638,7 +640,7 @@ public class OperationListActivity extends ABVUIActivity {
mOperationLogic.createJsonForOperationContent(operationDto.operationId, contentPath, operationDto.reportType == ReportType.RoutineTask);
// 絞り検索マスタデータを受信、JSONファイルを生成
mApertureLastEditDate = receptionApertureMasterData(operationDto.operationId, contentPath);
mApertureMasterDataLogic.initializeApertureMasterData(ABVDataCache.getInstance().getTempApertureMasterDataFetchDate());
// サーバ作業後、対応必要
StringBuffer path = new StringBuffer();
......@@ -1922,28 +1924,9 @@ public class OperationListActivity extends ABVUIActivity {
}
/**
* 絞り検索マスタデータの受信
* @param operationId
* @return
* @throws NetworkDisconnectedException
* @throws ABVException
* @throws IOException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws ZipException
* 絞り検索の日付を設定
*/
public Date receptionApertureMasterData(long operationId, String contentPath) throws NetworkDisconnectedException, ABVException, IOException {
// 絞り検索のためparamを設定
GetApertureMasterDataParameters param = new GetApertureMasterDataParameters(ABVDataCache.getInstance().getMemberInfo().sid, operationId);
// 絞り検索した日付の保存
Date lastEditDate;
// JSONデータのparsing
ApertureMasterDataJSON json = AcmsClient.getInstance(ABVDataCache.getInstance().getUrlPath(), ABVEnvironment.getInstance().networkAdapter).getApertureMasterData(param);
// JSONファイルを生成
mOperationLogic.createJsonForApertureData(json.apertureJson, contentPath);
// 絞り検索した日付を取得
lastEditDate = json.lastEditDate;
return lastEditDate;
private void setApertureMasterDataFetchDate() {
putUserPref(AppDefType.UserPrefKey.APERTURE_MASTER_DATA_FETCH_DATE, ABVDataCache.getInstance().getTempApertureMasterDataFetchDate());
}
}
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