fix create
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.champonthis</groupId>
|
<groupId>de.champonthis</groupId>
|
||||||
<artifactId>abi</artifactId>
|
<artifactId>abi</artifactId>
|
||||||
<version>0.2.7</version>
|
<version>0.2.8</version>
|
||||||
<name>abi</name>
|
<name>abi</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|||||||
@@ -45,20 +45,23 @@ public class ContactManager {
|
|||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (StringUtils.isNoneEmpty(line) && !line.startsWith("#")
|
if (StringUtils.isNoneEmpty(line)) {
|
||||||
&& contactRepository.findFirstByName(line).isEmpty()) {
|
|
||||||
Contact contact = new Contact();
|
|
||||||
String[] nameParts = line.split(";");
|
String[] nameParts = line.split(";");
|
||||||
contact.setName(nameParts[0]);
|
String name = nameParts[0];
|
||||||
if (nameParts.length > 1) {
|
if (StringUtils.isNoneEmpty(name) && !name.startsWith("#")
|
||||||
contact.setSearchName(nameParts[1]);
|
&& contactRepository.findByName(name).isEmpty()) {
|
||||||
} else {
|
Contact contact = new Contact();
|
||||||
contact.setSearchName(nameParts[0]);
|
contact.setName(name);
|
||||||
|
if (nameParts.length > 1) {
|
||||||
|
contact.setSearchName(nameParts[1]);
|
||||||
|
} else {
|
||||||
|
contact.setSearchName(name);
|
||||||
|
}
|
||||||
|
save(contact);
|
||||||
|
logger.info("Created contact: #" + contact.getId() + ": " + contact.getName()
|
||||||
|
+ (contact.getName().equals(contact.getSearchName()) ? ""
|
||||||
|
: " | " + contact.getSearchName()));
|
||||||
}
|
}
|
||||||
save(contact);
|
|
||||||
logger.info("Created contact: #" + contact.getId() + ": " + contact.getName()
|
|
||||||
+ (contact.getName().equals(contact.getSearchName()) ? ""
|
|
||||||
: " | " + contact.getSearchName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +78,7 @@ public class ContactManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Contact findByName(String name) {
|
public Contact findByName(String name) {
|
||||||
return contactRepository.findFirstByName(name).orElse(null);
|
return contactRepository.findByName(name).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact findByToken(String token) {
|
public Contact findByToken(String token) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import de.champonthis.abi.entity.Contact;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface ContactRepository extends JpaRepository<Contact, Long> {
|
public interface ContactRepository extends JpaRepository<Contact, Long> {
|
||||||
|
|
||||||
Optional<Contact> findFirstByName(String name);
|
Optional<Contact> findByName(String name);
|
||||||
|
|
||||||
Optional<Contact> findByToken(String token);
|
Optional<Contact> findByToken(String token);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user