diff --git a/.gitignore b/.gitignore
index 32bcbc8..1783511 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
/.idea/
/target/
.DS_Store
-/MangranaCommons.iml
-/tokens/
-/src/main/resources/credentials.json
+/MangranaCommons.iml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d7039b6..adaee2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
tv.mangrana
mangrana-commons
- 4.1.3
+ 6.0.0
8
@@ -43,25 +43,6 @@
4.4
-
-
- com.google.apis
- google-api-services-drive
- v3-rev20220508-1.32.1
-
-
-
- com.google.api-client
- google-api-client
- 1.35.1
-
-
-
- com.google.oauth-client
- google-oauth-client-jetty
- 1.34.1
-
-
org.testng
diff --git a/src/main/java/org/o7planning/googledrive/example/GoogleDriveUtils.java b/src/main/java/org/o7planning/googledrive/example/GoogleDriveUtils.java
deleted file mode 100644
index a7a5567..0000000
--- a/src/main/java/org/o7planning/googledrive/example/GoogleDriveUtils.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.o7planning.googledrive.example;
-
-
-import com.google.api.client.auth.oauth2.Credential;
-import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
-import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
-import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
-import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
-import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
-import com.google.api.client.http.HttpTransport;
-import com.google.api.client.json.JsonFactory;
-import com.google.api.client.json.gson.GsonFactory;
-import com.google.api.client.util.store.FileDataStoreFactory;
-import com.google.api.services.drive.Drive;
-import com.google.api.services.drive.DriveScopes;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Collections;
-import java.util.List;
-
-import static tv.mangrana.utils.Output.log;
-
-public class GoogleDriveUtils {
-
- private static final String APPLICATION_NAME = "Google Drive API Java Quickstart";
-
- private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
-
- private static final List SCOPES = Collections.singletonList(DriveScopes.DRIVE);
-
- private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
-
- private static final String TOKENS_DIRECTORY_PATH = "tokens";
-
- // Global instance of the HTTP transport.
- private static HttpTransport HTTP_TRANSPORT;
-
- private static Drive _driveService;
-
- static {
- try {
- HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
- } catch (Throwable t) {
- t.printStackTrace();
- System.exit(1);
- }
- }
-
- public static Credential getCredentials() throws IOException {
-
- // Load client secrets.
- InputStream in = GoogleDriveUtils.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
- if (in == null) {
- throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
- }
- GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
-
- // Build flow and trigger user authorization request.
- GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
- HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
- .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
- .setAccessType("offline")
- .build();
- LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
- Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
- //returns an authorized Credential object.
- return credential;
- }
-
- public static Drive getDriveService() throws IOException {
- if (_driveService != null) {
- return _driveService;
- }
- Credential credential = getCredentials();
- //
- _driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) //
- .setApplicationName(APPLICATION_NAME).build();
- log("Google Drive service initialized");
- return _driveService;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/tv/mangrana/google/api/client/QuickTester.java b/src/main/java/tv/mangrana/google/api/client/QuickTester.java
deleted file mode 100644
index 5c2576a..0000000
--- a/src/main/java/tv/mangrana/google/api/client/QuickTester.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package tv.mangrana.google.api.client;
-
-import tv.mangrana.exception.NoElementFoundException;
-import com.google.api.services.drive.Drive;
-import com.google.api.services.drive.model.TeamDrive;
-import org.o7planning.googledrive.example.GoogleDriveUtils;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Optional;
-
-import static tv.mangrana.utils.Output.log;
-
-public class QuickTester {
-
- public static void main(String[] args) throws IOException, NoElementFoundException {
- new QuickTester()
- .listTDs();
- }
-
- public QuickTester() throws IOException {
- service = GoogleDriveUtils.getDriveService();
- }
-
- Drive service;
-
- private void listTDs() throws IOException, NoElementFoundException {
- List list = Optional.ofNullable(
- service.teamdrives().list().execute().getTeamDrives())
- .orElseThrow(() -> new NoElementFoundException("No TDs found :("));
-
- list.forEach(td -> log(td.getName()));
- log("Ok, if you have been seeing some TDs in the output, that means GoogleDriveUtils works \uD83D\uDC4D");
- }
-
-}
diff --git a/src/main/java/tv/mangrana/google/api/client/gateway/GoogleDriveApiGateway.java b/src/main/java/tv/mangrana/google/api/client/gateway/GoogleDriveApiGateway.java
deleted file mode 100644
index 91f2ca1..0000000
--- a/src/main/java/tv/mangrana/google/api/client/gateway/GoogleDriveApiGateway.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package tv.mangrana.google.api.client.gateway;
-
-import tv.mangrana.exception.NoElementFoundException;
-import com.google.api.services.drive.Drive;
-import com.google.api.services.drive.model.File;
-import com.google.api.services.drive.model.FileList;
-import org.apache.commons.collections4.CollectionUtils;
-import org.o7planning.googledrive.example.GoogleDriveUtils;
-
-import java.io.IOException;
-import java.util.*;
-
-import static tv.mangrana.utils.Output.log;
-
-public class GoogleDriveApiGateway {
-
- Drive service;
-
- public enum GoogleElementType {FOLDER, VIDEO}
-
- public GoogleDriveApiGateway() throws IOException {
- service = GoogleDriveUtils.getDriveService();
- }
-
- public File lookupElementById(String elementId) throws IOException {
- return service.files()
- .get(elementId)
- .setSupportsTeamDrives(true)
- .execute();
- }
-
- public File lookupElementByName(String elementName, GoogleElementType type, String relatedTeamDriveId) throws IOException, NoElementFoundException {
- String query = "name = '" + elementName.replace("'","\\'") + "'"
- + " and trashed=false"
- + getTypeFilterQuery(type);
-
- FileList fileList =
- service.files()
- .list()
- .setCorpora("drive")
- .setTeamDriveId(relatedTeamDriveId)
- .setIncludeItemsFromAllDrives(true)
- .setSupportsTeamDrives(true)
- .setQ(query)
- .execute();
-
- List files = Optional.ofNullable(
- fileList.getFiles())
- .orElseThrow(() -> new NoElementFoundException("element not found by name: " + elementName));
-
- if (CollectionUtils.isNotEmpty(files)) {
- if (files.size() > 1) {
- log("WARN: There are more than one matching element!!!");
- files.forEach(fl -> log("> element with name {0} an id {1}", fl.getName(), fl.getId()));
- }
- return files.get(0);
- } else {
- throw new NoElementFoundException("no elements in the list xO");
- }
- }
-
- public List getChildrenFromParent(File parent, boolean onlyFolders) {
- String query =
- "trashed=false and "+
- (onlyFolders ? "mimeType = 'application/vnd.google-apps.folder' and " : "")+
- "'"+parent.getId()+"' in parents";
-
- return getChildrenCommonCall(query);
- }
-
- public File getChildFromParentByName(String name, File parent, boolean onlyFolder) throws NoElementFoundException {
- String query = "name = '" + name.replace("'","\\'") + "'" +
- " and trashed=false and "+
- (onlyFolder ? "mimeType = 'application/vnd.google-apps.folder' and " : "")+
- "'"+parent.getId()+"' in parents";
- List children = getChildrenCommonCall(query);
- 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 for <{0}> and parent <{1}>", name, parent.getName());
- return children.get(0);
- }
-
- private List getChildrenCommonCall(String query) {
- List fullFileList = new ArrayList<>();
- String pageToken = null;
- do {
- try {
- FileList fileList = service.files()
- .list()
- .setQ(query)
- .setIncludeItemsFromAllDrives(true)
- .setSupportsTeamDrives(true)
- .setFields("nextPageToken, files(id, name)")
- .setPageToken(pageToken)
- .setOrderBy("name")
- .execute();
-
- fullFileList.addAll(fileList.getFiles());
- pageToken = fileList.getNextPageToken();
- } catch (IOException e) {
- log("ERROR during api call");
- e.printStackTrace();
- }
- } while (pageToken != null);
-
- return fullFileList;
- }
-
- public void copyFile(String fileId, String destinationFolderId) throws IOException {
- File newFileReference = new File();
- newFileReference.setParents(Collections.singletonList(destinationFolderId));
- service.files()
- .copy(fileId, newFileReference)
- .setSupportsTeamDrives(true)
- .execute();
- }
-
- public void moveFile(File file, String destinationFolderId, String newFileName) throws IOException {
- String parentId = getParent(file.getId());
- File newFileReference = new File();
- newFileReference.setName(newFileName);
- service.files()
- .update(file.getId(), newFileReference)
- .setSupportsTeamDrives(true)
- .setAddParents(destinationFolderId)
- .setRemoveParents(parentId)
- .setFields("id, name, parents")
- .execute();
- }
-
- private String getParent(String fileId) throws IOException {
- File file = service.files()
- .get(fileId)
- .setFields("parents")
- .setSupportsTeamDrives(true)
- .execute();
- return file.getParents().get(0);
- }
-
- public File createFolder(String name, String parentFolderId) throws IOException {
- File fileMetadata = new File();
- fileMetadata.setName(name);
- fileMetadata.setMimeType("application/vnd.google-apps.folder");
- fileMetadata.setParents(Collections.singletonList(parentFolderId));
- return service
- .files()
- .create(fileMetadata)
- .setSupportsTeamDrives(true)
- .execute();
- }
-
- private String getTypeFilterQuery(GoogleElementType type) {
- switch (type) {
- case VIDEO:
- return " and mimeType contains 'video'";
- case FOLDER:
- return " and mimeType = 'application/vnd.google-apps.folder'";
- default:
- return "";
- }
- }
-
-}
diff --git a/src/main/java/tv/mangrana/jobs/JobsFileStorage.java b/src/main/java/tv/mangrana/jobs/JobsFileStorage.java
index e0d3d50..579b4c2 100644
--- a/src/main/java/tv/mangrana/jobs/JobsFileStorage.java
+++ b/src/main/java/tv/mangrana/jobs/JobsFileStorage.java
@@ -1,6 +1,7 @@
package tv.mangrana.jobs;
import org.apache.commons.lang.StringUtils;
+import tv.mangrana.exception.IncorrectWorkingReferencesException;
import java.io.FileWriter;
import java.io.IOException;
@@ -10,7 +11,9 @@ import java.nio.file.Paths;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -26,8 +29,11 @@ public class JobsFileStorage {
static final String ELEMENT_NAME = "element";
public final String JOB_LINE_FORMAT;
+ private static final String RESUME_FILE = JobFileManager.getResumeFile();
- public JobsFileStorage() {
+ private final List