summaryrefslogtreecommitdiffstats
path: root/warehouse/src/main/java/app/market/web/services
diff options
context:
space:
mode:
Diffstat (limited to 'warehouse/src/main/java/app/market/web/services')
-rw-r--r--warehouse/src/main/java/app/market/web/services/SpringBaseService.java248
-rw-r--r--warehouse/src/main/java/app/market/web/services/account/AccountService.java76
-rw-r--r--warehouse/src/main/java/app/market/web/services/account/impl/AccountServiceImpl.java220
-rw-r--r--warehouse/src/main/java/app/market/web/services/app/AppService.java124
-rw-r--r--warehouse/src/main/java/app/market/web/services/app/impl/AppServiceImpl.java511
-rw-r--r--warehouse/src/main/java/app/market/web/services/login/LoginService.java25
-rw-r--r--warehouse/src/main/java/app/market/web/services/login/impl/LoginServiceImpl.java81
-rw-r--r--warehouse/src/main/java/app/market/web/services/main/MainService.java27
-rw-r--r--warehouse/src/main/java/app/market/web/services/main/impl/MainServiceImpl.java71
-rw-r--r--warehouse/src/main/java/app/market/web/services/user/UserService.java35
-rw-r--r--warehouse/src/main/java/app/market/web/services/user/impl/UserServiceImpl.java141
11 files changed, 1559 insertions, 0 deletions
diff --git a/warehouse/src/main/java/app/market/web/services/SpringBaseService.java b/warehouse/src/main/java/app/market/web/services/SpringBaseService.java
new file mode 100644
index 0000000..8c54aaf
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/SpringBaseService.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.client.HttpClientErrorException;
+
+import com.alibaba.fastjson.JSONObject;
+
+import app.market.WebServiceClient;
+import app.market.model.app.App;
+import app.market.utils.constants.Constants;
+import app.market.utils.datatable.DataTableMap;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.json.JsonResult;
+import app.market.utils.property.KeysConstants;
+import app.market.utils.property.MessageUtil;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.utils.webservice.ApiParam;
+
+public abstract class SpringBaseService {
+
+ protected String convertEmptyStr(Object obj) {
+ if ( obj == null ) {
+ return Constants.EMPTY_STRING_FALG;
+ }
+ if ( obj instanceof String ) {
+ String s = (String) obj;
+ return StringUtils.isEmpty( s ) ? Constants.EMPTY_STRING_FALG : s;
+
+ } else if ( obj instanceof Integer ) {
+ Integer i = (Integer) obj;
+ return i == null ? Constants.EMPTY_STRING_FALG : i + "";
+
+ } else {
+ return obj.toString();
+ }
+ }
+
+ protected JsonResult validateAuthentication(HttpSession session) {
+ JsonResult jr = new JsonResult();
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ try {
+ String jsonStr = restTemplate.get( WebServiceClient.REST_TOKEN_VALIDATETOKENAUTHORTICATION, session, new String[] {} );
+ jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ return jr;
+ } catch ( Exception e ) {
+ if ( e instanceof HttpClientErrorException ) {
+ HttpClientErrorException hcee = (HttpClientErrorException) e;
+ switch ( hcee.getStatusCode().value() ) {
+ case Constants.STATUS_UNAUTHORIZED:
+ if (updateAccessToken(jr, session)) {
+ jr = validateAuthentication(session);
+ } else {
+ jr.setStatus(Constants.STATUS_UNAUTHORIZED);
+ jr.setData(MessageUtil.getPropertites(KeysConstants.STATUS_UNAUTHORIZED));
+ }
+ break;
+ case Constants.STATUS_TOO_MANY_CONNECTIONS:
+ jr.setStatus( Constants.STATUS_TOO_MANY_CONNECTIONS );
+ jr.setData( MessageUtil.getPropertites( KeysConstants.STATUS_TOO_MANY_CONNECTIONS ) );
+ break;
+ case Constants.STATUS_FORBIDDEN:
+ jr.setStatus( Constants.STATUS_FORBIDDEN );
+ jr.setData( MessageUtil.getPropertites( KeysConstants.STATUS_FORBIDDEN ) );
+ break;
+ default:
+ jr.setStatus( Constants.STATUS_ERROR );
+ jr.setData( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ break;
+ }
+ } else {
+ jr.setStatus( Constants.STATUS_ERROR );
+ jr.setData( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ return jr;
+ }
+ }
+
+ /**
+ * update acess token
+ * @param jr
+ * @param session
+ * @return
+ */
+ private boolean updateAccessToken(JsonResult jr, HttpSession session) {
+ boolean ret = false;
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ try {
+ String refreshToken = (String) session.getAttribute(Constants.SESSION_REFRESH_TOKEN);
+
+ String jsonStr = restTemplate.get(WebServiceClient.REST_TOKEN, session, new String[] { refreshToken });
+ JSONObject json = JsonMapperUtils.getJsonObject(jsonStr);
+ String token = json.getString(ApiParam.API_RESPONSE_TOKEN);
+ //String refreshtoken = json.getString(ApiParam.API_RESPONSE_REFRESHTOKEN);
+ session.setAttribute( Constants.SESSION_TOKEN, token );
+ //session.setAttribute( Constants.SESSION_REFRESH_TOKEN, refreshtoken );
+ ret = true;
+ } catch (HttpClientErrorException e) {
+ switch (e.getStatusCode().value()) {
+ case Constants.STATUS_UNAUTHORIZED:
+ jr.setStatus(Constants.STATUS_UNAUTHORIZED);
+ jr.setData(MessageUtil.getPropertites(KeysConstants.STATUS_UNAUTHORIZED));
+ break;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return ret;
+ }
+
+// private JsonResult updateAccessToken(JsonResult jr) {
+// RestTemplateUtil restTemplate = new RestTemplateUtil();
+// try {
+// String refreshToken = SpringWebUtil.getRequest().getParameter(ApiParam.API_RESPONSE_REFRESHTOKEN);
+// String jsonStr = restTemplate.get(WebServiceClient.REST_TOKEN, new String[] { refreshToken });
+// jr.setStatus( Constants.STATUS_REFRESH_TOKEN );
+// jr.setData( jsonStr);
+// } catch (HttpClientErrorException e) {
+// switch (e.getStatusCode().value()) {
+// case Constants.STATUS_UNAUTHORIZED:
+// jr.setStatus( Constants.STATUS_UNAUTHORIZED );
+// jr.setData( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+// break;
+// }
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// return jr;
+// }
+ /**
+ * search start
+ *
+ * @param restURI
+ * @param obj
+ * @param model
+ * @param params
+ * @return
+ */
+ protected String selectPaginationData(String restURI, Object obj, Object model, Map<String, Object> params, HttpSession session) {
+ Class<?> form = obj.getClass();
+ List<Object> dataList = new ArrayList<Object>();
+ DataTableMap map = null;
+ List<String> errList = new ArrayList<String>();
+
+ try {
+ map = new DataTableMap(form.getMethod("getDraw", null).invoke(obj).toString(), dataList);
+
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.getByQueryParam(restURI, params, session);
+
+ JSONObject json = JsonMapperUtils.getJsonObject(jsonStr);
+ int counter = json.getInteger(Constants.PAGINATION_COUNTER);
+ List<App> list = json.getObject(Constants.PAGINATION_DATA, List.class);
+
+ map.setTotal(counter);
+ dataList.addAll(list);
+ } catch ( Exception e ) {
+ exceptionHandler( e, map );
+ }
+ return JsonMapperUtils.writeValueAsString( map.getMapData() );
+ }
+
+ protected void exceptionHandler(Exception e, DataTableMap map) {
+ if (e instanceof HttpClientErrorException) {
+ HttpClientErrorException hcee = (HttpClientErrorException) e;
+ if (hcee.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED) {
+ map.setErrorMsg(Constants.STATUS_UNAUTHORIZED,
+ MessageUtil.getPropertites(KeysConstants.STATUS_UNAUTHORIZED));
+ } else if (hcee.getStatusCode().value() == Constants.STATUS_BAD_REQUEST) {
+ map.setErrorMsg(Constants.STATUS_BAD_REQUEST, MessageUtil.getPropertites(KeysConstants.STATUS_BAD_REQUEST));
+ } else {
+ map.setErrorMsg(Constants.STATUS_UNAUTHORIZED, MessageUtil.getPropertites(KeysConstants.PROJECT_ERROR));
+ }
+ } else {
+ // failed
+ map.setErrorMsg(Constants.STATUS_ERROR, MessageUtil.getPropertites(KeysConstants.PROJECT_ERROR));
+ }
+ }
+
+ protected String exceptionHandler(Exception e, List<String> msgList) {
+ if ( e instanceof HttpClientErrorException ) {
+ HttpClientErrorException hcee = (HttpClientErrorException) e;
+ // unauthorized
+ if ( hcee.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED ) {
+ msgList.add( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+ } else {
+ msgList.add( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, msgList );
+ } else {
+ msgList.add( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, msgList );
+ }
+ }
+
+ protected void exceptionHandler(Exception e, JsonResult jr) {
+ jr.setStatus( Constants.STATUS_ERROR );
+ if ( e instanceof HttpClientErrorException ) {
+ HttpClientErrorException hcee = (HttpClientErrorException) e;
+ // unauthorized
+ if ( hcee.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED ) {
+ jr.setData( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+ } else {
+ jr.setData( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ } else {
+ jr.setData( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ }
+
+ protected void exceptionHandler(Exception e) throws Exception {
+ if ( e instanceof HttpClientErrorException ) {
+ HttpClientErrorException hcee = (HttpClientErrorException) e;
+ if ( hcee.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED ) {
+ throw new Exception( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+ } else {
+ throw new Exception( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ } else {
+ throw new Exception( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ }
+
+ public void initPageList(Map<String, Object> model, boolean hasSpace) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/warehouse/src/main/java/app/market/web/services/account/AccountService.java b/warehouse/src/main/java/app/market/web/services/account/AccountService.java
new file mode 100644
index 0000000..69f8cc0
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/account/AccountService.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.account;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import app.market.utils.json.JsonResult;
+import app.market.web.form.account.AccountForm;
+
+public interface AccountService {
+
+ /**
+ * Authentication
+ *
+ * @return
+ */
+ JsonResult validateAuthentication1(HttpSession session);
+
+ /**
+ * Search AccountForm By UserId
+ *
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ AccountForm searchFormById(String id, HttpSession session) throws Exception;
+
+ /**
+ *
+ * Page Search
+ *
+ * @param form
+ * @return
+ */
+ String selectPaginationData(AccountForm form, HttpSession session);
+
+ /**
+ * Account Delete
+ *
+ * @param id
+ * @return
+ */
+ String delete(String id, HttpSession session);
+
+ /**
+ * Account Save
+ *
+ * @param form
+ * @return
+ */
+ String save(AccountForm form, HttpSession session);
+
+ /**
+ * Get Account List
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ void getAuthorityList(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception;
+}
diff --git a/warehouse/src/main/java/app/market/web/services/account/impl/AccountServiceImpl.java b/warehouse/src/main/java/app/market/web/services/account/impl/AccountServiceImpl.java
new file mode 100644
index 0000000..5d8e7ec
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/account/impl/AccountServiceImpl.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.account.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+
+import com.alibaba.fastjson.JSONObject;
+
+import app.market.WebServiceClient;
+import app.market.model.user.User;
+import app.market.utils.Utils;
+import app.market.utils.constants.Constants;
+import app.market.utils.datetime.DateTimeUtils;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.json.JsonResult;
+import app.market.utils.property.KeysConstants;
+import app.market.utils.property.MessageUtil;
+import app.market.utils.property.Option;
+import app.market.utils.property.PropertyUtil;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.utils.webservice.ApiParam;
+
+import app.market.web.controller.ControllerMapping;
+import app.market.web.form.account.AccountForm;
+import app.market.web.services.SpringBaseService;
+import app.market.web.services.account.AccountService;
+
+@Service
+public class AccountServiceImpl extends SpringBaseService implements AccountService {
+ private static Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class);
+
+ /**
+ * Authentication
+ *
+ * @return
+ */
+ @Override
+ public JsonResult validateAuthentication1(HttpSession session) {
+ return super.validateAuthentication(session);
+ }
+
+ /**
+ *
+ * Page Search
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public String selectPaginationData(AccountForm form, HttpSession session) {
+ logger.debug("account list start --Class: " + this.getClass().getName() + "--method: "
+ + Thread.currentThread().getStackTrace()[1].getMethodName() + form.getUserId());
+ String date = null;
+ if(form.getCreateDate() != null){
+ date = DateTimeUtils.getDate(DateTimeUtils.DATE_FORMAT_YYYYMMDD,form.getCreateDate());
+ }
+ Map<String, Object> param = new HashMap<>();
+ param.put( ApiParam.API_USER_PARAM_USERNAME, form.getUserName() );
+ param.put( ApiParam.API_USER_PARAM_AUID, form.getAuId() );
+ param.put( ApiParam.API_USER_PARAM_MAIL, form.getMailAddress() );
+ param.put( ApiParam.API_USER_PARAM_CREATEDATE, date );
+ param.put( ApiParam.API_PARAM_ORDER, form.getOrder() );
+ param.put( ApiParam.API_PARAM_SORT, form.getSort());
+ param.put( ApiParam.API_PARAM_OFFSET, form.getOffset() );
+ param.put( ApiParam.API_PARAM_LIMIT, form.getLimit() );
+ param.put( ApiParam.API_APP_PARAM_KEYWORD, form.getKeyWord() );
+ return super.selectPaginationData( WebServiceClient.REST_USER_SELECTPAGINATIONDATABYEXAMPLE, form, null, param, session);
+ }
+
+ /**
+ * Account Save
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public String save(AccountForm form, HttpSession session) {
+ logger.debug("save account start");
+ User record = new User();
+ String ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, null, null);
+ List<String> msgList = new ArrayList<String>();
+ try {
+ Utils.reflect(form, record);
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Resttemplate Operation
+ String jsonStr = restTemplate.post(WebServiceClient.REST_USER, record, session);
+
+ JSONObject json = JsonMapperUtils.getJsonObject(jsonStr);
+ String userId = json.getString(ApiParam.API_RESPONSE_APPID);
+ form.setUserId(userId);
+
+ msgList.add(MessageUtil.getPropertites(KeysConstants.USER_SAVE_IS_SUCCESS));
+ ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, ControllerMapping.ACCOUNT.toString(), msgList);
+ } catch (HttpClientErrorException e) {
+ if (e.getStatusCode().value() == Constants.STATUS_BAD_REQUEST) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.INVALID_QUERYPARAM));
+ ret = JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ }
+ if (e.getStatusCode().value() == Constants.STATUS_ALREADY_EXISTS) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.RESOURCE_ALREADY_EXISTS));
+ ret = JsonMapperUtils.getJsonString(Constants.STATUS_ALREADY_EXISTS, null, msgList);
+ }
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ } catch (Exception e) {
+ ret = exceptionHandler(e, msgList);
+ }
+ logger.debug("save account stop");
+ return ret;
+ }
+
+ /**
+ * Account Delete
+ *
+ * @param id
+ * @return
+ */
+ @Override
+ public String delete(String id, HttpSession session) {
+ logger.debug("delete account start");
+ List<String> msgList = new ArrayList<String>();
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Rest template operation
+ restTemplate.delete( WebServiceClient.REST_USER_BY_USERID, id, session );
+ } catch (HttpClientErrorException e ) {
+ if(e.getStatusCode().value() == Constants.STATUS_ALREADY_EXISTS){
+ msgList.add(MessageUtil.getPropertites(KeysConstants.USER_NOT_DELETE));
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ALREADY_EXISTS, null, msgList);
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, "" );
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, "" );
+ }
+ logger.debug("delete account stop ");
+ return JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, null, "" );
+ }
+
+ /**
+ * Get Account List
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ @Override
+ public void getAuthorityList(Map<String, Object> model,boolean hasSpace, HttpSession session) throws Exception {
+ logger.debug( "getAccounList" );
+ try{
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ List<Option> list = new ArrayList<Option>();
+ // Resttemplate operation
+ String jsonStr = restTemplate.get( WebServiceClient.REST_AUTHORITY_GET_LIST_OPTION, session );
+ @SuppressWarnings("unchecked")
+ List<Option> typelist = (List<Option>)JsonMapperUtils.getJsonList(jsonStr, Option.class);
+
+ if ( hasSpace ) {
+ Option option = new Option( PropertyUtil.DEFAULLABEL, "" );
+ list.add( option );
+ }
+ for (Option type : typelist) {
+ Option option1 = new Option( type.getLabel(), type.getValue().toString() );
+ list.add( option1 );
+ }
+ model.put( "authorityList", list );
+ } catch (Exception e) {
+ logger.debug(e.getMessage());
+ model.put("authorityList", new ArrayList<Option>());
+ }
+ }
+
+
+ /**
+ * Search AccountForm By UserId
+ *
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ @Override
+ public AccountForm searchFormById(String id, HttpSession session) throws Exception {
+ AccountForm acForm = new AccountForm();
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Rest template Operation
+ String jsonStr = restTemplate.get(WebServiceClient.REST_USER_BY_USERID, session, new String[] { id });
+ User user = JsonMapperUtils.readValue( jsonStr, User.class );
+ Utils.reflect(user, acForm);
+ } catch (Exception e) {
+ logger.debug(this.getClass().getName() + ".searchFormById(id) failed.");
+ logger.debug(e.getMessage());
+ super.exceptionHandler(e);
+ }
+ return acForm;
+ }
+
+}
diff --git a/warehouse/src/main/java/app/market/web/services/app/AppService.java b/warehouse/src/main/java/app/market/web/services/app/AppService.java
new file mode 100644
index 0000000..5655bd8
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/app/AppService.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.app;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.multipart.MultipartFile;
+
+import app.market.utils.json.JsonResult;
+import app.market.web.form.app.AppForm;
+
+public interface AppService {
+
+ /**
+ * Authentication
+ *
+ * @return
+ */
+ JsonResult validateAuthentication1(HttpSession session);
+
+ /**
+ * Search AppForm By AppId
+ *
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ AppForm searchFormById(String id, HttpSession session) throws Exception;
+
+ /***
+ * Search AppForm By AppIdCustom
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ AppForm searchFormByCustomId(String id, HttpSession session) throws Exception;
+
+ /**
+ * Page Search
+ *
+ * @param form
+ * @return
+ */
+ String selectPaginationData(AppForm form, HttpSession session);
+
+ /**
+ * App Delete
+ *
+ * @param id
+ * @return
+ */
+ String delete(String id, HttpSession session);
+
+ /**
+ * App Save
+ *
+ * @param form
+ * @return
+ */
+ String save(AppForm form, HttpSession session);
+
+ /**
+ * Get App type Option
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ void getAppTypeOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception;
+
+ /**
+ * Get App devicetype Option
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ void getDeviceTypeOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception;
+
+ /**
+ * App Upload
+ *
+ * @param form
+ * @param file
+ * @return
+ */
+ String upload(AppForm form, MultipartFile file, String fileName, boolean isImage, HttpSession session);
+
+ /**
+ * App Version Save
+ *
+ * @param form
+ * @return
+ */
+ String saveVersion(AppForm form, HttpSession session);
+
+ /**
+ * App Download
+ *
+ * @param form
+ * @return
+ */
+ ResponseEntity<byte[]> download(AppForm form, HttpSession session);
+
+ void getIsPublicOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception;
+
+ String saveDictionary(String dicType, String dicValue, String dicLabel, HttpSession session);
+}
diff --git a/warehouse/src/main/java/app/market/web/services/app/impl/AppServiceImpl.java b/warehouse/src/main/java/app/market/web/services/app/impl/AppServiceImpl.java
new file mode 100644
index 0000000..77a0e56
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/app/impl/AppServiceImpl.java
@@ -0,0 +1,511 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.app.impl;
+
+import java.io.File;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.multipart.MultipartFile;
+
+import com.alibaba.fastjson.JSONObject;
+
+import app.market.LogUtil;
+import app.market.WebServiceClient;
+import app.market.model.app.App;
+import app.market.model.app.AppVersion;
+import app.market.model.app.FileInfo;
+import app.market.model.resource.Dictionary;
+import app.market.utils.Utils;
+import app.market.utils.constants.Constants;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.json.JsonResult;
+import app.market.utils.property.KeysConstants;
+import app.market.utils.property.MessageUtil;
+import app.market.utils.property.Option;
+import app.market.utils.property.PropertyUtil;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.utils.webservice.ApiParam;
+import app.market.web.controller.ControllerMapping;
+import app.market.web.controller.PageMapping;
+import app.market.web.form.app.AppForm;
+import app.market.web.services.SpringBaseService;
+import app.market.web.services.app.AppService;
+
+@Service
+public class AppServiceImpl extends SpringBaseService implements AppService {
+ private static Logger logger = LoggerFactory.getLogger( AppServiceImpl.class );
+
+ /**
+ * Authentication
+ *
+ * @return
+ */
+ @Override
+ public JsonResult validateAuthentication1(HttpSession session) {
+ return super.validateAuthentication(session);
+ }
+
+ /**
+ * Page Search
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public String selectPaginationData(AppForm form, HttpSession session) {
+ logger.debug( "search app list start--Class: " + this.getClass().getName() + "--method: "
+ + Thread.currentThread().getStackTrace()[1].getMethodName() + form.getAppId() );
+
+ Map<String, Object> param = new HashMap<>();
+ param.put( ApiParam.API_APP_PARAM_APPNAME, form.getAppName() );
+ param.put( ApiParam.API_APP_PARAM_APPTYPEID, form.getTypeId() );
+ param.put( ApiParam.API_APP_PARAM_DEVELOPER, form.getDeveloper() );
+ param.put( ApiParam.API_PARAM_ORDER, form.getOrder() );
+ param.put( ApiParam.API_APP_PARAM_APPISPUBLIC, form.getAppIsPublic() );
+ param.put( ApiParam.API_PARAM_SORT, form.getSort());
+ param.put( ApiParam.API_PARAM_OFFSET, form.getOffset() );
+ param.put( ApiParam.API_PARAM_LIMIT, form.getLimit() );
+ param.put( ApiParam.API_APP_PARAM_APPDEVICETYPEID, form.getAppDeviceTypeId() );
+ param.put( ApiParam.API_APP_PARAM_KEYWORD, form.getKeyWord());
+
+ return super.selectPaginationData( WebServiceClient.REST_APP_COLLECTION_APP, form, null, param , session);
+ }
+
+ /**
+ * App Save
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public String save(AppForm form, HttpSession session) {
+ logger.debug("save app --S--");
+ App record = new App();
+ String ret = "";
+ List<String> msgList = new ArrayList<String>();
+ String appId;
+ try {
+ Utils.reflect(form, record);
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.post(WebServiceClient.REST_APP_INFO, record, session);
+
+ JSONObject json = JsonMapperUtils.getJsonObject(jsonStr);
+ appId = json.getString(ApiParam.API_RESPONSE_APPID);
+ form.setAppId(appId);
+ ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, PageMapping.INIT_INFO.toString(), form);
+ } catch (HttpClientErrorException e) {
+ if (e.getStatusCode().value() == Constants.STATUS_BAD_REQUEST) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.INVALID_QUERYPARAM));
+ return ret = JsonMapperUtils.getJsonString(Constants.STATUS_BAD_REQUEST, null, msgList);
+ }else if( e.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED){
+ msgList.add( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+ return ret = JsonMapperUtils.getJsonString(Constants.STATUS_UNAUTHORIZED, null, msgList);
+ }else if( e.getStatusCode().value() == Constants.STATUS_ALREADY_EXISTS){
+ msgList.add( MessageUtil.getPropertites( KeysConstants.RESOURCE_APP_ALREADY_EXISTS ) );
+ return ret = JsonMapperUtils.getJsonString(Constants.STATUS_ALREADY_EXISTS, null, msgList);
+ }else if( e.getStatusCode().value() == Constants.STATUS_FORBIDDEN){
+ msgList.add( MessageUtil.getPropertites( KeysConstants.STATUS_FORBIDDEN ) );
+ return ret = JsonMapperUtils.getJsonString(Constants.STATUS_ALREADY_EXISTS, null, msgList);
+ }
+ else{
+ msgList.add(MessageUtil.getPropertites(KeysConstants.PROJECT_ERROR));
+ return ret = JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ }
+
+ } catch (Exception e) {
+ return ret = exceptionHandler(e, msgList);
+ }
+
+ logger.debug("save app --E-- ret=" + ret);
+ return ret;
+ }
+
+ /**
+ * App Upload
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public String upload(AppForm form, MultipartFile multFile, String fileName,boolean isImage, HttpSession session) {
+ logger.debug("upload app start");
+ String ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, null, null);
+ List<String> msgList = new ArrayList<String>();
+ FileInfo fileInfo = null;
+ String[] pathParam = null;
+ String httpUrl = WebServiceClient.REST_APP_IMAGE;
+
+ try {
+ //create fileResource
+
+ File file = getResource(multFile, fileName);
+ if (file == null) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.APP_UPLOAD_PARAM_FILE_IS_NULL));
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ }
+ MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
+ FileSystemResource fileSystemResource = new FileSystemResource(file);
+ param.add(ApiParam.API_APP_PARAM_MULTIPARTFILE, fileSystemResource);
+ param.add(ApiParam.API_APP_PARAM_FILE_NAME, fileName);
+
+ if (!isImage) {
+ // create md5
+ String md5Hex = DigestUtils.md5Hex(fileSystemResource.getInputStream());
+ param.add(ApiParam.API_APP_PARAM_FILE_HASH, md5Hex);
+
+ // create pathParam
+ String id = form.getAppId();
+ String appDeviceTypeId = form.getAppDeviceTypeId();
+ pathParam = new String[] { URLDecoder.decode(fileName, Constants.CHARACTER_UTF8), appDeviceTypeId, id };
+
+ httpUrl = WebServiceClient.REST_APP_FILE_PARM_FILENAME_TYPEID_APPID;
+ }
+
+ //http post
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.post(httpUrl, param, String.class, pathParam, session);
+
+ //delete tempFile
+ deleteFile(file);
+
+ //
+ fileInfo = JsonMapperUtils.readValue(jsonStr, FileInfo.class);
+ if (!isImage) {
+ form.setVerFilePath(fileInfo.getFilePath());
+ form.setAppSize(fileInfo.getFileSize());
+ }else{
+ form.setImagePath(fileInfo.getIconPath());
+ }
+ ret = JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, null, fileInfo );
+ } catch ( HttpClientErrorException e ) {
+ if ( e.getStatusCode().value() == Constants.STATUS_BAD_FILE ) {
+ msgList.add( MessageUtil.getPropertites( KeysConstants.APP_UPLOAD_MD5 ) );
+ } else if(e.getStatusCode().value() == Constants.STATUS_UNSUPPORT){
+ msgList.add( MessageUtil.getPropertites( KeysConstants.APP_FILE_TYPE_IS_UNSUPPORTED ) );
+ } else if(e.getStatusCode().value() == Constants.STATUS_BAD_REQUEST){
+ msgList.add( MessageUtil.getPropertites( KeysConstants.APP_FILE_UNCOMPRESS_FAILED ) );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, msgList );
+ } catch (Exception e) {
+ msgList.add(e.getMessage());
+ logger.debug(this.getClass().getName());
+ logger.debug(e.getMessage());
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ }
+ return ret;
+ }
+
+ /**
+ * MultipartFile-> File
+ * @param multfile
+ * @param fileName2
+ * @return
+ * @throws Exception
+ */
+ public File getResource(MultipartFile multfile, String fileName) throws Exception {
+ File file = null;
+ try {
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
+ String prefix = FilenameUtils.getBaseName(fileName);
+ if(prefix.length() < 3) {
+ prefix += "aaa";
+ }
+ file = File.createTempFile(prefix, suffix);
+ multfile.transferTo(file);
+ //deleteFile(file);
+ } catch (Exception e) {
+ LogUtil.printCatchLog(logger, e);
+ logger.error( e.getMessage() );
+ }
+ return file;
+ }
+
+ /**
+ * delete file
+ * @param files
+ */
+ private void deleteFile(File... files) {
+ for (File file : files) {
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+ }
+
+
+ /**
+ * App Version Save
+ *
+ * @param form
+ * @return
+ */
+
+ @Override
+ public String saveVersion(AppForm form, HttpSession session) {
+ logger.debug( "save app version start" );
+ AppVersion record = new AppVersion();
+ String ret = JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, null, null );
+ List<String> msgList = new ArrayList<String>();
+ try {
+ record.setFilePath(form.getVerFilePath());
+ record.setSize((int)form.getAppSize());
+ record.setvAppId(form.getAppId());
+ record.setVersionName(form.getVersionName());
+ record.setMd5(form.getHashcode());
+ record.setVersionId(form.getAppVersionId());
+ record.setImagePath(form.getImagePath());
+ //Size is equal to 0 when modified, and should be assigned to null
+ if(StringUtils.isNotEmpty(form.getAppVersionId())){
+ record.setSize(null);
+ }
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.post( WebServiceClient.REST_APP_VERSION_INFO, record, session);
+
+ JSONObject json = JsonMapperUtils.getJsonObject(jsonStr);
+ String versionId = json.getString(ApiParam.API_RESPONSE_APPVERSIONID);
+ ret = JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, PageMapping.INIT_CHECK.toString(), form );
+ } catch (HttpClientErrorException e) {
+ if (e.getStatusCode().value() == Constants.STATUS_BAD_REQUEST) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.INVALID_QUERYPARAM));
+ }else if(e.getStatusCode().value() == Constants.STATUS_CONFLICT) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.ALREADY_EXIST));
+ }
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ } catch (Exception e) {
+ ret = exceptionHandler(e, msgList);
+ }
+ return ret;
+ }
+
+ /**
+ * App Delete
+ *
+ * @param id
+ * @return
+ */
+ @Override
+ public String delete(String id, HttpSession session) {
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Rest template operation
+ restTemplate.delete( WebServiceClient.REST_APP_INFO_PARM_ID, id, session);
+ } catch ( Exception e ) {
+ return String.valueOf( Constants.STATUS_ERROR );
+ }
+
+ return String.valueOf( Constants.STATUS_SUCCESS );
+ }
+
+ /**
+ * Search AppForm By AppId
+ *
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ @Override
+ public AppForm searchFormById(String id, HttpSession session) throws Exception {
+ AppForm appForm = null;
+ try {
+ appForm = getAppInfoById(WebServiceClient.REST_APP_INFO_PARM_ID, id, session);
+ } catch ( Exception e ) {
+ super.exceptionHandler( e );
+ }
+ return appForm;
+ }
+
+ /**
+ * Search AppForm By CustomId
+ *
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ @Override
+ public AppForm searchFormByCustomId(String id, HttpSession session) throws Exception {
+ AppForm appForm = new AppForm();
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Rest template operation
+ String jsonStr = restTemplate.get( WebServiceClient.REST_APP_INFO_PARM_CUSTOMID, session, new String[] { id } );
+ App app = JsonMapperUtils.readValue( jsonStr, App.class );
+ Utils.reflect( app, appForm );
+ } catch ( Exception e ) {
+ appForm = null;
+ }
+ return appForm;
+ }
+
+ /***
+ * Search AppInfo By Id
+ * @param url
+ * @param id
+ * @return
+ * @throws Exception
+ */
+ private AppForm getAppInfoById(String url,String id, HttpSession session) throws Exception {
+ AppForm appForm = new AppForm();
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ // Rest template operation
+ String jsonStr = restTemplate.get( url, session, new String[] { id } );
+ App app = JsonMapperUtils.readValue( jsonStr, App.class );
+ Utils.reflect( app, appForm );
+ } catch ( Exception e ) {
+ super.exceptionHandler( e );
+ }
+ return appForm;
+ }
+
+ /**
+ * Get App type Option
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ @Override
+ public void getAppTypeOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception {
+ List<Option> list = getOption(hasSpace, ApiParam.API_PARAM_VALUE_DICTIONARY_CATEGORY, session);
+ model.put("appTypeList", list);
+ }
+
+ /**
+ * Get device type Option
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ @Override
+ public void getDeviceTypeOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception {
+ List<Option> list = getOption(hasSpace, ApiParam.API_PARAM_VALUE_DICTIONARY_DEVICETYPE, session);
+ model.put("appDeviceTypeList", list);
+ }
+
+ /**
+ * Get device type Option
+ *
+ * @param model
+ * @param hasSpace
+ * @throws Exception
+ */
+ @Override
+ public void getIsPublicOption(Map<String, Object> model, boolean hasSpace, HttpSession session) throws Exception {
+ List<Option> list = getOption(hasSpace, ApiParam.API_PARAM_VALUE_DICTIONARY_ISPUBLIC, session);
+ model.put("appIsPublicList", list);
+ }
+
+ private List<Option> getOption( boolean hasSpace,String optionType, HttpSession session) throws Exception {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ List<Option> list = new ArrayList<Option>();
+ // Rest template operation
+ try {
+ String jsonStr = restTemplate.get(WebServiceClient.REST_DICTIONARY_COLLECTION, session, optionType);
+ List<Dictionary> typelist = (List<Dictionary>)JsonMapperUtils.getJsonList(jsonStr, Dictionary.class);
+
+ if (hasSpace) {
+ Option option = new Option(PropertyUtil.DEFAULLABEL, "");
+ list.add(option);
+ }
+ for (Dictionary type : typelist) {
+ Option option = new Option(type.getDicLabel(), type.getDicValue().toString());
+ list.add(option);
+ }
+ } catch (Exception e) {
+ super.exceptionHandler(e);
+ }
+
+ return list;
+ }
+
+ /**
+ * App Download
+ *
+ * @param form
+ * @return
+ */
+ @Override
+ public ResponseEntity<byte[]> download(AppForm form, HttpSession session) {
+ String url = WebServiceClient.REST_APP_FILE_PARM_FILEPATH;
+ ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(null, null, HttpStatus.FORBIDDEN);;
+
+ try {
+ Map<String, Object> param = new HashMap<>();
+ param.put( ApiParam.API_APP_PARAM_FILE_PATH, form.getVerFilePath() );
+
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ response = restTemplate.download(url, param, session);
+ } catch (Exception e) {
+ LogUtil.printCatchLog(logger, e);
+ e.printStackTrace();
+ }
+ return response;
+ }
+
+ /**
+ * Add Or Update Type/Device Type
+ *
+ * @param dicType
+ * @param dicValue
+ * @param dicLabel
+ * @return
+ */
+ public String saveDictionary(String dicType, String dicValue, String dicLabel, HttpSession session) {
+ logger.debug("APPを更新・新規する");
+ Dictionary record = new Dictionary();
+ String ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, null, null);
+ List<String> msgList = new ArrayList<String>();
+ try {
+ record.setDicType(dicType);
+ record.setDicValue(dicValue);
+ record.setDicLabel(dicLabel);
+
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ restTemplate.post(WebServiceClient.REST_DICTIONARY_INFO, record, session);
+ ret = JsonMapperUtils.getJsonString(Constants.STATUS_SUCCESS, PageMapping.APP_TYPE.toString(), null);
+ } catch (HttpClientErrorException e) {
+ if (e.getStatusCode().value() == Constants.STATUS_BAD_REQUEST) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.INVALID_QUERYPARAM));
+ } else if (e.getStatusCode().value() == Constants.STATUS_CONFLICT) {
+ msgList.add(MessageUtil.getPropertites(KeysConstants.ALREADY_EXIST));
+ }
+ return JsonMapperUtils.getJsonString(Constants.STATUS_ERROR, null, msgList);
+ } catch (Exception e) {
+ ret = exceptionHandler(e, msgList);
+ }
+ return ret;
+ }
+}
diff --git a/warehouse/src/main/java/app/market/web/services/login/LoginService.java b/warehouse/src/main/java/app/market/web/services/login/LoginService.java
new file mode 100644
index 0000000..688b043
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/login/LoginService.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.login;
+
+import javax.servlet.http.HttpSession;
+
+public interface LoginService {
+
+ String loginUser(String loginId, String userPw, HttpSession session) throws Exception;
+
+ int deleteUserById(int id);
+}
diff --git a/warehouse/src/main/java/app/market/web/services/login/impl/LoginServiceImpl.java b/warehouse/src/main/java/app/market/web/services/login/impl/LoginServiceImpl.java
new file mode 100644
index 0000000..8ec66e6
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/login/impl/LoginServiceImpl.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.login.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpSession;
+
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+
+import com.alibaba.fastjson.JSONObject;
+
+import app.market.utils.constants.Constants;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.property.KeysConstants;
+import app.market.utils.property.MessageUtil;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.utils.webservice.ApiParam;
+import app.market.WebServiceClient;
+import app.market.web.controller.ControllerMapping;
+import app.market.web.services.login.LoginService;
+
+@Service
+public class LoginServiceImpl implements LoginService {
+
+ //private static Logger logger = LoggerFactory.getLogger( LoginServiceImpl.class );
+
+ @Override
+ public String loginUser(String loginId, String userPw, HttpSession session) {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ ResponseEntity<String> rEntity;
+
+ List<String> errList = new ArrayList<String>();
+ try {
+ JSONObject postData = new JSONObject();
+ postData.put(ApiParam.API_APP_PARAM_LOGINID, loginId);
+ postData.put(ApiParam.API_APP_PARAM_PASSWORD, userPw);
+ rEntity = restTemplate.Post(WebServiceClient.REST_USER_SELECTLOGINUSER, postData, session);
+
+// JSONObject json = JsonMapperUtils.getJsonObject(rEntity.getBody());
+// String token = json.getString(ApiParam.API_RESPONSE_TOKEN);
+// String refreshtoken = json.getString(ApiParam.API_RESPONSE_REFRESHTOKEN);
+ return JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, ControllerMapping.MAIN.toString(), rEntity.getBody());
+ } catch ( HttpClientErrorException e ) {
+ if ( e.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED ) {
+ errList.add( MessageUtil.getPropertites( KeysConstants.LOGIN_LOGINID_IS_NOT_EXIST ) );
+ }else if( e.getStatusCode().value() == Constants.STATUS_ERROR){
+ errList.add( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }else if( e.getStatusCode().value() == Constants.NOT_FOUND){
+ errList.add( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, errList );
+ } catch ( Exception e ) {
+ errList.add( MessageUtil.getPropertites( KeysConstants.USER_LOGINID_IS_FAILED ) );
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, errList );
+ }
+ }
+
+ @Override
+ public int deleteUserById(int id) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
diff --git a/warehouse/src/main/java/app/market/web/services/main/MainService.java b/warehouse/src/main/java/app/market/web/services/main/MainService.java
new file mode 100644
index 0000000..2002eed
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/main/MainService.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.main;
+
+import javax.servlet.http.HttpSession;
+
+import app.market.utils.json.JsonResult;
+
+public interface MainService {
+
+ JsonResult validateAuthentication1(HttpSession session);
+
+ String selectMenuResourceByLoginId(HttpSession session) throws Exception;
+}
diff --git a/warehouse/src/main/java/app/market/web/services/main/impl/MainServiceImpl.java b/warehouse/src/main/java/app/market/web/services/main/impl/MainServiceImpl.java
new file mode 100644
index 0000000..3d4cc4e
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/main/impl/MainServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.main.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpSession;
+
+import org.codehaus.jackson.type.JavaType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import app.market.model.resource.Resource;
+import app.market.utils.constants.Constants;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.json.JsonResult;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.WebServiceClient;
+import app.market.web.services.SpringBaseService;
+import app.market.web.services.main.MainService;
+
+@Service
+public class MainServiceImpl extends SpringBaseService implements MainService {
+
+ private static Logger logger = LoggerFactory.getLogger( MainServiceImpl.class );
+
+ @Override
+ public JsonResult validateAuthentication1(HttpSession session) {
+ return super.validateAuthentication(session);
+ }
+
+ @Override
+ public String selectMenuResourceByLoginId(HttpSession session) throws Exception {
+ String path = "";
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.get( WebServiceClient.REST_RESOURCE_GET_MENU_RESOURCES_BY_LOGINID, session);
+ JsonResult jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ if ( Constants.STATUS_SUCCESS == jr.getStatus() ) {
+ JavaType javaType = JsonMapperUtils.getInstance().getTypeFactory().constructParametricType( ArrayList.class, Resource.class );
+ List<Resource> list = JsonMapperUtils.readValue( jr.getData().toString(), javaType );
+ for (Resource r : list) {
+ path += r.getAccessPath();
+ }
+ } else {
+ throw new Exception( jr.getData().toString() );
+ }
+ } catch ( Exception e ) {
+ logger.debug( this.getClass().getName() + ".selectMenuResourceByLoginId(token) failed." );
+ logger.debug( e.getMessage() );
+ super.exceptionHandler( e );
+ }
+ return path;
+ }
+
+}
diff --git a/warehouse/src/main/java/app/market/web/services/user/UserService.java b/warehouse/src/main/java/app/market/web/services/user/UserService.java
new file mode 100644
index 0000000..dc31b48
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/user/UserService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.user;
+
+import javax.servlet.http.HttpSession;
+
+import app.market.model.user.User;
+import app.market.utils.json.JsonResult;
+import app.market.web.form.user.UserForm;
+
+public interface UserService {
+
+ User selectCurrentUser(HttpSession session) throws Exception;
+
+ User selectUserByUserName(String userName, String token, HttpSession session) throws Exception;
+
+ String saveInfo(UserForm form, HttpSession session);
+
+ String saveUser(UserForm form, HttpSession session);
+
+ JsonResult validateAuthentication1(HttpSession session);
+}
diff --git a/warehouse/src/main/java/app/market/web/services/user/impl/UserServiceImpl.java b/warehouse/src/main/java/app/market/web/services/user/impl/UserServiceImpl.java
new file mode 100644
index 0000000..23cbb42
--- /dev/null
+++ b/warehouse/src/main/java/app/market/web/services/user/impl/UserServiceImpl.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.web.services.user.impl;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.http.HttpSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+
+import app.market.WebServiceClient;
+import app.market.model.user.User;
+import app.market.utils.Utils;
+import app.market.utils.constants.Constants;
+import app.market.utils.json.JsonMapperUtils;
+import app.market.utils.json.JsonResult;
+import app.market.utils.property.KeysConstants;
+import app.market.utils.property.MessageUtil;
+import app.market.utils.rest.RestTemplateUtil;
+import app.market.web.form.user.UserForm;
+import app.market.web.services.SpringBaseService;
+import app.market.web.services.user.UserService;
+
+@Service
+public class UserServiceImpl extends SpringBaseService implements UserService {
+
+ private static Logger logger = LoggerFactory.getLogger( UserServiceImpl.class );
+
+ @Override
+ public User selectCurrentUser(HttpSession session) throws Exception {
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String token = (String) session.getAttribute(Constants.SESSION_TOKEN);
+ String jsonStr = restTemplate.get( WebServiceClient.REST_USER_SELECT_CURRENT, session, token );
+ JsonResult jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ if ( Constants.STATUS_SUCCESS == jr.getStatus() ) {
+ return JsonMapperUtils.readValue( jr.getData().toString(), User.class );
+ }
+ return null;
+ } catch ( Exception e ) {
+ logger.debug( this.getClass().getName() + ".selectCurrentUser() failed" );
+ logger.debug( e.getMessage() );
+ super.exceptionHandler( e );
+ }
+ return null;
+ }
+
+ @Override
+ public User selectUserByUserName(String userName, String token, HttpSession session) throws Exception {
+ try {
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.get( WebServiceClient.REST_USER_BY_USERNAME, session, userName );
+ JsonResult jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ if ( Constants.STATUS_SUCCESS == jr.getStatus() ) {
+ return JsonMapperUtils.readValue( jr.getData().toString(), User.class );
+ }
+ return null;
+ } catch ( Exception e ) {
+ super.exceptionHandler( e );
+ }
+ return null;
+ }
+
+ @Override
+ public String saveUser(UserForm form, HttpSession session) {
+ User user = new User();
+ List<String> errList = new ArrayList<String>();
+ try {
+ Utils.reflect( form, user );
+ user.setToken( form.getToken() );
+ user.setIsDel( "0" );
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.post( WebServiceClient.REST_USER, user, session );
+ JsonResult jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ if ( jr.getStatus() == Constants.STATUS_ERROR ) {
+ errList.add( jr.getData().toString() );
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, errList );
+ }
+ errList.add( MessageUtil.getPropertites( KeysConstants.USER_IS_SUCCESS ) );
+ } catch ( HttpClientErrorException e ) {
+ // unauthorized
+ if ( e.getStatusCode().value() == Constants.STATUS_UNAUTHORIZED ) {
+ errList.add( MessageUtil.getPropertites( KeysConstants.STATUS_UNAUTHORIZED ) );
+ } else {
+ errList.add( MessageUtil.getPropertites( KeysConstants.PROJECT_ERROR ) );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, errList );
+ } catch ( Exception e ) {
+ errList.add( MessageUtil.getPropertites( KeysConstants.USER_SAVE_IS_FAILED ) );
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, errList );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, null, errList );
+ }
+
+ @Override
+ public String saveInfo(UserForm form, HttpSession session) {
+ List<String> msgList = new LinkedList<String>();
+ try {
+ User user = new User();
+ Utils.reflect( form, user );
+ user.setToken( form.getToken() );
+ RestTemplateUtil restTemplate = new RestTemplateUtil();
+ String jsonStr = restTemplate.post( WebServiceClient.REST_USER, user, session );
+ JsonResult jr = JsonMapperUtils.readValue( jsonStr, JsonResult.class );
+ if ( jr.getStatus() == Constants.STATUS_ERROR ) {
+ msgList.add( jr.getData().toString() );
+ return JsonMapperUtils.getJsonString( Constants.STATUS_ERROR, null, msgList );
+ }
+ msgList.add( MessageUtil.getPropertites( KeysConstants.USER_INFO_CHANGE_SUCCESS ) );
+ } catch ( Exception e ) {
+ logger.debug( this.getClass().getName() + ".info() failed." );
+ logger.debug( e.getMessage() );
+ super.exceptionHandler( e, msgList );
+ }
+ return JsonMapperUtils.getJsonString( Constants.STATUS_SUCCESS, null, msgList );
+ }
+
+ @Override
+ public JsonResult validateAuthentication1(HttpSession session) {
+ return super.validateAuthentication(session);
+ }
+
+}