List of usage examples for org.hibernate StatelessSession get
Object get(Class entityClass, Serializable id);
From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java
License:Open Source License
@Test public void testCreateBooking() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();/*from ww w . j av a2 s. c o m*/ UserClass uclass1 = new UserClass(); uclass1.setName("booktestclass"); uclass1.setActive(true); uclass1.setQueuable(false); uclass1.setBookable(true); uclass1.setTimeHorizon(0); ses.save(uclass1); User us1 = new User(); us1.setName("bktestuser1"); us1.setNamespace("BKNS"); us1.setPersona("USER"); ses.save(us1); User us2 = new User(); us2.setName("bktestuser2"); us2.setNamespace("BKNS"); us2.setPersona("USER"); ses.save(us2); UserAssociation assoc = new UserAssociation(new UserAssociationId(us2.getId(), uclass1.getId()), uclass1, us2); ses.save(assoc); RigType rigType1 = new RigType("booktestrigtype", 300, false); ses.save(rigType1); RigType rigType2 = new RigType("booktestrigtype2", 300, false); ses.save(rigType2); RigCapabilities caps1 = new RigCapabilities("book,test,foo"); ses.save(caps1); RigCapabilities caps2 = new RigCapabilities("book,test,bar"); ses.save(caps2); RigCapabilities caps3 = new RigCapabilities("book,baz,foo"); ses.save(caps3); RequestCapabilities rcaps1 = new RequestCapabilities("book"); ses.save(rcaps1); RequestCapabilities rcaps2 = new RequestCapabilities("foo"); ses.save(rcaps2); RequestCapabilities rcaps3 = new RequestCapabilities("bar"); ses.save(rcaps3); Rig r1 = new Rig(); r1.setName("bkrig1"); r1.setRigType(rigType1); r1.setLastUpdateTimestamp(new Date()); r1.setRigCapabilities(caps1); ses.save(r1); Rig r2 = new Rig(); r2.setName("bkrig2"); r2.setRigType(rigType1); r2.setLastUpdateTimestamp(new Date()); r2.setRigCapabilities(caps2); ses.save(r2); Rig r3 = new Rig(); r3.setName("bkrig3"); r3.setRigType(rigType2); r3.setLastUpdateTimestamp(new Date()); r3.setRigCapabilities(caps3); ses.save(r3); ResourcePermission perm1 = new ResourcePermission(); perm1.setUserClass(uclass1); perm1.setType("TYPE"); perm1.setSessionDuration(3600); perm1.setQueueActivityTimeout(300); perm1.setAllowedExtensions((short) 10); perm1.setSessionActivityTimeout(300); perm1.setExtensionDuration(300); perm1.setMaximumBookings(10); perm1.setRigType(rigType1); Calendar cal = TimeUtil.getDayBegin(this.dayStr); cal.add(Calendar.DAY_OF_MONTH, -3); perm1.setStartTime(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, 6); perm1.setExpiryTime(cal.getTime()); perm1.setDisplayName("bookperm"); ses.save(perm1); /* #### BOOKINGS FOR R1 ########################################### */ Calendar r1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk1 = new Bookings(); bk1.setActive(true); bk1.setDuration(3600); /* Slots 2 - 5. */ r1tm.add(Calendar.MINUTE, 30); bk1.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 1); bk1.setEndTime(r1tm.getTime()); bk1.setResourcePermission(perm1); bk1.setResourceType("RIG"); bk1.setRig(r1); bk1.setUser(us1); bk1.setUserName(us1.getName()); bk1.setUserNamespace(us1.getNamespace()); ses.save(bk1); Bookings bk2 = new Bookings(); bk2.setActive(true); bk2.setCancelReason("Test cancel."); bk2.setDuration(1800); /* Slots 8 - 9. */ r1tm.add(Calendar.MINUTE, 30); bk2.setStartTime(r1tm.getTime()); r1tm.add(Calendar.MINUTE, 30); bk2.setEndTime(r1tm.getTime()); bk2.setResourcePermission(perm1); bk2.setResourceType("RIG"); bk2.setRig(r1); bk2.setUser(us1); bk2.setUserName(us1.getName()); bk2.setUserNamespace(us1.getNamespace()); ses.save(bk2); Bookings bk3 = new Bookings(); bk3.setActive(true); bk3.setDuration(7200); /* Slots 36 - 43. */ r1tm.add(Calendar.MINUTE, 30); r1tm.add(Calendar.HOUR, 6); bk3.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 2); bk3.setEndTime(r1tm.getTime()); bk3.setResourcePermission(perm1); bk3.setResourceType("RIG"); bk3.setRig(r1); bk3.setUser(us1); bk3.setUserName(us1.getName()); bk3.setUserNamespace(us1.getNamespace()); ses.save(bk3); /* #### BOOKINGS FOR R2 ########################################### */ Calendar r2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk8 = new Bookings(); bk8.setActive(true); bk8.setDuration(3600); /* Slots 13 - 16. */ r2tm.add(Calendar.HOUR, 3); bk8.setStartTime(r2tm.getTime()); r2tm.add(Calendar.HOUR, 1); bk8.setEndTime(r2tm.getTime()); bk8.setResourcePermission(perm1); bk8.setResourceType("RIG"); bk8.setRig(r2); bk8.setUser(us1); bk8.setUserName(us1.getName()); bk8.setUserNamespace(us1.getNamespace()); ses.save(bk8); Bookings bk9 = new Bookings(); bk9.setActive(true); bk9.setDuration(1800); /* Slots 36 - 37. */ r2tm.add(Calendar.HOUR, 5); bk9.setStartTime(r2tm.getTime()); r2tm.add(Calendar.MINUTE, 30); bk9.setEndTime(r2tm.getTime()); bk9.setResourcePermission(perm1); bk9.setResourceType("RIG"); bk9.setRig(r2); bk9.setUser(us1); bk9.setUserName(us1.getName()); bk9.setUserNamespace(us1.getNamespace()); ses.save(bk9); /* #### BOOKINGS FOR R3 ########################################### */ Calendar r3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk10 = new Bookings(); bk10.setActive(true); bk10.setDuration(1800); /* Slots 2 - 3. */ r3tm.add(Calendar.MINUTE, 30); bk10.setStartTime(r3tm.getTime()); r3tm.add(Calendar.MINUTE, 30); bk10.setEndTime(r3tm.getTime()); bk10.setResourcePermission(perm1); bk10.setResourceType("RIG"); bk10.setRig(r3); bk10.setUser(us1); bk10.setUserName(us1.getName()); bk10.setUserNamespace(us1.getNamespace()); ses.save(bk10); Bookings bk11 = new Bookings(); bk11.setActive(true); bk11.setDuration(3600); /* Slots 12 - 15. */ r3tm.add(Calendar.HOUR, 2); bk11.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk11.setEndTime(r3tm.getTime()); bk11.setResourcePermission(perm1); bk11.setResourceType("RIG"); bk11.setRig(r3); bk11.setUser(us1); bk11.setUserName(us1.getName()); bk11.setUserNamespace(us1.getNamespace()); ses.save(bk11); Bookings bk12 = new Bookings(); bk12.setActive(true); bk12.setDuration(3600); /* Slots 24 - 27. */ r3tm.add(Calendar.HOUR, 2); bk12.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk12.setEndTime(r3tm.getTime()); bk12.setResourcePermission(perm1); bk12.setResourceType("RIG"); bk12.setRig(r3); bk12.setUser(us1); bk12.setUserName(us1.getName()); bk12.setUserNamespace(us1.getNamespace()); ses.save(bk12); /* #### Type bookings for RigType1 ####################################*/ Calendar rt1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk4 = new Bookings(); bk4.setActive(true); bk4.setDuration(1800); /* Slots 0 - 1. */ bk4.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.MINUTE, 30); bk4.setEndTime(rt1tm.getTime()); bk4.setResourcePermission(perm1); bk4.setResourceType("TYPE"); bk4.setRigType(rigType1); bk4.setUser(us1); bk4.setUserName(us1.getName()); bk4.setUserNamespace(us1.getNamespace()); ses.save(bk4); Bookings bk13 = new Bookings(); bk13.setActive(true); bk13.setDuration(7200); /* Slots 0 - 7. */ rt1tm.add(Calendar.MINUTE, -30); bk13.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 2); bk13.setEndTime(rt1tm.getTime()); bk13.setResourcePermission(perm1); bk13.setResourceType("TYPE"); bk13.setRigType(rigType1); bk13.setUser(us1); bk13.setUserName(us1.getName()); bk13.setUserNamespace(us1.getNamespace()); ses.save(bk13); Bookings bk5 = new Bookings(); bk5.setActive(true); bk5.setDuration(3600); /* Slots 20 - 23. */ rt1tm.add(Calendar.HOUR, 3); bk5.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk5.setEndTime(rt1tm.getTime()); bk5.setResourcePermission(perm1); bk5.setResourceType("TYPE"); bk5.setRigType(rigType1); bk5.setUser(us1); bk5.setUserName(us1.getName()); bk5.setUserNamespace(us1.getNamespace()); ses.save(bk5); Bookings bk14 = new Bookings(); bk14.setActive(true); bk14.setDuration(3600); /* Slots 24 - 27. */ bk14.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk14.setEndTime(rt1tm.getTime()); bk14.setResourcePermission(perm1); bk14.setResourceType("TYPE"); bk14.setRigType(rigType1); bk14.setUser(us1); bk14.setUserName(us1.getName()); bk14.setUserNamespace(us1.getNamespace()); ses.save(bk14); Bookings bk15 = new Bookings(); bk15.setActive(true); bk15.setDuration(5400); /* Slots 52 - 58. */ rt1tm.add(Calendar.HOUR, 6); bk15.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); rt1tm.add(Calendar.MINUTE, 30); bk15.setEndTime(rt1tm.getTime()); bk15.setResourcePermission(perm1); bk15.setResourceType("TYPE"); bk15.setRigType(rigType1); bk15.setUser(us1); bk15.setUserName(us1.getName()); bk15.setUserNamespace(us1.getNamespace()); ses.save(bk15); /* #### Type bookings for RigType2 ####################################*/ Calendar rt2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk16 = new Bookings(); bk16.setActive(true); bk16.setDuration(3600); /* Slots 52 - 59. */ rt2tm.add(Calendar.HOUR, 7); bk16.setStartTime(rt2tm.getTime()); rt2tm.add(Calendar.HOUR, 1); rt2tm.add(Calendar.MINUTE, 15); bk16.setEndTime(rt2tm.getTime()); bk16.setResourcePermission(perm1); bk16.setResourceType("TYPE"); bk16.setRigType(rigType2); bk16.setUser(us1); bk16.setUserName(us1.getName()); bk16.setUserNamespace(us1.getNamespace()); ses.save(bk16); /* #### Bookings for Request Caps 1. #################################*/ Calendar rcap1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk6 = new Bookings(); bk6.setActive(true); bk6.setDuration(1800); /* Slots 20 - 21. */ rcap1tm.add(Calendar.HOUR, 5); bk6.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk6.setEndTime(rcap1tm.getTime()); bk6.setResourcePermission(perm1); bk6.setResourceType("CAPABILITY"); bk6.setRequestCapabilities(rcaps1); bk6.setUser(us1); bk6.setUserName(us1.getName()); bk6.setUserNamespace(us1.getNamespace()); ses.save(bk6); Bookings bk7 = new Bookings(); bk7.setActive(true); bk7.setDuration(1800); /* Slots 22 - 23. */ bk7.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk7.setEndTime(rcap1tm.getTime()); bk7.setResourcePermission(perm1); bk7.setResourceType("CAPABILITY"); bk7.setRequestCapabilities(rcaps1); bk7.setUser(us1); bk7.setUserName(us1.getName()); bk7.setUserNamespace(us1.getNamespace()); ses.save(bk7); Bookings bk17 = new Bookings(); bk17.setActive(true); bk17.setDuration(1800); /* Slots 32 - 35. */ rcap1tm.add(Calendar.HOUR, 2); bk17.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.HOUR, 1); bk17.setEndTime(rcap1tm.getTime()); bk17.setResourcePermission(perm1); bk17.setResourceType("CAPABILITY"); bk17.setRequestCapabilities(rcaps1); bk17.setUser(us1); bk17.setUserName(us1.getName()); bk17.setUserNamespace(us1.getNamespace()); ses.save(bk17); /* #### Bookings for Request Caps 2. #################################*/ Calendar rcap2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk18 = new Bookings(); bk18.setActive(true); bk18.setDuration(1800); /* Slots 56 - 59. */ rcap2tm.add(Calendar.HOUR, 14); bk18.setStartTime(rcap2tm.getTime()); rcap2tm.add(Calendar.HOUR, 1); bk18.setEndTime(rcap2tm.getTime()); bk18.setResourcePermission(perm1); bk18.setResourceType("CAPABILITY"); bk18.setRequestCapabilities(rcaps2); bk18.setUser(us1); bk18.setUserName(us1.getName()); bk18.setUserNamespace(us1.getNamespace()); ses.save(bk18); /* #### Bookings for Request Caps 3. #################################*/ Calendar rcap3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk19 = new Bookings(); bk19.setActive(true); bk19.setDuration(4500); /* Slots 56 - 59. */ rcap3tm.add(Calendar.HOUR, 7); bk19.setStartTime(rcap3tm.getTime()); rcap3tm.add(Calendar.HOUR, 1); rcap3tm.add(Calendar.MINUTE, 15); bk19.setEndTime(rcap3tm.getTime()); bk19.setResourcePermission(perm1); bk19.setResourceType("CAPABILITY"); bk19.setRequestCapabilities(rcaps3); bk19.setUser(us1); bk19.setUserName(us1.getName()); bk19.setUserNamespace(us1.getNamespace()); ses.save(bk19); ses.getTransaction().commit(); ses.beginTransaction(); MatchingCapabilities mat1 = new MatchingCapabilities(rcaps1, caps1); ses.save(mat1); MatchingCapabilities mat2 = new MatchingCapabilities(rcaps1, caps2); ses.save(mat2); MatchingCapabilities mat3 = new MatchingCapabilities(rcaps1, caps3); ses.save(mat3); MatchingCapabilities mat4 = new MatchingCapabilities(rcaps2, caps1); ses.save(mat4); MatchingCapabilities mat5 = new MatchingCapabilities(rcaps2, caps3); ses.save(mat5); MatchingCapabilities mat6 = new MatchingCapabilities(rcaps3, caps2); ses.save(mat6); ses.getTransaction().commit(); ses.refresh(rcaps1); ses.refresh(rcaps2); ses.refresh(rcaps3); ses.refresh(caps1); ses.refresh(caps2); ses.refresh(caps3); ses.refresh(r1); ses.refresh(r2); ses.refresh(r3); ses.refresh(rigType1); ses.refresh(rigType2); CreateBooking request = new CreateBooking(); CreateBookingType param = new CreateBookingType(); request.setCreateBooking(param); UserIDType uid = new UserIDType(); UserNSNameSequence seq = new UserNSNameSequence(); seq.setUserNamespace(us2.getNamespace()); seq.setUserName(us2.getName()); uid.setUserNSNameSequence(seq); param.setUserID(uid); BookingType bt = new BookingType(); param.setBooking(bt); PermissionIDType pid = new PermissionIDType(); pid.setPermissionID(perm1.getId().intValue()); bt.setPermissionID(pid); Calendar bkSt = TimeUtil.getDayBegin(this.dayStr); bkSt.add(Calendar.HOUR, 5); bt.setStartTime(bkSt); Calendar bkEd = TimeUtil.getDayBegin(this.dayStr); bkEd.add(Calendar.HOUR, 6); bt.setEndTime(bkEd); CreateBookingResponse response = this.service.createBooking(request); BookingIDType bid = response.getCreateBookingResponse().getBookingID(); Bookings b = null; if (bid != null) { StatelessSession ss = DataAccessActivator.getNewStatelessSession(); Long id = Long.valueOf(bid.getBookingID()); b = (Bookings) ss.get(Bookings.class, id); } if (b != null) { ses.beginTransaction(); ses.delete(b); ses.getTransaction().commit(); } ses.beginTransaction(); ses.delete(bk1); ses.delete(bk2); ses.delete(bk3); ses.delete(bk4); ses.delete(bk5); ses.delete(bk6); ses.delete(bk7); ses.delete(bk8); ses.delete(bk9); ses.delete(bk10); ses.delete(bk11); ses.delete(bk12); ses.delete(bk13); ses.delete(bk14); ses.delete(bk15); ses.delete(bk16); ses.delete(bk17); ses.delete(bk18); ses.delete(bk19); ses.delete(perm1); ses.delete(r1); ses.delete(r2); ses.delete(r3); ses.delete(mat1); ses.delete(mat2); ses.delete(mat3); ses.delete(mat4); ses.delete(mat5); ses.delete(mat6); ses.delete(caps1); ses.delete(caps2); ses.delete(caps3); ses.delete(rcaps1); ses.delete(rcaps2); ses.delete(rcaps3); ses.delete(rigType1); ses.delete(rigType2); ses.delete(assoc); ses.delete(us1); ses.delete(us2); ses.delete(uclass1); ses.getTransaction().commit(); assertTrue(bk1.isActive()); assertTrue(bk2.isActive()); assertTrue(bk3.isActive()); assertTrue(bk4.isActive()); assertTrue(bk5.isActive()); assertTrue(bk6.isActive()); assertTrue(bk7.isActive()); assertTrue(bk8.isActive()); assertTrue(bk9.isActive()); assertTrue(bk10.isActive()); assertTrue(bk11.isActive()); assertTrue(bk12.isActive()); assertTrue(bk13.isActive()); assertTrue(bk14.isActive()); assertTrue(bk15.isActive()); assertTrue(bk16.isActive()); assertTrue(bk17.isActive()); assertTrue(bk18.isActive()); assertTrue(bk19.isActive()); assertNotNull(response); assertTrue(response.getCreateBookingResponse().getSuccess()); assertNotNull(bid); assertNotNull(b); }
From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java
License:Open Source License
@Test public void testCreateBookingFits() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();/*from www . ja v a2s.c o m*/ UserClass uclass1 = new UserClass(); uclass1.setName("booktestclass"); uclass1.setActive(true); uclass1.setQueuable(false); uclass1.setBookable(true); uclass1.setTimeHorizon(0); ses.save(uclass1); User us1 = new User(); us1.setName("bktestuser1"); us1.setNamespace("BKNS"); us1.setPersona("USER"); ses.save(us1); User us2 = new User(); us2.setName("bktestuser2"); us2.setNamespace("BKNS"); us2.setPersona("USER"); ses.save(us2); UserAssociation assoc = new UserAssociation(new UserAssociationId(us2.getId(), uclass1.getId()), uclass1, us2); ses.save(assoc); RigType rigType1 = new RigType("booktestrigtype", 300, false); ses.save(rigType1); RigType rigType2 = new RigType("booktestrigtype2", 300, false); ses.save(rigType2); RigCapabilities caps1 = new RigCapabilities("book,test,foo"); ses.save(caps1); RigCapabilities caps2 = new RigCapabilities("book,test,bar"); ses.save(caps2); RigCapabilities caps3 = new RigCapabilities("book,baz,foo"); ses.save(caps3); RequestCapabilities rcaps1 = new RequestCapabilities("book"); ses.save(rcaps1); RequestCapabilities rcaps2 = new RequestCapabilities("foo"); ses.save(rcaps2); RequestCapabilities rcaps3 = new RequestCapabilities("bar"); ses.save(rcaps3); Rig r1 = new Rig(); r1.setName("bkrig1"); r1.setRigType(rigType1); r1.setLastUpdateTimestamp(new Date()); r1.setRigCapabilities(caps1); ses.save(r1); Rig r2 = new Rig(); r2.setName("bkrig2"); r2.setRigType(rigType1); r2.setLastUpdateTimestamp(new Date()); r2.setRigCapabilities(caps2); ses.save(r2); Rig r3 = new Rig(); r3.setName("bkrig3"); r3.setRigType(rigType2); r3.setLastUpdateTimestamp(new Date()); r3.setRigCapabilities(caps3); ses.save(r3); ResourcePermission perm1 = new ResourcePermission(); perm1.setUserClass(uclass1); perm1.setType("TYPE"); perm1.setSessionDuration(3600); perm1.setQueueActivityTimeout(300); perm1.setAllowedExtensions((short) 10); perm1.setSessionActivityTimeout(300); perm1.setExtensionDuration(300); perm1.setMaximumBookings(10); perm1.setRigType(rigType1); Calendar cal = TimeUtil.getDayBegin(this.dayStr); cal.add(Calendar.DAY_OF_MONTH, -3); perm1.setStartTime(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, 6); perm1.setExpiryTime(cal.getTime()); perm1.setDisplayName("bookperm"); ses.save(perm1); /* #### BOOKINGS FOR R1 ########################################### */ Calendar r1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk1 = new Bookings(); bk1.setActive(true); bk1.setDuration(3600); /* Slots 2 - 5. */ r1tm.add(Calendar.MINUTE, 30); bk1.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 1); bk1.setEndTime(r1tm.getTime()); bk1.setResourcePermission(perm1); bk1.setResourceType("RIG"); bk1.setRig(r1); bk1.setUser(us1); bk1.setUserName(us1.getName()); bk1.setUserNamespace(us1.getNamespace()); ses.save(bk1); Bookings bk2 = new Bookings(); bk2.setActive(true); bk2.setCancelReason("Test cancel."); bk2.setDuration(1800); /* Slots 8 - 9. */ r1tm.add(Calendar.MINUTE, 30); bk2.setStartTime(r1tm.getTime()); r1tm.add(Calendar.MINUTE, 30); bk2.setEndTime(r1tm.getTime()); bk2.setResourcePermission(perm1); bk2.setResourceType("RIG"); bk2.setRig(r1); bk2.setUser(us1); bk2.setUserName(us1.getName()); bk2.setUserNamespace(us1.getNamespace()); ses.save(bk2); Bookings bk3 = new Bookings(); bk3.setActive(true); bk3.setDuration(7200); /* Slots 36 - 43. */ r1tm.add(Calendar.MINUTE, 30); r1tm.add(Calendar.HOUR, 6); bk3.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 2); bk3.setEndTime(r1tm.getTime()); bk3.setResourcePermission(perm1); bk3.setResourceType("RIG"); bk3.setRig(r1); bk3.setUser(us1); bk3.setUserName(us1.getName()); bk3.setUserNamespace(us1.getNamespace()); ses.save(bk3); /* #### BOOKINGS FOR R2 ########################################### */ Calendar r2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk8 = new Bookings(); bk8.setActive(true); bk8.setDuration(3600); /* Slots 13 - 16. */ r2tm.add(Calendar.HOUR, 3); bk8.setStartTime(r2tm.getTime()); r2tm.add(Calendar.HOUR, 1); bk8.setEndTime(r2tm.getTime()); bk8.setResourcePermission(perm1); bk8.setResourceType("RIG"); bk8.setRig(r2); bk8.setUser(us1); bk8.setUserName(us1.getName()); bk8.setUserNamespace(us1.getNamespace()); ses.save(bk8); Bookings bk9 = new Bookings(); bk9.setActive(true); bk9.setDuration(1800); /* Slots 36 - 37. */ r2tm.add(Calendar.HOUR, 5); bk9.setStartTime(r2tm.getTime()); r2tm.add(Calendar.MINUTE, 30); bk9.setEndTime(r2tm.getTime()); bk9.setResourcePermission(perm1); bk9.setResourceType("RIG"); bk9.setRig(r2); bk9.setUser(us1); bk9.setUserName(us1.getName()); bk9.setUserNamespace(us1.getNamespace()); ses.save(bk9); /* #### BOOKINGS FOR R3 ########################################### */ Calendar r3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk10 = new Bookings(); bk10.setActive(true); bk10.setDuration(1800); /* Slots 2 - 3. */ r3tm.add(Calendar.MINUTE, 30); bk10.setStartTime(r3tm.getTime()); r3tm.add(Calendar.MINUTE, 30); bk10.setEndTime(r3tm.getTime()); bk10.setResourcePermission(perm1); bk10.setResourceType("RIG"); bk10.setRig(r3); bk10.setUser(us1); bk10.setUserName(us1.getName()); bk10.setUserNamespace(us1.getNamespace()); ses.save(bk10); Bookings bk11 = new Bookings(); bk11.setActive(true); bk11.setDuration(3600); /* Slots 12 - 15. */ r3tm.add(Calendar.HOUR, 2); bk11.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk11.setEndTime(r3tm.getTime()); bk11.setResourcePermission(perm1); bk11.setResourceType("RIG"); bk11.setRig(r3); bk11.setUser(us1); bk11.setUserName(us1.getName()); bk11.setUserNamespace(us1.getNamespace()); ses.save(bk11); Bookings bk12 = new Bookings(); bk12.setActive(true); bk12.setDuration(3600); /* Slots 24 - 27. */ r3tm.add(Calendar.HOUR, 2); bk12.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk12.setEndTime(r3tm.getTime()); bk12.setResourcePermission(perm1); bk12.setResourceType("RIG"); bk12.setRig(r3); bk12.setUser(us1); bk12.setUserName(us1.getName()); bk12.setUserNamespace(us1.getNamespace()); ses.save(bk12); /* #### Type bookings for RigType1 ####################################*/ Calendar rt1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk4 = new Bookings(); bk4.setActive(true); bk4.setDuration(1800); /* Slots 0 - 1. */ bk4.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.MINUTE, 30); bk4.setEndTime(rt1tm.getTime()); bk4.setResourcePermission(perm1); bk4.setResourceType("TYPE"); bk4.setRigType(rigType1); bk4.setUser(us1); bk4.setUserName(us1.getName()); bk4.setUserNamespace(us1.getNamespace()); ses.save(bk4); Bookings bk13 = new Bookings(); bk13.setActive(true); bk13.setDuration(7200); /* Slots 0 - 7. */ rt1tm.add(Calendar.MINUTE, -30); bk13.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 2); bk13.setEndTime(rt1tm.getTime()); bk13.setResourcePermission(perm1); bk13.setResourceType("TYPE"); bk13.setRigType(rigType1); bk13.setUser(us1); bk13.setUserName(us1.getName()); bk13.setUserNamespace(us1.getNamespace()); ses.save(bk13); Bookings bk5 = new Bookings(); bk5.setActive(true); bk5.setDuration(3600); /* Slots 20 - 23. */ rt1tm.add(Calendar.HOUR, 3); bk5.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk5.setEndTime(rt1tm.getTime()); bk5.setResourcePermission(perm1); bk5.setResourceType("TYPE"); bk5.setRigType(rigType1); bk5.setUser(us1); bk5.setUserName(us1.getName()); bk5.setUserNamespace(us1.getNamespace()); ses.save(bk5); Bookings bk14 = new Bookings(); bk14.setActive(true); bk14.setDuration(3600); /* Slots 24 - 27. */ bk14.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk14.setEndTime(rt1tm.getTime()); bk14.setResourcePermission(perm1); bk14.setResourceType("TYPE"); bk14.setRigType(rigType1); bk14.setUser(us1); bk14.setUserName(us1.getName()); bk14.setUserNamespace(us1.getNamespace()); ses.save(bk14); Bookings bk15 = new Bookings(); bk15.setActive(true); bk15.setDuration(5400); /* Slots 52 - 58. */ rt1tm.add(Calendar.HOUR, 6); bk15.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); rt1tm.add(Calendar.MINUTE, 30); bk15.setEndTime(rt1tm.getTime()); bk15.setResourcePermission(perm1); bk15.setResourceType("TYPE"); bk15.setRigType(rigType1); bk15.setUser(us1); bk15.setUserName(us1.getName()); bk15.setUserNamespace(us1.getNamespace()); ses.save(bk15); /* #### Type bookings for RigType2 ####################################*/ Calendar rt2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk16 = new Bookings(); bk16.setActive(true); bk16.setDuration(3600); /* Slots 52 - 59. */ rt2tm.add(Calendar.HOUR, 7); bk16.setStartTime(rt2tm.getTime()); rt2tm.add(Calendar.HOUR, 1); rt2tm.add(Calendar.MINUTE, 15); bk16.setEndTime(rt2tm.getTime()); bk16.setResourcePermission(perm1); bk16.setResourceType("TYPE"); bk16.setRigType(rigType2); bk16.setUser(us1); bk16.setUserName(us1.getName()); bk16.setUserNamespace(us1.getNamespace()); ses.save(bk16); /* #### Bookings for Request Caps 1. #################################*/ Calendar rcap1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk6 = new Bookings(); bk6.setActive(true); bk6.setDuration(1800); /* Slots 20 - 21. */ rcap1tm.add(Calendar.HOUR, 5); bk6.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk6.setEndTime(rcap1tm.getTime()); bk6.setResourcePermission(perm1); bk6.setResourceType("CAPABILITY"); bk6.setRequestCapabilities(rcaps1); bk6.setUser(us1); bk6.setUserName(us1.getName()); bk6.setUserNamespace(us1.getNamespace()); ses.save(bk6); Bookings bk7 = new Bookings(); bk7.setActive(true); bk7.setDuration(1800); /* Slots 22 - 23. */ bk7.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk7.setEndTime(rcap1tm.getTime()); bk7.setResourcePermission(perm1); bk7.setResourceType("CAPABILITY"); bk7.setRequestCapabilities(rcaps1); bk7.setUser(us1); bk7.setUserName(us1.getName()); bk7.setUserNamespace(us1.getNamespace()); ses.save(bk7); Bookings bk17 = new Bookings(); bk17.setActive(true); bk17.setDuration(1800); /* Slots 32 - 35. */ rcap1tm.add(Calendar.HOUR, 2); bk17.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.HOUR, 1); bk17.setEndTime(rcap1tm.getTime()); bk17.setResourcePermission(perm1); bk17.setResourceType("CAPABILITY"); bk17.setRequestCapabilities(rcaps1); bk17.setUser(us1); bk17.setUserName(us1.getName()); bk17.setUserNamespace(us1.getNamespace()); ses.save(bk17); /* #### Bookings for Request Caps 2. #################################*/ Calendar rcap2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk18 = new Bookings(); bk18.setActive(true); bk18.setDuration(1800); /* Slots 56 - 59. */ rcap2tm.add(Calendar.HOUR, 14); bk18.setStartTime(rcap2tm.getTime()); rcap2tm.add(Calendar.HOUR, 1); bk18.setEndTime(rcap2tm.getTime()); bk18.setResourcePermission(perm1); bk18.setResourceType("CAPABILITY"); bk18.setRequestCapabilities(rcaps2); bk18.setUser(us1); bk18.setUserName(us1.getName()); bk18.setUserNamespace(us1.getNamespace()); ses.save(bk18); /* #### Bookings for Request Caps 3. #################################*/ Calendar rcap3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk19 = new Bookings(); bk19.setActive(true); bk19.setDuration(4500); /* Slots 56 - 59. */ rcap3tm.add(Calendar.HOUR, 7); bk19.setStartTime(rcap3tm.getTime()); rcap3tm.add(Calendar.HOUR, 1); rcap3tm.add(Calendar.MINUTE, 15); bk19.setEndTime(rcap3tm.getTime()); bk19.setResourcePermission(perm1); bk19.setResourceType("CAPABILITY"); bk19.setRequestCapabilities(rcaps3); bk19.setUser(us1); bk19.setUserName(us1.getName()); bk19.setUserNamespace(us1.getNamespace()); ses.save(bk19); ses.getTransaction().commit(); ses.beginTransaction(); MatchingCapabilities mat1 = new MatchingCapabilities(rcaps1, caps1); ses.save(mat1); MatchingCapabilities mat2 = new MatchingCapabilities(rcaps1, caps2); ses.save(mat2); MatchingCapabilities mat3 = new MatchingCapabilities(rcaps1, caps3); ses.save(mat3); MatchingCapabilities mat4 = new MatchingCapabilities(rcaps2, caps1); ses.save(mat4); MatchingCapabilities mat5 = new MatchingCapabilities(rcaps2, caps3); ses.save(mat5); MatchingCapabilities mat6 = new MatchingCapabilities(rcaps3, caps2); ses.save(mat6); ses.getTransaction().commit(); ses.refresh(rcaps1); ses.refresh(rcaps2); ses.refresh(rcaps3); ses.refresh(caps1); ses.refresh(caps2); ses.refresh(caps3); ses.refresh(r1); ses.refresh(r2); ses.refresh(r3); ses.refresh(rigType1); ses.refresh(rigType2); CreateBooking request = new CreateBooking(); CreateBookingType param = new CreateBookingType(); request.setCreateBooking(param); UserIDType uid = new UserIDType(); UserNSNameSequence seq = new UserNSNameSequence(); seq.setUserNamespace(us2.getNamespace()); seq.setUserName(us2.getName()); uid.setUserNSNameSequence(seq); param.setUserID(uid); BookingType bt = new BookingType(); param.setBooking(bt); PermissionIDType pid = new PermissionIDType(); pid.setPermissionID(perm1.getId().intValue()); bt.setPermissionID(pid); Calendar bkSt = TimeUtil.getDayBegin(this.dayStr); bkSt.add(Calendar.HOUR, 1); bt.setStartTime(bkSt); Calendar bkEd = TimeUtil.getDayBegin(this.dayStr); bkEd.add(Calendar.HOUR, 2); bt.setEndTime(bkEd); CreateBookingResponse response = this.service.createBooking(request); BookingIDType bid = response.getCreateBookingResponse().getBookingID(); Bookings b = null; if (bid != null) { StatelessSession ss = DataAccessActivator.getNewStatelessSession(); Long id = Long.valueOf(bid.getBookingID()); b = (Bookings) ss.get(Bookings.class, id); } if (b != null) { ses.beginTransaction(); ses.delete(b); ses.getTransaction().commit(); } ses.beginTransaction(); ses.delete(bk1); ses.delete(bk2); ses.delete(bk3); ses.delete(bk4); ses.delete(bk5); ses.delete(bk6); ses.delete(bk7); ses.delete(bk8); ses.delete(bk9); ses.delete(bk10); ses.delete(bk11); ses.delete(bk12); ses.delete(bk13); ses.delete(bk14); ses.delete(bk15); ses.delete(bk16); ses.delete(bk17); ses.delete(bk18); ses.delete(bk19); ses.delete(perm1); ses.delete(r1); ses.delete(r2); ses.delete(r3); ses.delete(mat1); ses.delete(mat2); ses.delete(mat3); ses.delete(mat4); ses.delete(mat5); ses.delete(mat6); ses.delete(caps1); ses.delete(caps2); ses.delete(caps3); ses.delete(rcaps1); ses.delete(rcaps2); ses.delete(rcaps3); ses.delete(rigType1); ses.delete(rigType2); ses.delete(assoc); ses.delete(us1); ses.delete(us2); ses.delete(uclass1); ses.getTransaction().commit(); assertTrue(bk1.isActive()); assertTrue(bk2.isActive()); assertTrue(bk3.isActive()); assertTrue(bk4.isActive()); assertTrue(bk5.isActive()); assertTrue(bk6.isActive()); assertTrue(bk7.isActive()); assertTrue(bk8.isActive()); assertTrue(bk9.isActive()); assertTrue(bk10.isActive()); assertTrue(bk11.isActive()); assertTrue(bk12.isActive()); assertTrue(bk13.isActive()); assertTrue(bk14.isActive()); assertTrue(bk15.isActive()); assertTrue(bk16.isActive()); assertTrue(bk17.isActive()); assertTrue(bk18.isActive()); assertTrue(bk19.isActive()); assertNotNull(response); assertNull(bid); assertNull(b); BookingResponseType resp = response.getCreateBookingResponse(); assertNotNull(resp); assertFalse(resp.getSuccess()); assertEquals("Resource not free.", resp.getFailureReason()); BookingListType fitsList = resp.getBestFits(); assertNotNull(fitsList); BookingType fits[] = fitsList.getBookings(); assertNotNull(fits); assertEquals(1, fits.length); BookingType f = fits[0]; assertNotNull(f); Calendar s = f.getStartTime(); assertEquals(1, s.get(Calendar.HOUR)); assertEquals(30, s.get(Calendar.MINUTE)); assertEquals(0, s.get(Calendar.SECOND)); assertEquals(bkSt.get(Calendar.DAY_OF_MONTH), s.get(Calendar.DAY_OF_MONTH)); assertEquals(bkSt.get(Calendar.MONTH), s.get(Calendar.MONTH)); assertEquals(bkSt.get(Calendar.YEAR), s.get(Calendar.YEAR)); Calendar e = f.getEndTime(); assertEquals(2, e.get(Calendar.HOUR)); assertEquals(0, e.get(Calendar.MINUTE)); assertEquals(0, e.get(Calendar.SECOND)); assertEquals(bkSt.get(Calendar.DAY_OF_MONTH), s.get(Calendar.DAY_OF_MONTH)); assertEquals(bkSt.get(Calendar.MONTH), s.get(Calendar.MONTH)); assertEquals(bkSt.get(Calendar.YEAR), s.get(Calendar.YEAR)); PermissionIDType pi = f.getPermissionID(); assertNotNull(pi); assertEquals(perm1.getId().intValue(), pi.getPermissionID()); }
From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java
License:Open Source License
@Test public void testCreateBookingConcurrentFit() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();//from ww w .j a va2s . co m UserClass uclass1 = new UserClass(); uclass1.setName("booktestclass"); uclass1.setActive(true); uclass1.setQueuable(false); uclass1.setBookable(true); uclass1.setTimeHorizon(0); ses.save(uclass1); User us1 = new User(); us1.setName("bktestuser1"); us1.setNamespace("BKNS"); us1.setPersona("USER"); ses.save(us1); User us2 = new User(); us2.setName("bktestuser2"); us2.setNamespace("BKNS"); us2.setPersona("USER"); ses.save(us2); UserAssociation assoc = new UserAssociation(new UserAssociationId(us2.getId(), uclass1.getId()), uclass1, us2); ses.save(assoc); RigType rigType1 = new RigType("booktestrigtype", 300, false); ses.save(rigType1); RigType rigType2 = new RigType("booktestrigtype2", 300, false); ses.save(rigType2); RigCapabilities caps1 = new RigCapabilities("book,test,foo"); ses.save(caps1); RigCapabilities caps2 = new RigCapabilities("book,test,bar"); ses.save(caps2); RigCapabilities caps3 = new RigCapabilities("book,baz,foo"); ses.save(caps3); RequestCapabilities rcaps1 = new RequestCapabilities("book"); ses.save(rcaps1); RequestCapabilities rcaps2 = new RequestCapabilities("foo"); ses.save(rcaps2); RequestCapabilities rcaps3 = new RequestCapabilities("bar"); ses.save(rcaps3); Rig r1 = new Rig(); r1.setName("bkrig1"); r1.setRigType(rigType1); r1.setLastUpdateTimestamp(new Date()); r1.setRigCapabilities(caps1); ses.save(r1); Rig r2 = new Rig(); r2.setName("bkrig2"); r2.setRigType(rigType1); r2.setLastUpdateTimestamp(new Date()); r2.setRigCapabilities(caps2); ses.save(r2); Rig r3 = new Rig(); r3.setName("bkrig3"); r3.setRigType(rigType2); r3.setLastUpdateTimestamp(new Date()); r3.setRigCapabilities(caps3); ses.save(r3); ResourcePermission perm1 = new ResourcePermission(); perm1.setUserClass(uclass1); perm1.setType("TYPE"); perm1.setSessionDuration(3600); perm1.setQueueActivityTimeout(300); perm1.setAllowedExtensions((short) 10); perm1.setSessionActivityTimeout(300); perm1.setExtensionDuration(300); perm1.setMaximumBookings(10); perm1.setRigType(rigType1); Calendar cal = TimeUtil.getDayBegin(this.dayStr); cal.add(Calendar.DAY_OF_MONTH, -3); perm1.setStartTime(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, 6); perm1.setExpiryTime(cal.getTime()); perm1.setDisplayName("bookperm"); ses.save(perm1); /* #### BOOKINGS FOR R1 ########################################### */ Calendar r1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk1 = new Bookings(); bk1.setActive(true); bk1.setDuration(3600); /* Slots 2 - 5. */ r1tm.add(Calendar.MINUTE, 30); bk1.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 1); bk1.setEndTime(r1tm.getTime()); bk1.setResourcePermission(perm1); bk1.setResourceType("RIG"); bk1.setRig(r1); bk1.setUser(us1); bk1.setUserName(us1.getName()); bk1.setUserNamespace(us1.getNamespace()); ses.save(bk1); Bookings bk2 = new Bookings(); bk2.setActive(true); bk2.setCancelReason("Test cancel."); bk2.setDuration(1800); /* Slots 8 - 9. */ r1tm.add(Calendar.MINUTE, 30); bk2.setStartTime(r1tm.getTime()); r1tm.add(Calendar.MINUTE, 30); bk2.setEndTime(r1tm.getTime()); bk2.setResourcePermission(perm1); bk2.setResourceType("RIG"); bk2.setRig(r1); bk2.setUser(us1); bk2.setUserName(us1.getName()); bk2.setUserNamespace(us1.getNamespace()); ses.save(bk2); Bookings bk3 = new Bookings(); bk3.setActive(true); bk3.setDuration(7200); /* Slots 36 - 43. */ r1tm.add(Calendar.MINUTE, 30); r1tm.add(Calendar.HOUR, 6); bk3.setStartTime(r1tm.getTime()); r1tm.add(Calendar.HOUR, 2); bk3.setEndTime(r1tm.getTime()); bk3.setResourcePermission(perm1); bk3.setResourceType("RIG"); bk3.setRig(r1); bk3.setUser(us1); bk3.setUserName(us1.getName()); bk3.setUserNamespace(us1.getNamespace()); ses.save(bk3); /* #### BOOKINGS FOR R2 ########################################### */ Calendar r2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk8 = new Bookings(); bk8.setActive(true); bk8.setDuration(3600); /* Slots 13 - 16. */ r2tm.add(Calendar.HOUR, 3); bk8.setStartTime(r2tm.getTime()); r2tm.add(Calendar.HOUR, 1); bk8.setEndTime(r2tm.getTime()); bk8.setResourcePermission(perm1); bk8.setResourceType("RIG"); bk8.setRig(r2); bk8.setUser(us1); bk8.setUserName(us1.getName()); bk8.setUserNamespace(us1.getNamespace()); ses.save(bk8); Bookings bk9 = new Bookings(); bk9.setActive(true); bk9.setDuration(1800); /* Slots 36 - 37. */ r2tm.add(Calendar.HOUR, 5); bk9.setStartTime(r2tm.getTime()); r2tm.add(Calendar.MINUTE, 30); bk9.setEndTime(r2tm.getTime()); bk9.setResourcePermission(perm1); bk9.setResourceType("RIG"); bk9.setRig(r2); bk9.setUser(us1); bk9.setUserName(us1.getName()); bk9.setUserNamespace(us1.getNamespace()); ses.save(bk9); /* #### BOOKINGS FOR R3 ########################################### */ Calendar r3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk10 = new Bookings(); bk10.setActive(true); bk10.setDuration(1800); /* Slots 2 - 3. */ r3tm.add(Calendar.MINUTE, 30); bk10.setStartTime(r3tm.getTime()); r3tm.add(Calendar.MINUTE, 30); bk10.setEndTime(r3tm.getTime()); bk10.setResourcePermission(perm1); bk10.setResourceType("RIG"); bk10.setRig(r3); bk10.setUser(us1); bk10.setUserName(us1.getName()); bk10.setUserNamespace(us1.getNamespace()); ses.save(bk10); Bookings bk11 = new Bookings(); bk11.setActive(true); bk11.setDuration(3600); /* Slots 12 - 15. */ r3tm.add(Calendar.HOUR, 2); bk11.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk11.setEndTime(r3tm.getTime()); bk11.setResourcePermission(perm1); bk11.setResourceType("RIG"); bk11.setRig(r3); bk11.setUser(us1); bk11.setUserName(us1.getName()); bk11.setUserNamespace(us1.getNamespace()); ses.save(bk11); Bookings bk12 = new Bookings(); bk12.setActive(true); bk12.setDuration(3600); /* Slots 24 - 27. */ r3tm.add(Calendar.HOUR, 2); bk12.setStartTime(r3tm.getTime()); r3tm.add(Calendar.HOUR, 1); bk12.setEndTime(r3tm.getTime()); bk12.setResourcePermission(perm1); bk12.setResourceType("RIG"); bk12.setRig(r3); bk12.setUser(us1); bk12.setUserName(us1.getName()); bk12.setUserNamespace(us1.getNamespace()); ses.save(bk12); /* #### Type bookings for RigType1 ####################################*/ Calendar rt1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk4 = new Bookings(); bk4.setActive(true); bk4.setDuration(1800); /* Slots 0 - 1. */ bk4.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.MINUTE, 30); bk4.setEndTime(rt1tm.getTime()); bk4.setResourcePermission(perm1); bk4.setResourceType("TYPE"); bk4.setRigType(rigType1); bk4.setUser(us1); bk4.setUserName(us1.getName()); bk4.setUserNamespace(us1.getNamespace()); ses.save(bk4); Bookings bk13 = new Bookings(); bk13.setActive(true); bk13.setDuration(7200); /* Slots 0 - 7. */ rt1tm.add(Calendar.MINUTE, -30); bk13.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 2); bk13.setEndTime(rt1tm.getTime()); bk13.setResourcePermission(perm1); bk13.setResourceType("TYPE"); bk13.setRigType(rigType1); bk13.setUser(us1); bk13.setUserName(us1.getName()); bk13.setUserNamespace(us1.getNamespace()); ses.save(bk13); Bookings bk5 = new Bookings(); bk5.setActive(true); bk5.setDuration(3600); /* Slots 20 - 23. */ rt1tm.add(Calendar.HOUR, 3); bk5.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk5.setEndTime(rt1tm.getTime()); bk5.setResourcePermission(perm1); bk5.setResourceType("TYPE"); bk5.setRigType(rigType1); bk5.setUser(us1); bk5.setUserName(us1.getName()); bk5.setUserNamespace(us1.getNamespace()); ses.save(bk5); Bookings bk14 = new Bookings(); bk14.setActive(true); bk14.setDuration(3600); /* Slots 24 - 27. */ bk14.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); bk14.setEndTime(rt1tm.getTime()); bk14.setResourcePermission(perm1); bk14.setResourceType("TYPE"); bk14.setRigType(rigType1); bk14.setUser(us1); bk14.setUserName(us1.getName()); bk14.setUserNamespace(us1.getNamespace()); ses.save(bk14); Bookings bk15 = new Bookings(); bk15.setActive(true); bk15.setDuration(5400); /* Slots 52 - 58. */ rt1tm.add(Calendar.HOUR, 6); bk15.setStartTime(rt1tm.getTime()); rt1tm.add(Calendar.HOUR, 1); rt1tm.add(Calendar.MINUTE, 30); bk15.setEndTime(rt1tm.getTime()); bk15.setResourcePermission(perm1); bk15.setResourceType("TYPE"); bk15.setRigType(rigType1); bk15.setUser(us1); bk15.setUserName(us1.getName()); bk15.setUserNamespace(us1.getNamespace()); ses.save(bk15); /* #### Type bookings for RigType2 ####################################*/ Calendar rt2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk16 = new Bookings(); bk16.setActive(true); bk16.setDuration(3600); /* Slots 52 - 59. */ rt2tm.add(Calendar.HOUR, 14); bk16.setStartTime(rt2tm.getTime()); rt2tm.add(Calendar.HOUR, 1); bk16.setEndTime(rt2tm.getTime()); bk16.setResourcePermission(perm1); bk16.setResourceType("TYPE"); bk16.setRigType(rigType2); bk16.setUser(us2); bk16.setUserName(us2.getName()); bk16.setUserNamespace(us2.getNamespace()); ses.save(bk16); /* #### Bookings for Request Caps 1. #################################*/ Calendar rcap1tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk6 = new Bookings(); bk6.setActive(true); bk6.setDuration(1800); /* Slots 20 - 21. */ rcap1tm.add(Calendar.HOUR, 5); bk6.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk6.setEndTime(rcap1tm.getTime()); bk6.setResourcePermission(perm1); bk6.setResourceType("CAPABILITY"); bk6.setRequestCapabilities(rcaps1); bk6.setUser(us1); bk6.setUserName(us1.getName()); bk6.setUserNamespace(us1.getNamespace()); ses.save(bk6); Bookings bk7 = new Bookings(); bk7.setActive(true); bk7.setDuration(1800); /* Slots 22 - 23. */ bk7.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.MINUTE, 30); bk7.setEndTime(rcap1tm.getTime()); bk7.setResourcePermission(perm1); bk7.setResourceType("CAPABILITY"); bk7.setRequestCapabilities(rcaps1); bk7.setUser(us1); bk7.setUserName(us1.getName()); bk7.setUserNamespace(us1.getNamespace()); ses.save(bk7); Bookings bk17 = new Bookings(); bk17.setActive(true); bk17.setDuration(1800); /* Slots 32 - 35. */ rcap1tm.add(Calendar.HOUR, 2); bk17.setStartTime(rcap1tm.getTime()); rcap1tm.add(Calendar.HOUR, 1); bk17.setEndTime(rcap1tm.getTime()); bk17.setResourcePermission(perm1); bk17.setResourceType("CAPABILITY"); bk17.setRequestCapabilities(rcaps1); bk17.setUser(us1); bk17.setUserName(us1.getName()); bk17.setUserNamespace(us1.getNamespace()); ses.save(bk17); /* #### Bookings for Request Caps 2. #################################*/ Calendar rcap2tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk18 = new Bookings(); bk18.setActive(true); bk18.setDuration(1800); /* Slots 56 - 59. */ rcap2tm.add(Calendar.HOUR, 14); bk18.setStartTime(rcap2tm.getTime()); rcap2tm.add(Calendar.HOUR, 1); bk18.setEndTime(rcap2tm.getTime()); bk18.setResourcePermission(perm1); bk18.setResourceType("CAPABILITY"); bk18.setRequestCapabilities(rcaps2); bk18.setUser(us1); bk18.setUserName(us1.getName()); bk18.setUserNamespace(us1.getNamespace()); ses.save(bk18); /* #### Bookings for Request Caps 3. #################################*/ Calendar rcap3tm = TimeUtil.getDayBegin(this.dayStr); Bookings bk19 = new Bookings(); bk19.setActive(true); bk19.setDuration(4500); /* Slots 56 - 59. */ rcap3tm.add(Calendar.HOUR, 7); bk19.setStartTime(rcap3tm.getTime()); rcap3tm.add(Calendar.HOUR, 1); rcap3tm.add(Calendar.MINUTE, 15); bk19.setEndTime(rcap3tm.getTime()); bk19.setResourcePermission(perm1); bk19.setResourceType("CAPABILITY"); bk19.setRequestCapabilities(rcaps3); bk19.setUser(us1); bk19.setUserName(us1.getName()); bk19.setUserNamespace(us1.getNamespace()); ses.save(bk19); ses.getTransaction().commit(); ses.beginTransaction(); MatchingCapabilities mat1 = new MatchingCapabilities(rcaps1, caps1); ses.save(mat1); MatchingCapabilities mat2 = new MatchingCapabilities(rcaps1, caps2); ses.save(mat2); MatchingCapabilities mat3 = new MatchingCapabilities(rcaps1, caps3); ses.save(mat3); MatchingCapabilities mat4 = new MatchingCapabilities(rcaps2, caps1); ses.save(mat4); MatchingCapabilities mat5 = new MatchingCapabilities(rcaps2, caps3); ses.save(mat5); MatchingCapabilities mat6 = new MatchingCapabilities(rcaps3, caps2); ses.save(mat6); ses.getTransaction().commit(); ses.refresh(rcaps1); ses.refresh(rcaps2); ses.refresh(rcaps3); ses.refresh(caps1); ses.refresh(caps2); ses.refresh(caps3); ses.refresh(r1); ses.refresh(r2); ses.refresh(r3); ses.refresh(rigType1); ses.refresh(rigType2); CreateBooking request = new CreateBooking(); CreateBookingType param = new CreateBookingType(); request.setCreateBooking(param); UserIDType uid = new UserIDType(); UserNSNameSequence seq = new UserNSNameSequence(); seq.setUserNamespace(us2.getNamespace()); seq.setUserName(us2.getName()); uid.setUserNSNameSequence(seq); param.setUserID(uid); BookingType bt = new BookingType(); param.setBooking(bt); PermissionIDType pid = new PermissionIDType(); pid.setPermissionID(perm1.getId().intValue()); bt.setPermissionID(pid); Calendar bkSt = TimeUtil.getDayBegin(this.dayStr); bkSt.setTime(rt2tm.getTime()); bt.setStartTime(bkSt); Calendar bkEd = TimeUtil.getDayBegin(this.dayStr); bkEd.setTime(rt2tm.getTime()); bkEd.add(Calendar.HOUR, 1); bt.setEndTime(bkEd); CreateBookingResponse response = this.service.createBooking(request); BookingIDType bid = response.getCreateBookingResponse().getBookingID(); Bookings b = null; if (bid != null) { StatelessSession ss = DataAccessActivator.getNewStatelessSession(); Long id = Long.valueOf(bid.getBookingID()); b = (Bookings) ss.get(Bookings.class, id); } if (b != null) { ses.beginTransaction(); ses.delete(b); ses.getTransaction().commit(); } ses.beginTransaction(); ses.delete(bk1); ses.delete(bk2); ses.delete(bk3); ses.delete(bk4); ses.delete(bk5); ses.delete(bk6); ses.delete(bk7); ses.delete(bk8); ses.delete(bk9); ses.delete(bk10); ses.delete(bk11); ses.delete(bk12); ses.delete(bk13); ses.delete(bk14); ses.delete(bk15); ses.delete(bk16); ses.delete(bk17); ses.delete(bk18); ses.delete(bk19); ses.delete(perm1); ses.delete(r1); ses.delete(r2); ses.delete(r3); ses.delete(mat1); ses.delete(mat2); ses.delete(mat3); ses.delete(mat4); ses.delete(mat5); ses.delete(mat6); ses.delete(caps1); ses.delete(caps2); ses.delete(caps3); ses.delete(rcaps1); ses.delete(rcaps2); ses.delete(rcaps3); ses.delete(rigType1); ses.delete(rigType2); ses.delete(assoc); ses.delete(us1); ses.delete(us2); ses.delete(uclass1); ses.getTransaction().commit(); assertTrue(bk1.isActive()); assertTrue(bk2.isActive()); assertTrue(bk3.isActive()); assertTrue(bk4.isActive()); assertTrue(bk5.isActive()); assertTrue(bk6.isActive()); assertTrue(bk7.isActive()); assertTrue(bk8.isActive()); assertTrue(bk9.isActive()); assertTrue(bk10.isActive()); assertTrue(bk11.isActive()); assertTrue(bk12.isActive()); assertTrue(bk13.isActive()); assertTrue(bk14.isActive()); assertTrue(bk15.isActive()); assertTrue(bk16.isActive()); assertTrue(bk17.isActive()); assertTrue(bk18.isActive()); assertTrue(bk19.isActive()); assertNotNull(response); assertTrue(response.getCreateBookingResponse().getSuccess()); assertNotNull(bid); assertNotNull(b); }
From source file:au.edu.uts.eng.remotelabs.schedserver.queuer.intf.tests.QueuerSOAPImplTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.queuer.intf.QueuerSOAPImpl#removeUserFromQueue(au.edu.uts.eng.remotelabs.schedserver.queuer.intf.types.RemoveUserFromQueue)}. *//*from w ww. j a v a 2s . c o m*/ public void testRemoveUserFromQueue() { org.hibernate.Session db = DataAccessActivator.getNewSession(); Date before = new Date(System.currentTimeMillis() - 1000000); Date after = new Date(System.currentTimeMillis() + 1000000); Date now = new Date(); db.beginTransaction(); User user = new User("qperm1", "testns", "USER"); db.persist(user); UserClass uc1 = new UserClass(); uc1.setName("uc1"); uc1.setActive(true); uc1.setQueuable(true); uc1.setPriority((short) 4); db.persist(uc1); UserAssociation ass = new UserAssociation(new UserAssociationId(user.getId(), uc1.getId()), uc1, user); db.persist(ass); RigType rt = new RigType(); rt.setName("Perm_Test_Rig_Type"); db.persist(rt); RigCapabilities caps = new RigCapabilities("perm,test,rig,type"); db.persist(caps); Rig r = new Rig(); r.setName("Perm_Rig_Test_Rig1"); r.setRigType(rt); r.setRigCapabilities(caps); r.setLastUpdateTimestamp(before); r.setActive(true); r.setOnline(true); r.setInSession(true); db.persist(r); ResourcePermission p1 = new ResourcePermission(); p1.setType("RIG"); p1.setUserClass(uc1); p1.setStartTime(before); p1.setExpiryTime(after); p1.setRig(r); p1.setAllowedExtensions((short) 10); db.persist(p1); Session ses = new Session(); ses.setActive(true); ses.setReady(true); ses.setActivityLastUpdated(now); ses.setExtensions((short) 5); ses.setPriority((short) 5); ses.setRequestTime(now); ses.setRequestedResourceId(r.getId()); ses.setRequestedResourceName(r.getName()); ses.setResourceType("RIG"); ses.setResourcePermission(p1); ses.setUser(user); ses.setUserName(user.getName()); ses.setUserNamespace(user.getNamespace()); ses.setAssignedRigName(r.getName()); ses.setRig(r); db.persist(ses); db.getTransaction().commit(); /* Request parameters. */ RemoveUserFromQueue request = new RemoveUserFromQueue(); UserIDType uId = new UserIDType(); request.setRemoveUserFromQueue(uId); uId.setUserQName(user.getNamespace() + ":" + user.getName()); RemoveUserFromQueueResponse resp = this.queuer.removeUserFromQueue(request); StatelessSession ssdb = DataAccessActivator.getNewStatelessSession(); Session sses = (Session) ssdb.get(Session.class, ses.getId()); db.beginTransaction(); db.delete(ses); db.delete(p1); db.delete(r); db.delete(rt); db.delete(caps); db.delete(ass); db.delete(uc1); db.delete(user); db.getTransaction().commit(); db.close(); assertNotNull(resp); InQueueType in = resp.getRemoveUserFromQueueResponse(); assertNotNull(in); assertFalse(sses.isActive()); assertNotNull(sses.getRemovalReason()); assertNotNull(sses.getRemovalTime()); }
From source file:au.edu.uts.eng.remotelabs.schedserver.queuer.intf.tests.QueuerSOAPImplTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.queuer.intf.QueuerSOAPImpl#removeUserFromQueue(au.edu.uts.eng.remotelabs.schedserver.queuer.intf.types.RemoveUserFromQueue)}. *///from w w w. j a v a2 s. c om public void testRemoveUserFromQueueID() { org.hibernate.Session db = DataAccessActivator.getNewSession(); Date before = new Date(System.currentTimeMillis() - 1000000); Date after = new Date(System.currentTimeMillis() + 1000000); Date now = new Date(); db.beginTransaction(); User user = new User("qperm1", "testns", "USER"); db.persist(user); UserClass uc1 = new UserClass(); uc1.setName("uc1"); uc1.setActive(true); uc1.setQueuable(true); uc1.setPriority((short) 4); db.persist(uc1); UserAssociation ass = new UserAssociation(new UserAssociationId(user.getId(), uc1.getId()), uc1, user); db.persist(ass); RigType rt = new RigType(); rt.setName("Perm_Test_Rig_Type"); db.persist(rt); RigCapabilities caps = new RigCapabilities("perm,test,rig,type"); db.persist(caps); Rig r = new Rig(); r.setName("Perm_Rig_Test_Rig1"); r.setRigType(rt); r.setRigCapabilities(caps); r.setLastUpdateTimestamp(before); r.setActive(true); r.setOnline(true); r.setInSession(true); db.persist(r); ResourcePermission p1 = new ResourcePermission(); p1.setType("RIG"); p1.setUserClass(uc1); p1.setStartTime(before); p1.setExpiryTime(after); p1.setRig(r); p1.setAllowedExtensions((short) 10); db.persist(p1); Session ses = new Session(); ses.setActive(true); ses.setReady(true); ses.setActivityLastUpdated(now); ses.setExtensions((short) 5); ses.setPriority((short) 5); ses.setRequestTime(now); ses.setRequestedResourceId(r.getId()); ses.setRequestedResourceName(r.getName()); ses.setResourceType("RIG"); ses.setResourcePermission(p1); ses.setUser(user); ses.setUserName(user.getName()); ses.setUserNamespace(user.getNamespace()); ses.setAssignedRigName(r.getName()); ses.setRig(r); db.persist(ses); db.getTransaction().commit(); /* Request parameters. */ RemoveUserFromQueue request = new RemoveUserFromQueue(); UserIDType uId = new UserIDType(); request.setRemoveUserFromQueue(uId); uId.setUserID(String.valueOf(user.getId())); RemoveUserFromQueueResponse resp = this.queuer.removeUserFromQueue(request); StatelessSession sldb = DataAccessActivator.getNewStatelessSession(); Session sses = (Session) sldb.get(Session.class, ses.getId()); db.beginTransaction(); db.delete(ses); db.delete(p1); db.delete(r); db.delete(rt); db.delete(caps); db.delete(ass); db.delete(uc1); db.delete(user); db.getTransaction().commit(); db.close(); assertNotNull(resp); InQueueType in = resp.getRemoveUserFromQueueResponse(); assertNotNull(in); assertFalse(sses.isActive()); assertNotNull(sses.getRemovalReason()); assertNotNull(sses.getRemovalTime()); }
From source file:edu.utah.further.core.data.hibernate.listeners.PreUpdatePreventNullOverwriteListener.java
License:Apache License
@SuppressWarnings("resource") @Override/* www .j a v a 2 s .com*/ public boolean onPreUpdate(final PreUpdateEvent event) { if (log.isDebugEnabled()) { log.debug("Received pre-update event"); } final EntityPersister entityPersister = event.getPersister(); final EntityMode entityMode = entityPersister.guessEntityMode(event.getEntity()); final Connection connection = getConnection(entityPersister); final StatelessSession session = entityPersister.getFactory().openStatelessSession(connection); session.beginTransaction(); final Serializable entityId = entityPersister.getIdentifier(event.getEntity(), (SessionImplementor) session); final Object existingEntity = session.get(event.getEntity().getClass(), entityId); if (log.isDebugEnabled()) { log.debug("Loaded existing entity " + existingEntity); } boolean updatedExistingEntity = false; for (int i = 0; i < entityPersister.getPropertyNames().length; i++) { final Object oldPropValue = entityPersister.getPropertyValue(existingEntity, i, entityMode); if (oldPropValue == null) { if (log.isDebugEnabled()) { log.debug("Found a property in the existing " + "entity that was null, checking new entity"); } final Object newPropValue = entityPersister.getPropertyValue(event.getEntity(), i, entityMode); if (!(newPropValue instanceof Collection<?>) && newPropValue != null) { if (log.isDebugEnabled()) { log.debug("The new entity contains a non-null " + "value, updating existing entity"); } entityPersister.setPropertyValue(existingEntity, i, newPropValue, entityMode); updatedExistingEntity = true; } } } if (updatedExistingEntity) { entityPersister.getFactory().getCurrentSession().cancelQuery(); session.update(existingEntity); } session.getTransaction().commit(); session.close(); return updatedExistingEntity; }
From source file:org.jahia.modules.external.id.ExternalProviderInitializerServiceImpl.java
License:Open Source License
@Override public String getExternalIdentifier(String internalId) throws RepositoryException { String externalId = null;//from www. j a va2s .c o m StatelessSession session = null; try { session = getHibernateSessionFactory().openStatelessSession(); session.beginTransaction(); UuidMapping mapping = (UuidMapping) session.get(UuidMapping.class, internalId); if (mapping != null) { externalId = mapping.getExternalId(); } session.getTransaction().commit(); } catch (Exception e) { if (session != null) { session.getTransaction().rollback(); } throw new RepositoryException(e); } finally { if (session != null) { session.close(); } } return externalId; }
From source file:vault.queryrouter.models.dao.JobQueueDAO.java
License:Apache License
public static void deleteFromJobQueue(StatelessSession session, int logID) { TenantUpdateJob query = (TenantUpdateJob) session.get(TenantUpdateJob.class, logID); session.delete(query);/*from www. j a va 2 s . c o m*/ }
From source file:vault.queryrouter.models.dao.JobQueueDAO.java
License:Apache License
public static TenantUpdateJob getPendingQueryLock(StatelessSession session, String workerId) throws Exception { try {// w ww. j a va 2 s . c om session.getTransaction().begin(); //Update the pending query(order by last_touch_timestamp) status from pending to processing String hql = "UPDATE TenantUpdateJob set status= '" + TenantUpdateJobStatus.Processing.toString() + "', workerId = '" + workerId + "' WHERE status='" + TenantUpdateJobStatus.Pending.toString() + "' AND type ='" + TenantUpdateJobType.queryrouter.toString() + "' ORDER BY lastTouchTime LIMIT 1"; org.hibernate.Query query = session.createQuery(hql); int result = query.executeUpdate(); session.getTransaction().commit(); //Pending query exists and the status changes from "Pending" to "Processing" if (result != 0) { //Find the processing query by the thread(workerId) Criteria criteria = session.createCriteria(TenantUpdateJob.class); criteria.add(Expression.eq("workerId", workerId.toString())); criteria.add(Expression.eq("status", TenantUpdateJobStatus.Processing.toString())); TenantUpdateJob pendingQueueCandidate = (TenantUpdateJob) criteria.uniqueResult(); Query q = QueryDAO.getQuery(session, pendingQueueCandidate.getQueryId()); //Check the availability of the processing Query that could be actual processed //If the number of conflictQuery is more than 0 which means the processing query conflicts with the another processing query(e.g.move_tenant_mppdb_data) int conflictQuery = JobQueueDAO.getProcessingQuery(session, q.getTenantMppdbId()); //No conflict query -> Return the query(TenantUpdateJob Object) if (conflictQuery == 0) { return pendingQueueCandidate; } //Conflict query exists -> Status of the processing query turn back to "Pending" and the last_touch_timestamp will be updated else { try { session.getTransaction().begin(); TenantUpdateJob jq = (TenantUpdateJob) session.get(TenantUpdateJob.class, pendingQueueCandidate.getJobQueueId()); jq.setStatus(TenantUpdateJobStatus.Pending.toString()); jq.setWorkerId(""); session.update(jq); session.getTransaction().commit(); } catch (HibernateException e) { logger.error("Exception: ", e); if (session.getTransaction() != null) session.getTransaction().rollback(); e.printStackTrace(); } return null; } } //No pending query exists else { return null; } } catch (Exception e) { logger.error(e.toString()); throw e; } }
From source file:vault.queryrouter.models.dao.QueryDAO.java
License:Apache License
public static void updateQueryLog(StatelessSession session, String QuerylogID, Timestamp endTime, QueryLogStatus queryStatus) {/*from www .j a va 2s. c o m*/ Query query = (Query) session.get(Query.class, QuerylogID); query.setEndTime(endTime); query.setQueryStatus(queryStatus.toString()); session.update(query); }