Search in sources :

Example 1 with OfferImpl

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;
}
Also used : Offer(org.olat.resource.accesscontrol.Offer) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl)

Example 2 with OfferImpl

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;
}
Also used : OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) Date(java.util.Date)

Example 3 with OfferImpl

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());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) Test(org.junit.Test)

Example 4 with OfferImpl

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());
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OLATResourceable(org.olat.core.id.OLATResourceable) OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) Test(org.junit.Test)

Example 5 with OfferImpl

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;
}
Also used : OfferImpl(org.olat.resource.accesscontrol.model.OfferImpl) Date(java.util.Date)

Aggregations

OfferImpl (org.olat.resource.accesscontrol.model.OfferImpl)6 Date (java.util.Date)4 Test (org.junit.Test)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 OLATResource (org.olat.resource.OLATResource)2 Offer (org.olat.resource.accesscontrol.Offer)2 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)2 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)2