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);
}
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();
}
}
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);
}
Aggregations