cleaned requests and services
This commit is contained in:
@@ -15,37 +15,20 @@ import org.springframework.stereotype.Controller;
|
|||||||
@Controller
|
@Controller
|
||||||
public class DecodeLogic {
|
public class DecodeLogic {
|
||||||
|
|
||||||
private Integer codeCollectState = 0;
|
|
||||||
private IRCode irCode;
|
|
||||||
|
|
||||||
private static DecodeLogic decodeLogic;
|
private static DecodeLogic decodeLogic;
|
||||||
|
|
||||||
public static DecodeLogic getInstance(IRCode irCode) {
|
public static DecodeLogic getInstance() {
|
||||||
if (null == decodeLogic) {
|
if (null == decodeLogic) {
|
||||||
decodeLogic = new DecodeLogic(irCode);
|
decodeLogic = new DecodeLogic();
|
||||||
}
|
}
|
||||||
return decodeLogic;
|
return decodeLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeLogic(IRCode irCode) {
|
|
||||||
this.irCode = irCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DecodeLogic() {
|
public DecodeLogic() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean collectCodeWorkUnit() {
|
public int[] decode() {
|
||||||
// step 1. figure out the category and brand for this code
|
return null;
|
||||||
|
|
||||||
// step 2. go through the FSM for remote in each category
|
|
||||||
codeCollectState++;
|
|
||||||
System.out.println("state = " + codeCollectState + " : " + irCode.getKey());
|
|
||||||
|
|
||||||
// step 3. record key code
|
|
||||||
|
|
||||||
// step 4. temporarily save to file
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.irext.decoder.businesslogic;
|
||||||
|
|
||||||
|
import net.irext.decoder.model.RemoteIndex;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: CollectCodeLogic
|
||||||
|
* Revised: Date: 2018-12-08
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: IRext Code Collector Collect Code Logic
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-08: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class IndexLogic {
|
||||||
|
|
||||||
|
private static IndexLogic indexLogic;
|
||||||
|
|
||||||
|
public static IndexLogic getInstance() {
|
||||||
|
if (null == indexLogic) {
|
||||||
|
indexLogic = new IndexLogic();
|
||||||
|
}
|
||||||
|
return indexLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteIndex getRemoteIndex(int indexId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/java/net/irext/decoder/request/CloseRequest.java
Normal file
33
src/main/java/net/irext/decoder/request/CloseRequest.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package net.irext.decoder.request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: CloseRequest.java
|
||||||
|
* Revised: Date: 2018-12-18
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: HTTP decode online
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-18: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public class CloseRequest {
|
||||||
|
|
||||||
|
private int indexId;
|
||||||
|
|
||||||
|
public CloseRequest(int indexId) {
|
||||||
|
this.indexId = indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloseRequest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndexId() {
|
||||||
|
return indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexId(int indexId) {
|
||||||
|
this.indexId = indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
src/main/java/net/irext/decoder/request/OpenRequest.java
Normal file
33
src/main/java/net/irext/decoder/request/OpenRequest.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package net.irext.decoder.request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: OpenRequest.java
|
||||||
|
* Revised: Date: 2018-12-18
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: HTTP decode online
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-18: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public class OpenRequest {
|
||||||
|
|
||||||
|
private int indexId;
|
||||||
|
|
||||||
|
public OpenRequest(int indexId) {
|
||||||
|
this.indexId = indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenRequest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndexId() {
|
||||||
|
return indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexId(int indexId) {
|
||||||
|
this.indexId = indexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package net.irext.decoder.service;
|
package net.irext.decoder.service;
|
||||||
|
|
||||||
|
import net.irext.decoder.businesslogic.DecodeLogic;
|
||||||
|
import net.irext.decoder.businesslogic.IndexLogic;
|
||||||
import net.irext.decoder.model.RemoteIndex;
|
import net.irext.decoder.model.RemoteIndex;
|
||||||
|
import net.irext.decoder.request.CloseRequest;
|
||||||
import net.irext.decoder.request.DecodeRequest;
|
import net.irext.decoder.request.DecodeRequest;
|
||||||
|
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.Status;
|
import net.irext.decoder.response.Status;
|
||||||
|
import net.irext.decoder.service.base.AbstractBaseService;
|
||||||
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.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -20,13 +26,32 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/irext")
|
@RequestMapping("/irext")
|
||||||
public class IRDecodeService {
|
public class IRDecodeService extends AbstractBaseService {
|
||||||
|
|
||||||
public IRDecodeService() {
|
public IRDecodeService() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/decode")
|
@PostMapping("/open")
|
||||||
|
public ServiceResponse irOpen(@RequestBody OpenRequest openRequest) {
|
||||||
|
try {
|
||||||
|
int indexId = openRequest.getIndexId();
|
||||||
|
|
||||||
|
ServiceResponse response = new ServiceResponse();
|
||||||
|
RemoteIndex index = IndexLogic.getInstance().getRemoteIndex(indexId);
|
||||||
|
if (null == index) {
|
||||||
|
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return getExceptionResponse(DecodeResponse.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/decode")
|
||||||
public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) {
|
public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) {
|
||||||
try {
|
try {
|
||||||
int indexId = decodeRequest.getIndexId();
|
int indexId = decodeRequest.getIndexId();
|
||||||
@@ -34,18 +59,22 @@ public class IRDecodeService {
|
|||||||
int keyCode = decodeRequest.getKeyCode();
|
int keyCode = decodeRequest.getKeyCode();
|
||||||
int changeWindDir = decodeRequest.getChangeWindDir();
|
int changeWindDir = decodeRequest.getChangeWindDir();
|
||||||
|
|
||||||
RemoteIndex index = indexingLogic.getRemoteIndex(indexId);
|
DecodeResponse response = new DecodeResponse();
|
||||||
if (null == index) {
|
int[] irArray = DecodeLogic.getInstance().decode();
|
||||||
response.setEntity(null);
|
|
||||||
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte []binaryContent = operationLogic.prepareBinary(indexId);
|
return response;
|
||||||
System.out.println("binary content fetched : " + binaryContent.length);
|
} catch (Exception e) {
|
||||||
int []decoded = operationLogic.decodeIR(index.getCategoryId(), index.getSubCate(),
|
e.printStackTrace();
|
||||||
binaryContent, acstatus, keyCode, changeWindDir);
|
return getExceptionResponse(DecodeResponse.class);
|
||||||
response.setEntity(decoded);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/close")
|
||||||
|
public ServiceResponse irClose(@RequestBody CloseRequest closeRequest) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
ServiceResponse response = new ServiceResponse();
|
||||||
|
DecodeLogic.getInstance().decode();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.irext.decoder.service.base;
|
||||||
|
|
||||||
|
import net.irext.decoder.Constants;
|
||||||
|
import net.irext.decoder.response.ServiceResponse;
|
||||||
|
import net.irext.decoder.response.Status;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: AbstractBaseService.java
|
||||||
|
* Revised: Date: 2017-04-27
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: Base service abstract class implemented service interface
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2017-04-27: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public abstract class AbstractBaseService {
|
||||||
|
// note : not using ASPECT here but keep the ASPECT sketch
|
||||||
|
protected static Log log = LogFactory.getLog(AbstractBaseService.class);
|
||||||
|
|
||||||
|
protected ServiceResponse getExceptionResponse() {
|
||||||
|
ServiceResponse r = new ServiceResponse();
|
||||||
|
Status status = new Status();
|
||||||
|
status.setCode(Constants.ERROR_CODE_AUTH_FAILURE);
|
||||||
|
r.setStatus(status);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T extends ServiceResponse> T getExceptionResponse(Class<T> c) {
|
||||||
|
T r = null;
|
||||||
|
Status status = new Status();
|
||||||
|
try {
|
||||||
|
r = c.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error when new instance of class: " + c.getName(), e);
|
||||||
|
}
|
||||||
|
status.setCode(Constants.ERROR_CODE_AUTH_FAILURE);
|
||||||
|
if (null != r) {
|
||||||
|
r.setStatus(status);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user