diff --git a/.gitignore b/.gitignore index 63177e3..267e8e1 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ ### VS Code ### .vscode/ + +### SPRING BOOT LOG ### +logs/ +bin/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index c220a9a..4d78ed7 100644 --- a/build.gradle +++ b/build.gradle @@ -30,4 +30,5 @@ compile("com.h2database:h2:1.4.196") compile("com.fasterxml.jackson.core:jackson-databind") compile("org.hibernate:hibernate-core:5.4.2.Final") + compileOnly('org.projectlombok:lombok:1.16.10') } diff --git a/src/main/java/com/example/common/LogUtils.java b/src/main/java/com/example/common/LogUtils.java new file mode 100644 index 0000000..f56d157 --- /dev/null +++ b/src/main/java/com/example/common/LogUtils.java @@ -0,0 +1,23 @@ +package com.example.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LogUtils { + protected final static Logger logger = LoggerFactory.getLogger(LogUtils.class); + public static void info(String msg) { + logger.info(msg); + } + public static void warn(String msg) { + logger.warn(msg); + } + public static void error(String msg) { + logger.error(msg); + } + public static void debug(String msg) { + logger.debug(msg); + } + public static void trace(String msg) { + logger.trace(msg); + } +} diff --git a/src/main/java/com/example/cosmos_serversb/entities/Group.java b/src/main/java/com/example/cosmos_serversb/entities/Group.java index 7b34aaa..c900ac4 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Group.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Group.java @@ -70,13 +70,6 @@ requests.add(request); } - /* - public ArrayList getRequestsList(){ - ArrayList list = new ArrayList(getRequests()); - return list; - } - */ - public void setMembers(Set members) { this.members = members; } diff --git a/src/main/java/com/example/cosmos_serversb/entities/Token.java b/src/main/java/com/example/cosmos_serversb/entities/Token.java index a544e82..6e5a120 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Token.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Token.java @@ -1,7 +1,13 @@ package com.example.cosmos_serversb.entities; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +@Data public class Token { - public String token,uId; + public String token; + @JsonIgnore + private String uId; public Token(){ } @@ -10,15 +16,6 @@ setToken(token); setuId(uId); } - - public void setToken(String token) { - this.token = token; - } - - public String getToken() { - return token; - } - public void setuId(String uId) { this.uId = uId; } @@ -26,4 +23,5 @@ public String getuId() { return uId; } + } diff --git a/src/main/java/com/example/cosmos_serversb/entities/User.java b/src/main/java/com/example/cosmos_serversb/entities/User.java index c638bdd..714ca25 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/User.java +++ b/src/main/java/com/example/cosmos_serversb/entities/User.java @@ -3,6 +3,14 @@ import java.util.HashSet; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import lombok.Data; +import com.example.cosmos_serversb.views.UsersView; + +@Data public class User { /** * USER用のクラス @@ -13,19 +21,31 @@ * @param iconUri String iconの保存先 * @param login Boolean トークンが存在するか否か * @param groups Set 所属するグループ - * @param tokens String userが持トークン一覧 + * @param tokens Set 所持するトークン + * @param firstToken String 初期トークン * * TODO: Tokenのデータベース接続 - * TODO: tokenの持ち方要検討 + * TODO: ダミートークン削除 */ - - public String uId, uri, name, iconUri; + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonProperty("token") + public String firstToken;//初期トークン + @JsonView(UsersView.putUsersView.class) + public String uId; + @JsonView(UsersView.putUsersView.class) + public String uri; + @JsonView(UsersView.getUsersView.class) + public String name; + @JsonView(UsersView.getUsersView.class) + public String iconUri; + @JsonIgnore public boolean login = true; - public Set groups = new HashSet<>();//HashSetでいいのかな? - //仕様ではStringを返すため - //public Set tokens = new HashSet<>(); + @JsonIgnore + public Set groups = new HashSet<>(); + @JsonIgnore + public Set tokens = new HashSet<>(); //public Set tokens = new HashSet<>(); - public String token; + @JsonIgnore private String dummyToken = "a9965652-c2ec-4a0d-a78a-b457e8b2deca"; public User() { @@ -36,7 +56,7 @@ setUri(uri); setName(name); setIconUri(iconUri); - setToken(this.dummyToken); + setFirstToken(dummyToken); //addToken(this.dummyToken); this.login = true; } @@ -49,67 +69,6 @@ this.uId = uId; } - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getIconUri() { - return iconUri; - } - - public void setIconUri(String iconUri) { - this.iconUri = iconUri; - } - - public boolean getLogin() { - return login; - } - - public void setLogin(boolean login) { - this.login = login; - } - - public void setToken(String token) { - this.token = token; - } - - public String getToken() { - return token; - } - - /* - * //仕様ではStringで返すため - * public Set getTokens(){ - * return tokens; - * } - * public void setTokens(Set tokens){ - * this.tokens=tokens; - * } - * public void addToken (String token){ - * tokens.add(token); - * } - */ - - public Set getGroups() { - return groups; - } - - public void setGroups(Set groups) { - this.groups = groups; - } - public void addGroups(Group group){ groups.add(group); } diff --git a/src/main/java/com/example/cosmos_serversb/jsons/RequestJson.java b/src/main/java/com/example/cosmos_serversb/jsons/RequestJson.java new file mode 100644 index 0000000..17ac3c5 --- /dev/null +++ b/src/main/java/com/example/cosmos_serversb/jsons/RequestJson.java @@ -0,0 +1,103 @@ +package com.example.cosmos_serversb.jsons; + +import com.example.cosmos_serversb.entities.Request; +import com.example.cosmos_serversb.entities.User; +import com.example.cosmos_serversb.models.Users; + +import java.util.Date; + +public class RequestJson { + private String rId; + private String uri, product; + private UserJsonForRequests Issuer; + private Date date, deadline; + private int location;// YahooローカルサーチAPIの業種コード + private boolean done = false; + + public RequestJson(){ + + } + + public RequestJson(Request request){ + setrId(request.getrId()); + setUri(request.getrId()); + setDate(request.getDate()); + SetIssuerByUid(request.getIssuerUid()); + setProduct(request.getProduct()); + setDeadline(request.getDeadline()); + setLocation(request.getLocation()); + this.done = false; + } + + private void setrId(String rId){ + this.rId = rId; + } + + public String getrId(){ + return rId; + } + + private void setUri(String uri){ + this.uri = uri; + } + + public String getUri(){ + return uri; + } + + private void setDate(Date date){ + this.date = date; + } + + public Date getDate() { + return date; + } + + public UserJsonForRequests getIssuer(){ + return Issuer; + } + + private void setIssuer(UserJsonForRequests user){ + this.Issuer = user; + } + + private void SetIssuerByUid(String uId){ + this.Issuer = new UserJsonForRequests(Users.getInstance().getUserById(uId)); + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + public Date getDeadline() { + return deadline; + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public int getLocation() { + return location; + } + + public void setLocation(int location) { + this.location = location; + } + + public boolean isDone() { + return done; + } + + public boolean getDone() { + return done; + } + + public void setDone(boolean done) { + this.done = done; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/cosmos_serversb/jsons/RequestsJson.java b/src/main/java/com/example/cosmos_serversb/jsons/RequestsJson.java new file mode 100644 index 0000000..44e2f21 --- /dev/null +++ b/src/main/java/com/example/cosmos_serversb/jsons/RequestsJson.java @@ -0,0 +1,31 @@ +package com.example.cosmos_serversb.jsons; + +import com.example.cosmos_serversb.entities.Request; + +import java.util.ArrayList; +import java.util.Set; + + +public class RequestsJson { + public ArrayList requests = new ArrayList<>(); + + public RequestsJson(Set set, int quantity){ + changeRequests(set, quantity); + } + + public ArrayList getRequests(){ + return requests; + } + + public void setRequests(ArrayList requests) { + this.requests = requests; + } + + private void changeRequests(Set set, int quantity){ + if(quantity <= 0) return; + for( Request request : (Set) set ) { + requests.add(new RequestJson(request)); + if(requests.size() == quantity) break; + } + } +} diff --git a/src/main/java/com/example/cosmos_serversb/jsons/UserJsonForRequests.java b/src/main/java/com/example/cosmos_serversb/jsons/UserJsonForRequests.java new file mode 100644 index 0000000..0c9fe54 --- /dev/null +++ b/src/main/java/com/example/cosmos_serversb/jsons/UserJsonForRequests.java @@ -0,0 +1,74 @@ +package com.example.cosmos_serversb.jsons; + +import com.example.cosmos_serversb.entities.Group; +import com.example.cosmos_serversb.entities.User; + +import java.util.HashSet; +import java.util.Set; + +public class UserJsonForRequests { + public String uId, uri, name, iconUri; + public boolean login = true; + public String token; + + public UserJsonForRequests() { + + } + public UserJsonForRequests(User user) { + setuId(user.getuId()); + setUri(user.getUri()); + setName(user.getName()); + setIconUri(user.getIconUri()); + setToken(user.getToken()); + this.login = true; + } + + public String getuId() { + return uId; + } + + public void setuId(String uId) { + this.uId = uId; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIconUri() { + return iconUri; + } + + public void setIconUri(String iconUri) { + this.iconUri = iconUri; + } + + public boolean getLogin() { + return login; + } + + public void setLogin(boolean login) { + this.login = login; + } + + public void setToken(String token) { + this.token = token; + } + + public String getToken() { + return token; + } + +} diff --git a/src/main/java/com/example/cosmos_serversb/models/DeleteResult.java b/src/main/java/com/example/cosmos_serversb/models/DeleteResult.java index ab3b9a7..17dabcc 100644 --- a/src/main/java/com/example/cosmos_serversb/models/DeleteResult.java +++ b/src/main/java/com/example/cosmos_serversb/models/DeleteResult.java @@ -2,5 +2,6 @@ public enum DeleteResult { SUCCESS, - FAILURE + FAILURE, + ERROR } diff --git a/src/main/java/com/example/cosmos_serversb/models/Groups.java b/src/main/java/com/example/cosmos_serversb/models/Groups.java index e878ca0..6e1abbb 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Groups.java +++ b/src/main/java/com/example/cosmos_serversb/models/Groups.java @@ -68,7 +68,6 @@ return editGroup; } } - return null; } @@ -105,23 +104,55 @@ return null; } - public static HashMap getRequestsListByGid(String gId){ + /* + public static Group getGroupByGid(String gId){ + Group editGroup; + Session session = SessionManager.getInstance().getSession(); + List groupResult = session.createQuery( "from Group" ).list(); + for ( Group group : (List) groupResult ) { + editGroup = group; + if (editGroup.getgId().equals(gId)) { + return editGroup; + } + } return null; } - public static Request addRequests(String gId, String uId, String product, String deadline, int location){ + */ + + public static RequestsJson getRequestsListByGid(String gId, boolean detail, int quantity){ + Session session = SessionManager.getInstance().getSession(); + Group group = session.get(Group.class, gId); + if(group != null) { + RequestsJson requestsJson = new RequestsJson(group.getRequests(), quantity); + return requestsJson; + } + //例外処理 + return null; + } + + public static Request addRequests(String gId, String uId, String product, Date deadline, int location){ //テスト用 String rId = getInstance().createRId(); String uri = baseURI + AppName + "/groups/" + gId + "/requests/" + rId; - Request testRequest = new Request(rId, uri, new Date(1999,01,01), uId, product, new Date(1999,12,01), 999); - return testRequest; + Request request = new Request(rId, uri, new Date(1999,01,01), uId, product, deadline, location); + + Session session = SessionManager.getInstance().getSession(); + Group editGroup = session.get(Group.class, gId); + if(editGroup != null) { + editGroup.addRequests(request); + session.update(editGroup); + return request; + } + //例外処理 + return null; } public static Request getRequestDetailByGidAndRid(String gId, String rId){ return null; } - public static Request updateRequest(String gId, String rId, String uId, String product, String deadline, int location, boolean done){ + public static Request updateRequest(String gId, String rId, String uId, String product, Date deadline, int location, boolean done){ //テスト用 Request testRequest = new Request(rId, "http://test.com", new Date(1999,01,01), uId, product, new Date(1999,12,01), 999); diff --git a/src/main/java/com/example/cosmos_serversb/models/Users.java b/src/main/java/com/example/cosmos_serversb/models/Users.java index 4d564bc..ea79570 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Users.java +++ b/src/main/java/com/example/cosmos_serversb/models/Users.java @@ -3,18 +3,32 @@ import java.util.List; import java.util.UUID; import javax.inject.Singleton; +import javax.ws.rs.WebApplicationException; import com.example.cosmos_serversb.entities.*; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Value; @Singleton public class Users { + /** + * ユーザの情報を操作するためクラス + * + * @param Users + * @param SessionFactory + * @param baseURI + * @param AppName + * + * TODO:statusコードを返す + * TODO:baseURIなどは定義ファイルで保持させる + */ + private static Users theInstance = null; private static SessionFactory sessionFactory; - private static String baseURI = "http://nitta-lab-www.is.konan-u.ac.jp/"; - private static String AppName = "cosmos"; + private static String baseURI="http://nitta-lab-www.is.konan-u.ac.jp/"; + private static String AppName="cosmos"; private Users() { sessionFactory = SessionFactoryManager.getInstance().getSessionFactory(); @@ -28,21 +42,27 @@ } public static Token createToken(String uId) { - //Tokenを作成しuIdと関連付けしDBに保存し作成したTokenを返す + /** + * Tokenを作成返すためのメソッド + * + * @param uId String + * @param token_str String + * @return token Token + * + * TODO :どこでトークンを保存するか要検討 + */ String token = UUID.randomUUID().toString(); - Token testToken =new Token(token, uId); - - /*TODO:Session managerを作成しセッションの二重作成をしない - Session session = sessionFactory.openSession(); - session.beginTransaction(); - session.save(testToken); - session.getTransaction().commit(); - session.close();*/ - return testToken; + Token return_token =new Token(token, uId); + return return_token; } public static String createUId() { - //uIdを作成し既存していないかチェック後DBに保存し作成したuIdを返す + /** + * uIdを作成し既存していないかチェック後DBに保存し作成したuIdを返すためのメソッド + * + * @param uId String + * + */ String uId = UUID.randomUUID().toString(); return uId; } @@ -52,15 +72,26 @@ String uri = baseURI + AppName +"/users/" +uId; Session session = SessionManager.getInstance().getSession(); - createToken(uId); - Password password = new Password(pw, uId);//パスワードとユーザー情報を紐づけ - User testUser = new User(name, uId, uri, iconImage);//名前、uId、ユーザーuri、アイコンイメージを保存 - session.save(password); + Token token = createToken(uId); + User testUser = new User(name, uId, uri, iconImage); + Password password = new Password(pw, uId); session.save(testUser); + session.save(password); + session.save(token); return testUser; } public static User setUser(String uId, String name, String pw, String iconImage) { + /** + * Userの情報を変更するためのメソッド + * + * @param uId String + * @param name String + * @param pw String + * @param iconImage String + * + * TODO: checkPasswordメソッドを用いパスワードを確認する + */ Session session = SessionManager.getInstance().getSession(); List usersList = session.createQuery( "from User" ).list(); List passwordList = session.createQuery("from Password").list(); @@ -83,7 +114,11 @@ } public static User getUserById(String uId) { - //与えられたuIdのUser情報を返す + /** + * 与えられたuIdのUser情報を返すためのメソッド + * @param uId + * + */ Session session = SessionManager.getInstance().getSession(); List usersList = session.createQuery( "from User" ).list(); //uIdを比較し、一致した場合はNameとiconUriを返す。一致しない場合はbreak @@ -94,8 +129,7 @@ return findUser; } } - //一致しない場合は返す必要がないのでnull - return null; + throw new WebApplicationException(404); } public static User getUserByToken(String token) { @@ -106,27 +140,38 @@ public static DeleteResult deleteUser(String uId) { Session session = SessionManager.getInstance().getSession(); - Request deleteRequest = (Request) session.load(Request.class, uId); - if(deleteRequest != null){ - session.delete(deleteRequest); + User deleteUser = (User) session.load(User.class, uId); + if(deleteUser != null){ + session.delete(deleteUser); System.out.println("massage: Already Deleted"); } return DeleteResult.SUCCESS; } public static Token login(String uId,String pw) { + /** + * tokenを作成したりloginフラグの操作を行うフラグ + * @param uId String + * @param pw String + * + */ if(checkPassword(uId,pw)) { Token testtoken = getInstance().createToken(uId); - //tokenを作成後値を返す return testtoken;//testToken }else{ - return null; + throw new WebApplicationException(401); } } public static DeleteResult logout(String uId,String token) { + /** + * トークンを削除しログインフラグを操作するためのメソッド + * + * TODO: queryの文に条件文を追加 + * TODO :logout 変更 + */ Session session = SessionManager.getInstance().getSession(); - List usersList = session.createQuery( "from logout" ).list(); + List usersList = session.createQuery( "from User" ).list(); for ( User user : (List) usersList ) { if (user.getuId().equals(uId)) { if (Users.getInstance().getUserByToken(token).uId == null) { @@ -137,16 +182,27 @@ } } } - return null; + throw new WebApplicationException(400); } public static boolean checkToken(String uId, String token) { - //与えられたtokenとUserのtokenを比較し結果を返す + /** + * uIdとtokenを比較し結果を返すためのメソッド + * @param uId + * @param + */ return true; } public static boolean checkPassword(String uId, String pw) { - //与えられたパスワードとUserのパスワードを比較し結果を返す + /** + * UIDをキーにパスワードを引き抜き参照 + * @param uId + * @param pw String userが提示したパスワード + * @param pw_ans String DBに格納されたパスワード + * + * TODO:パスワードはhash、塩コショウかけて味を調える + */ Session session = SessionManager.getInstance().getSession(); Password findPassword = (Password) session.load(Password.class, uId); if (findPassword.getPw().equals(pw)) { @@ -154,6 +210,5 @@ } else { return false; } - } } \ No newline at end of file diff --git a/src/main/java/com/example/cosmos_serversb/resources/GroupsRest.java b/src/main/java/com/example/cosmos_serversb/resources/GroupsRest.java index 0fc15aa..64a3e3e 100644 --- a/src/main/java/com/example/cosmos_serversb/resources/GroupsRest.java +++ b/src/main/java/com/example/cosmos_serversb/resources/GroupsRest.java @@ -13,6 +13,7 @@ import com.example.cosmos_serversb.models.*; import java.io.IOException; +import java.util.Date; @Component @Path("/groups") @@ -105,19 +106,29 @@ return json; } +// @Path("/{gId}/requests") +// @GET +// public String getRequestsListByGid(@PathParam("gId") String gId, @QueryParam("token") String token) throws JsonProcessingException{ +// SessionManager.getInstance().getSession(); +// ObjectMapper mapper = new ObjectMapper(); +// String json = mapper.writeValueAsString(Groups.getInstance().getRequestsListByGid(gId)); +// SessionManager.getInstance().closeSession(); +// return json; +// } + @Path("/{gId}/requests") @GET - public String getRequestsListByGid(@PathParam("gId") String gId, @QueryParam("token") String token) throws JsonProcessingException{ + public String getRequestsListByGid(@PathParam("gId") String gId, @QueryParam("token") String token, @QueryParam("detail") boolean detail, @QueryParam("quantity") int quantity) throws JsonProcessingException{ SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(Groups.getInstance().getRequestsListByGid(gId)); + String json = mapper.writeValueAsString(Groups.getInstance().getRequestsListByGid(gId, detail, quantity)); SessionManager.getInstance().closeSession(); return json; } @Path("/{gId}/requests") @POST - public String addRequests(@PathParam("gId") String gId, @FormParam("uId") String uId, @FormParam("product") String product, @FormParam("deadline") String deadline, @FormParam("location") int location, @FormParam("token") String token) throws JsonProcessingException{ + public String addRequests(@PathParam("gId") String gId, @FormParam("uId") String uId, @FormParam("product") String product, @FormParam("deadline") Date deadline, @FormParam("location") int location, @FormParam("token") String token) throws JsonProcessingException{ SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Groups.getInstance().addRequests(gId, uId, product, deadline, location)); @@ -137,7 +148,7 @@ @Path("{gId}/requests/{rId}") @PUT - public String updateRequest(@PathParam("gId") String gId, @PathParam("rId") String rId, @FormParam("uId") String uId, @FormParam("product") String product, @FormParam("deadline") String deadline, @FormParam("location") int location, @FormParam("done") boolean done, @FormParam("token") String token) throws JsonProcessingException{ + public String updateRequest(@PathParam("gId") String gId, @PathParam("rId") String rId, @FormParam("uId") String uId, @FormParam("product") String product, @FormParam("deadline") Date deadline, @FormParam("location") int location, @FormParam("done") boolean done, @FormParam("token") String token) throws JsonProcessingException{ SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Groups.getInstance().updateRequest(gId, rId, uId, product, deadline, location, done)); diff --git a/src/main/java/com/example/cosmos_serversb/resources/ServerCheckRest.java b/src/main/java/com/example/cosmos_serversb/resources/ServerCheckRest.java index 9586664..daba7ef 100644 --- a/src/main/java/com/example/cosmos_serversb/resources/ServerCheckRest.java +++ b/src/main/java/com/example/cosmos_serversb/resources/ServerCheckRest.java @@ -1,12 +1,14 @@ package com.example.cosmos_serversb.resources; import org.springframework.stereotype.Component; import javax.ws.rs.*; +import com.example.common.LogUtils; @Component @Path("/") public class ServerCheckRest { @GET public String serverCheck() { + LogUtils.info("サーバーをチェックしています。"); return "{\"ServerStatus\":\"200\"}"; } } \ No newline at end of file diff --git a/src/main/java/com/example/cosmos_serversb/resources/UsersRest.java b/src/main/java/com/example/cosmos_serversb/resources/UsersRest.java index 99362f6..88766dc 100644 --- a/src/main/java/com/example/cosmos_serversb/resources/UsersRest.java +++ b/src/main/java/com/example/cosmos_serversb/resources/UsersRest.java @@ -8,28 +8,22 @@ import javax.ws.rs.*; import com.example.cosmos_serversb.models.*; +import com.example.cosmos_serversb.views.UsersView; + +import com.example.common.LogUtils; @Component @Path("/users") public class UsersRest { - - public interface RemoveuIdAndUri { - @JsonIgnore String getuId(); - @JsonIgnore String getUri(); - } - - public interface RemoveNameAndIconUri { - @JsonIgnore String getName(); - @JsonIgnore String getIconUri(); - } - + @POST public String createUsers(@FormParam("name") String name, @FormParam("pw") String pw, @FormParam("iconImage") String iconImage) throws JsonProcessingException { SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Users.getInstance().createUser(name, pw, iconImage)); SessionManager.getInstance().closeSession(); + LogUtils.info(name+" さんのアカウント作成が完了しました。"); return json; } @@ -38,9 +32,9 @@ public String getUsersInfo(@PathParam("uId") String uId, @QueryParam("token") String token) throws JsonProcessingException { SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(Users.getInstance().getUserById(uId)); - mapper.addMixIn(json.getClass(),RemoveuIdAndUri.class); + String json = mapper.writerWithView(UsersView.getUsersView.class).writeValueAsString(Users.getInstance().getUserById(uId)); SessionManager.getInstance().closeSession(); + LogUtils.info("uId:"+uId+" の方のデータを送信します"); return json; } @@ -50,8 +44,8 @@ SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Users.getInstance().setUser(uId, name, pw, iconImage)); - mapper.addMixIn(json.getClass(),RemoveNameAndIconUri.class); SessionManager.getInstance().closeSession(); + LogUtils.info("uId:"+uId+" の方がプロフィールを変更しました。"); return json; } @@ -62,6 +56,7 @@ ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Users.getInstance().deleteUser(uId)); SessionManager.getInstance().closeSession(); + LogUtils.info("uId:"+uId+" ユーザを削除しました"); return json; } @@ -72,6 +67,7 @@ ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Users.getInstance().login(uId,pw)); SessionManager.getInstance().closeSession(); + LogUtils.info("uId:"+uId+" ログインしました"); return json; } @@ -82,6 +78,7 @@ ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(Users.getInstance().logout(uId,token)); SessionManager.getInstance().closeSession(); + LogUtils.info("uId:"+uId+" ログアウトしました"); return json; } } diff --git a/src/main/java/com/example/cosmos_serversb/views/UsersView.java b/src/main/java/com/example/cosmos_serversb/views/UsersView.java new file mode 100644 index 0000000..db43fe7 --- /dev/null +++ b/src/main/java/com/example/cosmos_serversb/views/UsersView.java @@ -0,0 +1,7 @@ +package com.example.cosmos_serversb.views; + +public class UsersView { + public class postUsersView{} + public class getUsersView{} + public class putUsersView{} +} diff --git a/src/main/resources/Request.hbm.xml b/src/main/resources/Request.hbm.xml index 010d45a..2d3fc7e 100644 --- a/src/main/resources/Request.hbm.xml +++ b/src/main/resources/Request.hbm.xml @@ -16,10 +16,10 @@ - + - + diff --git a/src/main/resources/application-development.properties b/src/main/resources/application-development.properties new file mode 100644 index 0000000..4c76c3b --- /dev/null +++ b/src/main/resources/application-development.properties @@ -0,0 +1,15 @@ +# datasource +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:sampledb +spring.datasource.username=sa +spring.datasource.password=sa + +# h2 for debug tool +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console +spring.h2.console.settings.web-allow-others=true + +#baseURI +cosmos.baseURI=http://nitta-lab-www.is.konan-u.ac.jp/ +cosmos.appName=cosmsos +cosmos.URL=${cosmos.baseURI}${cosmos.appName} \ No newline at end of file diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/resources/application-production.properties diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index aef1113..e68ce2d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,10 +1,2 @@ -# datasource -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:sampledb -spring.datasource.username=sa -spring.datasource.password=sa - -# h2 for debug tool -spring.h2.console.enabled=true -spring.h2.console.path=/h2-console -spring.h2.console.settings.web-allow-others=true \ No newline at end of file +#Environmental setting +spring.profiles.active=development \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..10c0c93 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${logFilePath}%d{yyyy/MM/dd}.log + 7 + + + UTF-8 + %d{yyyy/MM/dd HH:mm:ss} %-5level [%thread] - %msg%n + + + + + + + + \ No newline at end of file