<commit_before>package org.marsik.elshelves.backend.services;

import org.apache.tika.metadata.Metadata;
import org.marsik.elshelves.backend.entities.Document;
import org.marsik.elshelves.backend.repositories.DocumentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.nio.file.Path;
import java.util.UUID;

@Service
public class DocumentAnalysisDoneService implements FileAnalysisDoneHandler {
	@Autowired
	DocumentRepository documentRepository;

	@Override
	@Transactional
	public void downloadFinished(UUID uuid, Path path, Long size, String contentType, Metadata metadata) {
		Document d = documentRepository.findByUuid(uuid);
		if (d == null) {
			return;
		}

		d.setContentType(contentType != null ? contentType : d.getContentType());
		d.setSize(size != null ? size : d.getSize());

		if (metadata != null) {
            if (metadata.get(Metadata.TITLE) != null) {
                d.setName(metadata.get(Metadata.TITLE));
            }
		}
	}
}<commit_msg>Do not rename documents when the title is empty<commit_after>package org.marsik.elshelves.backend.services;

import org.apache.tika.metadata.Metadata;
import org.marsik.elshelves.backend.entities.Document;
import org.marsik.elshelves.backend.repositories.DocumentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.nio.file.Path;
import java.util.UUID;

@Service
public class DocumentAnalysisDoneService implements FileAnalysisDoneHandler {
	@Autowired
	DocumentRepository documentRepository;

	@Override
	@Transactional
	public void downloadFinished(UUID uuid, Path path, Long size, String contentType, Metadata metadata) {
		Document d = documentRepository.findByUuid(uuid);
		if (d == null) {
			return;
		}

		d.setContentType(contentType != null ? contentType : d.getContentType());
		d.setSize(size != null ? size : d.getSize());

		if (metadata != null) {
            if (metadata.get(Metadata.TITLE) != null
                    && !metadata.get(Metadata.TITLE).trim().isEmpty()) {
                d.setName(metadata.get(Metadata.TITLE));
            }
		}
	}
}
{'fraction_non_alphanumeric': 0.10867697594501718, 'fraction_numerical': 0.0, 'mean_word_length': 4.4543325526932085, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6005254', 'n_tokens_mistral': 700, 'n_tokens_neox': 679, 'n_words': 135}