<commit_before>package qa.qcri.aidr.data.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import qa.qcri.aidr.data.dao.CollectionSummaryDao;
import qa.qcri.aidr.data.model.CollectionSummaryInfo;
import qa.qcri.aidr.data.persistence.entity.CollectionSummary;


@Service
public class CollectionSummaryService {

	private static final String NA_STRING = "n/a";
	
	@Autowired
	private CollectionSummaryDao collectionSummaryDao;
	
    public List<CollectionSummaryInfo> fetchAllCollections() {
        List<CollectionSummary> aidrData = collectionSummaryDao.getAllCollections();
        return adaptCollectionSummaryListToCollectionSummaryInfoList(aidrData);
    }
    
    public void saveUpdateCollectionSummary(CollectionSummaryInfo collectionSummaryInfo) {
    	
    	CollectionSummary summary = new CollectionSummary();
    	collectionSummaryDao.saveUpdateCollectionSummary(summary);
    }
	
    public void saveUpdateCollectionSummary(List<CollectionSummaryInfo> collectionSummaryInfos) {
    	List<CollectionSummary> listToSave = new ArrayList<CollectionSummary>();
    	
    	for(CollectionSummaryInfo summaryInfo : collectionSummaryInfos) {
    		CollectionSummary collectionSummary = collectionSummaryDao.getByCode(summaryInfo.getCode());
    		collectionSummary = adaptCollectionSummaryInfoToCollectionSummary(summaryInfo, collectionSummary);
    		listToSave.add(collectionSummary);
    	}
    	collectionSummaryDao.saveUpdateCollectionSummaryList(listToSave);
    }

    private CollectionSummary adaptCollectionSummaryInfoToCollectionSummary(CollectionSummaryInfo summaryInfo, CollectionSummary collectionSummary) {
    	if(collectionSummary == null) {
    		collectionSummary = new CollectionSummary();
    		collectionSummary.setCode(summaryInfo.getCode());
    		collectionSummary.setCollectionCreationDate(summaryInfo.getCollectionCreationDate());
    	}
    	
    	collectionSummary.setName(summaryInfo.getName());
    	collectionSummary.setTotalCount(summaryInfo.getTotalCount());
    	collectionSummary.setCurator(summaryInfo.getCurator());
    	collectionSummary.setGeo(summaryInfo.getGeo());
    	collectionSummary.setLabelCount(summaryInfo.getLabelCount());
    	collectionSummary.setStartDate(summaryInfo.getStartDate());
    	collectionSummary.setEndDate(summaryInfo.getEndDate());
    	collectionSummary.setKeywords(summaryInfo.getKeywords());
    	collectionSummary.setStatus(summaryInfo.getStatus());
    	collectionSummary.setLanguage(summaryInfo.getLanguage());
    	
    	return collectionSummary;
    }
    
    private List<CollectionSummaryInfo> adaptCollectionSummaryListToCollectionSummaryInfoList(List<CollectionSummary> collectionSummaries) {
    	
    	List<CollectionSummaryInfo> collectionSummaryInfos = new ArrayList<CollectionSummaryInfo>();
    	
    	for(CollectionSummary collectionSummary : collectionSummaries) {
    		collectionSummaryInfos.add(adaptCollectionSummaryToCollectionSummaryInfo(collectionSummary));
    	}

    	return collectionSummaryInfos;
    }
    
    private CollectionSummaryInfo adaptCollectionSummaryToCollectionSummaryInfo(CollectionSummary collectionSummary) {
    	
    	String lang = NA_STRING;
    	CollectionSummaryInfo summaryInfo = new CollectionSummaryInfo();
    	summaryInfo.setCode(collectionSummary.getCode());
    	summaryInfo.setName(collectionSummary.getName());
    	summaryInfo.setCurator(collectionSummary.getCurator());
    	summaryInfo.setTotalCount(collectionSummary.getTotalCount());
    	summaryInfo.setLabelCount(collectionSummary.getLabelCount());
    	summaryInfo.setStartDate(collectionSummary.getStartDate());
    	summaryInfo.setEndDate(collectionSummary.getEndDate());
    	summaryInfo.setLanguage(collectionSummary.getLanguage());
    	summaryInfo.setCollectionCreationDate(collectionSummary.getCollectionCreationDate());
    	summaryInfo.setKeywords(collectionSummary.getKeywords());
    	summaryInfo.setGeo(collectionSummary.getGeo());
    	summaryInfo.setStatus(collectionSummary.getStatus());
    	
    	if (collectionSummary.getLanguage() != null && !collectionSummary.getLanguage().isEmpty()) { 
    		lang = collectionSummary.getLanguage();
    	}
    	
    	summaryInfo.setLanguage(lang);
    	return summaryInfo;
    }
}<commit_msg>Commit for #103838828: change status to running or stopped in api<commit_after>package qa.qcri.aidr.data.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import qa.qcri.aidr.data.dao.CollectionSummaryDao;
import qa.qcri.aidr.data.model.CollectionSummaryInfo;
import qa.qcri.aidr.data.persistence.entity.CollectionSummary;


@Service
public class CollectionSummaryService {

