-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanning.java
More file actions
107 lines (96 loc) · 3.93 KB
/
Scanning.java
File metadata and controls
107 lines (96 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package scanning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
public class Scanning {
private static final Logger logger = LoggerFactory.getLogger(Scanning.class);
public String getFileNamePartByWordLookupMatch(List<String> pdfWordList, List<LookupWordsTO> lookupWordsList) throws NoMatchingLookupWordsException {
for (LookupWordsTO lookupWordsTO : lookupWordsList) {
// logger.debug(lookupWordsTO.toString());
int lookupWordList = lookupWordsTO.getWordList().size();
//logger.debug("LookupWordlist size: "+ lookupWordList);
int countWordMatches = countMatch(lookupWordsTO.getWordList(), pdfWordList);
//logger.debug("Words matching: " +countWordMatches);
if (lookupWordList == countWordMatches) {
logger.debug("--> Full Match!");
return lookupWordsTO.getzielKategorie()+"_"+lookupWordsTO.getzielName();
}
}
throw new NoMatchingLookupWordsException();
}
public String getFileNamePartByDateLookup(String pdfText) {
return getRelevantDateFromString(pdfText);
}
private static int countMatch(List<String> list1,List<String> list2) {
//List<String> list1 = new ArrayList(Arrays.asList(a));
//List<String> list2 = Arrays.asList(b);
list1.retainAll(list2);
return list1.size();
}
public String getRelevantDateFromString(String input) {
//String input = "coming from the 01.12.1988 to the 12.01.2000";
String[] elements = input.split(" ");
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd.MM.yyyy");
List<LocalDate> dates = new ArrayList<>();
for (String element : elements) {
try {
//logger.debug(element);
element = cleanElementForDateRecon(element);
LocalDate ld = LocalDate.parse(element, f);
dates.add(ld);
logger.debug(String.valueOf(ld));
} catch (DateTimeParseException e) {
// Ignore the exception. Move on to next element.
}
}
//Collections.sort(dates, Collections.reverseOrder());
LocalDate xmin = LocalDate.parse("2010-01-01"); //default, ISO_LOCAL_DATE
//logger.debug("XMIN: " +xmin);
//logger.debug("Anzahl Datum: " +dates.size());
for (ListIterator<LocalDate> iter = dates.listIterator(); iter.hasNext(); ) {
LocalDate datum = iter.next();
if (datum.isBefore(xmin)) {
logger.debug("delete");
iter.remove();
}
}
//logger.debug("Anzahl Datum: " +dates.size());
Collections.sort(dates);
//System.out.println(dates);
if (dates.size() >0) {
System.out.println(dates.get(0));
return String.valueOf(dates.get(0)).replace("-", "_");
} else {
return null;
}
}
public String cleanElementForDateRecon(String element) {
//26.07.2018-31
if (element.contains(".2018-")) {
return element.substring(0,element.indexOf(".2018-")+5);
}
return element;
}
public void renameFile(String oldNameAndPath, String newNameAndPath) {
Path sourcePath = Paths.get(oldNameAndPath);
Path destinationPath = Paths.get(newNameAndPath);
try {
Files.move(sourcePath, destinationPath,
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
//moving file failed.
e.printStackTrace();
}
}
}