<commit_before>package com.commafeed.backend.services;

import javax.ejb.Stateless;
import javax.inject.Inject;

import com.commafeed.backend.dao.FeedEntryStatusDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User;

@Stateless
public class FeedEntryService {

	@Inject
	FeedEntryStatusDAO feedEntryStatusDAO;

	@Inject
	FeedSubscriptionDAO feedSubscriptionDAO;

	public void markEntry(User user, Long entryId, Long subscriptionId,
			boolean read) {
		FeedSubscription sub = feedSubscriptionDAO.findById(user,
				subscriptionId);
		if (sub == null) {
			return;
		}

		FeedEntry entry = new FeedEntry();
		entry.setId(entryId);

		FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);

		if (read) {
			if (status.getId() != null) {
				if (status.isStarred()) {
					status.setRead(true);
					feedEntryStatusDAO.saveOrUpdate(status);
				} else {
					feedEntryStatusDAO.delete(status);
				}
			}
		} else {
			if (status.getId() == null) {
				status = new FeedEntryStatus(user, sub, entry);
				status.setSubscription(sub);
			}
			status.setRead(false);
			feedEntryStatusDAO.saveOrUpdate(status);
		}

	}

	public void starEntry(User user, Long entryId, Long subscriptionId,
			boolean starred) {

		FeedSubscription sub = feedSubscriptionDAO.findById(user,
				subscriptionId);
		if (sub == null) {
			return;
		}

		FeedEntry entry = new FeedEntry();
		entry.setId(entryId);

		FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);

		if (!starred) {
			if (status.getId() != null) {
				if (!status.isRead()) {
					status.setStarred(false);
					feedEntryStatusDAO.saveOrUpdate(status);
				} else {
					feedEntryStatusDAO.delete(status);
				}
			}
		} else {
			if (status.getId() == null) {
				status = new FeedEntryStatus(user, sub, entry);
				status.setSubscription(sub);
				status.setRead(true);
			}
			status.setStarred(true);
			feedEntryStatusDAO.saveOrUpdate(status);
		}
	}
}
<commit_msg>fetch the entry instead of creating an empty one<commit_after>package com.commafeed.backend.services;

import javax.ejb.Stateless;
import javax.inject.Inject;

import com.commafeed.backend.dao.FeedEntryDAO;
import com.commafeed.backend.dao.FeedEntryStatusDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User;

@Stateless
public class FeedEntryService {

	@Inject
	FeedEntryStatusDAO feedEntryStatusDAO;

	@Inject
	FeedSubscriptionDAO feedSubscriptionDAO;
	
	@Inject 
	FeedEntryDAO feedEntryDAO;

	public void markEntry(User user, Long entryId, Long subscriptionId,
			boolean read) {
		FeedSubscription sub = feedSubscriptionDAO.findById(user,
				subscriptionId);
		if (sub == null) {
			return;
		}

		FeedEntry entry = feedEntryDAO.findById(entryId);
		if (entry == null) {
			return;
		}

		FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);

		if (read) {
			if (status.getId() != null) {
				if (status.isStarred()) {
					status.setRead(true);
					feedEntryStatusDAO.saveOrUpdate(status);
				} else {
					feedEntryStatusDAO.delete(status);
				}
			}
		} else {
			if (status.getId() == null) {
				status = new FeedEntryStatus(user, sub, entry);
				status.setSubscription(sub);
			}
			status.setRead(false);
			feedEntryStatusDAO.saveOrUpdate(status);
		}

	}

	public void starEntry(User user, Long entryId, Long subscriptionId,
			boolean starred) {

		FeedSubscription sub = feedSubscriptionDAO.findById(user,
				subscriptionId);
		if (sub == null) {
			return;
		}

		FeedEntry entry = feedEntryDAO.findById(entryId);
		if (entry == null) {
			return;
		}

		FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);

		if (!starred) {
			if (status.getId() != null) {
				if (!status.isRead()) {
					status.setStarred(false);
					feedEntryStatusDAO.saveOrUpdate(status);
				} else {
					feedEntryStatusDAO.delete(status);
				}
			}
		} else {
			if (status.getId() == null) {
				status = new FeedEntryStatus(user, sub, entry);
				status.setSubscription(sub);
				status.setRead(true);
			}
			status.setStarred(true);
			feedEntryStatusDAO.saveOrUpdate(status);
		}
	}
}

{'fraction_non_alphanumeric': 0.11094355881085739, 'fraction_numerical': 0.0, 'mean_word_length': 3.335200746965453, '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': '6720678', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1514, 'n_words': 275}