Skip to content

Commit

Permalink
Merge pull request #116 from PAException/dev
Browse files Browse the repository at this point in the history
Roll 1.0.0 to production
  • Loading branch information
PAException authored Nov 22, 2023
2 parents 6fa7978 + 1a9fa51 commit 536e1f8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SubstituteMessageModel {
@Setter(AccessLevel.NONE)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int substituteMessageId;
private long substituteMessageId;

@NotNull
@Column(unique = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ public class SubstituteModel {
@Setter(AccessLevel.NONE)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int substituteId;
private long substituteId;

@NotNull
private Date date;
@NotBlank
private String className;
private int lesson;
private String subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import io.github.paexception.engelsburg.api.endpoint.dto.response.SubstituteNotificationDTO;
import io.github.paexception.engelsburg.api.util.LoggingComponent;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.validation.constraints.NotNull;
import java.time.Duration;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -82,32 +87,31 @@ private static List<String> splitClasses(String className) {
* @return formatted text
*/
private static String getSubstituteText(@NotNull SubstituteNotificationDTO substitute) {
return (substitute.getClassName() == null ? "" : substitute.getClassName()) +
(substitute.getClassName() == null ? "" : " – ") +
(substitute.getSubject() == null ? "" : substitute.getSubject()) + " (" +
(substitute.getSubstituteTeacher() == null || substitute.getSubstituteTeacher().equals("+")
? ""
: substitute.getSubstituteTeacher()) +
(substitute.getSubstituteTeacher() != null &&
!substitute.getSubstituteTeacher().equals("+") &&
substitute.getTeacher() == null
? ")"
: "") +
(substitute.getSubstituteTeacher() != null &&
!substitute.getSubstituteTeacher().equals("+") &&
substitute.getTeacher() != null &&
!substitute.getSubstituteTeacher().equals(substitute.getTeacher())
? " statt "
: "") +
(substitute.getTeacher() == null || substitute.getTeacher().equals(substitute.getSubstituteTeacher())
? ""
: substitute.getTeacher()) +
(substitute.getTeacher() != null ? ")" : "") +
(substitute.getRoom() == null ? "" : " in " + substitute.getRoom()) +
(substitute.getText() == null || substitute.getText().isEmpty()
? ""
: " – " + substitute.getText()) +
(substitute.getSubstituteOf() == null ? "" : " – " + substitute.getSubstituteOf());
String lesson = "[" + substitute.getLesson() + "]";
String type = " " + substitute.getType();
String className = "";
if (substitute.getClassName() != null) className = " - " + substitute.getClassName();

String subject = "";
if (substitute.getSubject() != null) subject = " - " + substitute.getSubject();

String teachers = "";
if (substitute.getTeacher() != null && substitute.getSubstituteTeacher() != null) {
teachers = " (" + substitute.getSubstituteTeacher() + " statt " + substitute.getTeacher() + ")";
} else if (substitute.getSubstituteTeacher() != null) {
teachers = " (" + substitute.getSubstituteTeacher() + ")";
}

String room = "";
if (substitute.getRoom() != null) room = " in " + substitute.getRoom();

String text = "";
if (substitute.getText() != null) text = " - " + substitute.getText();

String substituteOf = "";
if (substitute.getSubstituteOf() != null) substituteOf = " - " + substitute.getSubstituteOf();

return lesson + type + className + subject + teachers + room + text + substituteOf;
}

/**
Expand All @@ -118,8 +122,17 @@ private static String getSubstituteText(@NotNull SubstituteNotificationDTO subst
* @return title
*/
private static String getSubstituteTitle(SubstituteNotificationDTO substitute, boolean created) {
return (!created ? "Geändert" + ": " : "")
+ substitute.getLesson() + " " + substitute.getType();
String actuality = created ? "Neue" : "Geänderte";
String relationalDay;
if (DateUtils.isSameDay(substitute.getDate(), Date.from(Instant.now()))) {
relationalDay = "heute";
} else if (DateUtils.isSameDay(substitute.getDate(), Date.from(Instant.now().plus(Duration.ofDays(1))))) {
relationalDay = "morgen";
} else {
relationalDay = "den " + DateTimeFormatter.ofPattern("dd.MM.").format(substitute.getDate().toInstant());
}

return actuality + " Vertretung für " + relationalDay;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public void updateSubstitutes() {

//If the row does not contain a className then this row is used to extend the text from
// the previous substitute, so it needs to be added to the latest substitute
String className = row.child(0).text();
if (!substitutes.isEmpty() && !className.matches("(.*)[0-9](.*)")) {
String lesson = row.child(1).text();
if (!substitutes.isEmpty() && !lesson.matches("(.*)[0-9](.*)")) {
this.appendTextOnLastSubstitute(row, substitutes);
String appendedText = substitutes.get(substitutes.size() - 1).getText();

Expand All @@ -195,8 +195,6 @@ public void updateSubstitutes() {
for (int i = 1; i <= splitSubstitute; i++) {
substitutes.get(substitutes.size() - 1 - i).setText(appendedText);
}

splitSubstitute = 0;
} else {
var newDtos = this.createSubstituteDTOs(row, currentDate);

Expand Down Expand Up @@ -252,7 +250,6 @@ else if (entry.text().startsWith("Abwesende Klassen"))
dayAndMonth = rawDate.substring(0, rawDate.lastIndexOf('.'));
currentDate = this.parseDate(dayAndMonth, weeks.get(week));
LOGGER.trace("[SUBSTITUTE] Switching to new date: " + dayAndMonth + "." + weeks.get(week));
System.out.println("[SUBSTITUTE] Switching to new date: " + dayAndMonth + "." + weeks.get(week));
}
}
}
Expand All @@ -277,7 +274,7 @@ private List<SubstituteDTO> createSubstituteDTOs(Element row, Date currentDate)
List<SubstituteDTO> dtos = new ArrayList<>();
SubstituteDTO dto = new SubstituteDTO();
dto.setDate(currentDate);
dto.setClassName(row.child(0).text());
if (row.child(0).text().matches("(.*)[0-9](.*)")) dto.setClassName(row.child(0).text());
String lessons = row.child(1).text().replace(" ", "");
if (lessons.contains("-")) { //5 - 6, //3 - 6
int low = Integer.parseInt(lessons.substring(0, lessons.indexOf("-"))),
Expand Down

0 comments on commit 536e1f8

Please sign in to comment.