Search in sources :

Example 1 with RepositoryItem

use of org.craftercms.studio.api.v1.repository.RepositoryItem in project studio by craftercms.

the class SitesServiceInternalImpl method getBlueprintLocation.

@Override
public String getBlueprintLocation(String blueprintId) {
    RepositoryItem[] blueprintsFolders = getBlueprintsFolders();
    for (RepositoryItem folder : blueprintsFolders) {
        if (folder.isFolder) {
            Path descriptorPath = getBlueprintPath(folder);
            PluginDescriptor descriptor = loadDescriptor(folder);
            if (descriptor != null && descriptor.getPlugin().getId().equals(blueprintId)) {
                return descriptorPath.getParent().toAbsolutePath().toString();
            }
        }
    }
    return StringUtils.EMPTY;
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) Path(java.nio.file.Path) PluginDescriptor(org.craftercms.commons.plugin.model.PluginDescriptor)

Example 2 with RepositoryItem

use of org.craftercms.studio.api.v1.repository.RepositoryItem in project studio by craftercms.

the class GitContentRepository method getContentChildren.

@Override
public RepositoryItem[] getContentChildren(String site, String path) {
    // TODO: SJ: Rethink this API call for 3.1+
    final List<RepositoryItem> retItems = new ArrayList<RepositoryItem>();
    try {
        GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
        Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);
        RevTree tree = helper.getTreeForLastCommit(repo);
        try (TreeWalk tw = TreeWalk.forPath(repo, helper.getGitPath(path), tree)) {
            if (tw != null) {
                // Loop for all children and gather path of item excluding the item, file/folder name, and
                // whether or not it's a folder
                ObjectLoader loader = repo.open(tw.getObjectId(0));
                if (loader.getType() == OBJ_TREE) {
                    int depth = tw.getDepth();
                    tw.enterSubtree();
                    while (tw.next()) {
                        if (tw.getDepth() == depth + 1) {
                            RepositoryItem item = new RepositoryItem();
                            item.name = tw.getNameString();
                            String visitFolderPath = FILE_SEPARATOR + tw.getPathString();
                            loader = repo.open(tw.getObjectId(0));
                            item.isFolder = loader.getType() == OBJ_TREE;
                            int lastIdx = visitFolderPath.lastIndexOf(FILE_SEPARATOR + item.name);
                            if (lastIdx > 0) {
                                item.path = visitFolderPath.substring(0, lastIdx);
                            }
                            if (!ArrayUtils.contains(IGNORE_FILES, item.name)) {
                                retItems.add(item);
                            }
                        }
                    }
                    tw.close();
                } else {
                    logger.debug("Object is not tree for site: " + site + " path: " + path + " - it does not have children");
                }
            } else {
                String gitPath = helper.getGitPath(path);
                if (StringUtils.isEmpty(gitPath) || gitPath.equals(".")) {
                    try (TreeWalk treeWalk = new TreeWalk(repo)) {
                        treeWalk.addTree(tree);
                        while (treeWalk.next()) {
                            ObjectLoader loader = repo.open(treeWalk.getObjectId(0));
                            RepositoryItem item = new RepositoryItem();
                            item.name = treeWalk.getNameString();
                            String visitFolderPath = FILE_SEPARATOR + treeWalk.getPathString();
                            loader = repo.open(treeWalk.getObjectId(0));
                            item.isFolder = loader.getType() == OBJ_TREE;
                            int lastIdx = visitFolderPath.lastIndexOf(FILE_SEPARATOR + item.name);
                            if (lastIdx > 0) {
                                item.path = visitFolderPath.substring(0, lastIdx);
                            } else {
                                item.path = EMPTY;
                            }
                            if (!ArrayUtils.contains(IGNORE_FILES, item.name)) {
                                retItems.add(item);
                            }
                        }
                    } catch (IOException e) {
                        logger.error("Error while getting children for site: " + site + " path: " + path, e);
                    }
                }
            }
        } catch (IOException e) {
            logger.error("Error while getting children for site: " + site + " path: " + path, e);
        }
    } catch (IOException | CryptoException e) {
        logger.error("Failed to create RevTree for site: " + site + " path: " + path, e);
    }
    RepositoryItem[] items = new RepositoryItem[retItems.size()];
    items = retItems.toArray(items);
    return items;
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RemoteRepository(org.craftercms.studio.api.v2.dal.RemoteRepository) Repository(org.eclipse.jgit.lib.Repository) ContentRepository(org.craftercms.studio.api.v1.repository.ContentRepository) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) GitRepositoryHelper(org.craftercms.studio.api.v2.utils.GitRepositoryHelper) CryptoException(org.craftercms.commons.crypto.CryptoException) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 3 with RepositoryItem

