bugfix and responsability relocation
This commit is contained in:
parent
e719a8dd4f
commit
f206289dba
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>tv.mangrana</groupId>
|
<groupId>tv.mangrana</groupId>
|
||||||
<artifactId>mangrana-commons</artifactId>
|
<artifactId>mangrana-commons</artifactId>
|
||||||
<version>3.1.3</version>
|
<version>3.1.5</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class GoogleDriveApiGateway {
|
||||||
"'"+parent.getId()+"' in parents";
|
"'"+parent.getId()+"' in parents";
|
||||||
List<File> children = getChildrenCommonCall(query);
|
List<File> children = getChildrenCommonCall(query);
|
||||||
if (children.isEmpty()) throw new NoElementFoundException("no elements in the list xO");
|
if (children.isEmpty()) throw new NoElementFoundException("no elements in the list xO");
|
||||||
if (children.size() > 1) log("WARNING: more than one element here not expected");
|
if (children.size() > 1) log("WARNING: more than one element here not expected for <{0}> and parent <{1}>", name, parent.getName());
|
||||||
return children.get(0);
|
return children.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +114,17 @@ public class GoogleDriveApiGateway {
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void moveFile(File file, String destinationFolderId, String newName) throws IOException {
|
||||||
|
File newFileReference = new File();
|
||||||
|
newFileReference.setName(newName);
|
||||||
|
service.files()
|
||||||
|
.update(file.getId(), newFileReference)
|
||||||
|
.setAddParents(destinationFolderId)
|
||||||
|
.setRemoveParents(file.getParents().get(0))
|
||||||
|
.setSupportsTeamDrives(true)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
public File createFolder(String name, String parentFolderId) throws IOException {
|
public File createFolder(String name, String parentFolderId) throws IOException {
|
||||||
File fileMetadata = new File();
|
File fileMetadata = new File();
|
||||||
fileMetadata.setName(name);
|
fileMetadata.setName(name);
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
package tv.mangrana.jobs;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static tv.mangrana.utils.Output.DATE_TIME_FORMAT;
|
||||||
|
|
||||||
|
public class JobsFileStorage {
|
||||||
|
|
||||||
|
static final String COMPLETED_DATE = "done";
|
||||||
|
static final String JOB_TYPE = "type";
|
||||||
|
static final String HASH = "hash";
|
||||||
|
static final String ARR_ID = "arrId";
|
||||||
|
static final String INTERNET_DB_ID = "iId";
|
||||||
|
static final String ELEMENT_NAME = "element";
|
||||||
|
|
||||||
|
public final String JOB_LINE_FORMAT;
|
||||||
|
|
||||||
|
public JobsFileStorage() {
|
||||||
|
String preFormat = "{COMPLETED_DATE}: {5} | {JOB_TYPE}: {0} | {HASH}: {1} | {ARR_ID}: {2} | {INTERNET_DB_ID}: {3} | {ELEMENT_NAME}: {4}";
|
||||||
|
JOB_LINE_FORMAT = preFormat
|
||||||
|
.replace("{COMPLETED_DATE}", COMPLETED_DATE)
|
||||||
|
.replace("{JOB_TYPE}", JOB_TYPE)
|
||||||
|
.replace("{HASH}", HASH)
|
||||||
|
.replace("{ARR_ID}", ARR_ID)
|
||||||
|
.replace("{INTERNET_DB_ID}", INTERNET_DB_ID)
|
||||||
|
.replace("{ELEMENT_NAME}", ELEMENT_NAME);
|
||||||
|
}
|
||||||
|
String resumeFile = JobFileManager.getResumeFile();
|
||||||
|
|
||||||
|
public void persistCompleted(String type, String downloadId, int arrId, int iId, String element, LocalDateTime time){
|
||||||
|
String jobLine = MessageFormat.format(JOB_LINE_FORMAT,
|
||||||
|
type,
|
||||||
|
downloadId,
|
||||||
|
fixLength(String.valueOf(arrId)),
|
||||||
|
fixLength(String.valueOf(iId)),
|
||||||
|
element,
|
||||||
|
formatTime(time));
|
||||||
|
addLine(jobLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fixLength(String text) {
|
||||||
|
return StringUtils.rightPad(text, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addLine(String jobLine) {
|
||||||
|
try (FileWriter fw = new FileWriter(resumeFile, true);
|
||||||
|
PrintWriter pw = new PrintWriter(fw)) {
|
||||||
|
|
||||||
|
pw.println(jobLine);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIIDByElement(String element) {
|
||||||
|
try (Stream<String> linesStream = Files.lines(Paths.get(resumeFile))) {
|
||||||
|
return linesStream
|
||||||
|
.map(this::line2Map)
|
||||||
|
.filter(mappedLine -> mappedLine.get(ELEMENT_NAME).equals(element))
|
||||||
|
.findAny()
|
||||||
|
.map(found -> found.get(INTERNET_DB_ID))
|
||||||
|
.orElse(null);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> line2Map(String line) {
|
||||||
|
Map<String, String> mappedLine = new HashMap<>();
|
||||||
|
String[] infoList = line.split("\\|");
|
||||||
|
for (String elementInfo : infoList) {
|
||||||
|
if (!elementInfo.trim().startsWith(COMPLETED_DATE)) {
|
||||||
|
String[] fieldValue = elementInfo.split(":");
|
||||||
|
String field = fieldValue[0].trim();
|
||||||
|
String value = fieldValue[1].trim();
|
||||||
|
mappedLine.put(field, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mappedLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
String formatTime(LocalDateTime time) {
|
||||||
|
return time.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -62,6 +62,11 @@ public class FakeYmlLoader {
|
||||||
Map<String, String> keyValueMap = new HashMap<>();
|
Map<String, String> keyValueMap = new HashMap<>();
|
||||||
stringStream.forEach(line -> {
|
stringStream.forEach(line -> {
|
||||||
try {
|
try {
|
||||||
|
int firstPosition = line.indexOf(':');
|
||||||
|
if (firstPosition != line.lastIndexOf(':')) {
|
||||||
|
line = line.replace(':', '-');
|
||||||
|
line = line.replaceFirst("-", ":");
|
||||||
|
}
|
||||||
String[] keyValue = line.split(":");
|
String[] keyValue = line.split(":");
|
||||||
keyValueMap.put(keyValue[0], keyValue[1].trim());
|
keyValueMap.put(keyValue[0], keyValue[1].trim());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue