use of org.olat.resource.accesscontrol.model.OfferImpl in project OpenOLAT by OpenOLAT.
the class TokenAccessConfigurationController method commitChanges.
@Override
public OfferAccess commitChanges() {
Offer offer = link.getOffer();
if (offer instanceof OfferImpl) {
((OfferImpl) offer).setToken(tokenEl.getValue());
}
offer.setDescription(descEl.getValue());
offer.setValidFrom(dateFrom.getDate());
offer.setValidTo(dateTo.getDate());
link.setValidFrom(dateFrom.getDate());
link.setValidTo(dateTo.getDate());
return link;
}
use of org.olat.resource.accesscontrol.model.OfferImpl in project OpenOLAT by OpenOLAT.
the class ACOfferDAO method createOffer.
public Offer createOffer(OLATResource resource, String resourceName) {
OfferImpl offer = new OfferImpl();
Date now = new Date();
offer.setCreationDate(now);
offer.setLastModified(now);
offer.setResource(resource);
offer.setValid(true);
offer.setConfirmationEmail(false);
if (resourceName != null && resourceName.length() > 255) {
resourceName = resourceName.substring(0, 250);
}
offer.setResourceDisplayName(resourceName);
offer.setResourceId(resource.getResourceableId());
String resourceTypeName = resource.getResourceableTypeName();
if (resourceTypeName != null && resourceTypeName.length() > 255) {
resourceTypeName = resourceTypeName.substring(0, 250);
}
offer.setResourceTypeName(resourceTypeName);
return offer;
}
use of org.olat.resource.accesscontrol.model.OfferImpl in project OpenOLAT by OpenOLAT.
the class ACOfferManagerTest method testSaveOffer.
@Test
public void testSaveOffer() {
// create a resource
OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
assertNotNull(testOres);
dbInstance.commitAndCloseSession();
// create an offer
Offer offer = acOfferManager.createOffer(testOres, "TestSaveOffer");
assertNotNull(offer);
assertEquals(OfferImpl.class, offer.getClass());
if (offer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) offer;
offerImpl.setToken("token1");
}
offer.setValidFrom(new Date());
offer.setValidTo(new Date());
// and save the offer
acOfferManager.saveOffer(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// check if the offer is saved
List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
assertNotNull(offers);
assertEquals(1, offers.size());
Offer savedOffer = offers.get(0);
assertNotNull(savedOffer);
assertEquals(OfferImpl.class, savedOffer.getClass());
if (savedOffer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) savedOffer;
assertEquals("token1", offerImpl.getToken());
}
assertNotNull(offer.getValidFrom());
assertNotNull(offer.getValidTo());
assertEquals(testOres.getResourceableId(), savedOffer.getResourceId());
assertEquals(testOres.getResourceableTypeName(), savedOffer.getResourceTypeName());
assertEquals("TestSaveOffer", savedOffer.getResourceDisplayName());
}
use of org.olat.resource.accesscontrol.model.OfferImpl in project openolat by klemens.
the class ACOfferManagerTest method testSaveOffer.
@Test
public void testSaveOffer() {
// create a resource
OLATResourceable testOreable = new TypedResourceable(UUID.randomUUID().toString().replace("-", ""));
OLATResource testOres = OLATResourceManager.getInstance().findOrPersistResourceable(testOreable);
assertNotNull(testOres);
dbInstance.commitAndCloseSession();
// create an offer
Offer offer = acOfferManager.createOffer(testOres, "TestSaveOffer");
assertNotNull(offer);
assertEquals(OfferImpl.class, offer.getClass());
if (offer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) offer;
offerImpl.setToken("token1");
}
offer.setValidFrom(new Date());
offer.setValidTo(new Date());
// and save the offer
acOfferManager.saveOffer(offer);
dbInstance.commitAndCloseSession();
// create a link offer to method
List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
AccessMethod method = methods.get(0);
OfferAccess access = acMethodManager.createOfferAccess(offer, method);
acMethodManager.save(access);
dbInstance.commitAndCloseSession();
// check if the offer is saved
List<Offer> offers = acOfferManager.findOfferByResource(testOres, true, null);
assertNotNull(offers);
assertEquals(1, offers.size());
Offer savedOffer = offers.get(0);
assertNotNull(savedOffer);
assertEquals(OfferImpl.class, savedOffer.getClass());
if (savedOffer instanceof OfferImpl) {
OfferImpl offerImpl = (OfferImpl) savedOffer;
assertEquals("token1", offerImpl.getToken());
}
assertNotNull(offer.getValidFrom());
assertNotNull(offer.getValidTo());
assertEquals(testOres.getResourceableId(), savedOffer.getResourceId());
assertEquals(testOres.getResourceableTypeName(), savedOffer.getResourceTypeName());
assertEquals("TestSaveOffer", savedOffer.getResourceDisplayName());
}
use of org.olat.resource.accesscontrol.model.OfferImpl in project openolat by klemens.
the class ACOfferDAO method createOffer.
public Offer createOffer(OLATResource resource, String resourceName) {
OfferImpl offer = new OfferImpl();
Date now = new Date();
offer.setCreationDate(now);
offer.setLastModified(now);
offer.setResource(resource);
offer.setValid(true);
offer.setConfirmationEmail(false);
if (resourceName != null && resourceName.length() > 255) {
resourceName = resourceName.substring(0, 250);
}
offer.setResourceDisplayName(resourceName);
offer.setResourceId(resource.getResourceableId());
String resourceTypeName = resource.getResourceableTypeName();
if (resourceTypeName != null && resourceTypeName.length() > 255) {
resourceTypeName = resourceTypeName.substring(0, 250);
}
offer.setResourceTypeName(resourceTypeName);
return offer;
}
Aggregations