diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Account.java b/src/main/java/org/ntlab/acanthus_server/entities/Account.java index 0f911e4..127c775 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Account.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Account.java @@ -67,8 +67,8 @@ //----------------------------------------------------------------- //コンストラクト - public Account() { - createDummyAccount(); + public Account(Integer idMargin) { + createDummyAccount(idMargin); } //----------------------------------------------------------------- @@ -171,30 +171,32 @@ public boolean isMatchedPassword(String password) { return this.password.equals(password); } + //----------------------------------------------------------------- // トークンのチェック - public boolean isCollectToken(String token){ + public boolean isCollectToken(String token) { var timeoutThreshold = 3; var nowDateTime = LocalDateTime.now(); - if(lastAccess==null) lastAccess = nowDateTime; + if (lastAccess == null) lastAccess = nowDateTime; // 時刻比較 var duration = Duration.between(lastAccess, nowDateTime).toHours(); - if(duration > timeoutThreshold) return false; + if (duration > timeoutThreshold) return false; return token.equals(this.token); } + //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミー - private void createDummyAccount() { + private void createDummyAccount(Integer idMargin) { this.isDummy = true; - this.uid = 1; - this.name = "dummy"; - this.email = "d@dummy.com"; + this.uid = 1 + idMargin; + this.name = "dummy" + idMargin.toString(); + this.email = "d" + idMargin.toString() + "@dummy.com"; this.password = "nittalab"; - this.token = "abc"; + this.token = "abc" + idMargin.toString(); this.lastAccess = LocalDateTime.now(); //this.lastAccess = LocalDateTime.of(2015, 12, 15, 0, 0); diff --git a/src/main/java/org/ntlab/acanthus_server/entities/EditorJson.java b/src/main/java/org/ntlab/acanthus_server/entities/EditorJson.java index 3fccca2..b218367 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/EditorJson.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/EditorJson.java @@ -8,8 +8,8 @@ //editorsをレスポンスとして返す public EditorJson(Collection editorList){ - for (var intUid : editorList){ - String strUid = "/Editor/" + intUid.getEditor().getUid(); + for (var editor : editorList){ + String strUid = "/Editor/" + editor.getEditor().getUid(); uid.add(strUid); } } diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java b/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java index 4900751..af314c4 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java @@ -6,7 +6,7 @@ import org.ntlab.acanthus_server.entities.Position; public class Stroke { - private static int i; //strokeNoを数えるためだけ + private static int strokeNoCount; //strokeNoを数えるためだけ private int strokeNo; private int pen; private int color; @@ -25,12 +25,15 @@ public int getThickness() { return this.thickness; } + public ArrayList getPositions() { + return this.positions; + } //書き始めたらstrokeNoを追加する。 public void addStrokeNo(){ - this.i++; - this.strokeNo = i; -} + strokeNoCount++; + this.strokeNo = strokeNoCount; + } public void addStrokes(int pen, int color, int thickness) { this.pen = pen; @@ -38,6 +41,10 @@ this.thickness = thickness; } + public void addPosition(ArrayList positions) { + this.positions = positions; + } + } diff --git a/src/main/java/org/ntlab/acanthus_server/entities/WorkJson.java b/src/main/java/org/ntlab/acanthus_server/entities/WorkJson.java index 2bf3752..e82a1b6 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/WorkJson.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/WorkJson.java @@ -12,8 +12,8 @@ //ユーザーの制作作品idをレスポンスとして返す際に、JSONのレスポンスに合わせる public WorkJson(Collection workList){ - for (var intAid : workList){ - String strAid = "/gallery/" + intAid.getAnimation().getAid(); + for (var work : workList){ + String strAid = "/gallery/" + work.getAnimation().getAid(); aid.add(strAid); } diff --git a/src/main/java/org/ntlab/acanthus_server/models/Accounts.java b/src/main/java/org/ntlab/acanthus_server/models/Accounts.java index 92a0020..7dfa63d 100644 --- a/src/main/java/org/ntlab/acanthus_server/models/Accounts.java +++ b/src/main/java/org/ntlab/acanthus_server/models/Accounts.java @@ -2,6 +2,7 @@ import org.ntlab.acanthus_server.entities.Account; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -20,7 +21,7 @@ //----------------------------------------------------------------- // インスタンス生成禁止 private Accounts() { - createDummyAccount(); //ダミー + createDummyAccounts(2); } //----------------------------------------------------------------- @@ -40,6 +41,7 @@ //----------------------------------------------------------------- // Uidからアカウントを返す + /** * @param uid ユーザーID */ @@ -49,6 +51,7 @@ //----------------------------------------------------------------- // e-mailからアカウントを返す + /** * @param email メアド */ @@ -61,6 +64,7 @@ //----------------------------------------------------------------- // 名前からアカウントのリストを返す + /** * @param name ユーザー名 */ @@ -75,28 +79,36 @@ } //----------------------------------------------------------------- // アカウントを登録する. + /** - * @param name ユーザー名 - * @param email メアド + * @param name ユーザー名 + * @param email メアド * @param password パスワード */ public Account registerAccount(String name, String email, String password) { var uid = new Random().nextInt(); // uidが被ったらuidの振り直し - while(getAccountByUid(uid) != null) uid = new Random().nextInt(); + while (getAccountByUid(uid) != null) uid = new Random().nextInt(); - var newAccount = new Account (uid, name, email, password); + var newAccount = new Account(uid, name, email, password); accountHashMap.put(uid, newAccount); return newAccount; } + //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミーアカウント生成 - private void createDummyAccount(){ - var dummyAccount = new Account(); + private void createDummyAccount(Integer idMargin) { + var dummyAccount = new Account(idMargin); accountHashMap.put(dummyAccount.getUid(), dummyAccount); } + //----------------------------------------------------------------- + // ダミーを指定数生成 + private void createDummyAccounts(int numOfAccounts) { + for (int i = 0; i < numOfAccounts; i++) createDummyAccount(i); //ダミー + } + } diff --git a/src/main/java/org/ntlab/acanthus_server/models/Gallery.java b/src/main/java/org/ntlab/acanthus_server/models/Gallery.java index d91f92d..13eb98c 100644 --- a/src/main/java/org/ntlab/acanthus_server/models/Gallery.java +++ b/src/main/java/org/ntlab/acanthus_server/models/Gallery.java @@ -39,7 +39,7 @@ public Collection getAllAnimation(){return animationHashMap.values();} //----------------------------------------------------------------- - // 1つの作品の全ての情報を返す.この二つのメソッドは同じです。どっちを使っても + // 1つの作品の全ての情報を返す. public Animation getAnimationInformation( Integer aid){return animationHashMap.get(aid);} diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/InvitedRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/InvitedRest.java index dc69740..da21c06 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/accounts/InvitedRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/InvitedRest.java @@ -59,7 +59,7 @@ }else{ //招待された作品の招待者の中に自分が含まれているか確認 - if(invitedAnimation.searchAnimationInvites(aid, String.valueOf(invitedUid)) != null){ + if(invitedAnimation.searchAnimationInvites(invitedAccount) != null){ //Workクラスのstateを1に変更 accountInvitedMap.get(aid).setInvites(aid); diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/WorkRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/WorkRest.java index da19eaa..62505a4 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/accounts/WorkRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/WorkRest.java @@ -9,6 +9,7 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.util.Collection; @Component @@ -32,7 +33,8 @@ return new WorkJson(workList); }else{ //ユーザーID、トークンが間違っている時のレスポンス - throw new WebApplicationException(401); + var response = Response.status(401).entity("ユーザーIDまたはトークンが間違っています"); + throw new WebApplicationException(response.build()); } } @@ -58,7 +60,8 @@ return new AidJson(newAid); }else{ //ユーザーID、トークンが間違っている時のレスポンス - throw new WebApplicationException(401); + var response = Response.status(401).entity("ユーザーIDまたはトークンが間違っています"); + throw new WebApplicationException(response.build()); } } @@ -81,14 +84,16 @@ invitedWork.setWork(); //招待されている作品を参加している作品へ状態変化 //作品のeditorsにユーザーを追加 - animation.restWorkToEditors(aid, invitedUid); + animation.restWorkToEditors(account); }else{ //作品に招待されていない場合のレスポンス - throw new WebApplicationException(400); + var response = Response.status(400).entity("作品に招待されていません"); + throw new WebApplicationException(response.build()); } }else{ //ユーザーID、トークンが間違っている時のレスポンス - throw new WebApplicationException(401); + var response = Response.status(401).entity("ユーザーIDまたはトークンが間違っています"); + throw new WebApplicationException(response.build()); } } diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java index 3a3b6cd..10fbc9b 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java @@ -45,7 +45,7 @@ var account = accounts.getAccountByUid(uid); var animation = gallery.getAnimationInformation(aid); if (account != null && animation != null && account.getToken().equals(token)) { - animation.restWorkToEditors(aid, uid); + animation.restWorkToEditors(account); } else { //ユーザーID、トークンが間違っている時のレスポンス throw new WebApplicationException(401); diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java index 1abebd2..d7d6f83 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java @@ -9,6 +9,7 @@ import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; //import java.security.acl.Owner; import java.util.*; @@ -23,7 +24,7 @@ @Produces(MediaType.APPLICATION_JSON) public Collection getGallery(){ var animationJsonList = new ArrayList(); - for(var animation : gallery.getAllAnimation() ) animationJsonList.add(new AnimationJson(animation)); + for (var animation : gallery.getAllAnimation()) animationJsonList.add(new AnimationJson(animation)); return animationJsonList; } //public Animation getGallery(){return ;} @@ -33,9 +34,21 @@ @Produces(MediaType.APPLICATION_JSON) public Integer createAnimation(@FormParam("name") String name ,@FormParam("token") String token ,@FormParam("uid") Integer uid){ - Accounts accounts = Accounts.getInstance(); - Account Owner = accounts.getAccountByUid(uid); - return gallery.createAnimation(name, Owner); + var searchAccounts = Accounts.getInstance().getAccountByUid(uid); + if(searchAccounts == null){ + var response=Response.status(404).entity("該当アカウントが存在しません"); + throw new WebApplicationException(response.build()); + } + + if(!searchAccounts.isCollectToken(token)){ + var response = Response.status(400).entity("トークンが違います。"); + throw new WebApplicationException(response.build()); + } + else { + Accounts accounts = Accounts.getInstance(); + Account Owner = accounts.getAccountByUid(uid); + return gallery.createAnimation(name, Owner); + } } @@ -43,9 +56,8 @@ @GET @Produces(MediaType.APPLICATION_JSON) public Collection getAnimationInformation(@PathParam("aid") Integer aid){ + var searchAnimation =gallery.getAnimationInformation(aid); - - var animationJsonList = new ArrayList(); animationJsonList.add(new AnimationJson(searchAnimation)); diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java index e40f80a..3714886 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java @@ -57,6 +57,7 @@ Stroke Test = new Stroke(); Test.addStrokes(pen, color, thick); Test.addStrokeNo();//strokeNoを+1する + Test.addPosition(this.positions); this.strokes.add(Test); // if(animation != null) { // this.Test.setStrokes(pen, color, thick); @@ -93,12 +94,15 @@ @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/position") @POST @Produces(MediaType.APPLICATION_JSON) - public void addPositions(@PathParam("aid") Integer aid, @FormParam("x") Float x, @FormParam("y") Float y) { + public void addPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo, @FormParam("x") Float x, @FormParam("y") Float y) { var animation = gallery.getAnimationInformation(aid); - Position Position = new Position(); - Position.setXY(x, y); - this.positions.add(Position); +// Stroke stroke = strokes.get(strokeNo); + + Position position = new Position(); + position.setXY(x, y); +// stroke.addPosition(Position); + this.positions.add(position); // if(animation != null) { // this.Position.setXY(x, y); // this.positions.add(this.Position);