add search names, fix working bug, lowercase all mails
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.champonthis</groupId>
|
||||
<artifactId>abi</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<version>0.2.0</version>
|
||||
<name>abi</name>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -48,9 +48,17 @@ public class ContactManager {
|
||||
if (StringUtils.isNoneEmpty(line) && !line.startsWith("#")
|
||||
&& contactRepository.findByName(line).isEmpty()) {
|
||||
Contact contact = new Contact();
|
||||
contact.setName(line);
|
||||
String[] nameParts = line.split(";");
|
||||
contact.setName(nameParts[0]);
|
||||
if (nameParts.length > 1) {
|
||||
contact.setSearchName(nameParts[1]);
|
||||
} else {
|
||||
contact.setSearchName(nameParts[0]);
|
||||
}
|
||||
save(contact);
|
||||
logger.info("Created contact: #" + contact.getId() + ": " + contact.getName());
|
||||
logger.info("Created contact: #" + contact.getId() + ": " + contact.getName()
|
||||
+ (contact.getName().equals(contact.getSearchName()) ? ""
|
||||
: " | " + contact.getSearchName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,9 +88,28 @@ public class ContactManager {
|
||||
|
||||
public Contact findByLevenshteinDistance(String name, int threshold) {
|
||||
Contact result = null;
|
||||
String[] nameParts = name.toLowerCase().split(" ");
|
||||
if (nameParts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
for (Contact contact : contactRepository.findAll()) {
|
||||
int distance = levenshteinDistance.apply(name.toLowerCase(), contact.getName().toLowerCase());
|
||||
if (distance <= threshold) {
|
||||
String[] contactParts = contact.getSearchName().toLowerCase().split(" ");
|
||||
int matches = 0;
|
||||
int index = 0;
|
||||
if (contactParts.length < nameParts.length) {
|
||||
continue;
|
||||
}
|
||||
for (String namePart : nameParts) {
|
||||
for (int i = index; i < contactParts.length; i++) {
|
||||
int distance = levenshteinDistance.apply(namePart, contactParts[i]);
|
||||
if (distance <= threshold) {
|
||||
matches++;
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches > 1) {
|
||||
result = contact;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ContactDataController {
|
||||
sendToken = true;
|
||||
}
|
||||
|
||||
contactData.setEmail(request.getEmail());
|
||||
contactData.setEmail(request.getEmail().toLowerCase());
|
||||
contactData.setPhone(request.getPhone());
|
||||
|
||||
if (!contact.getId().equals(reportedBy.getId())
|
||||
|
||||
@@ -20,7 +20,11 @@ public class Contact {
|
||||
@Column(name = "id", nullable = false)
|
||||
@JsonIgnore
|
||||
private Long id;
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@JsonIgnore
|
||||
@Column(nullable = false)
|
||||
private String searchName;
|
||||
private String updatedName;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Commitment committed = Commitment.UNKNOWN;
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<form @submit.prevent="findSelf" class="d-flex flex-column gap-3 mb-3">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">
|
||||
Dein Name (wie auf dem Abi-T-Shirt)
|
||||
Dein Name (wie im Abi-Buch)
|
||||
</label>
|
||||
<input type="text" x-model="yourName" required autocomplete="off"
|
||||
class="form-control" autofocus />
|
||||
@@ -104,7 +104,7 @@
|
||||
<form @submit.prevent="continueStep1">
|
||||
<p>
|
||||
Hallo <span x-text="altName || userName"></span>! Falls sich dein Name geändert hat,
|
||||
kannst du ihn hier anpassen – oder einfach direkt weitermachen.
|
||||
kannst du ihn hier anpassen - oder einfach direkt weitermachen.
|
||||
</p>
|
||||
<div id="altNameCheckboxDiv" class="form-check mt-3" x-show="userName" x-transition>
|
||||
<input type="checkbox" x-model="altNameChecked" class="form-check-input"
|
||||
@@ -184,7 +184,7 @@
|
||||
</h2>
|
||||
<form @submit.prevent="findKnownContact" class="mb-3">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name auf dem Abi-T-Shirt:</label>
|
||||
<label class="form-label">Name (wie im Abi-Buch):</label>
|
||||
<input type="text" x-model="knownContactName" required autocomplete="off"
|
||||
class="form-control" autofocus />
|
||||
</div>
|
||||
@@ -314,7 +314,7 @@
|
||||
this.userName = resp.data.name;
|
||||
this.userToken = resp.data.token || null;
|
||||
} else if (resp.status === 404) {
|
||||
this.stepMsg = 'Sorry, wir konnten dich nicht finden. Schreib deinen Namen bitte genau so, wie er auf dem Abi-T-Shirt stand!';
|
||||
this.stepMsg = 'Sorry, wir konnten dich nicht finden. Schreib deinen Namen bitte so, wie er im Abi-Buch stand!';
|
||||
this.stepMsgType = 'warning';
|
||||
} else if (resp.status === 208) {
|
||||
this.stepMsg = 'Du hast deine Daten schon eingetragen. Danke dir!';
|
||||
@@ -395,16 +395,16 @@
|
||||
if (resp.status === 200) {
|
||||
this.foundKnownContactName = resp.data.name.trim();
|
||||
if (this.foundKnownContactName == this.yourName) {
|
||||
this.stepMsg = 'Das bist du selbst – deine Daten hast du ja schon eingetragen!';
|
||||
this.stepMsg = 'Das bist du selbst - deine Daten hast du ja schon eingetragen!';
|
||||
this.stepMsgType = 'warning';
|
||||
this.showKnownContactData = false;
|
||||
this.knownContactName = ''
|
||||
return;
|
||||
} else {
|
||||
this.knownContactName = this.foundKnownContactName;
|
||||
this.stepMsg = 'Super, trag bitte die Kontaktdaten ein!';
|
||||
this.stepMsgType = 'success';
|
||||
this.showKnownContactData = true;
|
||||
}
|
||||
this.knownContactName = this.foundKnownContactName;
|
||||
this.stepMsg = 'Super, trag bitte die Kontaktdaten ein!';
|
||||
this.stepMsgType = 'success';
|
||||
this.showKnownContactData = true;
|
||||
} else if (resp.status === 404) {
|
||||
this.stepMsg = 'Diesen Namen gibt es leider nicht in unserer Liste.';
|
||||
this.stepMsgType = 'warning';
|
||||
|
||||
Reference in New Issue
Block a user