[LM] new git.

Signed-off-by: Lukas Martin <contact@lukasmartin.eu>
main
Lukas Martin 2 years ago
commit 21f62c4e8f

38
.gitignore vendored

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="-716320ba:191be0e312a:-7ffa" />
</MTProjectMetadataState>
</option>
</component>
</project>

@ -0,0 +1,13 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.kaabp</groupId>
<artifactId>wichteln</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,23 @@
package de.kaabp;
import de.kaabp.util.Person;
import de.kaabp.parser.ReadCsv;
import de.kaabp.util.Matching;
import de.kaabp.parser.WriteCsv;
import de.kaabp.mail.sendMail;
import java.io.File;
import java.util.*;
public class Main {
public static void main(String[] args) {
ReadCsv readCsv = new ReadCsv();
List<Person> personList = readCsv.csvToList("src/main/resources/entries.csv");
List<Person> matchedPeople = new ArrayList<>();
Person[] matches = new Person[personList.size()];
Matching.matchPeople(personList, matchedPeople, matches);
WriteCsv.updateLastMatch(new File("src/main/resources/entries.csv"),matches, readCsv.csvToList("src/main/resources/entries.csv"));
sendMail.sendMail(readCsv.csvToList("src/main/resources/entries.csv"));
}
}

@ -0,0 +1,64 @@
package de.kaabp.mail;
import de.kaabp.util.Person;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.List;
import java.util.Properties;
public class sendMail {
/**
* @author Lukas Martin
* @param {@code String[][]}
* @param {@code String[]}
* @info Uses the params to send mails to the chosen people.
*/
public static void sendMail(List<Person> personList) {
//authentication info
final String username = "weihnachtswichteln0@gmail.com";
final String password = "fmrvjhogruskvjkj\n";
String fromEmail = "weihnachtswichteln0@gmail.com";
String toEmail = "lukas.martin155@outlook.de";
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.ssl.trust", "smtp.gmail.com");
Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
//Start our mail message
for(int i = 0; i < personList.size(); i++) {
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(fromEmail));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(personList.get(i).getEmail()));
msg.setSubject("Weihnachtswichteln 2023");
msg.setText("Hallo liebe/r " + personList.get(i).getName()+ "," + "\n" +
"\n" +
"Dein Match für das diesjährige Wichteln ist " + personList.get(personList.get(i).getLastMatch()).getName() + "." + "\n" +
"\n" +
"Mit freundlichen Grüßen \n" +
"Dein Wichtelsystem" + "\n" +
"\n" + "\n" +
"--Bitte beachtet, dass ungefähr für 25€ gewichtelt wird--");
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,49 @@
package de.kaabp.parser;
import de.kaabp.util.Person;
import de.kaabp.util.personCreate;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ReadCsv {
public List<Person> csvToList(String csv) {
List<Person> persons = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(csv))) {
// read the first line from the text file
String line = br.readLine();
// loop until all lines are read
while (line != null) {
// use string.split to load a string array with the values from
// each line of
// the file, using a comma as the delimiter
String[] attributes = line.split(",");
Person person = personCreate.createPerson(attributes);
// adding book into ArrayList
persons.add(person);
// read next line before looping
// if end of file reached, line would be null
line = br.readLine();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
return persons;
}
}

@ -0,0 +1,4 @@
package de.kaabp.parser;
public class ReadIni {
}

@ -0,0 +1,39 @@
package de.kaabp.parser;
import de.kaabp.util.Person;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
public class WriteCsv {
public static void updateLastMatch(File file, Person[] matches, List<Person> personList) {
if (matches.length == personList.size()) {
for (int i = 0; i < matches.length; i++) {
personList.get(i).setLastMatch(matches[i].getID());
}
}
writePersonListToCSV(file.toString(), personList);
}
private static void writePersonListToCSV(String csvFileName, List<Person> personList) {
try (FileWriter writer = new FileWriter(csvFileName)) {
for (Person person : personList) {
//System.out.println(person);
// Create a CSV row for each Person object
String csvRow = String.format("%d,%s,%s,%s,%d%n",
person.getID(), person.getName(), person.getEmail(), person.getGroups(), person.getLastMatch());
writer.write(csvRow);
}
System.out.println("Data has been written to " + csvFileName);
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,49 @@
package de.kaabp.util;
import java.util.*;
public class Matching {
public static Person[] matchPeople(List<Person> personList, List<Person> matchedPeople, Person[] matches) {
List<Person> cpPersonalList = new ArrayList<>(personList);
Collections.shuffle(cpPersonalList);
Collections.shuffle(personList);
while (!personList.isEmpty()) {
Person p = personList.get(0);
boolean foundMatch = false;
for (Person m : cpPersonalList) {
if (isMatchValid(p, m, matchedPeople)) {
matchedPeople.add(m);
matches[p.getID()] = m;
personList.remove(p); // Remove the matched person from the list
System.out.println(p.getName() + "->" + m.getName());
foundMatch = true;
break;
}
}
if (!foundMatch) {
System.out.println("Error: No valid match found for " + p.getName());
Arrays.fill(matches, null);
matchedPeople.clear();
personList = new ArrayList<>(cpPersonalList);
Collections.shuffle(personList);
}
}
return matches;
}
private static boolean isMatchValid(Person p1, Person p2, List<Person> matchedPeople) {
return p1.getID() != p2.getID() && !Objects.equals(p1.getGroups(), p2.getGroups()) && !matchedPeople.contains(p2);
}
}

@ -0,0 +1,68 @@
package de.kaabp.util;
public class Person {
private int ID;
private String name;
private String email;
private String groups;
private int lastMatch;
public Person(int ID, String name, String email, String groups, int lastMatch) {
this.ID = ID;
this.name = name;
this.email = email;
this.groups = groups;
this.lastMatch = lastMatch;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGroups() {
return groups;
}
public void setGroups(String groups) {
this.groups = groups;
}
public int getLastMatch() {
return lastMatch;
}
public void setLastMatch(int lastMatch) {
this.lastMatch = lastMatch;
}
@Override
public String toString() {
return "Person{" +
"ID=" + ID +
", name='" + name + '\'' +
", email='" + email + '\'' +
", groups=" + groups +
", lastMatch=" + lastMatch +
'}';
}
}

@ -0,0 +1,15 @@
package de.kaabp.util;
public class personCreate {
public static Person createPerson(String[] metadata) {
int ID = Integer.parseInt(metadata[0]);
String name = metadata[1];
String email = metadata[2];
String groups = metadata[3];
int lastMatch = Integer.parseInt(metadata[4]);
return new Person(ID, name, email, groups, lastMatch);
}
}
Loading…
Cancel
Save