Search in sources :

Example 1 with StudioBlobStore

use of org.craftercms.studio.api.v2.repository.blob.StudioBlobStore in project studio by craftercms.

the class BlobAwareContentRepository method publish.

@Override
public void publish(String site, String sandboxBranch, List<DeploymentItemTO> deploymentItems, String environment, String author, String comment) throws DeploymentException {
    logger.debug("Publishing items {0} to environment {1} in site {2}", deploymentItems, environment, site);
    Map<String, StudioBlobStore> stores = new LinkedHashMap<>();
    MultiValueMap<String, DeploymentItemTO> items = new LinkedMultiValueMap<>();
    List<DeploymentItemTO> localItems = new LinkedList<>();
    try {
        for (DeploymentItemTO item : deploymentItems) {
            StudioBlobStore store = getBlobStore(site, item.getPath());
            if (store != null) {
                stores.putIfAbsent(store.getId(), store);
                items.add(store.getId(), item);
                localItems.add(mapDeploymentItem(item));
            } else {
                localItems.add(item);
            }
        }
        for (String storeId : stores.keySet()) {
            logger.debug("Publishing blobs to environment {0} using store {1} for site {2}", environment, storeId, site);
            stores.get(storeId).publish(site, sandboxBranch, items.get(storeId), environment, author, comment);
        }
        logger.debug("Publishing local files to environment {0} for site {1}", environment, site);
        localRepositoryV2.publish(site, sandboxBranch, localItems, environment, author, comment);
    } catch (Exception e) {
        throw new DeploymentException("Error during deployment to environment " + environment + " for site " + site, e);
    }
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudioBlobStore(org.craftercms.studio.api.v2.repository.blob.StudioBlobStore) DeploymentItemTO(org.craftercms.studio.api.v1.to.DeploymentItemTO) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) LinkedList(java.util.LinkedList) 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) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with StudioBlobStore

use of org.craftercms.studio.api.v2.repository.blob.StudioBlobStore 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)

Example 3 with StudioBlobStore

use of org.craftercms.studio.api.v2.repository.blob.StudioBlobStore in project studio by craftercms.

the class BlobAwareContentRepository method moveContent.

@Override
public Map<String, String> moveContent(String site, String fromPath, String toPath, String newName) {
    logger.debug("Moving content from {0} to {1} in site {2}", fromPath, toPath, site);
    try {
        StudioBlobStore store = getBlobStore(site, fromPath, toPath);
        if (store != null) {
            Map<String, String> result = store.moveContent(site, normalize(fromPath), normalize(toPath), newName);
            if (result != null) {
                boolean isFolder = isFolder(site, fromPath);
                Map<String, String> diskResult = localRepositoryV1.moveContent(site, isFolder ? fromPath : getPointerPath(site, fromPath), isFolder ? toPath : getPointerPath(site, toPath), newName);
                Set<String> keys = new HashSet<>(diskResult.keySet());
                keys.forEach(k -> {
                    String val = diskResult.get(k);
                    diskResult.put(getPathFromPointerPath(site, k), val);
                });
                return diskResult;
            }
        }
        return localRepositoryV1.moveContent(site, fromPath, toPath, newName);
    } catch (Exception e) {
        logger.error("Error moving content from {0} to {1} in site {2}", e, fromPath, toPath, site);
        return null;
    }
}
Also used : StudioBlobStore(org.craftercms.studio.api.v2.repository.blob.StudioBlobStore) 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) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)3 ConfigurationException (org.craftercms.commons.config.ConfigurationException)3 CryptoException (org.craftercms.commons.crypto.CryptoException)3 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)3 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)3 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)3 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)3 RepositoryLockedException (org.craftercms.studio.api.v2.exception.RepositoryLockedException)3 StudioBlobStore (org.craftercms.studio.api.v2.repository.blob.StudioBlobStore)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Blob (org.craftercms.commons.file.blob.Blob)1 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1