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 be52147..924caed 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Groups.java +++ b/src/main/java/com/example/cosmos_serversb/models/Groups.java @@ -16,34 +16,11 @@ private static ArrayList groups = new ArrayList<>(); private static SessionFactory sessionFactory; - - public static void setUp() { - // A SessionFactory is set up once for an application! - final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() - .configure() // configures settings from hibernate.cfg.xml - .build(); - try { - sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory(); - } - catch (Exception e) { - // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory - // so destroy it manually. - StandardServiceRegistryBuilder.destroy( registry ); - } - } - - public static void tearDown() { - try { - if ( sessionFactory != null ) { - sessionFactory.close(); - } - } catch (Exception e) { - System.out.println("Exception!"); - } - } + private static String baseURI = "http://nitta-lab-www.is.konan-u.ac.jp/"; + private static String AppName = "cosmos"; private Groups(){ - setUp(); + sessionFactory = SessionFactoryManager.getInstance().getSessionFactory(); } public static Groups getInstance(){ @@ -53,13 +30,27 @@ return theInstance; } + public static String createGId() { + //gIdを作成し既存していないかチェック後DBに保存し作成したgIdを返す + String gId = UUID.randomUUID().toString(); + return gId; + } + + public static String createRId() { + //rIdを作成し既存していないかチェック後DBに保存し作成したrIdを返す + String rId = UUID.randomUUID().toString(); + return rId; + } + public static HashMap getGroupsListByUid(String uId){ return createTestHashMap(); } public static Group createGroup(String name, String uId){ //先にGidとuriの発行を行う - Group testGroup = new Group("123456789", "http://test.com", name, uId); + String gId = getInstance().createGId(); + String uri = baseURI + AppName + "/groups/" + gId; + Group testGroup = new Group(gId, uri, name, uId); Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(testGroup); @@ -113,7 +104,9 @@ public static Request addRequests(String gId, String uId, String product, String deadline, int location){ //テスト用 - Request testRequest = new Request("123456789", "http://test.com", "1999/01/01/15:00:00", + String rId = getInstance().createRId(); + String uri = baseURI + AppName + "/groups/" + gId + "/requests/" + rId; + Request testRequest = new Request(rId, uri, "1999/01/01/15:00:00", uId, product, "1999/01/01/15:00:00", 999); return testRequest; } @@ -125,7 +118,7 @@ public static Request updateRequest(String gId, String rId, String uId, String product, String deadline, int location, boolean done){ //テスト用 - Request testRequest = new Request("123456789", "http://test.com", "1999/01/01/15:00:00", + Request testRequest = new Request(rId, "http://test.com", "1999/01/01/15:00:00", uId, product, "1999/01/01/15:00:00", 999); return testRequest;