	private static final String NA_STRING = "n/a";
	private static final String RUNNING_STATUS = "RUNNING";
	private static final String RUNNING_WARNING_STATUS = "RUNNING_WARNING";
	private static final String STOPPED_STATUS = "STOPPED";
	
	@Autowired
	private CollectionSummaryDao collectionSummaryDao;
	
    public List<CollectionSummaryInfo> fetchAllCollections() {
        List<CollectionSummary> aidrData = collectionSummaryDao.getAllCollections();
        return adaptCollectionSummaryListToCollectionSummaryInfoList(aidrData);
    }
    
    public void saveUpdateCollectionSummary(CollectionSummaryInfo collectionSummaryInfo) {
    	
    	CollectionSummary summary = new CollectionSummary();
    	collectionSummaryDao.saveUpdateCollectionSummary(summary);
    }
	
    public void saveUpdateCollectionSummary(List<CollectionSummaryInfo> collectionSummaryInfos) {
    	List<CollectionSummary> listToSave = new ArrayList<CollectionSummary>();
    	
    	for(CollectionSummaryInfo summaryInfo : collectionSummaryInfos) {
    		CollectionSummary collectionSummary = collectionSummaryDao.getByCode(summaryInfo.getCode());
    		collectionSummary = adaptCollectionSummaryInfoToCollectionSummary(summaryInfo, collectionSummary);
    		listToSave.add(collectionSummary);
    	}
    	collectionSummaryDao.saveUpdateCollectionSummaryList(listToSave);
    }

    private CollectionSummary adaptCollectionSummaryInfoToCollectionSummary(CollectionSummaryInfo summaryInfo, CollectionSummary collectionSummary) {
    	if(collectionSummary == null) {
    		collectionSummary = new CollectionSummary();
    		collectionSummary.setCode(summaryInfo.getCode());
    		collectionSummary.setCollectionCreationDate(summaryInfo.getCollectionCreationDate());
    	}
    	
    	collectionSummary.setName(summaryInfo.getName());
    	collectionSummary.setTotalCount(summaryInfo.getTotalCount());
    	collectionSummary.setCurator(summaryInfo.getCurator());
    	collectionSummary.setGeo(summaryInfo.getGeo());
    	collectionSummary.setLabelCount(summaryInfo.getLabelCount());
    	collectionSummary.setStartDate(summaryInfo.getStartDate());
    	collectionSummary.setEndDate(summaryInfo.getEndDate());
    	collectionSummary.setKeywords(summaryInfo.getKeywords());
    	collectionSummary.setStatus(summaryInfo.getStatus());
    	collectionSummary.setLanguage(summaryInfo.getLanguage());
    	
    	return collectionSummary;
    }
    
    private List<CollectionSummaryInfo> adaptCollectionSummaryListToCollectionSummaryInfoList(List<CollectionSummary> collectionSummaries) {
    	
    	List<CollectionSummaryInfo> collectionSummaryInfos = new ArrayList<CollectionSummaryInfo>();
    	
    	for(CollectionSummary collectionSummary : collectionSummaries) {
    		collectionSummaryInfos.add(adaptCollectionSummaryToCollectionSummaryInfo(collectionSummary));
    	}

    	return collectionSummaryInfos;
    }
    
    private CollectionSummaryInfo adaptCollectionSummaryToCollectionSummaryInfo(CollectionSummary collectionSummary) {
    	
    	String lang = NA_STRING;
    	CollectionSummaryInfo summaryInfo = new CollectionSummaryInfo();
    	summaryInfo.setCode(collectionSummary.getCode());
    	summaryInfo.setName(collectionSummary.getName());
    	summaryInfo.setCurator(collectionSummary.getCurator());
    	summaryInfo.setTotalCount(collectionSummary.getTotalCount());
    	summaryInfo.setLabelCount(collectionSummary.getLabelCount());
    	summaryInfo.setStartDate(collectionSummary.getStartDate());
    	summaryInfo.setEndDate(collectionSummary.getEndDate());
    	summaryInfo.setLanguage(collectionSummary.getLanguage());
    	summaryInfo.setCollectionCreationDate(collectionSummary.getCollectionCreationDate());
    	summaryInfo.setKeywords(collectionSummary.getKeywords());
    	summaryInfo.setGeo(collectionSummary.getGeo());
    	if(collectionSummary.getStatus() != null && (RUNNING_STATUS.equals(collectionSummary.getStatus()) 
    			|| RUNNING_WARNING_STATUS.equals(collectionSummary.getStatus()))) {
    		summaryInfo.setStatus(RUNNING_STATUS);
    	} else {
    		summaryInfo.setStatus(STOPPED_STATUS);
    	}
    	
    	if (collectionSummary.getLanguage() != null && !collectionSummary.getLanguage().isEmpty()) { 
    		lang = collectionSummary.getLanguage();
    	}
    	
    	summaryInfo.setLanguage(lang);
    	return summaryInfo;
    }
}
{'fraction_non_alphanumeric': 0.08543478260869565, 'fraction_numerical': 0.0009782608695652175, 'mean_word_length': 5.456842105263158, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '7062498', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2376, 'n_words': 308}