implemented openIR with session_id
This commit is contained in:
@@ -18,10 +18,10 @@ public interface IDecodeSessionRepository {
|
|||||||
|
|
||||||
Map<Object, Object> findAllDecodeSessions();
|
Map<Object, Object> findAllDecodeSessions();
|
||||||
|
|
||||||
void add(DecodeSession decodeSession);
|
void add(String decodeSessionId, Integer remoteId);
|
||||||
|
|
||||||
void delete(Integer id);
|
void delete(String decodeSessionId);
|
||||||
|
|
||||||
DecodeSession find(Integer id);
|
Integer find(String decodeSessionId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,16 +37,16 @@ public class DecodeSessionRepositoryImpl implements IDecodeSessionRepository {
|
|||||||
hashOperations = redisTemplate.opsForHash();
|
hashOperations = redisTemplate.opsForHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(final DecodeSession decodeSession) {
|
public void add(final String decodeSessionId, Integer binaryId) {
|
||||||
hashOperations.put(KEY, decodeSession.getId(), decodeSession.getName());
|
hashOperations.put(KEY, decodeSessionId, binaryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(final Integer id) {
|
public void delete(String decodeSessionId) {
|
||||||
hashOperations.delete(KEY, id);
|
hashOperations.delete(KEY, decodeSessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeSession find(final Integer id) {
|
public Integer find(String decodeSessionId) {
|
||||||
return (DecodeSession) hashOperations.get(KEY, id);
|
return (Integer) hashOperations.get(KEY, decodeSessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Object, Object> findAllDecodeSessions() {
|
public Map<Object, Object> findAllDecodeSessions() {
|
||||||
|
|||||||
@@ -12,31 +12,31 @@ package net.irext.decoder.model;
|
|||||||
*/
|
*/
|
||||||
public class DecodeSession {
|
public class DecodeSession {
|
||||||
|
|
||||||
private Integer id;
|
private String sessionId;
|
||||||
private String name;
|
private Integer binaryId;
|
||||||
|
|
||||||
public DecodeSession(Integer id, String name) {
|
public DecodeSession(String sessionId, Integer binaryId) {
|
||||||
this.id = id;
|
this.sessionId = sessionId;
|
||||||
this.name = name;
|
this.binaryId = binaryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeSession() {
|
public DecodeSession() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public String getSessionId() {
|
||||||
return id;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setSessionId(String sessionId) {
|
||||||
this.id = id;
|
this.sessionId = sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public Integer getBinaryId() {
|
||||||
return name;
|
return binaryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setBinaryId(Integer binaryId) {
|
||||||
this.name = name;
|
this.binaryId = binaryId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class DecodeRequest {
|
|||||||
private ACStatus acStatus;
|
private ACStatus acStatus;
|
||||||
private int keyCode;
|
private int keyCode;
|
||||||
private int changeWindDir;
|
private int changeWindDir;
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
public DecodeRequest(int indexId, ACStatus acStatus, int keyCode, int changeWindDir) {
|
public DecodeRequest(int indexId, ACStatus acStatus, int keyCode, int changeWindDir) {
|
||||||
this.indexId = indexId;
|
this.indexId = indexId;
|
||||||
@@ -61,4 +62,12 @@ public class DecodeRequest {
|
|||||||
public void setChangeWindDir(int changeWindDir) {
|
public void setChangeWindDir(int changeWindDir) {
|
||||||
this.changeWindDir = changeWindDir;
|
this.changeWindDir = changeWindDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSessionId() {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionId(String sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/main/java/net/irext/decoder/response/StringResponse.java
Normal file
34
src/main/java/net/irext/decoder/response/StringResponse.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package net.irext.decoder.response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: StringResponse.java
|
||||||
|
* Revised: Date: 2017-05-16
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: String response
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2017-05-16: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public class StringResponse extends ServiceResponse {
|
||||||
|
|
||||||
|
private String entity;
|
||||||
|
|
||||||
|
public StringResponse(Status status, String entity) {
|
||||||
|
super(status);
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringResponse() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntity(String entity) {
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@ package net.irext.decoder.service;
|
|||||||
import net.irext.decoder.businesslogic.DecodeLogic;
|
import net.irext.decoder.businesslogic.DecodeLogic;
|
||||||
import net.irext.decoder.businesslogic.IndexLogic;
|
import net.irext.decoder.businesslogic.IndexLogic;
|
||||||
import net.irext.decoder.mapper.RemoteIndexMapper;
|
import net.irext.decoder.mapper.RemoteIndexMapper;
|
||||||
|
import net.irext.decoder.model.DecodeSession;
|
||||||
import net.irext.decoder.model.RemoteIndex;
|
import net.irext.decoder.model.RemoteIndex;
|
||||||
import net.irext.decoder.cache.IDecodeSessionRepository;
|
import net.irext.decoder.cache.IDecodeSessionRepository;
|
||||||
import net.irext.decoder.cache.IIRBinaryRepository;
|
import net.irext.decoder.cache.IIRBinaryRepository;
|
||||||
@@ -12,8 +13,10 @@ import net.irext.decoder.request.OpenRequest;
|
|||||||
import net.irext.decoder.response.DecodeResponse;
|
import net.irext.decoder.response.DecodeResponse;
|
||||||
import net.irext.decoder.response.ServiceResponse;
|
import net.irext.decoder.response.ServiceResponse;
|
||||||
import net.irext.decoder.response.Status;
|
import net.irext.decoder.response.Status;
|
||||||
|
import net.irext.decoder.response.StringResponse;
|
||||||
import net.irext.decoder.service.base.AbstractBaseService;
|
import net.irext.decoder.service.base.AbstractBaseService;
|
||||||
import net.irext.decoder.utils.LoggerUtil;
|
import net.irext.decoder.utils.LoggerUtil;
|
||||||
|
import net.irext.decoder.utils.MD5Util;
|
||||||
import net.irext.decodesdk.bean.ACStatus;
|
import net.irext.decodesdk.bean.ACStatus;
|
||||||
import net.irext.decodesdk.utils.Constants;
|
import net.irext.decodesdk.utils.Constants;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -21,6 +24,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: IRDecodeService.java
|
* Filename: IRDecodeService.java
|
||||||
@@ -55,16 +60,17 @@ public class IRDecodeService extends AbstractBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/open")
|
@PostMapping("/open")
|
||||||
public ServiceResponse irOpen(@RequestBody OpenRequest openRequest) {
|
public StringResponse irOpen(HttpServletRequest request, @RequestBody OpenRequest openRequest) {
|
||||||
try {
|
try {
|
||||||
int remoteIndexId = openRequest.getRemoteIndexId();
|
int remoteIndexId = openRequest.getRemoteIndexId();
|
||||||
|
|
||||||
LoggerUtil.getInstance().trace(TAG,"irOpen API called : " + remoteIndexId);
|
LoggerUtil.getInstance().trace(TAG,"irOpen API called : " + remoteIndexId);
|
||||||
|
|
||||||
ServiceResponse response = new ServiceResponse();
|
StringResponse response = new StringResponse();
|
||||||
RemoteIndex remoteIndex = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId);
|
RemoteIndex remoteIndex = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId);
|
||||||
if (null == remoteIndex) {
|
if (null == remoteIndex) {
|
||||||
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
|
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
|
||||||
|
response.setEntity(null);
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
LoggerUtil.getInstance().trace(TAG, "remoteIndex get : " + remoteIndex.getId() + ", " +
|
LoggerUtil.getInstance().trace(TAG, "remoteIndex get : " + remoteIndex.getId() + ", " +
|
||||||
@@ -74,12 +80,21 @@ public class IRDecodeService extends AbstractBaseService {
|
|||||||
|
|
||||||
if (null != binaryContent) {
|
if (null != binaryContent) {
|
||||||
LoggerUtil.getInstance().trace(TAG,"binary content fetched : " + binaryContent.length);
|
LoggerUtil.getInstance().trace(TAG,"binary content fetched : " + binaryContent.length);
|
||||||
|
// construct a session with this binary
|
||||||
|
String address = request.getRemoteAddr();
|
||||||
|
LoggerUtil.getInstance().trace(TAG, "request Address = " + address);
|
||||||
|
String timeStamp =
|
||||||
|
new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
|
||||||
|
String sessionId = MD5Util.MD5Encode(address + timeStamp, null);
|
||||||
|
DecodeSession decodeSession = new DecodeSession(sessionId, remoteIndex.getId());
|
||||||
|
decodeSessionRepository.add(decodeSession.getSessionId(), decodeSession.getBinaryId());
|
||||||
|
response.setEntity(decodeSession.getSessionId());
|
||||||
}
|
}
|
||||||
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, ""));
|
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, ""));
|
||||||
return response;
|
return response;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return getExceptionResponse(DecodeResponse.class);
|
return getExceptionResponse(StringResponse.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +105,7 @@ public class IRDecodeService extends AbstractBaseService {
|
|||||||
ACStatus acstatus = decodeRequest.getAcStatus();
|
ACStatus acstatus = decodeRequest.getAcStatus();
|
||||||
int keyCode = decodeRequest.getKeyCode();
|
int keyCode = decodeRequest.getKeyCode();
|
||||||
int changeWindDir = decodeRequest.getChangeWindDir();
|
int changeWindDir = decodeRequest.getChangeWindDir();
|
||||||
|
String sessionId = decodeRequest.getSessionId();
|
||||||
|
|
||||||
DecodeResponse response = new DecodeResponse();
|
DecodeResponse response = new DecodeResponse();
|
||||||
int[] irArray = DecodeLogic.getInstance().decode();
|
int[] irArray = DecodeLogic.getInstance().decode();
|
||||||
|
|||||||
Reference in New Issue
Block a user