use of org.craftercms.studio.api.v1.repository.RepositoryItem in project studio by craftercms.

the class ContentServiceImpl method addDependenciesToDelete.

protected void addDependenciesToDelete(String site, String sourceContentPath, String dependencyPath, GoLiveDeleteCandidates candidates) throws ServiceLayerException {
    Set<String> dependencyParentFolder = new HashSet<String>();
    // add dependencies as well
    Set<String> dependencies = dependencyService.getDeleteDependencies(site, sourceContentPath);
    for (String dependency : dependencies) {
        candidates.addDependency(dependency);
        logger.debug("Added to delete" + dependency);
    }
    // Find if any folder would get empty if remove the items and add just the folder
    for (String parentFolderToDelete : dependencyParentFolder) {
        RepositoryItem[] children = _contentRepository.getContentChildren(site, parentFolderToDelete);
        List<String> childItems = new ArrayList<String>();
        for (RepositoryItem child : children) {
            childItems.add(child.path + "/" + child.name);
        }
        if (candidates.getAllItems().containsAll(childItems)) {
            logger.debug("Added parentFolder for delete" + parentFolderToDelete);
            candidates.addDependencyParentFolder(parentFolderToDelete);
        }
    }
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with RepositoryItem

use of org.craftercms.studio.api.v1.repository.RepositoryItem in project studio by craftercms.

the class ContentTypeServiceImpl method reloadConfiguration.

@Override
@ValidateParams
public void reloadConfiguration(@ValidateStringParam(name = "site") String site) {
    String contentTypesRootPath = getConfigPath().replaceAll(StudioConstants.PATTERN_SITE, site);
    RepositoryItem[] folders = contentRepository.getContentChildren(site, contentTypesRootPath);
    List<ContentTypeConfigTO> contentTypes = new ArrayList<>();
    if (folders != null) {
        for (int i = 0; i < folders.length; i++) {
            String configPath = folders[i].path + FILE_SEPARATOR + folders[i].name + FILE_SEPARATOR + getConfigFileName();
            if (contentService.contentExists(site, configPath)) {
                ContentTypeConfigTO config = contentTypesConfig.reloadConfiguration(site, configPath.replace(contentTypesRootPath, "").replace(FILE_SEPARATOR + getConfigFileName(), ""));
                if (config != null) {
                    contentTypes.add(config);
                }
            }
            reloadContentTypeConfigForChildren(site, folders[i], contentTypes);
        }
    }
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ContentTypeConfigTO(org.craftercms.studio.api.v1.to.ContentTypeConfigTO) ArrayList(java.util.ArrayList) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 5 with RepositoryItem

use of org.craftercms.studio.api.v1.repository.RepositoryItem in project studio by craftercms.

the class DependencyServiceImpl method getAllChildrenRecursively.

private Set<String> getAllChildrenRecursively(String site, List<String> paths) {
    logger.debug("Get all content from subtree(s) for list of pats");
    Set<String> toRet = new HashSet<String>();
    for (String path : paths) {
        logger.debug("Get children from repository for content at site " + site + " path " + path);
        RepositoryItem[] children = contentRepository.getContentChildren(site, path);
        if (children != null) {
            List<String> childrenPaths = new ArrayList<String>();
            for (RepositoryItem child : children) {
                String childPath = child.path + "/" + child.name;
                childrenPaths.add(childPath);
            }
            logger.debug("Adding all collected children paths");
            toRet.addAll(childrenPaths);
            toRet.addAll(getAllChildrenRecursively(site, childrenPaths));
        }
    }
    return toRet;
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

RepositoryItem (org.craftercms.studio.api.v1.repository.RepositoryItem)14 ArrayList (java.util.ArrayList)8 ContentTypeConfigTO (org.craftercms.studio.api.v1.to.ContentTypeConfigTO)3 HashSet (java.util.HashSet)2 PluginDescriptor (org.craftercms.commons.plugin.model.PluginDescriptor)2 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 FastArrayList (org.apache.commons.collections.FastArrayList)1 CryptoException (org.craftercms.commons.crypto.CryptoException)1 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)1 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)1 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)1 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)1 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)1 SiteBlueprintTO (org.craftercms.studio.api.v1.to.SiteBlueprintTO)1