fix create

This commit is contained in:
2025-11-14 16:11:09 +01:00
parent c86f717da7
commit 9b0eec1388
3 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.champonthis</groupId>
<artifactId>abi</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
<name>abi</name>
<parent>
@@ -45,15 +45,17 @@ public class ContactManager {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (StringUtils.isNoneEmpty(line) && !line.startsWith("#")
&& contactRepository.findFirstByName(line).isEmpty()) {
Contact contact = new Contact();
if (StringUtils.isNoneEmpty(line)) {
String[] nameParts = line.split(";");
contact.setName(nameParts[0]);
String name = nameParts[0];
if (StringUtils.isNoneEmpty(name) && !name.startsWith("#")
&& contactRepository.findByName(name).isEmpty()) {
Contact contact = new Contact();
contact.setName(name);
if (nameParts.length > 1) {
contact.setSearchName(nameParts[1]);
} else {
contact.setSearchName(nameParts[0]);
contact.setSearchName(name);
}
save(contact);
logger.info("Created contact: #" + contact.getId() + ": " + contact.getName()
@@ -62,6 +64,7 @@ public class ContactManager {
}
}
}
}
} else {
logger.warn("No names.csv found!");
}
@@ -75,7 +78,7 @@ public class ContactManager {
}
public Contact findByName(String name) {
return contactRepository.findFirstByName(name).orElse(null);
return contactRepository.findByName(name).orElse(null);
}
public Contact findByToken(String token) {
@@ -10,7 +10,7 @@ import de.champonthis.abi.entity.Contact;
@Repository
public interface ContactRepository extends JpaRepository<Contact, Long> {
Optional<Contact> findFirstByName(String name);
Optional<Contact> findByName(String name);
Optional<Contact> findByToken(String token);
}