<commit_before>package com.nowellpoint.api.service;

import static com.mongodb.client.model.Filters.eq;

import javax.inject.Inject;

import org.bson.types.ObjectId;

import com.nowellpoint.api.model.domain.AccountProfile;
import com.nowellpoint.mongodb.DocumentManager;
import com.nowellpoint.mongodb.DocumentManagerFactory;

abstract class AbstractAccountProfileService {
	
	@Inject
	private DocumentManagerFactory documentManagerFactory;
	
	protected void create(AccountProfile accountProfile) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		documentManager.insertOne(accountProfile.toDocument());
	}
	
	protected void update(AccountProfile accountProfile) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		documentManager.replaceOne(accountProfile.toDocument());
	}
	
	protected AccountProfile findById(String id) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		com.nowellpoint.api.model.document.AccountProfile document = documentManager.findOne( com.nowellpoint.api.model.document.AccountProfile.class, new ObjectId( id ) );
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
	
	protected AccountProfile findByAccountHref(String accountHref) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		com.nowellpoint.api.model.document.AccountProfile document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "accountHref", accountHref ) );
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
	
	protected AccountProfile findByUsername(String username) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		com.nowellpoint.api.model.document.AccountProfile document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "username", username ) );
		AccountProfile accountProfile = new AccountProfile(document);
		return accountProfile;
	}
	
	protected AccountProfile findBySubscriptionId(String subscriptionId) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		com.nowellpoint.api.model.document.AccountProfile document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "subscription.subscriptionId", subscriptionId ) );
		AccountProfile accountProfile = new AccountProfile(document);
		return accountProfile;
	}
}<commit_msg>added cache to AbstractAccountProfileService<commit_after>package com.nowellpoint.api.service;

import static com.mongodb.client.model.Filters.eq;

import javax.inject.Inject;

import org.bson.types.ObjectId;

import com.nowellpoint.api.model.domain.AccountProfile;
import com.nowellpoint.aws.data.AbstractCacheService;
import com.nowellpoint.mongodb.DocumentManager;
import com.nowellpoint.mongodb.DocumentManagerFactory;
import com.nowellpoint.mongodb.document.MongoDocument;
import com.nowellpoint.util.Assert;

abstract class AbstractAccountProfileService extends AbstractCacheService {
	
	@Inject
	private DocumentManagerFactory documentManagerFactory;
	
	protected void create(AccountProfile accountProfile) {
		MongoDocument document = accountProfile.toDocument();
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		documentManager.insertOne(document);
		set(accountProfile.getId(), document);
	}
	
	protected void update(AccountProfile accountProfile) {
		MongoDocument document = accountProfile.toDocument();
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		documentManager.replaceOne(document);
		set(accountProfile.getId(), document);
	}
	
	protected AccountProfile findById(String id) {
		com.nowellpoint.api.model.document.AccountProfile document = get(com.nowellpoint.api.model.document.AccountProfile.class, id);
		if (Assert.isNull(document)) {
			DocumentManager documentManager = documentManagerFactory.createDocumentManager();
			document = documentManager.findOne( com.nowellpoint.api.model.document.AccountProfile.class, new ObjectId( id ) );
			set(id, document);
		}
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
	
	protected AccountProfile findByAccountHref(String accountHref) {
		com.nowellpoint.api.model.document.AccountProfile document = get(com.nowellpoint.api.model.document.AccountProfile.class, accountHref);
		if (Assert.isNull(document)) {
			DocumentManager documentManager = documentManagerFactory.createDocumentManager();
			document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "accountHref", accountHref ) );
			set(accountHref, document);
		}
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
	
	protected AccountProfile findByUsername(String username) {
		com.nowellpoint.api.model.document.AccountProfile document = get(com.nowellpoint.api.model.document.AccountProfile.class, username);
		if (Assert.isNull(document)) {
			DocumentManager documentManager = documentManagerFactory.createDocumentManager();
			document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "username", username ) );
			set(username, document);
		}
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
	
	protected AccountProfile findBySubscriptionId(String subscriptionId) {
		DocumentManager documentManager = documentManagerFactory.createDocumentManager();
		com.nowellpoint.api.model.document.AccountProfile document = documentManager.findOne(com.nowellpoint.api.model.document.AccountProfile.class, eq ( "subscription.subscriptionId", subscriptionId ) );
		AccountProfile accountProfile = new AccountProfile( document );
		return accountProfile;
	}
}
{'fraction_non_alphanumeric': 0.08836973082783138, 'fraction_numerical': 0.0, 'mean_word_length': 6.783926218708827, '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': '4828796', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1508, 'n_words': 278}