Search in sources :

Example 1 with DirectAccessUrl

use of org.alfresco.service.cmr.repository.DirectAccessUrl in project alfresco-repository by Alfresco.

the class AggregatingContentStoreTest method testGetDirectAccessUrl.

@Test
public void testGetDirectAccessUrl() {
    // Create the aggregating store
    AggregatingContentStore aggStore = new AggregatingContentStore();
    aggStore.setPrimaryStore(primaryStoreMock);
    aggStore.setSecondaryStores(List.of(secondaryStoreMock));
    UnsupportedOperationException unsupportedExc = new UnsupportedOperationException();
    UnsupportedContentUrlException unsupportedContentUrlExc = new UnsupportedContentUrlException(aggStore, "");
    // By default it is unsupported
    DirectAccessUrl directAccessUrl = aggStore.getDirectAccessUrl("url", null);
    assertNull(directAccessUrl);
    // Direct access not supported
    try {
        when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
        when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
        aggStore.getDirectAccessUrl("urlDANotSupported", null);
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    try {
        when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
        when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
        aggStore.getDirectAccessUrl("urlDANotSupported", null);
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    try {
        when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
        when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
        aggStore.getDirectAccessUrl("urlDANotSupported", null);
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    // Content url not supported
    try {
        when(primaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
        when(secondaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
        aggStore.getDirectAccessUrl("urlNotSupported", null);
        fail();
    } catch (UnsupportedContentUrlException e) {
    // Expected
    }
    when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
    when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedExc);
    directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
    assertNotNull(directAccessUrl);
    when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
    when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedContentUrlExc);
    directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
    assertNotNull(directAccessUrl);
    when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedExc);
    when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
    directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
    assertNotNull(directAccessUrl);
    when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedContentUrlExc);
    when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
    directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
    assertNotNull(directAccessUrl);
    when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
    when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
    directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
    assertNotNull(directAccessUrl);
    directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
    assertNotNull(directAccessUrl);
}
Also used : DirectAccessUrl(org.alfresco.service.cmr.repository.DirectAccessUrl) UnsupportedContentUrlException(org.alfresco.repo.content.UnsupportedContentUrlException) Test(org.junit.Test) AbstractWritableContentStoreTest(org.alfresco.repo.content.AbstractWritableContentStoreTest)

Example 2 with DirectAccessUrl

use of org.alfresco.service.cmr.repository.DirectAccessUrl in project alfresco-repository by Alfresco.

the class AggregatingContentStore method getDirectAccessUrl.

public DirectAccessUrl getDirectAccessUrl(String contentUrl, Date expiresAt) {
    if (primaryStore == null) {
        throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
    }
    // get a read lock so that we are sure that no replication is underway
    readLock.lock();
    try {
        // Keep track of the unsupported state of the content URL - it might be a rubbish URL
        boolean contentUrlSupported = true;
        boolean directAccessUrlSupported = true;
        DirectAccessUrl directAccessUrl = null;
        // Check the primary store
        try {
            directAccessUrl = primaryStore.getDirectAccessUrl(contentUrl, expiresAt);
        } catch (UnsupportedOperationException e) {
            // The store does not support direct access URL
            directAccessUrlSupported = false;
        } catch (UnsupportedContentUrlException e) {
            // The store can't handle the content URL
            contentUrlSupported = false;
        }
        if (directAccessUrl != null) {
            return directAccessUrl;
        }
        // the content is not in the primary store so we have to go looking for it
        for (ContentStore store : secondaryStores) {
            try {
                directAccessUrl = store.getDirectAccessUrl(contentUrl, expiresAt);
            } catch (UnsupportedOperationException e) {
                // The store does not support direct access URL
                directAccessUrlSupported = false;
            } catch (UnsupportedContentUrlException e) {
                // The store can't handle the content URL
                contentUrlSupported = false;
            }
            if (directAccessUrl != null) {
                break;
            }
        }
        if (directAccessUrl == null) {
            if (!directAccessUrlSupported) {
                // The direct access URL was not supported
                throw new UnsupportedOperationException("Retrieving direct access URLs is not supported by this content store.");
            } else if (!contentUrlSupported) {
                // The content URL was not supported
                throw new UnsupportedContentUrlException(this, contentUrl);
            }
        }
        return directAccessUrl;
    } finally {
        readLock.unlock();
    }
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectAccessUrl(org.alfresco.service.cmr.repository.DirectAccessUrl) UnsupportedContentUrlException(org.alfresco.repo.content.UnsupportedContentUrlException) ContentStore(org.alfresco.repo.content.ContentStore) AbstractContentStore(org.alfresco.repo.content.AbstractContentStore) CachingContentStore(org.alfresco.repo.content.caching.CachingContentStore)

Example 3 with DirectAccessUrl

use of org.alfresco.service.cmr.repository.DirectAccessUrl in project alfresco-repository by Alfresco.

the class CachingContentStoreTest method getDirectAccessUrl.

@Test
public void getDirectAccessUrl() {
    when(backingStore.getDirectAccessUrl(anyString(), any())).thenReturn(new DirectAccessUrl());
    cachingStore.getDirectAccessUrl("url", null);
}
Also used : DirectAccessUrl(org.alfresco.service.cmr.repository.DirectAccessUrl) Test(org.junit.Test)

Aggregations

DirectAccessUrl (org.alfresco.service.cmr.repository.DirectAccessUrl)3 UnsupportedContentUrlException (org.alfresco.repo.content.UnsupportedContentUrlException)2 Test (org.junit.Test)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AbstractContentStore (org.alfresco.repo.content.AbstractContentStore)1 AbstractWritableContentStoreTest (org.alfresco.repo.content.AbstractWritableContentStoreTest)1 ContentStore (org.alfresco.repo.content.ContentStore)1 CachingContentStore (org.alfresco.repo.content.caching.CachingContentStore)1