<commit_before>package biz.netcentric.cq.tools.actool.installationhistory;

import java.util.Map;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(
		metatype = true,
		label = "AcHistory Service",
		immediate = true,
		description = "Service that writes & fetches Ac installation histories")

@Properties({
	@Property(label = "ACL number of histories to save", name = "AceService.nrOfSavedHistories", value = "5")

})

public class AcHistoryServiceImpl implements AcHistoryService{
	private static final int NR_OF_HISTORIES_TO_SAVE_DEFAULT = 5;
	private static final Logger LOG = LoggerFactory.getLogger(AcHistoryServiceImpl.class);
	private int nrOfSavedHistories;
	
	@Reference
	private SlingRepository repository;
	
	@Activate
	public void activate(@SuppressWarnings("rawtypes") final Map properties) throws Exception {
		this.nrOfSavedHistories = PropertiesUtil.toInteger(properties.get("AceService.nrOfSavedHistories"), NR_OF_HISTORIES_TO_SAVE_DEFAULT);

	}

	@Override
	public void persistHistory(AcInstallationHistoryPojo history){
		Session session = null;
		try {
			try {
				session = repository.loginAdministrative(null);
				HistoryUtils.persistHistory(session, history, this.nrOfSavedHistories);
			} catch (RepositoryException e) {
				LOG.error("RepositoryException: ", e);
			}
		}finally{
			if(session != null){
				session.logout();
			}
		}
	}

	@Override
	public String getInstallationLogPaths()  {
		Session session = null;
		try {
			session = repository.loginAdministrative(null);
			return HistoryUtils.getInstallationLogLinks(session);
		} catch (RepositoryException e) {
			LOG.error("RepositoryException: ", e);
		}finally{
			if(session != null){
				session.logout();
			}
		}
		return null;
	}

	@Override
	public String getLogHtml(Session session, String path) {
		return HistoryUtils.getLogHtml(session, path); 
	}

	@Override
	public String getLastInstallationHistory() {
		Session session = null;
		String history = "";
		try {
			
			session = repository.loginAdministrative(null);
			final Node rootNode = session.getRootNode();
			Node statisticsRootNode = HistoryUtils.getAcHistoryRootNode(session);
			NodeIterator it = statisticsRootNode.getNodes();
			Node lastHistoryNode = it.nextNode();
			
			if(lastHistoryNode != null){
				history = getLogHtml(session, lastHistoryNode.getName());
			}
		
		
		} catch (RepositoryException e) {
			LOG.error("RepositoryException: ", e);
		}finally{
			if(session != null){
				session.logout();
			}
		}
		return history;
		
	}

}<commit_msg>added error message in case no history is stored in CRX<commit_after>package biz.netcentric.cq.tools.actool.installationhistory;

import java.util.Map;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(
		metatype = true,
		label = "AcHistory Service",
		immediate = true,
		description = "Service that writes & fetches Ac installation histories")

@Properties({
	@Property(label = "ACL number of histories to save", name = "AceService.nrOfSavedHistories", value = "5")

})

public class AcHistoryServiceImpl implements AcHistoryService{
	private static final int NR_OF_HISTORIES_TO_SAVE_DEFAULT = 5;
	private static final Logger LOG = LoggerFactory.getLogger(AcHistoryServiceImpl.class);
	private int nrOfSavedHistories;

	@Reference
	private SlingRepository repository;

	@Activate
	public void activate(@SuppressWarnings("rawtypes") final Map properties) throws Exception {
		this.nrOfSavedHistories = PropertiesUtil.toInteger(properties.get("AceService.nrOfSavedHistories"), NR_OF_HISTORIES_TO_SAVE_DEFAULT);

	}

	@Override
	public void persistHistory(AcInstallationHistoryPojo history){
		Session session = null;
		try {
			try {
				session = repository.loginAdministrative(null);
				HistoryUtils.persistHistory(session, history, this.nrOfSavedHistories);
			} catch (RepositoryException e) {
				LOG.error("RepositoryException: ", e);
			}
		}finally{
			if(session != null){
				session.logout();
			}
		}
	}

	@Override
	public String getInstallationLogPaths()  {
		Session session = null;
		try {
			session = repository.loginAdministrative(null);
			return HistoryUtils.getInstallationLogLinks(session);
		} catch (RepositoryException e) {
			LOG.error("RepositoryException: ", e);
		}finally{
			if(session != null){
				session.logout();
			}
		}
		return null;
	}

	@Override
	public String getLogHtml(Session session, String path) {
		return HistoryUtils.getLogHtml(session, path); 
	}

	@Override
	public String getLastInstallationHistory() {
		Session session = null;
		String history = "";
		try {

			session = repository.loginAdministrative(null);
			final Node rootNode = session.getRootNode();
			Node statisticsRootNode = HistoryUtils.getAcHistoryRootNode(session);
			NodeIterator it = statisticsRootNode.getNodes();
			if(it.hasNext()){
				Node lastHistoryNode = it.nextNode();

				if(lastHistoryNode != null){
					history = getLogHtml(session, lastHistoryNode.getName());
				}
			}
			history = "no history found!";


		} catch (RepositoryException e) {
			LOG.error("RepositoryException: ", e);
		}finally{
			if(session != null){
				session.logout();
			}
		}
		return history;

	}

}
{'fraction_non_alphanumeric': 0.10684580934101087, 'fraction_numerical': 0.0012795905310300703, 'mean_word_length': 4.811338289962825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5018161', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1898, 'n_words': 405}