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