Search in sources :

Example 1 with IdentifierKey

use of org.olat.resource.accesscontrol.provider.auto.IdentifierKey in project OpenOLAT by OpenOLAT.

the class AdvanceOrderDAOTest method shouldFindPendingAdvaceOrderForIdentifiers.

@Test
public void shouldFindPendingAdvaceOrderForIdentifiers() {
    AdvanceOrder aoMatchingInternalId = sut.create(identity, IdentifierKey.internalId, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoMatchingInternalId);
    AdvanceOrder aoMatchingExternalId = sut.create(identity, IdentifierKey.externalId, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoMatchingExternalId);
    AdvanceOrder aoNotMatchingRef = sut.create(identity, IdentifierKey.externalRef, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoNotMatchingRef);
    AdvanceOrder aoNotMatchingValue = sut.create(identity, IdentifierKey.internalId, "not matching", freeMethod);
    sut.save(aoNotMatchingValue);
    dbInstance.commitAndCloseSession();
    Map<IdentifierKey, String> identifiers = new HashMap<>();
    identifiers.put(IdentifierKey.internalId, IDENTIFIER_VALUE);
    identifiers.put(IdentifierKey.externalId, IDENTIFIER_VALUE);
    Collection<AdvanceOrder> advanceOrders = sut.loadPendingAdvanceOrders(identifiers);
    assertThat(advanceOrders).hasSize(2).contains(aoMatchingInternalId, aoMatchingExternalId);
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) HashMap(java.util.HashMap) AdvanceOrder(org.olat.resource.accesscontrol.provider.auto.AdvanceOrder) Test(org.junit.Test)

Example 2 with IdentifierKey

use of org.olat.resource.accesscontrol.provider.auto.IdentifierKey in project OpenOLAT by OpenOLAT.

the class AdvanceOrderDAOTest method shouldFindPendingAdvaceOrderForIdentifiersIfNullValues.

@Test
public void shouldFindPendingAdvaceOrderForIdentifiersIfNullValues() {
    AdvanceOrder aoMatchingInternalId = sut.create(identity, IdentifierKey.internalId, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoMatchingInternalId);
    AdvanceOrder aoMatchingExternalId = sut.create(identity, IdentifierKey.externalId, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoMatchingExternalId);
    AdvanceOrder aoNotMatchingRef = sut.create(identity, IdentifierKey.externalRef, IDENTIFIER_VALUE, freeMethod);
    sut.save(aoNotMatchingRef);
    AdvanceOrder aoNotMatchingValue = sut.create(identity, IdentifierKey.internalId, "not matching", freeMethod);
    sut.save(aoNotMatchingValue);
    dbInstance.commitAndCloseSession();
    Map<IdentifierKey, String> identifiers = new HashMap<>();
    identifiers.put(IdentifierKey.internalId, IDENTIFIER_VALUE);
    identifiers.put(null, IDENTIFIER_VALUE);
    identifiers.put(IdentifierKey.externalId, "");
    Collection<AdvanceOrder> advanceOrders = sut.loadPendingAdvanceOrders(identifiers);
    assertThat(advanceOrders).hasSize(1).contains(aoMatchingInternalId);
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) HashMap(java.util.HashMap) AdvanceOrder(org.olat.resource.accesscontrol.provider.auto.AdvanceOrder) Test(org.junit.Test)

Example 3 with IdentifierKey

use of org.olat.resource.accesscontrol.provider.auto.IdentifierKey in project openolat by klemens.

the class InputValidatorTest method setUp.

@Before
public void setUp() {
    inputMock = mock(AdvanceOrderInput.class);
    when(inputMock.getIdentity()).thenReturn(new IdentityImpl());
    Set<IdentifierKey> keys = new HashSet<>();
    keys.add(IdentifierKey.externalId);
    when(inputMock.getKeys()).thenReturn(keys);
    when(inputMock.getRawValues()).thenReturn("rawValues");
    doReturn(AutoAccessMethod.class).when(inputMock).getMethodClass();
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) IdentityImpl(org.olat.basesecurity.IdentityImpl) AdvanceOrderInput(org.olat.resource.accesscontrol.provider.auto.AdvanceOrderInput) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 4 with IdentifierKey

use of org.olat.resource.accesscontrol.provider.auto.IdentifierKey in project openolat by klemens.

the class AutoAccessManagerImpl method loadPendingAdvanceOrders.

@Override
public Collection<AdvanceOrder> loadPendingAdvanceOrders(RepositoryEntry entry) {
    if (entry == null)
        return new ArrayList<>();
    Map<IdentifierKey, String> searchValues = new EnumMap<>(IdentifierKey.class);
    for (IdentifierKey key : IdentifierKey.values()) {
        String value = identifierHandler.getRepositoryEntryValue(key, entry);
        searchValues.put(key, value);
    }
    return advanceOrderDAO.loadPendingAdvanceOrders(searchValues);
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey) EnumMap(java.util.EnumMap)

Example 5 with IdentifierKey

use of org.olat.resource.accesscontrol.provider.auto.IdentifierKey in project openolat by klemens.

the class AutoAccessManagerImpl method createAdvanceOrders.

@Override
public void createAdvanceOrders(AdvanceOrderInput input) {
    if (!inputValidator.isValid(input))
        return;
    IdentifierValueSplitter splitter = splitterFactory.getSplitter(input.getSplitterType());
    Collection<String> values = splitter.split(input.getRawValues());
    for (IdentifierKey key : input.getKeys()) {
        for (String value : values) {
            createAndPersistAdvanceOrderIfNotExist(input.getIdentity(), key, value, input.getMethodClass());
        }
    }
}
Also used : IdentifierKey(org.olat.resource.accesscontrol.provider.auto.IdentifierKey)

Aggregations

IdentifierKey (org.olat.resource.accesscontrol.provider.auto.IdentifierKey)12 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AdvanceOrder (org.olat.resource.accesscontrol.provider.auto.AdvanceOrder)4 EnumMap (java.util.EnumMap)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 IdentityImpl (org.olat.basesecurity.IdentityImpl)2 AdvanceOrderInput (org.olat.resource.accesscontrol.provider.auto.AdvanceOrderInput)2