Search in sources :

Example 1 with Blob

use of org.craftercms.commons.file.blob.Blob in project core by craftercms.

the class ContentStoreServiceImpl method findContent.

@Override
public Content findContent(Context context, CachingOptions cachingOptions, String url) throws InvalidContextException, StoreException {
    if (context.getStoreAdapter().exists(context, cachingOptions, url)) {
        return context.getStoreAdapter().findContent(context, cachingOptions, url);
    } else {
        String blobUrl = blobUrlResolver.getBlobUrl(url);
        if (context.getStoreAdapter().exists(context, cachingOptions, blobUrl)) {
            Content content = context.getStoreAdapter().findContent(context, cachingOptions, blobUrl);
            try (InputStream is = content.getInputStream()) {
                Blob blob = mapper.readValue(is, Blob.class);
                BlobStore store = blobStoreResolver.getById(new ConfigurationProviderImpl(cachingOptions, context), blob.getStoreId());
                return new ResourceBasedContent(store.getResource(url, blob));
            } catch (IOException | ConfigurationException e) {
                throw new StoreException("Error reading blob file at " + blobUrl, e);
            }
        }
    }
    return null;
}
Also used : Blob(org.craftercms.commons.file.blob.Blob) ConfigurationException(org.craftercms.commons.config.ConfigurationException) Content(org.craftercms.core.service.Content) InputStream(java.io.InputStream) IOException(java.io.IOException) BlobStore(org.craftercms.commons.file.blob.BlobStore) StoreException(org.craftercms.core.exception.StoreException)

Example 2 with Blob

use of org.craftercms.commons.file.blob.Blob in project studio by craftercms.

the class BlobAwareContentRepository method writeContent.

@Override
public String writeContent(String site, String path, InputStream content) throws ServiceLayerException {
    logger.debug("Writing {0} in site {1}", path, site);
    try {
        StudioBlobStore store = getBlobStore(site, path);
        if (store != null) {
            store.writeContent(site, normalize(path), content);
            Blob reference = store.getReference(normalize(path));
            return localRepositoryV1.writeContent(site, getPointerPath(site, path), new ByteArrayInputStream(objectMapper.writeValueAsBytes(reference)));
        }
        return localRepositoryV1.writeContent(site, path, content);
    } catch (RepositoryLockedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Error writing content {0} in site {1}", e, path, site);
        throw new ServiceLayerException(e);
    }
}
Also used : Blob(org.craftercms.commons.file.blob.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryLockedException(org.craftercms.studio.api.v2.exception.RepositoryLockedException) StudioBlobStore(org.craftercms.studio.api.v2.repository.blob.StudioBlobStore) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ConfigurationException(org.craftercms.commons.config.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) IOException(java.io.IOException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) RepositoryLockedException(org.craftercms.studio.api.v2.exception.RepositoryLockedException)

Aggregations

IOException (java.io.IOException)2 ConfigurationException (org.craftercms.commons.config.ConfigurationException)2 Blob (org.craftercms.commons.file.blob.Blob)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 CryptoException (org.craftercms.commons.crypto.CryptoException)1 BlobStore (org.craftercms.commons.file.blob.BlobStore)1 StoreException (org.craftercms.core.exception.StoreException)1 Content (org.craftercms.core.service.Content)1 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)1 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)1 RepositoryLockedException (org.craftercms.studio.api.v2.exception.RepositoryLockedException)1 StudioBlobStore (org.craftercms.studio.api.v2.repository.blob.StudioBlobStore)1