diff --git a/decode-service.iml b/decode-service.iml index 18f7f8d..c9dade4 100644 --- a/decode-service.iml +++ b/decode-service.iml @@ -97,5 +97,7 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index aee9282..1d918d5 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ jar IRext Private Server - Decoding IR binaries online + IRext Private Server org.springframework.boot @@ -80,6 +80,16 @@ okio 2.2.2 + + com.google.code.gson + gson + 2.6.2 + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + diff --git a/src/main/java/net/irext/server/redis/model/CachedAdmin.java b/src/main/java/net/irext/server/redis/model/CachedAdmin.java new file mode 100644 index 0000000..d4a574a --- /dev/null +++ b/src/main/java/net/irext/server/redis/model/CachedAdmin.java @@ -0,0 +1,62 @@ +package net.irext.server.redis.model; + +import java.io.Serializable; + +/** + * Filename: CachedAdmin.java + * Revised: Date: 2017-04-27 + * Revision: Revision: 1.0 + *

+ * Description: CachedAdmin DAO for redis + *

+ * Revision log: + * 2017-04-27: created by strawmanbobi + */ +public class CachedAdmin implements Serializable { + + private static final long serialVersionUID = 1L; + + private static final String OBJECT_KEY = "ADMIN"; + + private String id; + private String token; + + public CachedAdmin() { + } + + public CachedAdmin(String id) { + } + + public CachedAdmin(String id, String token) { + this.id = id; + this.token = token; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String toString() { + return "CachedAdmin [id=" + id + ", token=" + token + "]"; + } + + public String getKey() { + return getId(); + } + + public String getObjectKey() { + return OBJECT_KEY; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/redis/model/CachedBinary.java b/src/main/java/net/irext/server/redis/model/CachedBinary.java new file mode 100644 index 0000000..197a82b --- /dev/null +++ b/src/main/java/net/irext/server/redis/model/CachedBinary.java @@ -0,0 +1,66 @@ +package net.irext.server.redis.model; + +import java.io.Serializable; + +/** + * Filename: CachedBinary.java + * Revised: Date: 2017-05-16 + * Revision: Revision: 1.0 + *

+ * Description: IR binary cache for performance optimization on decoding + *

+ * Revision log: + * 2017-05-16: created by strawmanbobi + */ +public class CachedBinary implements Serializable { + + private static final long serialVersionUID = 1L; + + private static final String OBJECT_KEY = "BINARY"; + + private int id; + private byte[] binaries; + + public CachedBinary() { + } + + public CachedBinary(String id) { + } + + public CachedBinary(int id, byte[] binaries) { + this.id = id; + this.binaries = binaries; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public byte[] getBinaries() { + return binaries; + } + + public void setBinaries(byte[] binaries) { + this.binaries = binaries; + } + + @Override + public String toString() { + return "CachedBinary{" + + "id='" + id + '\'' + + ", binaries=" + binaries.length + + '}'; + } + + public int getKey() { + return getId(); + } + + public String getObjectKey() { + return OBJECT_KEY; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/redis/service/AdminService.java b/src/main/java/net/irext/server/redis/service/AdminService.java new file mode 100644 index 0000000..82d9cab --- /dev/null +++ b/src/main/java/net/irext/server/redis/service/AdminService.java @@ -0,0 +1,50 @@ +package net.irext.server.redis.service; + +import net.irext.server.redis.model.CachedAdmin; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Repository; + +/** + * Filename: AdminService.java + * Revised: Date: 2017-04-27 + * Revision: Revision: 1.0 + *

+ * Description: CachedAdmin redis service + *

+ * Revision log: + * 2017-04-27: created by strawmanbobi + */ + +@Repository +public class AdminService { + + @Autowired + RedisTemplate redisTemplate; + + public RedisTemplate getRedisTemplate() { + return redisTemplate; + } + + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + public void put(CachedAdmin cachedAdmin) { + ValueOperations valueOper = redisTemplate.opsForValue(); + valueOper.set(cachedAdmin.getId(), cachedAdmin); + } + + public void delete(String id) { + ValueOperations valueOper = redisTemplate.opsForValue(); + RedisOperations RedisOperations = valueOper.getOperations(); + RedisOperations.delete(id); + } + + public CachedAdmin get(String id) { + ValueOperations valueOper = redisTemplate.opsForValue(); + return valueOper.get(id); + } +} diff --git a/src/main/java/net/irext/server/redis/service/BinaryService.java b/src/main/java/net/irext/server/redis/service/BinaryService.java new file mode 100644 index 0000000..ecbd639 --- /dev/null +++ b/src/main/java/net/irext/server/redis/service/BinaryService.java @@ -0,0 +1,50 @@ +package net.irext.server.redis.service; + +import net.irext.server.redis.model.CachedBinary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Repository; + +/** + * Filename: BinaryService.java + * Revised: Date: 2017-04-27 + * Revision: Revision: 1.0 + *

+ * Description: CachedBinary redis service + *

+ * Revision log: + * 2017-04-27: created by strawmanbobi + */ + +@Repository +public class BinaryService { + + @Autowired + RedisTemplate redisTemplate; + + public RedisTemplate getRedisTemplate() { + return redisTemplate; + } + + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + public void put(CachedBinary cachedBinary) { + ValueOperations valueOper = redisTemplate.opsForValue(); + valueOper.set(cachedBinary.getId(), cachedBinary); + } + + public void delete(Integer id) { + ValueOperations valueOper = redisTemplate.opsForValue(); + RedisOperations RedisOperations = valueOper.getOperations(); + RedisOperations.delete(id); + } + + public CachedBinary get(Integer id) { + ValueOperations valueOper = redisTemplate.opsForValue(); + return valueOper.get(id); + } +} diff --git a/src/main/java/net/irext/server/service/aspect/TokenValidation.java b/src/main/java/net/irext/server/service/aspect/TokenValidation.java new file mode 100644 index 0000000..641d383 --- /dev/null +++ b/src/main/java/net/irext/server/service/aspect/TokenValidation.java @@ -0,0 +1,22 @@ +package net.irext.server.service.aspect; + +import net.irext.server.service.response.ServiceResponse; + +/** + * Filename: TokenValidation.java + * Revised: Date: 2017-05-08 + * Revision: Revision: 1.0 + *

+ * Description: Token validation aspect logic + *

+ * Revision log: + * 2017-05-08: created by strawmanbobi + */ +public interface TokenValidation { + + ServiceResponse validateToken(String userId, String token); + + T validateToken(String userId, String token, + Class c); + +} diff --git a/src/main/java/net/irext/server/service/businesslogic/IndexLogic.java b/src/main/java/net/irext/server/service/businesslogic/IndexingLogic.java similarity index 67% rename from src/main/java/net/irext/server/service/businesslogic/IndexLogic.java rename to src/main/java/net/irext/server/service/businesslogic/IndexingLogic.java index 51d4b73..f98b0b1 100644 --- a/src/main/java/net/irext/server/service/businesslogic/IndexLogic.java +++ b/src/main/java/net/irext/server/service/businesslogic/IndexingLogic.java @@ -1,7 +1,9 @@ package net.irext.server.service.businesslogic; import net.irext.server.service.mapper.RemoteIndexMapper; +import net.irext.server.service.model.Category; import net.irext.server.service.model.RemoteIndex; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import java.util.List; @@ -17,23 +19,11 @@ import java.util.List; * 2018-12-08: created by strawmanbobi */ @Controller -public class IndexLogic { - - private static IndexLogic indexLogic; +public class IndexingLogic { + @Autowired private RemoteIndexMapper remoteIndexMapper; - public static IndexLogic getInstance(RemoteIndexMapper remoteIndexMapper) { - if (null == indexLogic) { - indexLogic = new IndexLogic(remoteIndexMapper); - } - return indexLogic; - } - - public IndexLogic(RemoteIndexMapper remoteIndexMapper) { - this.remoteIndexMapper = remoteIndexMapper; - } - public RemoteIndex getRemoteIndex(int indexId) { List remoteIndexList = remoteIndexMapper.getRemoteIndexById(indexId); if (null != remoteIndexList && remoteIndexList.size() > 0) { @@ -41,4 +31,8 @@ public class IndexLogic { } return null; } + + public List listCategories(int lang, int from, int count) { + return null; + } } diff --git a/src/main/java/net/irext/server/service/model/Brand.java b/src/main/java/net/irext/server/service/model/Brand.java new file mode 100644 index 0000000..0809499 --- /dev/null +++ b/src/main/java/net/irext/server/service/model/Brand.java @@ -0,0 +1,94 @@ +package net.irext.server.service.model; + +public class Brand { + private Integer id; + private String name; + private Integer categoryId; + private String categoryName; + private Byte status; + private String updateTime; + private Integer priority; + private String nameEn; + private String nameTw; + private String contributor; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getCategoryId() { + return categoryId; + } + + public void setCategoryId(Integer categoryId) { + this.categoryId = categoryId; + } + + public String getCategoryName() { + return categoryName; + } + + public void setCategoryName(String categoryName) { + this.categoryName = categoryName; + } + + public Byte getStatus() { + return status; + } + + public void setStatus(Byte status) { + this.status = status; + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + public Integer getPriority() { + return priority; + } + + public void setPriority(Integer priority) { + this.priority = priority; + } + + public String getNameEn() { + return nameEn; + } + + public void setNameEn(String nameEn) { + this.nameEn = nameEn; + } + + public String getNameTw() { + return nameTw; + } + + public void setNameTw(String nameTw) { + this.nameTw = nameTw; + } + + public String getContributor() { + return contributor; + } + + public void setContributor(String contributor) { + this.contributor = contributor; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/service/model/Category.java b/src/main/java/net/irext/server/service/model/Category.java new file mode 100644 index 0000000..83fbf59 --- /dev/null +++ b/src/main/java/net/irext/server/service/model/Category.java @@ -0,0 +1,67 @@ +package net.irext.server.service.model; + +public class Category { + private Integer id; + private String name; + private Byte status; + private String updateTime; + private String nameEn; + private String nameTw; + private String contributor; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Byte getStatus() { + return status; + } + + public void setStatus(Byte status) { + this.status = status; + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + public String getNameEn() { + return nameEn; + } + + public void setNameEn(String nameEn) { + this.nameEn = nameEn; + } + + public String getNameTw() { + return nameTw; + } + + public void setNameTw(String nameTw) { + this.nameTw = nameTw; + } + + public String getContributor() { + return contributor; + } + + public void setContributor(String contributor) { + this.contributor = contributor; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/service/model/City.java b/src/main/java/net/irext/server/service/model/City.java new file mode 100644 index 0000000..7a11747 --- /dev/null +++ b/src/main/java/net/irext/server/service/model/City.java @@ -0,0 +1,67 @@ +package net.irext.server.service.model; + +public class City { + private Integer id; + private String code; + private String name; + private Double longitude; + private Double latitude; + private Byte status; + private String nameTw; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getLongitude() { + return longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + public Double getLatitude() { + return latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + public Byte getStatus() { + return status; + } + + public void setStatus(Byte status) { + this.status = status; + } + + public String getNameTw() { + return nameTw; + } + + public void setNameTw(String nameTw) { + this.nameTw = nameTw; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/service/model/StbOperator.java b/src/main/java/net/irext/server/service/model/StbOperator.java new file mode 100644 index 0000000..daacdcf --- /dev/null +++ b/src/main/java/net/irext/server/service/model/StbOperator.java @@ -0,0 +1,67 @@ +package net.irext.server.service.model; + +public class StbOperator { + private Integer id; + private String operatorId; + private String operatorName; + private String cityCode; + private String cityName; + private Byte status; + private String operatorNameTw; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getOperatorId() { + return operatorId; + } + + public void setOperatorId(String operatorId) { + this.operatorId = operatorId; + } + + public String getOperatorName() { + return operatorName; + } + + public void setOperatorName(String operatorName) { + this.operatorName = operatorName; + } + + public String getCityCode() { + return cityCode; + } + + public void setCityCode(String cityCode) { + this.cityCode = cityCode; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public Byte getStatus() { + return status; + } + + public void setStatus(Byte status) { + this.status = status; + } + + public String getOperatorNameTw() { + return operatorNameTw; + } + + public void setOperatorNameTw(String operatorNameTw) { + this.operatorNameTw = operatorNameTw; + } +} \ No newline at end of file diff --git a/src/main/java/net/irext/server/service/request/BaseRequest.java b/src/main/java/net/irext/server/service/request/BaseRequest.java new file mode 100644 index 0000000..1f06e9b --- /dev/null +++ b/src/main/java/net/irext/server/service/request/BaseRequest.java @@ -0,0 +1,48 @@ +package net.irext.server.service.request; + +import com.google.gson.Gson; + +/** + * Filename: BaseRequest.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: authentication factors included + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class BaseRequest { + + private int id; + private String token; + + public BaseRequest(int id, String token) { + this.id = id; + this.token = token; + } + + BaseRequest() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String toJson() { + return new Gson().toJson(this, this.getClass()); + } +} diff --git a/src/main/java/net/irext/server/service/request/CloseRequest.java b/src/main/java/net/irext/server/service/request/CloseRequest.java index f24729e..c821099 100644 --- a/src/main/java/net/irext/server/service/request/CloseRequest.java +++ b/src/main/java/net/irext/server/service/request/CloseRequest.java @@ -10,7 +10,7 @@ package net.irext.server.service.request; * Revision log: * 2018-12-18: created by strawmanbobi */ -public class CloseRequest { +public class CloseRequest extends BaseRequest { private String sessionId; diff --git a/src/main/java/net/irext/server/service/request/DecodeRequest.java b/src/main/java/net/irext/server/service/request/DecodeRequest.java index 8cdbb71..53d0b9e 100644 --- a/src/main/java/net/irext/server/service/request/DecodeRequest.java +++ b/src/main/java/net/irext/server/service/request/DecodeRequest.java @@ -12,7 +12,7 @@ import net.irext.server.sdk.bean.ACStatus; * Revision log: * 2017-05-16: created by strawmanbobi */ -public class DecodeRequest { +public class DecodeRequest extends BaseRequest{ private int remoteIndexId; private ACStatus acStatus; diff --git a/src/main/java/net/irext/server/service/request/DownloadBinaryRequest.java b/src/main/java/net/irext/server/service/request/DownloadBinaryRequest.java index dfad5d8..c77c796 100755 --- a/src/main/java/net/irext/server/service/request/DownloadBinaryRequest.java +++ b/src/main/java/net/irext/server/service/request/DownloadBinaryRequest.java @@ -10,7 +10,7 @@ package net.irext.server.service.request; * Revision log: * 2017-04-14: created by strawmanbobi */ -public class DownloadBinaryRequest { +public class DownloadBinaryRequest extends BaseRequest { private int indexId; diff --git a/src/main/java/net/irext/server/service/request/GetACParametersRequest.java b/src/main/java/net/irext/server/service/request/GetACParametersRequest.java index 7685980..b975140 100644 --- a/src/main/java/net/irext/server/service/request/GetACParametersRequest.java +++ b/src/main/java/net/irext/server/service/request/GetACParametersRequest.java @@ -10,7 +10,7 @@ package net.irext.server.service.request; * Revision log: * 2019-02-14: created by strawmanbobi */ -public class GetACParametersRequest { +public class GetACParametersRequest extends BaseRequest { private int remoteIndexId; private String sessionId; diff --git a/src/main/java/net/irext/server/service/request/ListBrandsRequest.java b/src/main/java/net/irext/server/service/request/ListBrandsRequest.java new file mode 100644 index 0000000..bf24ec8 --- /dev/null +++ b/src/main/java/net/irext/server/service/request/ListBrandsRequest.java @@ -0,0 +1,52 @@ +package net.irext.server.service.request; + +/** + * Filename: ListBrandsRequest.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: HTTP list brands request + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class ListBrandsRequest extends BaseRequest { + + private int categoryId; + private int from; + private int count; + + public ListBrandsRequest(int categoryId, int from, int count) { + this.categoryId = categoryId; + this.from = from; + this.count = count; + } + + public ListBrandsRequest() { + + } + + public int getCategoryId() { + return categoryId; + } + + public void setCategoryId(int categoryId) { + this.categoryId = categoryId; + } + + public int getFrom() { + return from; + } + + public void setFrom(int from) { + this.from = from; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/src/main/java/net/irext/server/service/request/ListCategoriesRequest.java b/src/main/java/net/irext/server/service/request/ListCategoriesRequest.java new file mode 100644 index 0000000..c49644c --- /dev/null +++ b/src/main/java/net/irext/server/service/request/ListCategoriesRequest.java @@ -0,0 +1,42 @@ +package net.irext.server.service.request; + +/** + * Filename: ListCategoriesRequest.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: HTTP list categories request + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class ListCategoriesRequest extends BaseRequest { + + private int from; + private int count; + + public ListCategoriesRequest(int from, int count) { + this.from = from; + this.count = count; + } + + public ListCategoriesRequest() { + + } + + public int getFrom() { + return from; + } + + public void setFrom(int from) { + this.from = from; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/src/main/java/net/irext/server/service/request/ListCitiesRequest.java b/src/main/java/net/irext/server/service/request/ListCitiesRequest.java new file mode 100644 index 0000000..c8754e2 --- /dev/null +++ b/src/main/java/net/irext/server/service/request/ListCitiesRequest.java @@ -0,0 +1,32 @@ +package net.irext.server.service.request; + +/** + * Filename: ListCitiesRequest.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: HTTP list cities request + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class ListCitiesRequest extends BaseRequest { + + private String provincePrefix; + + public ListCitiesRequest(String provincePrefix) { + this.provincePrefix = provincePrefix; + } + + public ListCitiesRequest() { + + } + + public String getProvincePrefix() { + return provincePrefix; + } + + public void setProvincePrefix(String provincePrefix) { + this.provincePrefix = provincePrefix; + } +} diff --git a/src/main/java/net/irext/server/service/request/ListIndexesRequest.java b/src/main/java/net/irext/server/service/request/ListIndexesRequest.java new file mode 100644 index 0000000..c66423e --- /dev/null +++ b/src/main/java/net/irext/server/service/request/ListIndexesRequest.java @@ -0,0 +1,83 @@ +package net.irext.server.service.request; + +/** + * Filename: ListIndexesRequest.java + * Revised: Date: 2017-04-12 + * Revision: Revision: 1.0 + *

+ * Description: HTTP list remote indexes request + *

+ * Revision log: + * 2017-04-12: created by strawmanbobi + */ +public class ListIndexesRequest extends BaseRequest { + + private int from; + private int count; + private int categoryId; + private int brandId; + private String cityCode; + private String operatorId; + + public ListIndexesRequest(int from, int count, int categoryId, int brandId, + String cityCode, String operatorId) { + this.from = from; + this.count = count; + this.categoryId = categoryId; + this.brandId = brandId; + this.cityCode = cityCode; + this.operatorId = operatorId; + } + + public ListIndexesRequest() { + + } + + public int getFrom() { + return from; + } + + public void setFrom(int from) { + this.from = from; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getCategoryId() { + return categoryId; + } + + public void setCategoryId(int categoryId) { + this.categoryId = categoryId; + } + + public int getBrandId() { + return brandId; + } + + public void setBrandId(int brandId) { + this.brandId = brandId; + } + + public String getCityCode() { + return cityCode; + } + + public void setCityCode(String cityCode) { + this.cityCode = cityCode; + } + + public String getOperatorId() { + return operatorId; + } + + public void setOperatorId(String operatorId) { + this.operatorId = operatorId; + } +} diff --git a/src/main/java/net/irext/server/service/request/ListOperatorsRequest.java b/src/main/java/net/irext/server/service/request/ListOperatorsRequest.java new file mode 100644 index 0000000..6bac22e --- /dev/null +++ b/src/main/java/net/irext/server/service/request/ListOperatorsRequest.java @@ -0,0 +1,52 @@ +package net.irext.server.service.request; + +/** + * Filename: ListOperatorsRequest.java + * Revised: Date: 2017-04-10 + * Revision: Revision: 1.0 + *

+ * Description: HTTP list STB operators request + *

+ * Revision log: + * 2017-04-10: created by strawmanbobi + */ +public class ListOperatorsRequest extends BaseRequest { + + private int from; + private int count; + private String cityCode; + + public ListOperatorsRequest(int from, int count, String cityCode) { + this.from = from; + this.count = count; + this.cityCode = cityCode; + } + + public ListOperatorsRequest() { + + } + + public int getFrom() { + return from; + } + + public void setFrom(int from) { + this.from = from; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public String getCityCode() { + return cityCode; + } + + public void setCityCode(String cityCode) { + this.cityCode = cityCode; + } +} diff --git a/src/main/java/net/irext/server/service/response/BrandsResponse.java b/src/main/java/net/irext/server/service/response/BrandsResponse.java new file mode 100644 index 0000000..1e36c4e --- /dev/null +++ b/src/main/java/net/irext/server/service/response/BrandsResponse.java @@ -0,0 +1,37 @@ +package net.irext.server.service.response; + +import net.irext.server.service.model.Brand; + +import java.util.List; + +/** + * Filename: BrandsResponse.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: List brands response + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class BrandsResponse extends ServiceResponse { + + private List entity; + + public BrandsResponse(Status status, List brands) { + super(status); + this.entity = brands; + } + + public BrandsResponse() { + + } + + public List getEntity() { + return entity; + } + + public void setEntity(List entity) { + this.entity = entity; + } +} diff --git a/src/main/java/net/irext/server/service/response/CategoriesResponse.java b/src/main/java/net/irext/server/service/response/CategoriesResponse.java new file mode 100644 index 0000000..3fddcdd --- /dev/null +++ b/src/main/java/net/irext/server/service/response/CategoriesResponse.java @@ -0,0 +1,37 @@ +package net.irext.server.service.response; + +import net.irext.server.service.model.Category; + +import java.util.List; + +/** + * Filename: CategoriesResponse.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: List categories response + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class CategoriesResponse extends ServiceResponse { + + private List entity; + + public CategoriesResponse(Status status, List categories) { + super(status); + this.entity = categories; + } + + public CategoriesResponse() { + + } + + public List getEntity() { + return entity; + } + + public void setEntity(List entity) { + this.entity = entity; + } +} diff --git a/src/main/java/net/irext/server/service/response/CitiesResponse.java b/src/main/java/net/irext/server/service/response/CitiesResponse.java new file mode 100644 index 0000000..94ffbe7 --- /dev/null +++ b/src/main/java/net/irext/server/service/response/CitiesResponse.java @@ -0,0 +1,37 @@ +package net.irext.server.service.response; + +import net.irext.server.service.model.City; + +import java.util.List; + +/** + * Filename: CitiesResponse.java + * Revised: Date: 2017-04-07 + * Revision: Revision: 1.0 + *

+ * Description: List cities response + *

+ * Revision log: + * 2017-04-07: created by strawmanbobi + */ +public class CitiesResponse extends ServiceResponse { + + private List entity; + + public CitiesResponse(Status status, List cities) { + super(status); + this.entity = cities; + } + + public CitiesResponse() { + + } + + public List getEntity() { + return entity; + } + + public void setEntity(List entity) { + this.entity = entity; + } +} diff --git a/src/main/java/net/irext/server/service/response/OperatorsResponse.java b/src/main/java/net/irext/server/service/response/OperatorsResponse.java new file mode 100644 index 0000000..7175c57 --- /dev/null +++ b/src/main/java/net/irext/server/service/response/OperatorsResponse.java @@ -0,0 +1,35 @@ +package net.irext.server.service.response; + +import java.util.List; + +/** + * Filename: OperatorsResponse.java + * Revised: Date: 2017-04-10 + * Revision: Revision: 1.0 + *

+ * Description: List STB operators response + *

+ * Revision log: + * 2017-04-10: created by strawmanbobi + */ +public class OperatorsResponse extends ServiceResponse { + + private List entity; + + public OperatorsResponse(Status status, List cities) { + super(status); + this.entity = cities; + } + + public OperatorsResponse() { + + } + + public List getEntity() { + return entity; + } + + public void setEntity(List entity) { + this.entity = entity; + } +} diff --git a/src/main/java/net/irext/server/service/restapi/CategoryResponse.java b/src/main/java/net/irext/server/service/restapi/CategoryResponse.java new file mode 100644 index 0000000..9915441 --- /dev/null +++ b/src/main/java/net/irext/server/service/restapi/CategoryResponse.java @@ -0,0 +1,4 @@ +package net.irext.server.service.restapi; + +public class CategoryResponse { +} diff --git a/src/main/java/net/irext/server/service/restapi/IRDecodeService.java b/src/main/java/net/irext/server/service/restapi/IRDecodeService.java index cc0dc2e..fb8cd1c 100644 --- a/src/main/java/net/irext/server/service/restapi/IRDecodeService.java +++ b/src/main/java/net/irext/server/service/restapi/IRDecodeService.java @@ -14,7 +14,7 @@ import net.irext.server.service.request.OpenRequest; import net.irext.server.service.response.*; import net.irext.server.service.utils.LoggerUtil; import net.irext.server.service.utils.MD5Util; -import net.irext.server.service.businesslogic.IndexLogic; +import net.irext.server.service.businesslogic.IndexingLogic; import net.irext.server.service.restapi.base.AbstractBaseService; import net.irext.server.sdk.bean.ACStatus; import net.irext.server.sdk.utils.Constants; @@ -34,13 +34,13 @@ import java.text.SimpleDateFormat; * Revised: Date: 2018-12-16 * Revision: Revision: 1.0 *

- * Description: IRext Decode WebService + * Description: IRext Decode Webservice *

* Revision log: * 2018-12-16: created by strawmanbobi */ @RestController -@RequestMapping("/irext") +@RequestMapping("/irext-server/decode") @Service("IRDecodeService") public class IRDecodeService extends AbstractBaseService { @@ -69,7 +69,7 @@ public class IRDecodeService extends AbstractBaseService { LoggerUtil.getInstance().trace(TAG, "irOpen API called : " + remoteIndexId); StringResponse response = new StringResponse(); - RemoteIndex remoteIndex = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId); + RemoteIndex remoteIndex = IndexingLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId); if (null == remoteIndex) { response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, Constants.ERROR_CODE_NETWORK_ERROR_TEXT)); diff --git a/src/main/java/net/irext/server/service/restapi/IRIndexingService.java b/src/main/java/net/irext/server/service/restapi/IRIndexingService.java new file mode 100644 index 0000000..8c0e099 --- /dev/null +++ b/src/main/java/net/irext/server/service/restapi/IRIndexingService.java @@ -0,0 +1,89 @@ +package net.irext.server.service.restapi; + +import net.irext.server.service.Constants; +import net.irext.server.service.businesslogic.IndexingLogic; +import net.irext.server.service.mapper.RemoteIndexMapper; +import net.irext.server.service.model.Category; +import net.irext.server.service.request.*; +import net.irext.server.service.response.*; +import net.irext.server.service.restapi.base.AbstractBaseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.ServletContext; +import javax.ws.rs.HeaderParam; +import java.util.List; + +/** + * Filename: IRIndexingService.java + * Revised: Date: 2019-06-08 + * Revision: Revision: 1.0 + *

+ * Description: IRext Indexing Webservice + *

+ * Revision log: + * 2019-06-08: created by strawmanbobi + */ +@RestController +@RequestMapping("/irext-server/indexing") +@Service("IRDecodeService") +public class IRIndexingService extends AbstractBaseService { + + private static final String TAG = IRIndexingService.class.getSimpleName(); + + @Autowired + private ServletContext context; + + @Autowired + private IndexingLogic indexingLogic; + + public IRIndexingService(RemoteIndexMapper remoteIndexMapper) { + } + + @PostMapping("/list_categories") + public CategoriesResponse listCategories(@HeaderParam("user-lang") String userLang, + ListCategoriesRequest listCategoriesRequest) { + try { + int id = listCategoriesRequest.getId(); + String token = listCategoriesRequest.getToken(); + int from = listCategoriesRequest.getFrom(); + int count = listCategoriesRequest.getCount(); + int lang = Constants.LANG_ZH_CN; + + if (null != userLang) { + if (userLang.equals("en-US")) { + lang = Constants.LANG_EN; + } else if (userLang.equals("zh-TW")) { + lang = Constants.LANG_TW_CN; + } else { + lang = Constants.LANG_ZH_CN; + } + } + + System.out.println("language = " + lang); + + CategoriesResponse response = validateToken(Integer.toString(id), token, CategoriesResponse.class); + if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) { + return response; + } + + List categoryList = indexingLogic.listCategories(lang, from, count); + + if (categoryList != null) { + response.getStatus().setCode(Constants.ERROR_CODE_SUCCESS); + response.setEntity(categoryList); + } else { + response.getStatus().setCode(Constants.ERROR_CODE_NETWORK_ERROR); + } + + return response; + } catch (Exception e) { + e.printStackTrace(); + return getExceptionResponse(CategoriesResponse.class); + } + } + +} diff --git a/src/main/java/net/irext/server/service/restapi/base/AbstractBaseService.java b/src/main/java/net/irext/server/service/restapi/base/AbstractBaseService.java index f6b9963..84ab86f 100644 --- a/src/main/java/net/irext/server/service/restapi/base/AbstractBaseService.java +++ b/src/main/java/net/irext/server/service/restapi/base/AbstractBaseService.java @@ -1,10 +1,15 @@ package net.irext.server.service.restapi.base; +import net.irext.server.redis.model.CachedAdmin; +import net.irext.server.redis.service.AdminService; import net.irext.server.service.Constants; +import net.irext.server.service.aspect.TokenValidation; import net.irext.server.service.response.ServiceResponse; import net.irext.server.service.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 @@ -16,10 +21,54 @@ import org.apache.commons.logging.LogFactory; * Revision log: * 2017-04-27: created by strawmanbobi */ -public abstract class AbstractBaseService { - // note : not using ASPECT here but keep the ASPECT sketch +public abstract class AbstractBaseService implements TokenValidation { + protected static Log log = LogFactory.getLog(AbstractBaseService.class); + @Override + public ServiceResponse validateToken(String userId, String token) { + if (log.isDebugEnabled()) { + log.debug("Auth token id: " + userId + ", token: " + token); + } + ServiceResponse response = new ServiceResponse(); + Status status = new Status(); + + if (null == userId || null == token) { + status.setCode(Constants.ERROR_CODE_AUTH_FAILURE); + } else { + status = validateUserToken(userId, token); + } + + response.setStatus(status); + return response; + } + + @Override + public T validateToken(String userId, String token, + Class c) { + T r = null; + Status status = new Status(); + + if (null == userId || null == token) { + status.setCode(Constants.ERROR_CODE_AUTH_FAILURE); + } else { + status = validateUserToken(userId, token); + } + + try { + r = c.newInstance(); + } catch (InstantiationException e) { + log.error("Error when new instance of class: " + c.getName(), e); + } catch (IllegalAccessException e) { + log.error("Error when new instance of class: " + c.getName(), e); + } + + if (null != r) { + r.setStatus(status); + } + return r; + } + protected ServiceResponse getExceptionResponse() { ServiceResponse r = new ServiceResponse(); Status status = new Status(); @@ -33,7 +82,9 @@ public abstract class AbstractBaseService { Status status = new Status(); try { r = c.newInstance(); - } catch (Exception e) { + } catch (InstantiationException e) { + log.error("Error when new instance of class: " + c.getName(), e); + } catch (IllegalAccessException e) { log.error("Error when new instance of class: " + c.getName(), e); } status.setCode(Constants.ERROR_CODE_AUTH_FAILURE); @@ -42,4 +93,21 @@ public abstract class AbstractBaseService { } return r; } + + private Status validateUserToken(String userId, String token) { + Status status = new Status(); + ApplicationContext applicationContext; + AdminService adminService; + + applicationContext = new ClassPathXmlApplicationContext("redisBeans.xml"); + adminService = applicationContext.getBean(AdminService.class); + CachedAdmin cachedAdmin = adminService.get(userId); + if (null != cachedAdmin && cachedAdmin.getToken().equals(token)) { + status.setCode(Constants.ERROR_CODE_SUCCESS); + } else { + status.setCode(Constants.ERROR_CODE_AUTH_FAILURE); + } + + return status; + } }