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