<commit_before>package com.gentics.cailun.core.data.service;

import io.vertx.ext.apex.RoutingContext;

import java.util.List;
import java.util.Locale;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import com.gentics.cailun.core.data.model.Content;
import com.gentics.cailun.core.data.model.Language;
import com.gentics.cailun.core.data.model.Tag;
import com.gentics.cailun.core.data.model.auth.CaiLunPermission;
import com.gentics.cailun.core.data.model.auth.PermissionType;
import com.gentics.cailun.core.data.model.auth.User;
import com.gentics.cailun.core.data.model.relationship.Translated;
import com.gentics.cailun.core.data.service.generic.GenericPropertyContainerServiceImpl;
import com.gentics.cailun.core.repository.ContentRepository;
import com.gentics.cailun.core.repository.GroupRepository;
import com.gentics.cailun.core.rest.content.response.ContentResponse;
import com.gentics.cailun.core.rest.schema.response.SchemaReference;
import com.gentics.cailun.core.rest.user.response.UserResponse;
import com.gentics.cailun.error.HttpStatusCodeErrorException;
import com.gentics.cailun.etc.CaiLunSpringConfiguration;
import com.gentics.cailun.path.PagingInfo;

@Component
public class ContentServiceImpl extends GenericPropertyContainerServiceImpl<Content> implements ContentService {

	@Autowired
	private LanguageService languageService;

	@Autowired
	private ProjectService projectService;

	@Autowired
	private UserService userService;

	@Autowired
	private GroupRepository groupRepository;

	@Autowired
	private ObjectSchemaService objectSchemaService;

	@Autowired
	private TagService tagService;

	@Autowired
	private CaiLunSpringConfiguration springConfiguration;

	@Autowired
	private ContentRepository contentRepository;

	@Autowired
	private I18NService i18n;

	public void setTeaser(Content page, Language language, String text) {
		setProperty(page, language, Content.TEASER_KEY, text);
	}

	public void setTitle(Content page, Language language, String text) {
		setProperty(page, language, Content.TITLE_KEY, text);
	}

	@Override
	public Iterable<Content> findAll(String project) {
		return contentRepository.findAll(project);
	}

	@Override
	public ContentResponse transformToRest(RoutingContext rc, Content content, List<String> languageTags, int depth) {
		ContentResponse response = new ContentResponse();
		response.setUuid(content.getUuid());
		if (content.getSchema() != null) {
			String schemaName = content.getSchema().getName();
			String schemaUuid = content.getSchema().getUuid();
			response.setSchema(new SchemaReference(schemaName, schemaUuid));
		}
		UserResponse restUser = userService.transformToRest(content.getCreator());
		response.setAuthor(restUser);
		response.setPerms(userService.getPerms(rc, content));

		if (languageTags.size() == 0) {
			for (Translated transalated : content.getI18nTranslations()) {
				String languageTag = transalated.getLanguageTag();<commit_msg>Fix schema loading for contents<commit_after>package com.gentics.cailun.core.data.service;

import io.vertx.ext.apex.RoutingContext;

import java.util.List;
import java.util.Locale;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import com.gentics.cailun.core.data.model.Content;
import com.gentics.cailun.core.data.model.Language;
import com.gentics.cailun.core.data.model.ObjectSchema;
import com.gentics.cailun.core.data.model.Tag;
import com.gentics.cailun.core.data.model.auth.CaiLunPermission;
import com.gentics.cailun.core.data.model.auth.PermissionType;
import com.gentics.cailun.core.data.model.auth.User;
import com.gentics.cailun.core.data.model.relationship.Translated;
import com.gentics.cailun.core.data.service.generic.GenericPropertyContainerServiceImpl;
import com.gentics.cailun.core.repository.ContentRepository;
import com.gentics.cailun.core.repository.GroupRepository;
import com.gentics.cailun.core.rest.content.response.ContentResponse;
import com.gentics.cailun.core.rest.schema.response.SchemaReference;
import com.gentics.cailun.core.rest.user.response.UserResponse;
import com.gentics.cailun.error.HttpStatusCodeErrorException;
import com.gentics.cailun.etc.CaiLunSpringConfiguration;
import com.gentics.cailun.path.PagingInfo;

@Component
public class ContentServiceImpl extends GenericPropertyContainerServiceImpl<Content> implements ContentService {

	@Autowired
	private LanguageService languageService;

	@Autowired
	private ProjectService projectService;

	@Autowired
	private UserService userService;

	@Autowired
	private GroupRepository groupRepository;

	@Autowired
	private ObjectSchemaService objectSchemaService;

	@Autowired
	private TagService tagService;

	@Autowired
	private CaiLunSpringConfiguration springConfiguration;

	@Autowired
	private ContentRepository contentRepository;

	@Autowired
	private I18NService i18n;

	public void setTeaser(Content page, Language language, String text) {
		setProperty(page, language, Content.TEASER_KEY, text);
	}

	public void setTitle(Content page, Language language, String text) {
		setProperty(page, language, Content.TITLE_KEY, text);
	}

	@Override
	public Iterable<Content> findAll(String project) {
		return contentRepository.findAll(project);
	}

	@Override
	public ContentResponse transformToRest(RoutingContext rc, Content content, List<String> languageTags, int depth) {
		ContentResponse response = new ContentResponse();
		response.setUuid(content.getUuid());
		if (content.getSchema() != null) {
			ObjectSchema schema = neo4jTemplate.fetch(content.getSchema());
			response.setSchema(new SchemaReference(schema.getName(), schema.getUuid()));
		}
		UserResponse restUser = userService.transformToRest(content.getCreator());
		response.setAuthor(restUser);
		response.setPerms(userService.getPerms(rc, content));

		if (languageTags.size() == 0) {
			for (Translated transalated : content.getI18nTranslations()) {
				String languageTag = transalated.getLanguageTag();
{'fraction_non_alphanumeric': 0.09848363926576217, 'fraction_numerical': 0.0023942537909018356, 'mean_word_length': 6.441805225653207, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6650621', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1888, 'n_words': 340}