Commit 0474d906 by Kazuyuki Hida

ロックのコールバック呼び出しを実装した。

parent b46fc80c
......@@ -10,6 +10,7 @@ import jp.agentec.adf.util.DateTimeUtil;
public class UnlockReportJSON extends AcmsCommonJSON {
private Date presentTimeUTC;
private int reportStatus;
public UnlockReportJSON(String jsonString) throws AcmsException {
super(jsonString);
......@@ -18,20 +19,31 @@ public class UnlockReportJSON extends AcmsCommonJSON {
@Override
protected void parse(JSONObject json) {
presentTimeUTC = dateOrNull(json, "presentTimeUTC");
reportStatus = intOrDef(json, "", 999);
}
int getHttpStatus() {
public int getHttpStatus() {
return httpStatus;
}
Date getPresentTime() {
public Date getPresentTime() {
return presentTime;
}
Date getPresentTimeUTC() {
public Date getPresentTimeUTC() {
return presentTimeUTC;
}
public int getReportStatus() {return reportStatus; }
private int intOrDef(JSONObject json, String key, int def) {
if (json.has(key)) {
return json.getInt(key);
} else {
return def;
}
}
private Date dateOrNull(JSONObject json, String key) {
if (json.has(key)) {
return DateTimeUtil.toDate(json.getString(key), "UTC", DateTimeFormat.yyyyMMdd_hyphen);
......
package jp.agentec.abook.abv.bl.logic;
import org.json.adf.JSONObject;
import java.util.Date;
import java.util.Map;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.LockReportJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.LockReportParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.UnlockReportParameters;
import jp.agentec.abook.abv.bl.dto.MemberInfoDto;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil;
public class LockReportLogic extends AbstractLogic {
import static java.net.HttpURLConnection.HTTP_OK;
public class LockReportLogic extends AbstractLogic {
public static LockReportLogic newInstance() {
return new LockReportLogic();
}
public void lock(LockReportParameters param) {
public LockResult lock(Map<String, String> param) {
return sendLockReport(
param.get("taskKey"),
longOrNull(param.get("taskReportId")),
dateOrNull(param.get("reportStartDate"))
);
}
private LockResult sendLockReport(
String taskKey,
Long taskReportId,
Date reportStartDate
) {
AcmsClient client = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter);
MemberInfoDto member = cache.getMemberInfo();
LockReportParameters param = new LockReportParameters(
member.sid,
taskKey,
taskReportId,
reportStartDate,
member.loginId,
member.memberName
);
if (!networkAdapter.isNetworkConnected()) {
// オフラインだったら、ロック成功扱い
return LockResult.offLine();
}
try {
LockReportJSON reportJSON = client.sendLockReport(param);
return LockResult.succsess(reportJSON);
} catch (Throwable e) {
return LockResult.failure(e);
}
}
private Long longOrNull(String s) {
try {
return Long.valueOf(s);
} catch (Exception e) {
return null;
}
}
private Date dateOrNull(String s) {
try {
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMdd_hyphen);
} catch (Exception e) {
return null;
}
}
// コールバック用のパラメータ
public static class LockResult {
int result;
String message;
String extParam;
static LockResult succsess(LockReportJSON reportJSON) {
// 成功したとき
LockResult result = new LockResult();
result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", reportJSON.getReportStatus());
extParam.put("reportLockUserId", reportJSON.getReportLockUserId());
extParam.put("reportLockUserName", reportJSON.getReportLockUserName());
extParam.put("reportLockTime", reportJSON.getReportLockTime());
result.extParam = extParam.toString();
return result;
}
static LockResult failure(Throwable e) {
// 例外がでたとき
LockResult result = new LockResult();
result.result = 1;
result.message = e.getLocalizedMessage();
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "999");
extParam.put("reportLockUserId", (String)null);
extParam.put("reportLockUserName", (String)null);
extParam.put("reportLockTime", (String)null);
result.extParam = extParam.toString();
return result;
}
public void unlock(UnlockReportParameters param) {
static LockResult offLine() {
// オフラインは成功扱い
LockResult result = new LockResult();
result.result = 0;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "3"); // オフラインはstatus 3
extParam.put("reportLockUserId", (String)null);
extParam.put("reportLockUserName", (String)null);
extParam.put("reportLockTime", (String)null);
result.extParam = extParam.toString();
return result;
}
public int getResult() {
return result;
}
public String getMessage() {
return message;
}
public String getExtParam() {
return extParam;
}
}
}
package jp.agentec.abook.abv.bl.logic;
import org.json.adf.JSONObject;
import java.util.Date;
import java.util.Map;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.UnlockReportJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.UnlockReportParameters;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.nw.NetworkAdapter;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil;
import static java.net.HttpURLConnection.HTTP_OK;
public class UnlockReportLogic extends AbstractLogic {
public static UnlockReportLogic newInstance() {
return new UnlockReportLogic();
}
public Result unlock(Map<String, String> param) {
return sendUnlockReport(
param.get("taskKey"),
longOrNull(param.get("taskReportId")),
dateOrNull(param.get("reportStartDate"))
);
}
private Result sendUnlockReport(
String taskKey,
Long taskReportId,
Date reportStartDate
) {
NetworkAdapter adapter = ABVEnvironment.getInstance().networkAdapter;
AcmsClient client = AcmsClient.getInstance(cache.getUrlPath(), adapter);
UnlockReportParameters param = new UnlockReportParameters(
cache.getMemberInfo().sid,
taskKey,
taskReportId,
reportStartDate
);
if (!networkAdapter.isNetworkConnected()) {
// オフラインだったら、ロック成功扱い
return Result.offLine();
}
try {
UnlockReportJSON reportJSON = client.sendUnlockReport(param);
return Result.succsess(reportJSON);
} catch (Exception e) {
return Result.failure(e);
}
}
private Long longOrNull(String s) {
try {
return Long.valueOf(s);
} catch (Exception e) {
return null;
}
}
private Date dateOrNull(String s) {
try {
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMdd_hyphen);
} catch (Exception e) {
return null;
}
}
// コールバック用のパラメータ
public static class Result {
int result;
String message;
String extParam;
static Result succsess(UnlockReportJSON reportJSON) {
// 成功したとき
Result result = new Result();
result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", reportJSON.getReportStatus());
result.extParam = extParam.toString();
return result;
}
static Result failure(Throwable e) {
// 例外がでたとき
Result result = new Result();
result.result = 1;
result.message = e.getLocalizedMessage();
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "999");
result.extParam = extParam.toString();
return result;
}
static Result offLine() {
// オフラインは成功扱い
Result result = new Result();
result.result = 0;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "3"); // オフラインはstatus 3
result.extParam = extParam.toString();
return result;
}
public int getResult() {
return result;
}
public String getMessage() {
return message;
}
public String getExtParam() {
return extParam;
}
}
}
......@@ -50,7 +50,9 @@ import jp.agentec.abook.abv.bl.dto.OperationDto;
import jp.agentec.abook.abv.bl.dto.OperationTaskDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.ContentReadingLogLogic;
import jp.agentec.abook.abv.bl.logic.LockReportLogic;
import jp.agentec.abook.abv.bl.logic.OperationLogic;
import jp.agentec.abook.abv.bl.logic.UnlockReportLogic;
import jp.agentec.abook.abv.bl.websocket.MeetingManager;
import jp.agentec.abook.abv.cl.environment.DeviceInfo;
import jp.agentec.abook.abv.cl.helper.ContentMarkingFileHelper;
......@@ -1070,7 +1072,12 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// ビーコンデータを受信して目的のデバイスIDの信号から値を取得する
// 1:中心温度計 2:置くだけセンサー 3:バーコード
getDeviceInfo(abookCheckParam);
} else if (mCmd.equals(ABookKeys.CMD_LOCK_REPORT)) {
LockReportLogic.LockResult r = LockReportLogic.newInstance().lock(abookCheckParam);
afterABookCheckApi(mCmd, mTaskKey, r.getResult(), r.getMessage(), r.getExtParam());
} else if (mCmd.equals(ABookKeys.CMD_UNLOCK_REPORT)) {
UnlockReportLogic.Result r = UnlockReportLogic.newInstance().unlock(abookCheckParam);
afterABookCheckApi(mCmd, mTaskKey, r.getResult(), r.getMessage(), r.getExtParam());
}
}
......
......@@ -19,9 +19,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.parameters.LockReportParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.UnlockReportParameters;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.Callback;
import jp.agentec.abook.abv.bl.common.CommonExecutor;
......@@ -30,8 +27,6 @@ import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.exception.ABVExceptionCode;
import jp.agentec.abook.abv.bl.common.exception.AcmsException;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.common.nw.NetworkAdapter;
import jp.agentec.abook.abv.bl.data.ABVDataCache;
import jp.agentec.abook.abv.bl.dto.OperationDto;
import jp.agentec.abook.abv.bl.dto.OperationTaskDto;
import jp.agentec.abook.abv.bl.dto.TaskDto;
......@@ -142,12 +137,6 @@ public class ABookCheckWebViewHelper extends ABookHelper {
FileUtil.delete(ABVEnvironment.getInstance().getTempTaskDirPath(contentId, taskKey));
mFinishCallback.callback(false);
break;
case ABookKeys.CMD_LOCK_REPORT:
sendLockReport(param);
break;
case ABookKeys.CMD_UNLOCK_REPORT:
sendUnlockReport(param);
break;
}
}
......@@ -559,88 +548,4 @@ public class ABookCheckWebViewHelper extends ABookHelper {
return rotationAngle;
}
private void sendLockReport(Map<String, String> param) {
sendLockReport(
param.get("sid"),
param.get("taskKey"),
longOrNull(param.get("taskReportId")),
dateOrNull(param.get("reportStartDate")),
param.get("userId"),
param.get("userName")
);
}
private void sendLockReport(
String sid,
String taskKey,
Long taskReportId,
Date reportStartDate,
String userId,
String userName
) {
ABVDataCache cache = ABVDataCache.getInstance();
NetworkAdapter adapter = ABVEnvironment.getInstance().networkAdapter;
AcmsClient client = AcmsClient.getInstance(cache.getUrlPath(), adapter);
LockReportParameters param = new LockReportParameters(
sid,
taskKey,
taskReportId,
reportStartDate,
userId,
userName
);
try {
client.sendLockReport(param);
} catch (Exception e) {
// todo
}
}
private void sendUnlockReport(Map<String, String> param) {
sendUnlockReport(
param.get("sid"),
param.get("taskKey"),
longOrNull(param.get("taskReportId")),
dateOrNull(param.get("reportStartDate"))
);
}
private void sendUnlockReport(
String sid,
String taskKey,
Long taskReportId,
Date reportStartDate
) {
ABVDataCache cache = ABVDataCache.getInstance();
NetworkAdapter adapter = ABVEnvironment.getInstance().networkAdapter;
AcmsClient client = AcmsClient.getInstance(cache.getUrlPath(), adapter);
UnlockReportParameters param = new UnlockReportParameters(
sid,
taskKey,
taskReportId,
reportStartDate
);
try {
client.sendUnlockReport(param);
} catch (Exception e) {
// todo
}
}
private Long longOrNull(String s) {
try {
return Long.valueOf(s);
} catch (Exception e) {
return null;
}
}
private Date dateOrNull(String s) {
try {
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMdd_hyphen);
} catch (Exception e) {
return null;
}
}
}
......@@ -39,10 +39,10 @@ app_versioncode=1
#cms server
#acms_address=https://check.abookcloud.com/acms
#download_server_address=https://check.abookcloud.com/acms
#acms_address=https://abook188-1.abook.bz/acms
#download_server_address=https://abook188-1.abook.bz/acms
acms_address=http://10.0.2.2:8080/acms
download_server_address=http://10.0.2.2:8080/acms
acms_address=https://abook188-1.abook.bz/acms
download_server_address=https://abook188-1.abook.bz/acms
#acms_address=http://10.0.2.2:8080/acms
#download_server_address=http://10.0.2.2:8080/acms
#syncview server
websocket_server_http_url=https://abook188-1.abook.bz/v1
......
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