From 3b55d06b89bf64873e685c3d78fce5affbba3d17 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Tue, 16 Apr 2019 11:20:38 +0900 Subject: Add warehouse server source code. [Patch Set 2] Add ReadMe.md Change-Id: I6ade52d2490f5ca4ba107c1a27ed6d5b39048725 Signed-off-by: zheng_wenlong --- .../src/main/java/app/market/utils/Md5Util.java | 39 ++++ .../main/java/app/market/utils/RuntimeUtil.java | 66 ++++++ .../main/java/app/market/utils/SpringWebUtil.java | 80 ++++++++ .../src/main/java/app/market/utils/Utils.java | 136 ++++++++++++ .../java/app/market/utils/constants/Constants.java | 158 ++++++++++++++ .../utils/constants/ProjectUserRoleEnum.java | 71 +++++++ .../app/market/utils/datatable/DataTableMap.java | 99 +++++++++ .../app/market/utils/datetime/DateTimeUtils.java | 78 +++++++ .../app/market/utils/exception/ExceptionEnum.java | 32 +++ .../app/market/utils/json/JsonMapperUtils.java | 228 +++++++++++++++++++++ .../java/app/market/utils/json/JsonMessage.java | 49 +++++ .../java/app/market/utils/json/JsonResult.java | 60 ++++++ .../app/market/utils/property/KeysConstants.java | 110 ++++++++++ .../app/market/utils/property/MessageUtil.java | 55 +++++ .../java/app/market/utils/property/Option.java | 78 +++++++ .../market/utils/property/PropertyContants.java | 22 ++ .../app/market/utils/property/PropertyUtil.java | 127 ++++++++++++ .../app/market/utils/rest/RestTemplateUtil.java | 209 +++++++++++++++++++ .../java/app/market/utils/token/DeleteModel.java | 52 +++++ .../java/app/market/utils/token/TokenModel.java | 100 +++++++++ .../java/app/market/utils/webservice/ApiParam.java | 196 ++++++++++++++++++ .../app/market/utils/webservice/ErrorCode.java | 50 +++++ .../app/market/utils/webservice/ErrorCodeEnum.java | 41 ++++ .../app/market/utils/webservice/WebServiceURI.java | 77 +++++++ 24 files changed, 2213 insertions(+) create mode 100644 appmarket-utils/src/main/java/app/market/utils/Md5Util.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/SpringWebUtil.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/Utils.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/constants/Constants.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/constants/ProjectUserRoleEnum.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/datatable/DataTableMap.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/datetime/DateTimeUtils.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/exception/ExceptionEnum.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/json/JsonMapperUtils.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/json/JsonMessage.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/json/JsonResult.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/property/KeysConstants.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/property/MessageUtil.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/property/Option.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/property/PropertyContants.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/property/PropertyUtil.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/rest/RestTemplateUtil.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/token/DeleteModel.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/token/TokenModel.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/webservice/ApiParam.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/webservice/ErrorCode.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/webservice/ErrorCodeEnum.java create mode 100644 appmarket-utils/src/main/java/app/market/utils/webservice/WebServiceURI.java (limited to 'appmarket-utils/src/main/java') diff --git a/appmarket-utils/src/main/java/app/market/utils/Md5Util.java b/appmarket-utils/src/main/java/app/market/utils/Md5Util.java new file mode 100644 index 0000000..29edef8 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/Md5Util.java @@ -0,0 +1,39 @@ +/* + * 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.utils; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +/** + * + * @author huangxin + * + */ +public class Md5Util { + /** + * @param userPw + * @return + * @throws NoSuchAlgorithmException + */ + public static String md5(String userPw) throws NoSuchAlgorithmException{ + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(userPw.getBytes()); + String userPwMd = new BigInteger(1,md.digest()).toString(16); + return userPwMd; + } + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java b/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java new file mode 100644 index 0000000..195b7cc --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java @@ -0,0 +1,66 @@ +/* + * 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.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class RuntimeUtil { +/** + * Execute Command of Linux Shell + * @param cmd + * @return Execute's result + */ + public static boolean linuxCmdExec(String cmd) { + boolean ret = false; + + try { + Process process = Runtime.getRuntime().exec(cmd); + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String line; + + while ((line = stdoutReader.readLine()) != null) { + System.out.println(line); + } + + while ((line = stderrReader.readLine()) != null) { + System.out.println(line); + } + + int exitVal = process.waitFor(); + + System.out.println("Process exit value is " + exitVal); + if(exitVal != 0) { + return ret; + } + + ret = true; + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } catch (IndexOutOfBoundsException e) { + e.printStackTrace(); + } + return ret; + } +} diff --git a/appmarket-utils/src/main/java/app/market/utils/SpringWebUtil.java b/appmarket-utils/src/main/java/app/market/utils/SpringWebUtil.java new file mode 100644 index 0000000..02eaf37 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/SpringWebUtil.java @@ -0,0 +1,80 @@ +/* + * 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.utils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +public class SpringWebUtil { + + public static HttpServletRequest getRequest() { + ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + return requestAttributes == null ? null : requestAttributes.getRequest(); + } + + public static HttpSession getSession() { + return getRequest().getSession( false ); + } + + public static String getRealRootPath() { + return getRequest().getServletContext().getRealPath( "/" ); + } + + public static String getIp() { + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if ( servletRequestAttributes != null ) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + return request.getRemoteAddr(); + } + return null; + } + + public static Object getSessionAttribute(String name) { + HttpServletRequest request = getRequest(); + return request == null ? null : request.getSession().getAttribute( name ); + } + + public static void setSessionAttribute(String name, Object value) { + HttpServletRequest request = getRequest(); + if ( request != null ) { + request.getSession().setAttribute( name, value ); + } + } + + public static Object getRequestAttribute(String name) { + HttpServletRequest request = getRequest(); + return request == null ? null : request.getAttribute( name ); + } + + public static void setRequestAttribute(String name, Object value) { + HttpServletRequest request = getRequest(); + if ( request != null ) { + request.setAttribute( name, value ); + } + } + + public static String getContextPath() { + return getRequest().getContextPath(); + } + + public static void removeSessionAttribute(String name) { + getRequest().getSession().removeAttribute( name ); + } + +} \ No newline at end of file diff --git a/appmarket-utils/src/main/java/app/market/utils/Utils.java b/appmarket-utils/src/main/java/app/market/utils/Utils.java new file mode 100644 index 0000000..c0a1474 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/Utils.java @@ -0,0 +1,136 @@ +/* + * 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.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Date; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; + +import app.market.utils.constants.Constants; +import app.market.utils.datetime.DateTimeUtils; + +/** + * tools + * + * @author Toyota + * @date 2017/10/10 + */ +public class Utils { + + /** + * Entity converter + * + * @see set in/out class + * + * @param org + * @param dest + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static void reflect(Object org, Object dest) throws Exception { + Class orgClass = org.getClass(); + Class destClass = dest.getClass(); + + for (Field orgField : orgClass.getDeclaredFields()) { + orgField.setAccessible( true ); + String orgFieldName = orgField.getName(); + if ( "serialVersionUID".equals( orgFieldName ) ) { + continue; + } + Field destField; + try { + destField = destClass.getDeclaredField( orgFieldName ); + } catch ( NoSuchFieldException e ) { + continue; + } + destField.setAccessible( true ); + if ( ( orgField.getType().getName().equals( "java.lang.Integer" ) + || orgField.getType().getName().equals( "int" ) ) && orgField.get( org ) != null ) { + if ( destField.getType().getName().equals( "java.lang.String" ) ) { + destField.set( dest, String.valueOf( orgField.get( org ) ) ); + } else { + destField.set( dest, orgField.get( org ) ); + } + } else if ( orgField.getType().getName().equals( "java.util.Date" ) && orgField.get( org ) != null ) { + // to string + if ( destField.getType().getName().equals( "java.lang.String" ) ) { + destField.set( dest, DateTimeUtils.getDate( DateTimeUtils.DATE_FORMAT_YYYYMMDDHHMMSS, + (Date) orgField.get( org ) ) ); + } else { + destField.set( dest, (Date) orgField.get( org ) ); + } + } else if ( orgField.getType().getName().equals( "java.util.List" ) ) { + for (int i = 0; i < ( (ArrayList) orgField.get( org ) ).size(); i++) { + Object orgItem = ( (ArrayList) orgField.get( org ) ).get( i ); + Type destItemType = ( (ParameterizedType) destField.getGenericType() ).getActualTypeArguments()[0]; + Object destItem = ( Class.forName( destItemType.getTypeName() ) ).newInstance(); + reflect( orgItem, destItem ); + ( (ArrayList) destField.get( dest ) ).add( destItem ); + } + } else { + if ( destField.getType().getName().equals( "java.util.Date" ) && orgField.get( org ) != null + && StringUtils.isNotEmpty( orgField.get( org ).toString() ) ) { + destField.set( dest, DateTimeUtils.getDate( DateTimeUtils.DATE_FORMAT_YYYYMMDD, + orgField.get( org ).toString() ) ); + } else { + if ( destField.getType().getName().equals( orgField.getType().getName() ) ) { + destField.set( dest, orgField.get( org ) ); + } + } + } + } + } + + /** + * Get UUID + * + * @return + */ + public static String generatorUUID() { + return UUID.randomUUID().toString(); + } + + public static boolean strIsEmpty(String s) { + if (s == null || "".equals(s)) { + return true; + } + return false; + } + + /*** + * Get file name from path + * @param filePath + * @return succeed, return file name + * failed, return null + */ + public static String getFileNameFromPath(String filePath) { + String ret = ""; + try{ + ret = filePath.substring(filePath.lastIndexOf(Constants.PATH_SEPARATOR) + 1); + }catch (Exception e){ + e.printStackTrace(); + return null; + } + return ret; + } +} diff --git a/appmarket-utils/src/main/java/app/market/utils/constants/Constants.java b/appmarket-utils/src/main/java/app/market/utils/constants/Constants.java new file mode 100644 index 0000000..fef120a --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/constants/Constants.java @@ -0,0 +1,158 @@ +/* + * 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.utils.constants; + +import org.springframework.http.HttpStatus; + +public class Constants { + + public static final String CHARACTER_UTF8 = "UTF-8"; + public static final String CHARACTER_ISO = "ISO-8859-1"; + + /** success */ + public static final int STATUS_SUCCESS = HttpStatus.OK.value(); + /** unauthorized */ + public static final int STATUS_UNAUTHORIZED = 401; + + public static final int STATUS_REFRESH_TOKEN = 220; + + public static final int STATUS_BAD_FILE = 402; + /** forbidden */ + public static final int STATUS_FORBIDDEN = 403; + /** already exists */ + public static final int STATUS_ALREADY_EXISTS = 409; + /** unsupport media type */ + public static final int STATUS_UNSUPPORT = 415; + /** too many connections */ + public static final int STATUS_TOO_MANY_CONNECTIONS = 421; + /** bad request */ + public static final int STATUS_BAD_REQUEST = HttpStatus.BAD_REQUEST.value(); + /** error */ + public static final int STATUS_ERROR = HttpStatus.INTERNAL_SERVER_ERROR.value(); + + public static final int NOT_FOUND = HttpStatus.NOT_FOUND.value(); + + public static final int STATUS_CONFLICT = HttpStatus.CONFLICT.value(); + + public static final int STATUS_SERVER_ERROR = 500; + /** If parameter is blank, replace restful parameter. */ + public static final String EMPTY_STRING_FALG = "%22%22"; + /** Usefull deta flag */ + public static final String DETA_ENABLE_FLAG = "0"; + + /** token */ + public static final String GUEST_ID = "appMarketGuestAuthorizationUser"; + public static final String ADMID_ID = "super_user"; + + public static final String TOKEN_AUTHORIZATION = "authorization_token"; + public static final String TOKEN_AUTHORIZATION_REFRESH = "authorization_refreshtoken"; + public static final String TOKEN_AUTHORIZATION_RESOURCE = "authorization_servlet_path"; + public static final String AUTHORIZATION_CLIENT = "authorization_client"; + public static final String AUTHORIZATION_CLIENT_VALUE_TOOL = "tool"; + + public static final String PAGINATION_COUNTER = "pagination_counter"; + public static final String PAGINATION_DATA = "pagination_data"; + + public static final String USER_SESSION_KEY = "USER_SESSION_KEY"; + public static final String I18N_JA_JP = "ja.JP"; + + /** uploading */ + public static final int BUFFER_SIZE = 1024; + public static final String FILE_TYPE = ".wgt"; + public static final long IMAGE_SIZE = 1024*500; + public static final String IMAGE_TYPE = "image"; + public static final int IMAGE_INT = 0; + public static final String IMAGE_SVG = ".svg"; + public static final String IMAGE_PNG = ".PNG"; + + /** distinct modify or create app*/ + public static final int APP_CREATE_DETAIL = 0; + public static final int APP_MODIFY = 1; + public static final int APP_DETAIL_MODIFY = 2; + + //database delete flad + public static final String DATA_INVALID = "1"; + public static final String DATA_VALID = "0"; + + public static final String TOKEN_SEPARATOR = ":"; + + public static final String PROPERTIES_FILE_NAME_PROPERTIES = "config/properties.properties"; + + /** + * webservice Utils + */ + public static final String PROPERTIES_FILE_NAME_REDIS = "redis.properties"; + public static final String PROPERTIES_FILE_NAME_FILE = "fileManager.properties"; + public static final String PROPERTIES_FILE_NAME_DEFAULT = "properties.properties"; + + public static final String UPLOAD_PATH_DEFAULT="/var/lib/tomcat8/appFile/appMarket/appFile/"; + public static final String UPLOAD_PATH_TYPE_DEFAULT="appType/"; + public static final String UPLOAD_PATH_APP_DEFAULT="appId/"; + + public static final String PATH_SEPARATOR="/"; + + public static final String FILE_SEPARATOR = "_"; + + public static final String FILE_DOT = "."; + + //public static final String SERVER_PATH = "http://localhost:8080/resource"; + public static final String UPLOAD_APP_FILE_PATH = "/appFile"; + public static final String UPLOAD_APP_RES_PATH_ICON = "/appIcon"; + public static final String UPLOAD_APP_UNCOMPRESS_PATH = "/uncompress"; + + public static final String UPLOAD_APP_UNCOMPRESS_FILE_CONFIG = "/config.xml"; + + + /** + * wgt/config.xml + */ + public static final String CONFIG_APP_PARAM_ID = "id"; + public static final String CONFIG_APP_PARAM_VERSION = "version"; + public static final String CONFIG_APP_PARAM_NAME = "name"; + public static final String CONFIG_APP_PARAM_ICON = "icon"; + public static final String CONFIG_APP_PARAM_SRC = "src"; + public static final String CONFIG_APP_PARAM_DESCRIPTION = "description"; + + /*** + * local app list + */ + public static final String APP_ID_SEPARATOR = "@"; + public static final String APP_ID_LAUNCHER = "launcher@0.1"; + public static final String APP_ID_HOMESCREEN = "homescreen@0.1"; + public static final String APP_ID_WAREHOUSE = "warehouse@1.0"; + + /** + * download app + */ + public static final String APP_HEADER_KEY = "Content-Disposition"; + public static final String APP_HEADER_VALUE = "attachment;filename="; + + /** + * session + */ + public static final String SESSION_TOKEN = "session_token"; + public static final String SESSION_REFRESH_TOKEN = "session_refresh_token"; + public static final String SESSION_PORT = "session_port"; + public static final String SESSION_SYSTEM_TOKEN = "session_system_token"; + public static final String SESSION_INSTALL_PATH = "session_install_path"; + + /** + * access url parameter/ + */ + public static final String ACCESS_PORT = "port"; + public static final String ACCESS_SYSTEM_TOKEN = "systemToken"; + public static final String ACCESS_INSTALL_PATH = "installPath"; +} diff --git a/appmarket-utils/src/main/java/app/market/utils/constants/ProjectUserRoleEnum.java b/appmarket-utils/src/main/java/app/market/utils/constants/ProjectUserRoleEnum.java new file mode 100644 index 0000000..fc3cb3f --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/constants/ProjectUserRoleEnum.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.utils.constants; + +import org.apache.commons.lang3.StringUtils; + +/** + * User define in project + * + * @author Toyota + */ +public enum ProjectUserRoleEnum { + + MANAGER("pm", "0"), LEADER("leader", "1"), MEMBER("member", "2"), ALL("all", "99"); + + private String name; + private String value; + + private ProjectUserRoleEnum(String name, String value) { + this.name = name; + this.value = value; + } + + public static String getName(String value) { + for (ProjectUserRoleEnum c : ProjectUserRoleEnum.values()) { + if ( StringUtils.equalsIgnoreCase( c.getValue(), value ) ) { + return c.name; + } + } + return null; + } + + public static String getValue(String name) { + for (ProjectUserRoleEnum c : ProjectUserRoleEnum.values()) { + if ( StringUtils.equalsIgnoreCase( c.getName(), name ) ) { + return c.value; + } + } + return null; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/datatable/DataTableMap.java b/appmarket-utils/src/main/java/app/market/utils/datatable/DataTableMap.java new file mode 100644 index 0000000..d6de5d2 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/datatable/DataTableMap.java @@ -0,0 +1,99 @@ +/* + * 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.utils.datatable; + +import java.io.Serializable; +import java.util.LinkedHashMap; +import java.util.List; + +/** + * datatable data struction + * + * @author Toyota + */ +public class DataTableMap implements Serializable { + + private static final long serialVersionUID = 4334941724837603916L; + + private LinkedHashMap map; + + public DataTableMap() { + map = new LinkedHashMap(); + } + + /** + * Init data table + * + * @param draw + * @param list + */ + public DataTableMap(String draw, List list) { + map = new LinkedHashMap(); + map.put( "draw", draw ); + map.put( "recordsTotal", 0 ); + map.put( "recordsFiltered", 0 ); + map.put( "data", list ); + } + + /** + * Set page count + * + * @param total + */ + public void setTotal(int total) { + map.put( "recordsTotal", total ); + map.put( "recordsFiltered", total ); + } + + /** + * Add data + * + * @param list + */ + @SuppressWarnings("unchecked") + public void addData(List list) { + ( (List) map.get( "data" ) ).addAll( list ); + } + + /** + * Reset data + * + * @param list + */ + public void resetData(List list) { + map.put( "data", list ); + } + + /** + * Set error message + * + * @param errorCode + * @param errorText + */ + public void setErrorMsg(int errorCode, String errorText) { + map.put( "statusCode", errorCode ); + map.put( "statusText", errorText ); + } + + /** + * get data map + * + * @return + */ + public LinkedHashMap getMapData() { + return this.map; + } +} diff --git a/appmarket-utils/src/main/java/app/market/utils/datetime/DateTimeUtils.java b/appmarket-utils/src/main/java/app/market/utils/datetime/DateTimeUtils.java new file mode 100644 index 0000000..f7971e3 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/datetime/DateTimeUtils.java @@ -0,0 +1,78 @@ +/* + * 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.utils.datetime; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * date + * + * @author Toyota + * @date 2017/10/10 + */ +public class DateTimeUtils { + + /** yyyy */ + public static final String DATE_FORMAT_YYYY = "yyyy"; + /** yyyy/MM/dd */ + public static final String DATE_FORMAT_YYYYMMDD = "yyyy/MM/dd"; + /** yyyy/MM/dd hh:mm:ss */ + public static final String DATE_FORMAT_YYYYMMDDHHMMSS_SLASH = "yyyy/MM/dd hh:mm:ss"; + /** yyyy-MM-dd hh:mm:ss */ + public static final String DATE_FORMAT_YYYYMMDDHHMMSS_DASH = "yyyy-MM-dd hh:mm:ss"; + /** yyyyMMddhhmmss */ + public static final String DATE_FORMAT_YYYYMMDDHHMMSS = "yyyyMMddhhmmss"; + /** yyyyMMddhhmmssSSS */ + public static final String DATE_FORMAT_YYYYMMDDHHMMSSSSS = "yyyyMMddhhmmssSSS"; + + public static String getCurrectDate(String format) { + return new SimpleDateFormat( format ).format( new Date() ); + } + + public static String getDate(String format, Date date) { + return new SimpleDateFormat( format ).format( date ); + } + + public static Date getDate(String format, String date) { + try { + return new SimpleDateFormat( format ).parse( date ); + } catch ( ParseException e ) { + throw new RuntimeException(); + } + } + + /** + * @param date + * @return + */ + public static String betweenTime(String date){ + String strDate=date.replace("/",""); + int intDate = Integer.parseInt(strDate); + String end = String.valueOf(intDate+1); + StringBuilder sbOne = new StringBuilder(end); + String StrDateOne = sbOne.insert(4, "/").toString(); + StringBuilder sbTwo = new StringBuilder(StrDateOne); + String StrDateTwo = sbTwo.insert(7, "/").toString(); + return StrDateTwo; + + } + public static void main(String[] args) { + String s = DateTimeUtils.getDate( DATE_FORMAT_YYYYMMDDHHMMSS, new Date() ); + System.out.println( s ); + } +} diff --git a/appmarket-utils/src/main/java/app/market/utils/exception/ExceptionEnum.java b/appmarket-utils/src/main/java/app/market/utils/exception/ExceptionEnum.java new file mode 100644 index 0000000..0440cbc --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/exception/ExceptionEnum.java @@ -0,0 +1,32 @@ +/* + * 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.utils.exception; + +public enum ExceptionEnum { + + EMPTY_DATA { + @Override + public String toString() { + return "exception_empty_data"; + } + }, + MULTIPLE_DATA { + @Override + public String toString() { + return "exception_multiple_data"; + } + } +} diff --git a/appmarket-utils/src/main/java/app/market/utils/json/JsonMapperUtils.java b/appmarket-utils/src/main/java/app/market/utils/json/JsonMapperUtils.java new file mode 100644 index 0000000..7d0664a --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/json/JsonMapperUtils.java @@ -0,0 +1,228 @@ +/* + * 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.utils.json; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.JsonProcessingException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.JavaType; +import org.codehaus.jackson.type.TypeReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import app.market.utils.constants.Constants; + +/** + * JSON Tool + * + * @author Toyota + */ +public class JsonMapperUtils { + private static Logger logger = LoggerFactory.getLogger( JsonMapperUtils.class ); + + private static ObjectMapper mapper = new ObjectMapper(); + + public JsonMapperUtils() { + super(); + } + + public static ObjectMapper getInstance() { + return mapper; + } + + /** + * write object value + * + * @param object + * @return + */ + public static String writeValueAsString(Object object) { + String json = null; + try { + json = mapper.writeValueAsString( object ); + } catch ( JsonGenerationException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( JsonMappingException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( IOException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } + return json; + } + + /** + * read object value + * + * @see #constructParametricType(Class, Class...) + */ + @SuppressWarnings("unchecked") + public static T readValue(String jsonString, Class clazz) { + if ( StringUtils.isEmpty( jsonString ) ) { + return null; + } + Object obj = null; + try { + obj = mapper.readValue( jsonString, clazz ); + } catch ( JsonParseException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( JsonMappingException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( IOException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } + return (T) obj; + } + + /** + * read object value + * + * @see #constructParametricType(Class, Class...) + */ + @SuppressWarnings("unchecked") + public static T readValue(String jsonString, JavaType javaType) { + if ( StringUtils.isEmpty( jsonString ) ) { + return null; + } + Object obj = null; + try { + obj = mapper.readValue( jsonString, javaType ); + } catch ( JsonParseException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( JsonMappingException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( IOException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } + return (T) obj; + } + + /** + * read object value + * + * @see #constructParametricType(Class, Class...) + */ + @SuppressWarnings("unchecked") + public static T readValue(String jsonString, TypeReference typeReference) { + if ( StringUtils.isEmpty( jsonString ) ) { + return null; + } + Object obj = null; + try { + obj = mapper.readValue( jsonString, typeReference ); + } catch ( JsonParseException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( JsonMappingException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } catch ( IOException e ) { + logger.info( e.getMessage() ); + e.printStackTrace(); + } + return (T) obj; + } + + /** + * String to tree + * + * @param content + * @return + * @throws JsonProcessingException + * @throws IOException + */ + public static JsonNode readTree(String content) throws JsonProcessingException, IOException { + return mapper.readTree( content ); + } + + /** + * Get JSON information + * + * @param type + * @param forward + * @param msg + * @return + */ + public static String getJsonString(Object type, String forward, Object msg) { + Map map = new LinkedHashMap(); + map.put( "result", type ); + map.put( "forward", forward ); + if ( msg != null ) { + map.put( "message", msg ); + } else { + } + String jsonStr = JsonMapperUtils.writeValueAsString( map ); + logger.info( jsonStr ); + return jsonStr; + } + + public static boolean getResult(String jsonStr) { + boolean ret = false; + Map map = JsonMapperUtils.readValue(jsonStr, Map.class); + if ((int) map.get("result") == Constants.STATUS_SUCCESS) { + ret = true; + } + return ret; + } + + public static Object getMessage(String jsonStr) { + Map map = JsonMapperUtils.readValue(jsonStr, Map.class); + return (Object)map.get("message"); + } + + /** + * get json boject + * @param jsonStr + * @return + */ + public static JSONObject getJsonObject(String jsonStr) + { + JSONObject jsonObject = JSONObject.parseObject(jsonStr); + return jsonObject; + } + + public static List getJsonList(String jsonstring, Class cls) { + List list = new ArrayList(); + try { + list = JSON.parseArray(jsonstring, cls); + } catch (Exception e) { + // TODO: handle exception + } + return list; + } + +} \ No newline at end of file diff --git a/appmarket-utils/src/main/java/app/market/utils/json/JsonMessage.java b/appmarket-utils/src/main/java/app/market/utils/json/JsonMessage.java new file mode 100644 index 0000000..83e7dc1 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/json/JsonMessage.java @@ -0,0 +1,49 @@ +/* + * 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.utils.json; + +public class JsonMessage { + + private String name; + private Object value; + + public JsonMessage() { + super(); + } + + public JsonMessage(String name, Object value) { + super(); + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/json/JsonResult.java b/appmarket-utils/src/main/java/app/market/utils/json/JsonResult.java new file mode 100644 index 0000000..9aba3fa --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/json/JsonResult.java @@ -0,0 +1,60 @@ +/* + * 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.utils.json; + +import java.io.Serializable; + +import app.market.utils.constants.Constants; +import app.market.utils.datetime.DateTimeUtils; + +public class JsonResult implements Serializable { + + private static final long serialVersionUID = -6156654045350234343L; + + private int status; + private String timestamp; + private Object data; + + public JsonResult() { + this.status = Constants.STATUS_SUCCESS; + this.timestamp = DateTimeUtils.getCurrectDate( DateTimeUtils.DATE_FORMAT_YYYYMMDDHHMMSS ); + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/property/KeysConstants.java b/appmarket-utils/src/main/java/app/market/utils/property/KeysConstants.java new file mode 100644 index 0000000..c739762 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/property/KeysConstants.java @@ -0,0 +1,110 @@ +/* + * 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.utils.property; + +public class KeysConstants { + public static final String PROJECT_ERROR = "project_error"; + public static final String STATUS_UNAUTHORIZED = "status_unauthorized"; + public static final String STATUS_TOO_MANY_CONNECTIONS = "status_too_many_connections"; + public static final String STATUS_FORBIDDEN = "status_forbidden"; + public static final String STATUS_BAD_REQUEST = "bad_request"; + public static final String INVALID_QUERYPARAM = "invalid_query_param"; + public static final String INVALID_BODY = "invalid_body"; + public static final String ALREADY_EXIST = "already_exist"; + public static final String USER_NOT_DELETE = "user_not_delete"; + public static final String EXPIRED_REFRESH_TOKEN = "expired_refresh_token"; + /** ▼▼▼▼▼▼▼▼▼▼ ErrorCode Message ▼▼▼▼▼▼▼▼▼▼ */ + public static final String MISSING_NECESSARY_QUERYPARAM = "missing_necessary_queryparam"; + public static final String THE_PICTURE_SIZES = "the_picture_sizes_should_not_exceed_500KB"; + public static final String UPLOAD_PICTURES_ONLY = "you_can_upload_pictures_only"; + public static final String INVALID_OPERATION = "invalid_operation"; + public static final String RESOURCE_ALREADY_EXISTS = "resource_already_exists"; + public static final String RESOURCE_APP_ALREADY_EXISTS = "resource_app_already_exists"; + public static final String DEVELOPER_IS_NOT_EXIST = "developer_is_not_exist"; + public static final String TYPENAME_ALREADY_EXISTS = "typename_already_exists"; + /** ▲▲▲▲▲▲▲▲▲▲ ErrorCode Message ▲▲▲▲▲▲▲▲▲▲ */ + + /** ▼▼▼▼▼▼▼▼▼▼ login ▼▼▼▼▼▼▼▼▼▼ */ + public static final String LOGIN_LOGINID_IS_NOT_EXIST = "login_loginId_is_not_exist"; + public static final String LOGIN_LOGINID_IS_NOT_EMPTY = "login_loginId_is_not_empty"; + public static final String LOGIN_PASSWORD_IS_NOT_EMPTY = "login_password_is_not_empty"; + /** ▲▲▲▲▲▲▲▲▲▲ login ▲▲▲▲▲▲▲▲▲▲ */ + + /** ▼▼▼▼▼▼▼▼▼▼ user ▼▼▼▼▼▼▼▼▼▼ */ + public static final String USER_PASSWORD_IS_NOT_EMPTY = "user_password_is_not_empty"; + public static final String USER_PASSWORD_IS_NOT_SPACES = "no_spaces_can_be_found_in_the_password"; + public static final String USER_REPASSWORD_IS_NOT_EMPTY = "user_repassword_is_not_empty"; + public static final String USER_USERNAME_IS_NOT_EMPTY = "user_username_is_not_empty"; + public static final String USER_USERNAME_MAX_ERROR = "user_username_max_error"; + public static final String USER_PASSWORD_MAX_ERROR = "user_password_max_error"; + public static final String USER_REPASSWORD_MAX_ERROR = "user_repassword_max_error"; + public static final String USER_MAILADDRESS_MAX_ERROR = "user_mailaddress_max_error"; + public static final String USER_USERNAME_IS_NOT_REPEATED = "user_username_is_not_repeated"; + public static final String USER_MAILADDRESS_IS_NOT_EMPTY = "user_mailaddress_is_not_empty"; + public static final String USER_USERID_IS_NOT_EMPTY = "user_userid_is_not_empty"; + public static final String USER_OLD_PASSWORD_IS_NOT_EMPTY = "user_old_password_is_not_empty"; + public static final String USER_NEW_PASSWORD_IS_NOT_EMPTY = "user_new_password_is_not_empty"; + public static final String USER_NEW_REPASSWORD_IS_NOT_EMPTY = "user_new_repassword_is_not_empty"; + public static final String USER_NEW_REPASSWORD_IS_NOT_EQUALS = "user_new_repassword_is_not_equals"; + public static final String USER_SAVE_IS_FAILED = "user_save_is_failed"; + public static final String USER_SAVE_IS_SUCCESS = "user_save_is_success"; + public static final String USER_SAVE_IS_EXIST = "user_is_exist"; + public static final String USER_LOGINID_IS_FAILED = "user_loginid_is_failed"; + public static final String USER_INFO_CHANGE_SUCCESS = "user_info_change_success"; + public static final String USER_IS_SUCCESS = "user_is_success"; + public static final String USER_TITLE_NAME_INSERT = "user_title_name_insert"; + public static final String USER_TITLE_NAME_MODIFY = "user_title_name_modify"; + public static final String USER_NAME_IS_NOT_EMPTY = "user_name_is_not_empty"; + public static final String USER_GET_LIST_IS_FAILED = "user_get_list_is_failed"; + public static final String USER_DELETE_FAILED = "user_delete_failed"; + public static final String USER_MAILADDRESS_IS_NOT_EQUALS = "user_mailaddress_is_not_equals"; + public static final String USER_REPASSWORD_ERROR = "user_repassword_error"; + public static final String USER_PASSWORD_ERROR = "user_password_error"; + /** ▲▲▲▲▲▲▲▲▲▲ user ▲▲▲▲▲▲▲▲▲▲ */ + + /** ▼▼▼▼▼▼▼▼▼▼ app ▼▼▼▼▼▼▼▼▼▼ */ + public static final String APP_APPNAME_IS_NOT_EMPTY = "app_appname_is_not_empty"; + public static final String APP_DEVICETYPE_IS_NOT_EMPTY = "app_DeviceType_is_not_empty"; + public static final String APP_VERSIONNAME_IS_NOT_EMPTY = "app_versionname_is_not_empty"; + public static final String APP_TYPEID_IS_NOT_EMPTY = "app_typeid_is_not_empty"; + public static final String APP_FILEPATH_IS_NOT_EMPTY = "app_filepath_is_not_empty"; + public static final String APP_ABSTRACT_IS_NOT_EMPTY = "app_abstract_is_not_empty"; + public static final String APP_IMAGRPATH_IS_NOT_EMPTY = "app_imagepath_is_not_empty"; + public static final String APP_SAVE_IS_FAILED = "app_save_is_failed"; + public static final String APP_SAVE_IS_SUCCESS = "app_save_is_success"; + public static final String APP_UPLOAD_PARAM_FILE_IS_NULL = "app_upload_param_file_is_null"; + public static final String APP_UPLOAD_MD5 = "md5_failed"; + public static final String APP_TITLE_NAME_MODIFY = "app_title_name_modify"; + public static final String APP_TITLE_NAME_INSERT = "app_title_name_insert"; + public static final String APP_APPNAME_MAX_ERROR = "app_appname_max_error"; + public static final String APP_FILEPATH_MAX_ERROR = "app_filepath_max_error"; + public static final String APP_VERSIONNAME_MAX_ERROR = "app_versionname_max_error"; + public static final String APP_ABSTRACT_MAX_ERROR = "app_abstract_max_error"; + public static final String APP_FILE_TYPE_IS_UNSUPPORTED = "app_file_type_is_unsupported"; + public static final String APP_FILE_READ_FAILED = "app_file_read_failed"; + public static final String APP_FILE_UNCOMPRESS_FAILED = "app_file_uncompress_failed"; + /** ▲▲▲▲▲▲▲▲▲▲ app ▲▲▲▲▲▲▲▲▲▲ */ + + /** ▼▼▼▼▼▼▼▼▼▼ authority ▼▼▼▼▼▼▼▼▼▼ */ + public static final String AUTHORITY_ID_IS_NOT_EMPTY = "authority_id_is_not_empty"; + /** ▼▼▼▼▼▼▼▼▼▼ authority ▼▼▼▼▼▼▼▼▼▼ */ + + /** ▼▼▼▼▼▼▼▼▼▼ system ▼▼▼▼▼▼▼▼▼▼ */ + public static final String SYS_ERROR_SAVE_SUCCESS = "sys_error_save_success"; + /** ▼▼▼▼▼▼▼▼▼▼ system ▼▼▼▼▼▼▼▼▼▼ */ + + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/property/MessageUtil.java b/appmarket-utils/src/main/java/app/market/utils/property/MessageUtil.java new file mode 100644 index 0000000..e3bdfc2 --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/property/MessageUtil.java @@ -0,0 +1,55 @@ +/* + * 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.utils.property; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Properties; + +import app.market.utils.constants.Constants; + +public class MessageUtil { + + public static Properties prop = null; + public static String i18n = Constants.I18N_JA_JP; + + private static Properties getPropertyInstance() { + if ( prop == null ) { + prop = new Properties(); + try { + prop.load( new InputStreamReader( MessageUtil.class.getClassLoader().getResourceAsStream( "message." + i18n + ".properties" ), "UTF-8" ) ); + } catch ( FileNotFoundException e ) { + throw new RuntimeException(); + } catch ( IOException e ) { + throw new RuntimeException(); + } + } + return MessageUtil.prop; + } + + /** + * Get propertites + * + * @param type + * @return String + */ + public static String getPropertites(String type) { + prop = getPropertyInstance(); + return prop.getProperty( type ); + } + +} diff --git a/appmarket-utils/src/main/java/app/market/utils/property/Option.java b/appmarket-utils/src/main/java/app/market/utils/property/Option.java new file mode 100644 index 0000000..eb8413e --- /dev/null +++ b/appmarket-utils/src/main/java/app/market/utils/property/Option.java @@ -0,0 +1,78 @@ +/* + * 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.utils.property; + +import java.io.Serializable; + +/** + * Page select's option + * + * @author Toyota + */ +public class Option implements Serializable, Comparable