<commit_before>package utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.eclipse.jetty.util.StringUtil;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import qora.block.Block;
import qora.naming.Name;
import qora.transaction.ArbitraryTransaction;
import qora.transaction.Transaction;
import qora.web.BlogBlackWhiteList;
import qora.web.Profile;
import qora.web.blog.BlogEntry;
import api.BlogPostResource;
import controller.Controller;
import database.DBSet;
import database.NameMap;

public class BlogUtils {

	/**
	 * 
	 * @return triplet of name, title, description of all enabled blogs.
	 */
	public static List<Triplet<String, String, String>> getEnabledBlogs(
			String searchvalueOpt) {

		NameMap nameMap = DBSet.getInstance().getNameMap();
		List<Triplet<String, String, String>> results = new ArrayList<>();
		Set<String> names = nameMap.getKeys();

		for (String name : names) {
			Name nameObj = nameMap.get(name);

			Profile profile = Profile.getProfileOpt(nameObj);

			if (profile != null && profile.isProfileEnabled() && profile.isBlogEnabled()) {

				String title = profile.getBlogTitleOpt();
				String description = profile.getBlogDescriptionOpt();
				if (searchvalueOpt != null) {
					searchvalueOpt = searchvalueOpt.toLowerCase();
					if (name.toLowerCase().contains(searchvalueOpt)
							|| (title != null && title.toLowerCase().contains(
									searchvalueOpt))
							|| (description != null)
							&& description.toLowerCase().contains(
									searchvalueOpt)) {
						results.add(addTriplet(name, title, description));
					}
					continue;
				}
				results.add(addTriplet(name, title, description));
			}

		}

		return results;
	}

	private static Triplet<String, String, String> addTriplet(String name,
			String title, String description) {
		return new Triplet<String, String, String>(name, title == null ? ""
				: title, description == null ? "" : description);
	}

	public static List<BlogEntry> getBlogPosts(String blogOpt) {
		int height = Controller.getInstance().getHeight();
		int floor = 0;
		if (height > 10000) {
			floor = height - 10000;
		}
		Pair<Block, List<Transaction>> resultlist = Controller.getInstance()
				.scanTransactions(
						Controller.getInstance().getBlockByHeight(floor),
						10000, 1000, 10, 777, null);
		List<BlogEntry> results = new ArrayList<>();
		List<Transaction> b = resultlist.getB();<commit_msg>fixed bug when starting from scratch<commit_after>package utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.eclipse.jetty.util.StringUtil;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import qora.block.Block;
import qora.naming.Name;
import qora.transaction.ArbitraryTransaction;
import qora.transaction.Transaction;
import qora.web.BlogBlackWhiteList;
import qora.web.Profile;
import qora.web.blog.BlogEntry;
import api.BlogPostResource;
import controller.Controller;
import database.DBSet;
import database.NameMap;

public class BlogUtils {

	/**
	 * 
	 * @return triplet of name, title, description of all enabled blogs.
	 */
	public static List<Triplet<String, String, String>> getEnabledBlogs(
			String searchvalueOpt) {

		NameMap nameMap = DBSet.getInstance().getNameMap();
		List<Triplet<String, String, String>> results = new ArrayList<>();
		Set<String> names = nameMap.getKeys();

		for (String name : names) {
			Name nameObj = nameMap.get(name);

			Profile profile = Profile.getProfileOpt(nameObj);

			if (profile != null && profile.isProfileEnabled() && profile.isBlogEnabled()) {

				String title = profile.getBlogTitleOpt();
				String description = profile.getBlogDescriptionOpt();
				if (searchvalueOpt != null) {
					searchvalueOpt = searchvalueOpt.toLowerCase();
					if (name.toLowerCase().contains(searchvalueOpt)
							|| (title != null && title.toLowerCase().contains(
									searchvalueOpt))
							|| (description != null)
							&& description.toLowerCase().contains(
									searchvalueOpt)) {
						results.add(addTriplet(name, title, description));
					}
					continue;
				}
				results.add(addTriplet(name, title, description));
			}

		}

		return results;
	}

	private static Triplet<String, String, String> addTriplet(String name,
			String title, String description) {
		return new Triplet<String, String, String>(name, title == null ? ""
				: title, description == null ? "" : description);
	}

	public static List<BlogEntry> getBlogPosts(String blogOpt) {
		int height = Controller.getInstance().getHeight();
		int floor = 1;
		if (height > 10000) {
			floor = height - 10000;
		}
		Pair<Block, List<Transaction>> resultlist = Controller.getInstance()
				.scanTransactions(
						Controller.getInstance().getBlockByHeight(floor),
						10000, 1000, 10, 777, null);
		List<BlogEntry> results = new ArrayList<>();
		List<Transaction> b = resultlist.getB();
{'fraction_non_alphanumeric': 0.12402167369054787, 'fraction_numerical': 0.010034115994380895, 'mean_word_length': 4.2243186582809225, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3282732', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1437, 'n_words': 350}