This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 3c8edbc5bc NIFI-14303 Added More Metadata Attributes to Google Drive
Processors (#9779)
3c8edbc5bc is described below
commit 3c8edbc5bcda929a5e478512a6c5b00e15350159
Author: Peter Turcsanyi <[email protected]>
AuthorDate: Thu Mar 6 20:28:14 2025 +0100
NIFI-14303 Added More Metadata Attributes to Google Drive Processors (#9779)
- Added drive.created.time and drive.modified.time in
List/Fetch/PutGoogleDrive
- Added drive.path, drive.owner, drive.last.modifying.user,
drive.web.view.link, drive.web.content.link in ListGoogleDrive
- Fixed drive.timestamp in Fetch/PutGoogleDrive
Signed-off-by: David Handermann <[email protected]>
---
.../processors/gcp/drive/FetchGoogleDrive.java | 10 +-
.../gcp/drive/GoogleDriveAttributes.java | 23 +++
.../processors/gcp/drive/GoogleDriveFileInfo.java | 113 +++++++++++++-
.../gcp/drive/GoogleDriveFlowFileAttribute.java | 50 ------
.../processors/gcp/drive/GoogleDriveTrait.java | 26 ++--
.../nifi/processors/gcp/drive/ListGoogleDrive.java | 98 ++++++++----
.../nifi/processors/gcp/drive/PutGoogleDrive.java | 12 +-
.../gcp/drive/AbstractGoogleDriveTest.java | 9 +-
.../processors/gcp/drive/FetchGoogleDriveIT.java | 13 +-
.../processors/gcp/drive/FetchGoogleDriveTest.java | 4 +-
.../gcp/drive/ListGoogleDrivePathTest.java | 173 +++++++++++++++++++++
.../gcp/drive/ListGoogleDriveSimpleTest.java | 59 ++++++-
.../gcp/drive/ListGoogleDriveTestRunnerTest.java | 101 ++++++++++--
.../nifi/processors/gcp/drive/OutputChecker.java | 9 +-
.../processors/gcp/drive/PutGoogleDriveIT.java | 6 +-
.../processors/gcp/drive/PutGoogleDriveTest.java | 4 +-
16 files changed, 566 insertions(+), 144 deletions(-)
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDrive.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDrive.java
index 6bedfe3865..aabcb6e955 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDrive.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDrive.java
@@ -56,6 +56,8 @@ import
org.apache.nifi.processors.gcp.ProxyAwareTransportFactory;
import org.apache.nifi.processors.gcp.util.GoogleUtils;
import org.apache.nifi.proxy.ProxyConfiguration;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_CODE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_CODE_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_MESSAGE;
@@ -64,6 +66,8 @@ import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAM
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME_DESC;
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE_DESC;
@@ -84,6 +88,8 @@ import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTA
@WritesAttribute(attribute = SIZE, description = SIZE_DESC),
@WritesAttribute(attribute = SIZE_AVAILABLE, description =
SIZE_AVAILABLE_DESC),
@WritesAttribute(attribute = TIMESTAMP, description = TIMESTAMP_DESC),
+ @WritesAttribute(attribute = CREATED_TIME, description =
CREATED_TIME_DESC),
+ @WritesAttribute(attribute = MODIFIED_TIME, description =
MODIFIED_TIME_DESC),
@WritesAttribute(attribute = ERROR_CODE, description =
ERROR_CODE_DESC),
@WritesAttribute(attribute = ERROR_MESSAGE, description =
ERROR_MESSAGE_DESC)
})
@@ -285,7 +291,7 @@ public class FetchGoogleDrive extends AbstractProcessor
implements GoogleDriveTr
final long startNanos = System.nanoTime();
try {
final File fileMetadata = fetchFileMetadata(fileId);
- final Map<String, String> attributeMap =
createAttributeMap(fileMetadata);
+ final Map<String, String> attributeMap =
createGoogleDriveFileInfoBuilder(fileMetadata).build().toAttributeMap();
flowFile = fetchFile(fileMetadata, session, context, flowFile,
attributeMap);
@@ -401,7 +407,7 @@ public class FetchGoogleDrive extends AbstractProcessor
implements GoogleDriveTr
.files()
.get(fileId)
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size,
exportLinks")
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size, exportLinks")
.execute();
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveAttributes.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveAttributes.java
index 82fc4b239b..361615e415 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveAttributes.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveAttributes.java
@@ -37,9 +37,32 @@ public class GoogleDriveAttributes {
" The reason for this is that the original modified date of a file
is preserved when uploaded to Google Drive." +
" 'Created time' takes the time when the upload occurs. However
uploaded files can still be modified later.";
+ public static final String CREATED_TIME = "drive.created.time";
+ public static final String CREATED_TIME_DESC = "The file's creation time";
+
+ public static final String MODIFIED_TIME = "drive.modified.time";
+ public static final String MODIFIED_TIME_DESC = "The file's last
modification time";
+
public static final String MIME_TYPE = CoreAttributes.MIME_TYPE.key();
public static final String MIME_TYPE_DESC = "The MIME type of the file";
+ public static final String PATH = "drive.path";
+ public static final String PATH_DESC = "The path of the file's directory
from the base directory. The path contains the folder names" +
+ " in URL encoded form because Google Drive allows special
characters in file names, including '/' (slash) and '\\' (backslash)." +
+ " The URL encoded folder names are separated by '/' in the path.";
+
+ public static final String OWNER = "drive.owner";
+ public static final String OWNER_DESC = "The owner of the file";
+
+ public static final String LAST_MODIFYING_USER =
"drive.last.modifying.user";
+ public static final String LAST_MODIFYING_USER_DESC = "The last modifying
user of the file";
+
+ public static final String WEB_VIEW_LINK = "drive.web.view.link";
+ public static final String WEB_VIEW_LINK_DESC = "Web view link to the
file";
+
+ public static final String WEB_CONTENT_LINK = "drive.web.content.link";
+ public static final String WEB_CONTENT_LINK_DESC = "Web content link to
the file";
+
public static final String ERROR_MESSAGE = "error.message";
public static final String ERROR_MESSAGE_DESC = "The error message
returned by Google Drive";
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFileInfo.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFileInfo.java
index 12058dcbed..7b84807dbd 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFileInfo.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFileInfo.java
@@ -16,13 +16,6 @@
*/
package org.apache.nifi.processors.gcp.drive;
-import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME;
-import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
-import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE;
-import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
-import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
-import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTAMP;
-
import org.apache.nifi.processor.util.list.ListableEntity;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.apache.nifi.serialization.record.MapRecord;
@@ -31,10 +24,26 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.LAST_MODIFYING_USER;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.OWNER;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.PATH;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTAMP;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_CONTENT_LINK;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_VIEW_LINK;
public class GoogleDriveFileInfo implements ListableEntity {
private static final RecordSchema SCHEMA;
@@ -47,7 +56,14 @@ public class GoogleDriveFileInfo implements ListableEntity {
recordFields.add(new RecordField(SIZE,
RecordFieldType.LONG.getDataType(), false));
recordFields.add(new RecordField(SIZE_AVAILABLE,
RecordFieldType.BOOLEAN.getDataType(), false));
recordFields.add(new RecordField(TIMESTAMP,
RecordFieldType.LONG.getDataType(), false));
+ recordFields.add(new RecordField(CREATED_TIME,
RecordFieldType.STRING.getDataType(), false));
+ recordFields.add(new RecordField(MODIFIED_TIME,
RecordFieldType.STRING.getDataType(), false));
recordFields.add(new RecordField(MIME_TYPE,
RecordFieldType.STRING.getDataType()));
+ recordFields.add(new RecordField(PATH,
RecordFieldType.STRING.getDataType(), true));
+ recordFields.add(new RecordField(OWNER,
RecordFieldType.STRING.getDataType(), true));
+ recordFields.add(new RecordField(LAST_MODIFYING_USER,
RecordFieldType.STRING.getDataType(), true));
+ recordFields.add(new RecordField(WEB_VIEW_LINK,
RecordFieldType.STRING.getDataType(), true));
+ recordFields.add(new RecordField(WEB_CONTENT_LINK,
RecordFieldType.STRING.getDataType(), true));
SCHEMA = new SimpleRecordSchema(recordFields);
}
@@ -60,6 +76,12 @@ public class GoogleDriveFileInfo implements ListableEntity {
private final long modifiedTime;
private final String mimeType;
+ private final String path;
+ private final String owner;
+ private final String lastModifyingUser;
+ private final String webViewLink;
+ private final String webContentLink;
+
public String getId() {
return id;
}
@@ -84,18 +106,58 @@ public class GoogleDriveFileInfo implements ListableEntity
{
return mimeType;
}
+ public String getPath() {
+ return path;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public String getLastModifyingUser() {
+ return lastModifyingUser;
+ }
+
+ public String getWebViewLink() {
+ return webViewLink;
+ }
+
+ public String getWebContentLink() {
+ return webContentLink;
+ }
+
@Override
public Record toRecord() {
+ return new MapRecord(SCHEMA, toMap());
+ }
+
+ private Map<String, Object> toMap() {
final Map<String, Object> values = new HashMap<>();
values.put(ID, getId());
values.put(FILENAME, getName());
values.put(SIZE, getSize());
values.put(SIZE_AVAILABLE, isSizeAvailable());
+ values.put(CREATED_TIME,
Instant.ofEpochMilli(getCreatedTime()).toString());
+ values.put(MODIFIED_TIME,
Instant.ofEpochMilli(getModifiedTime()).toString());
values.put(TIMESTAMP, getTimestamp());
values.put(MIME_TYPE, getMimeType());
+ values.put(PATH, getPath());
+ values.put(OWNER, getOwner());
+ values.put(LAST_MODIFYING_USER, getLastModifyingUser());
+ values.put(WEB_VIEW_LINK, getWebViewLink());
+ values.put(WEB_CONTENT_LINK, getWebContentLink());
- return new MapRecord(SCHEMA, values);
+ return values;
+ }
+
+ public Map<String, String> toAttributeMap() {
+ return toMap().entrySet().stream()
+ .filter(e -> e.getValue() != null)
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
+ e -> e.getValue().toString()
+ ));
}
public static RecordSchema getRecordSchema() {
@@ -110,6 +172,11 @@ public class GoogleDriveFileInfo implements ListableEntity
{
private long createdTime;
private long modifiedTime;
private String mimeType;
+ private String path;
+ private String owner;
+ private String lastModifyingUser;
+ private String webViewLink;
+ private String webContentLink;
public Builder id(String id) {
this.id = id;
@@ -146,6 +213,31 @@ public class GoogleDriveFileInfo implements ListableEntity
{
return this;
}
+ public Builder path(String path) {
+ this.path = path;
+ return this;
+ }
+
+ public Builder owner(String owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ public Builder lastModifyingUser(String lastModifyingUser) {
+ this.lastModifyingUser = lastModifyingUser;
+ return this;
+ }
+
+ public Builder webViewLink(String webViewLink) {
+ this.webViewLink = webViewLink;
+ return this;
+ }
+
+ public Builder webContentLink(String webContentLink) {
+ this.webContentLink = webContentLink;
+ return this;
+ }
+
public GoogleDriveFileInfo build() {
return new GoogleDriveFileInfo(this);
}
@@ -190,6 +282,11 @@ public class GoogleDriveFileInfo implements ListableEntity
{
this.createdTime = builder.createdTime;
this.modifiedTime = builder.modifiedTime;
this.mimeType = builder.mimeType;
+ this.path = builder.path;
+ this.owner = builder.owner;
+ this.lastModifyingUser = builder.lastModifyingUser;
+ this.webViewLink = builder.webViewLink;
+ this.webContentLink = builder.webContentLink;
}
@Override
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFlowFileAttribute.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFlowFileAttribute.java
deleted file mode 100644
index 6f363d5954..0000000000
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveFlowFileAttribute.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.processors.gcp.drive;
-
-import org.apache.nifi.serialization.record.Record;
-
-import java.util.function.Function;
-
-public enum GoogleDriveFlowFileAttribute {
- ID(GoogleDriveAttributes.ID, GoogleDriveFileInfo::getId),
- FILENAME(GoogleDriveAttributes.FILENAME, GoogleDriveFileInfo::getName),
- SIZE(GoogleDriveAttributes.SIZE, fileInfo ->
String.valueOf(fileInfo.getSize())),
- SIZE_AVAILABLE(GoogleDriveAttributes.SIZE_AVAILABLE, fileInfo ->
String.valueOf(fileInfo.isSizeAvailable())),
- TIMESTAMP(GoogleDriveAttributes.TIMESTAMP, fileInfo ->
String.valueOf(fileInfo.getTimestamp())),
- MIME_TYPE(GoogleDriveAttributes.MIME_TYPE,
GoogleDriveFileInfo::getMimeType);
-
- private final String name;
- private final Function<GoogleDriveFileInfo, String> fromFileInfo;
-
- GoogleDriveFlowFileAttribute(String attributeName,
Function<GoogleDriveFileInfo, String> fromFileInfo) {
- this.name = attributeName;
- this.fromFileInfo = fromFileInfo;
- }
-
- public String getName() {
- return name;
- }
-
- public String getValue(Record record) {
- return record.getAsString(name);
- }
-
- public String getValue(GoogleDriveFileInfo fileInfo) {
- return fromFileInfo.apply(fileInfo);
- }
-}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
index 56fe1767af..02fa6a6bd1 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
@@ -21,14 +21,13 @@ import com.google.api.client.http.HttpRequestInitializer;
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.DateTime;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.expression.ExpressionLanguageScope;
@@ -39,6 +38,7 @@ import org.apache.nifi.processors.gcp.util.GoogleUtils;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
public interface GoogleDriveTrait {
@@ -96,8 +96,8 @@ public interface GoogleDriveTrait {
public void initialize(HttpRequest request) throws IOException {
super.initialize(request);
- final int connectTimeout =
context.getProperty(CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
- final int readTimeout =
context.getProperty(READ_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ final int connectTimeout =
context.getProperty(CONNECT_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ final int readTimeout =
context.getProperty(READ_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS).intValue();
request.setConnectTimeout(connectTimeout);
request.setReadTimeout(readTimeout);
@@ -114,14 +114,14 @@ public interface GoogleDriveTrait {
return gcpCredentialsService.getGoogleCredentials();
}
- default Map<String, String> createAttributeMap(File file) {
- final Map<String, String> attributes = new HashMap<>();
- attributes.put(GoogleDriveAttributes.ID, file.getId());
- attributes.put(GoogleDriveAttributes.FILENAME, file.getName());
- attributes.put(GoogleDriveAttributes.MIME_TYPE, file.getMimeType());
- attributes.put(GoogleDriveAttributes.TIMESTAMP,
String.valueOf(file.getCreatedTime()));
- attributes.put(GoogleDriveAttributes.SIZE,
String.valueOf(file.getSize() != null ? file.getSize() : 0L));
- attributes.put(GoogleDriveAttributes.SIZE_AVAILABLE,
String.valueOf(file.getSize() != null));
- return attributes;
+ default GoogleDriveFileInfo.Builder createGoogleDriveFileInfoBuilder(final
File file) {
+ return new GoogleDriveFileInfo.Builder()
+ .id(file.getId())
+ .fileName(file.getName())
+ .size(file.getSize() != null ? file.getSize() : 0L)
+ .sizeAvailable(file.getSize() != null)
+
.createdTime(Optional.ofNullable(file.getCreatedTime()).map(DateTime::getValue).orElse(0L))
+
.modifiedTime(Optional.ofNullable(file.getModifiedTime()).map(DateTime::getValue).orElse(0L))
+ .mimeType(file.getMimeType());
}
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrive.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrive.java
index 07da9843f9..6a9dc0cc3a 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrive.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrive.java
@@ -17,11 +17,11 @@
package org.apache.nifi.processors.gcp.drive;
import com.google.api.client.http.HttpTransport;
-import com.google.api.client.util.DateTime;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
+import com.google.api.services.drive.model.User;
import org.apache.nifi.annotation.behavior.InputRequirement;
import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
@@ -51,28 +51,43 @@ import org.apache.nifi.scheduling.SchedulingStrategy;
import org.apache.nifi.serialization.record.RecordSchema;
import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME_DESC;
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.LAST_MODIFYING_USER;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.LAST_MODIFYING_USER_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME_DESC;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.OWNER;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.OWNER_DESC;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.PATH;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.PATH_DESC;
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTAMP;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTAMP_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_CONTENT_LINK;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_CONTENT_LINK_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_VIEW_LINK;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_VIEW_LINK_DESC;
@PrimaryNodeOnly
@TriggerSerially
@@ -91,7 +106,14 @@ import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTA
@WritesAttribute(attribute = "mime.type", description =
MIME_TYPE_DESC),
@WritesAttribute(attribute = SIZE, description = SIZE_DESC),
@WritesAttribute(attribute = SIZE_AVAILABLE, description =
SIZE_AVAILABLE_DESC),
- @WritesAttribute(attribute = TIMESTAMP, description = TIMESTAMP_DESC)})
+ @WritesAttribute(attribute = TIMESTAMP, description = TIMESTAMP_DESC),
+ @WritesAttribute(attribute = CREATED_TIME, description =
CREATED_TIME_DESC),
+ @WritesAttribute(attribute = MODIFIED_TIME, description =
MODIFIED_TIME_DESC),
+ @WritesAttribute(attribute = PATH, description = PATH_DESC),
+ @WritesAttribute(attribute = OWNER, description = OWNER_DESC),
+ @WritesAttribute(attribute = LAST_MODIFYING_USER, description =
LAST_MODIFYING_USER_DESC),
+ @WritesAttribute(attribute = WEB_VIEW_LINK, description =
WEB_VIEW_LINK_DESC),
+ @WritesAttribute(attribute = WEB_CONTENT_LINK, description =
WEB_CONTENT_LINK_DESC)})
@Stateful(scopes = {Scope.CLUSTER}, description = "The processor stores
necessary data to be able to keep track what files have been listed already." +
" What exactly needs to be stored depends on the 'Listing Strategy'." +
" State is stored across the cluster so that this Processor can be run
on Primary Node only and if a new Primary Node is selected, the new node can
pick up" +
@@ -181,14 +203,7 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
final GoogleDriveFileInfo entity,
final ProcessContext context
) {
- final Map<String, String> attributes = new HashMap<>();
-
- for (GoogleDriveFlowFileAttribute attribute :
GoogleDriveFlowFileAttribute.values()) {
- Optional.ofNullable(attribute.getValue(entity))
- .ifPresent(value -> attributes.put(attribute.getName(),
value));
- }
-
- return attributes;
+ return entity.toAttributeMap();
}
@OnScheduled
@@ -197,7 +212,7 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
HttpTransport httpTransport = new
ProxyAwareTransportFactory(proxyConfiguration).create();
- driveService = createDriveService(context, httpTransport,
DriveScopes.DRIVE_METADATA_READONLY);
+ driveService = createDriveService(context, httpTransport,
DriveScopes.DRIVE, DriveScopes.DRIVE_METADATA_READONLY);
}
@Override
@@ -251,7 +266,7 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
if (minTimestamp != null && minTimestamp > 0) {
String formattedMinTimestamp =
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(Instant.ofEpochMilli(minTimestamp),
ZoneOffset.UTC));
- queryTemplateBuilder.append(" and (mimeType !=
'").append(DRIVE_FOLDER_MIME_TYPE).append("'");
+ queryTemplateBuilder.append(" and (mimeType =
'").append(DRIVE_FOLDER_MIME_TYPE).append("'");
queryTemplateBuilder.append(" or modifiedTime >=
'").append(formattedMinTimestamp).append("'");
queryTemplateBuilder.append(" or createdTime >=
'").append(formattedMinTimestamp).append( "'");
queryTemplateBuilder.append(")");
@@ -260,7 +275,7 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
long maxTimestamp = System.currentTimeMillis() - minAge;
String formattedMaxTimestamp =
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(Instant.ofEpochMilli(maxTimestamp),
ZoneOffset.UTC));
- queryTemplateBuilder.append(" and (mimeType !=
'").append(DRIVE_FOLDER_MIME_TYPE).append("'");
+ queryTemplateBuilder.append(" and (mimeType =
'").append(DRIVE_FOLDER_MIME_TYPE).append("'");
queryTemplateBuilder.append(" or (modifiedTime <
'").append(formattedMaxTimestamp).append("'");
queryTemplateBuilder.append(" and createdTime <
'").append(formattedMaxTimestamp).append("')");
queryTemplateBuilder.append(")");
@@ -268,7 +283,9 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
final String queryTemplate = queryTemplateBuilder.toString();
- queryFolder(driveService, folderId, queryTemplate, recursive, listing);
+ final String folderPath = urlEncode(getFolderName(folderId));
+
+ queryFolder(folderId, folderPath, queryTemplate, recursive, listing);
return listing;
}
@@ -278,14 +295,34 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
return performListing(context, null,
ListingMode.CONFIGURATION_VERIFICATION).size();
}
+ private String getFolderName(final String folderId) throws IOException {
+ final File folder = driveService
+ .files()
+ .get(folderId)
+ .setSupportsAllDrives(true)
+ .setFields("name, driveId")
+ .execute();
+
+ if (folder.getDriveId() == null) {
+ return folder.getName();
+ } else {
+ return driveService
+ .drives()
+ .get(folderId)
+ .setFields("name")
+ .execute()
+ .getName();
+ }
+ }
+
private void queryFolder(
- final Drive driveService,
final String folderId,
+ final String folderPath,
final String queryTemplate,
final boolean recursive,
final List<GoogleDriveFileInfo> listing
) throws IOException {
- final List<String> subFolderIds = new ArrayList<>();
+ final List<File> subfolders = new ArrayList<>();
String pageToken = null;
do {
@@ -295,23 +332,21 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
.setIncludeItemsFromAllDrives(true)
.setQ(String.format(queryTemplate, folderId))
.setPageToken(pageToken)
- .setFields("nextPageToken, files(id, name, size,
createdTime, modifiedTime, mimeType)")
+ .setFields("nextPageToken, files(id, name, size,
createdTime, modifiedTime, mimeType, owners, lastModifyingUser, webViewLink,
webContentLink)")
.execute();
for (final File file : result.getFiles()) {
if (DRIVE_FOLDER_MIME_TYPE.equals(file.getMimeType())) {
if (recursive) {
- subFolderIds.add(file.getId());
+ subfolders.add(file);
}
} else {
- GoogleDriveFileInfo.Builder builder = new
GoogleDriveFileInfo.Builder()
- .id(file.getId())
- .fileName(file.getName())
- .size(file.getSize() != null ? file.getSize() : 0L)
- .sizeAvailable(file.getSize() != null)
-
.createdTime(Optional.ofNullable(file.getCreatedTime()).map(DateTime::getValue).orElse(0L))
-
.modifiedTime(Optional.ofNullable(file.getModifiedTime()).map(DateTime::getValue).orElse(0L))
- .mimeType(file.getMimeType());
+ final GoogleDriveFileInfo.Builder builder =
createGoogleDriveFileInfoBuilder(file)
+ .path(folderPath)
+
.owner(Optional.ofNullable(file.getOwners()).filter(owners ->
!owners.isEmpty()).map(List::getFirst).map(User::getDisplayName).orElse(null))
+
.lastModifyingUser(Optional.ofNullable(file.getLastModifyingUser()).map(User::getDisplayName).orElse(null))
+ .webViewLink(file.getWebViewLink())
+ .webContentLink(file.getWebContentLink());
listing.add(builder.build());
}
@@ -320,8 +355,13 @@ public class ListGoogleDrive extends
AbstractListProcessor<GoogleDriveFileInfo>
pageToken = result.getNextPageToken();
} while (pageToken != null);
- for (final String subFolderId : subFolderIds) {
- queryFolder(driveService, subFolderId, queryTemplate, true,
listing);
+ for (final File subfolder : subfolders) {
+ final String subfolderPath = folderPath + "/" +
urlEncode(subfolder.getName());
+ queryFolder(subfolder.getId(), subfolderPath, queryTemplate, true,
listing);
}
}
+
+ private String urlEncode(final String str) {
+ return URLEncoder.encode(str, StandardCharsets.UTF_8);
+ }
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/PutGoogleDrive.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/PutGoogleDrive.java
index 45a4c7f78f..fc1816e0c8 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/PutGoogleDrive.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/PutGoogleDrive.java
@@ -78,6 +78,8 @@ import static java.util.stream.Collectors.joining;
import static
org.apache.nifi.processor.util.StandardValidators.DATA_SIZE_VALIDATOR;
import static
org.apache.nifi.processors.conflict.resolution.ConflictResolutionStrategy.FAIL;
import static
org.apache.nifi.processors.conflict.resolution.ConflictResolutionStrategy.IGNORE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_CODE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_CODE_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_MESSAGE;
@@ -87,6 +89,8 @@ import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAM
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID_DESC;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE_DESC;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME_DESC;
import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE_DESC;
@@ -107,6 +111,8 @@ import static
org.apache.nifi.processors.gcp.util.GoogleUtils.GCP_CREDENTIALS_PR
@WritesAttribute(attribute = SIZE, description = SIZE_DESC),
@WritesAttribute(attribute = SIZE_AVAILABLE, description =
SIZE_AVAILABLE_DESC),
@WritesAttribute(attribute = TIMESTAMP, description = TIMESTAMP_DESC),
+ @WritesAttribute(attribute = CREATED_TIME, description =
CREATED_TIME_DESC),
+ @WritesAttribute(attribute = MODIFIED_TIME, description =
MODIFIED_TIME_DESC),
@WritesAttribute(attribute = ERROR_CODE, description =
ERROR_CODE_DESC),
@WritesAttribute(attribute = ERROR_MESSAGE, description =
ERROR_MESSAGE_DESC)})
public class PutGoogleDrive extends AbstractProcessor implements
GoogleDriveTrait {
@@ -284,7 +290,7 @@ public class PutGoogleDrive extends AbstractProcessor
implements GoogleDriveTrai
}
if (uploadedFile != null) {
- final Map<String, String> attributes =
createAttributeMap(uploadedFile);
+ final Map<String, String> attributes =
createGoogleDriveFileInfoBuilder(uploadedFile).build().toAttributeMap();
final String url = DRIVE_URL + uploadedFile.getId();
flowFile = session.putAllAttributes(flowFile, attributes);
final long transferMillis =
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
@@ -328,12 +334,12 @@ public class PutGoogleDrive extends AbstractProcessor
implements GoogleDriveTrai
return driveService.files()
.create(fileMetadata, mediaContent)
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size");
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size");
} else {
return driveService.files()
.update(fileMetadata.getId(), new File(), mediaContent)
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size");
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size");
}
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/AbstractGoogleDriveTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/AbstractGoogleDriveTest.java
index d868d27eff..4c4cecdc50 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/AbstractGoogleDriveTest.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/AbstractGoogleDriveTest.java
@@ -28,6 +28,8 @@ import static org.mockito.Mockito.when;
import com.google.api.client.util.DateTime;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
+
+import java.time.Instant;
import java.util.Collections;
import java.util.Set;
import org.apache.nifi.processor.Relationship;
@@ -50,6 +52,7 @@ public class AbstractGoogleDriveTest {
public static final String SUBFOLDER_ID = "subFolderId";
public static final long TEST_SIZE = 42;
public static final long CREATED_TIME = 1659707000;
+ public static final long MODIFIED_TIME = 1659708000;
public static final String TEXT_TYPE = "text/plain";
protected TestRunner testRunner;
@@ -74,8 +77,11 @@ public class AbstractGoogleDriveTest {
final MockFlowFile flowFile =
testRunner.getFlowFilesForRelationship(relationship).get(0);
flowFile.assertAttributeEquals(GoogleDriveAttributes.ID, TEST_FILE_ID);
flowFile.assertAttributeEquals(GoogleDriveAttributes.FILENAME,
TEST_FILENAME);
- flowFile.assertAttributeEquals(GoogleDriveAttributes.TIMESTAMP,
String.valueOf(new DateTime(CREATED_TIME)));
+ flowFile.assertAttributeEquals(GoogleDriveAttributes.TIMESTAMP,
String.valueOf(MODIFIED_TIME));
+ flowFile.assertAttributeEquals(GoogleDriveAttributes.CREATED_TIME,
Instant.ofEpochMilli(CREATED_TIME).toString());
+ flowFile.assertAttributeEquals(GoogleDriveAttributes.MODIFIED_TIME,
Instant.ofEpochMilli(MODIFIED_TIME).toString());
flowFile.assertAttributeEquals(GoogleDriveAttributes.SIZE,
Long.toString(TEST_SIZE));
+ flowFile.assertAttributeEquals(GoogleDriveAttributes.SIZE_AVAILABLE,
Boolean.toString(true));
flowFile.assertAttributeEquals(GoogleDriveAttributes.MIME_TYPE,
TEXT_TYPE);
}
@@ -101,6 +107,7 @@ public class AbstractGoogleDriveTest {
file.setName(name);
file.setParents(singletonList(parentId));
file.setCreatedTime(new DateTime(CREATED_TIME));
+ file.setModifiedTime(new DateTime(MODIFIED_TIME));
file.setSize(TEST_SIZE);
file.setMimeType(mimeType);
return file;
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveIT.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveIT.java
index 8b62a4474b..49efc5df4b 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveIT.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveIT.java
@@ -18,6 +18,12 @@ package org.apache.nifi.processors.gcp.drive;
import static java.lang.String.valueOf;
import static java.util.Collections.singletonList;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ERROR_CODE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
import com.google.api.services.drive.model.File;
import java.util.HashMap;
@@ -122,11 +128,6 @@ public class FetchGoogleDriveIT extends
AbstractGoogleDriveIT<FetchGoogleDrive>
@Override
public Set<String> getCheckedAttributeNames() {
- Set<String> checkedAttributeNames =
OutputChecker.super.getCheckedAttributeNames();
-
- checkedAttributeNames.add(GoogleDriveAttributes.ERROR_CODE);
- checkedAttributeNames.remove(GoogleDriveAttributes.TIMESTAMP);
-
- return checkedAttributeNames;
+ return Set.of(ID, FILENAME, SIZE, SIZE_AVAILABLE, MIME_TYPE,
ERROR_CODE);
}
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveTest.java
index b2bd9716a6..48257d4882 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveTest.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/FetchGoogleDriveTest.java
@@ -104,7 +104,7 @@ public class FetchGoogleDriveTest extends
AbstractGoogleDriveTest {
when(mockDriverService.files()
.get(fileId)
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size,
exportLinks")
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size, exportLinks")
.execute()).thenReturn(createFile());
}
@@ -118,7 +118,7 @@ public class FetchGoogleDriveTest extends
AbstractGoogleDriveTest {
when(mockDriverService.files()
.get(fileId)
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size,
exportLinks")
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size, exportLinks")
.execute()).thenReturn(createFile());
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrivePathTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrivePathTest.java
new file mode 100644
index 0000000000..388d752eaf
--- /dev/null
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDrivePathTest.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.gcp.drive;
+
+import com.google.api.client.http.HttpTransport;
+import com.google.api.services.drive.Drive;
+import com.google.api.services.drive.model.File;
+import org.apache.nifi.processor.ProcessContext;
+import
org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
+import org.apache.nifi.processors.gcp.util.GoogleUtils;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.PATH;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ListGoogleDrivePathTest implements OutputChecker {
+ private ListGoogleDrive testSubject;
+ private TestRunner testRunner;
+
+ private Drive mockDriverService;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ mockDriverService = mock(Drive.class, Mockito.RETURNS_DEEP_STUBS);
+
+ testSubject = new ListGoogleDrive() {
+ @Override
+ protected List<GoogleDriveFileInfo> performListing(ProcessContext
context, Long minTimestamp, ListingMode ignoredListingMode) throws IOException {
+ return super.performListing(context, minTimestamp,
ListingMode.EXECUTION);
+ }
+
+ @Override
+ public Drive createDriveService(ProcessContext context,
HttpTransport httpTransport, String... scopes) {
+ return mockDriverService;
+ }
+ };
+
+ testRunner = TestRunners.newTestRunner(testSubject);
+
+ String gcpCredentialsControllerServiceId =
"gcp_credentials_provider_service";
+
+ GCPCredentialsControllerService gcpCredentialsControllerService =
mock(GCPCredentialsControllerService.class, RETURNS_DEEP_STUBS);
+
when(gcpCredentialsControllerService.getIdentifier()).thenReturn(gcpCredentialsControllerServiceId);
+
+ testRunner.addControllerService(gcpCredentialsControllerServiceId,
gcpCredentialsControllerService);
+ testRunner.enableControllerService(gcpCredentialsControllerService);
+ testRunner.setProperty(GoogleUtils.GCP_CREDENTIALS_PROVIDER_SERVICE,
gcpCredentialsControllerServiceId);
+ }
+
+ @Test
+ void testPath() throws Exception {
+ String folderId1 = "folder_id_1";
+ String folderName1 = "Base Folder";
+
+ String folderId2 = "folder_id_2";
+ String folderName2 = "Folder/with/slashes";
+
+ String fileId1 = "file_id_1";
+ String fileName1 = "file_name_1";
+
+ String fileId2 = "file_id_2";
+ String fileName2 = "file_name_2";
+
+ testRunner.setProperty(ListGoogleDrive.FOLDER_ID, folderId1);
+
+ mockGetFolderName(folderId1, folderName1);
+
+ mockFolderQuery(folderId1,
+ createFile(folderId2, folderName2,
GoogleDriveTrait.DRIVE_FOLDER_MIME_TYPE),
+ createFile(fileId1, fileName1, "text/plain")
+ );
+
+ mockFolderQuery(folderId2,
+ createFile(fileId2, fileName2, "text/plain")
+ );
+
+ Set<Map<String, String>> expectedAttributes = Set.of(
+ createAttributeMap(fileId1, fileName1, urlEncode(folderName1)),
+ createAttributeMap(fileId2, fileName2, urlEncode(folderName1)
+ "/" + urlEncode(folderName2))
+ );
+
+ testRunner.run();
+
+ checkAttributes(ListGoogleDrive.REL_SUCCESS, expectedAttributes);
+ }
+
+ private void mockGetFolderName(String folderId, String folderName) throws
IOException {
+ when(mockDriverService.files()
+ .get(folderId)
+ .setSupportsAllDrives(true)
+ .setFields("name, driveId")
+ .execute()
+ ).thenReturn(new File()
+ .setName(folderName)
+ );
+ }
+
+ private void mockFolderQuery(String folderId, File... files) throws
IOException {
+ when(mockDriverService.files()
+ .list()
+ .setSupportsAllDrives(true)
+ .setIncludeItemsFromAllDrives(true)
+ .setQ("('" + folderId + "' in parents) and (mimeType !=
'application/vnd.google-apps.shortcut') and trashed = false")
+ .setPageToken(null)
+ .setFields("nextPageToken, files(id, name, size, createdTime,
modifiedTime, mimeType, owners, lastModifyingUser, webViewLink,
webContentLink)")
+ .execute()
+ .getFiles()
+ ).thenReturn(Arrays.asList(files));
+ }
+
+ private File createFile(
+ String id,
+ String name,
+ String mimeType
+ ) {
+ return new File()
+ .setId(id)
+ .setName(name)
+ .setMimeType(mimeType);
+ }
+
+ private Map<String, String> createAttributeMap(String fileId, String
fileName, String path) {
+ return Map.of(
+ GoogleDriveAttributes.ID, fileId,
+ GoogleDriveAttributes.FILENAME, fileName,
+ GoogleDriveAttributes.PATH, path
+ );
+ }
+
+ private String urlEncode(final String str) {
+ return URLEncoder.encode(str, StandardCharsets.UTF_8);
+ }
+
+ @Override
+ public TestRunner getTestRunner() {
+ return testRunner;
+ }
+
+ @Override
+ public Set<String> getCheckedAttributeNames() {
+ return Set.of(ID, FILENAME, PATH);
+ }
+}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveSimpleTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveSimpleTest.java
index dbe8ef4924..29d785f1a6 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveSimpleTest.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveSimpleTest.java
@@ -20,6 +20,7 @@ import com.google.api.client.http.HttpTransport;
import com.google.api.client.util.DateTime;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
+import com.google.api.services.drive.model.User;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.util.EqualsWrapper;
import org.junit.jupiter.api.BeforeEach;
@@ -72,20 +73,41 @@ public class ListGoogleDriveSimpleTest {
Long minTimestamp = 0L;
listingModeAsString = "EXECUTION";
+ String folderId = "folder_id";
+ String folderName = "folder_name";
+
String id = "id_1";
String filename = "file_name_1";
long size = 125L;
long createdTime = 123456L;
long modifiedTime = 234567L;
String mimeType = "mime_type_1";
+ String owner = "user1";
+ String lastModifyingUser = "user2";
+ String webViewLink = "http://web.view";
+ String webContentLink = "http://web.content";
+
+ when(mockProcessContext.getProperty(ListGoogleDrive.FOLDER_ID)
+ .evaluateAttributeExpressions()
+ .getValue()
+ ).thenReturn(folderId);
+
+ when(mockDriverService.files()
+ .get(folderId)
+ .setSupportsAllDrives(true)
+ .setFields("name, driveId")
+ .execute()
+ ).thenReturn(new File()
+ .setName(folderName)
+ );
when(mockDriverService.files()
.list()
.setSupportsAllDrives(true)
.setIncludeItemsFromAllDrives(true)
- .setQ("('null' in parents) and (mimeType !=
'application/vnd.google-apps.shortcut') and trashed = false")
+ .setQ("('" + folderId + "' in parents) and (mimeType !=
'application/vnd.google-apps.shortcut') and trashed = false")
.setPageToken(null)
- .setFields("nextPageToken, files(id, name, size, createdTime,
modifiedTime, mimeType)")
+ .setFields("nextPageToken, files(id, name, size, createdTime,
modifiedTime, mimeType, owners, lastModifyingUser, webViewLink,
webContentLink)")
.execute()
.getFiles()
).thenReturn(singletonList(
@@ -95,7 +117,11 @@ public class ListGoogleDriveSimpleTest {
size,
new DateTime(createdTime),
new DateTime(modifiedTime),
- mimeType
+ mimeType,
+ owner,
+ lastModifyingUser,
+ webViewLink,
+ webContentLink
)
));
@@ -104,9 +130,15 @@ public class ListGoogleDriveSimpleTest {
.id(id)
.fileName(filename)
.size(size)
+ .sizeAvailable(true)
.createdTime(createdTime)
.modifiedTime(modifiedTime)
.mimeType(mimeType)
+ .path(folderName)
+ .owner(owner)
+ .lastModifyingUser(lastModifyingUser)
+ .webViewLink(webViewLink)
+ .webContentLink(webContentLink)
.build()
);
@@ -119,10 +151,16 @@ public class ListGoogleDriveSimpleTest {
GoogleDriveFileInfo::getIdentifier,
GoogleDriveFileInfo::getName,
GoogleDriveFileInfo::getSize,
+ GoogleDriveFileInfo::isSizeAvailable,
GoogleDriveFileInfo::getTimestamp,
GoogleDriveFileInfo::getCreatedTime,
GoogleDriveFileInfo::getModifiedTime,
- GoogleDriveFileInfo::getMimeType
+ GoogleDriveFileInfo::getMimeType,
+ GoogleDriveFileInfo::getPath,
+ GoogleDriveFileInfo::getOwner,
+ GoogleDriveFileInfo::getLastModifyingUser,
+ GoogleDriveFileInfo::getWebViewLink,
+ GoogleDriveFileInfo::getWebContentLink
);
List<EqualsWrapper<GoogleDriveFileInfo>> expectedWrapper =
wrapList(expected, propertyProviders);
@@ -137,8 +175,11 @@ public class ListGoogleDriveSimpleTest {
Long size,
DateTime createdTime,
DateTime modifiedTime,
- String mimeType
- ) {
+ String mimeType,
+ String owner,
+ String lastModifyingUser,
+ String webViewLink,
+ String webContentLink) {
File file = new File();
file
@@ -147,7 +188,11 @@ public class ListGoogleDriveSimpleTest {
.setMimeType(mimeType)
.setCreatedTime(createdTime)
.setModifiedTime(modifiedTime)
- .setSize(size);
+ .setSize(size)
+ .setOwners(List.of(new User().setDisplayName(owner)))
+ .setLastModifyingUser(new
User().setDisplayName(lastModifyingUser))
+ .setWebViewLink(webViewLink)
+ .setWebContentLink(webContentLink);
return file;
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
index 10c50a492b..b827358278 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
@@ -18,6 +18,19 @@ package org.apache.nifi.processors.gcp.drive;
import static java.lang.String.valueOf;
import static java.util.Collections.singletonList;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.CREATED_TIME;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.FILENAME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.ID;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.LAST_MODIFYING_USER;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MIME_TYPE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.MODIFIED_TIME;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.OWNER;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.PATH;
+import static org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.SIZE_AVAILABLE;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.TIMESTAMP;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_CONTENT_LINK;
+import static
org.apache.nifi.processors.gcp.drive.GoogleDriveAttributes.WEB_VIEW_LINK;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -27,11 +40,15 @@ import com.google.api.client.util.DateTime;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import java.io.IOException;
+import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+
+import com.google.api.services.drive.model.User;
import org.apache.nifi.json.JsonRecordSetWriter;
import org.apache.nifi.processor.ProcessContext;
import
org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
@@ -51,11 +68,21 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
private Drive mockDriverService;
private final String folderId = "folderId";
+ private final String folderName = "folderName";
@BeforeEach
void setUp() throws Exception {
mockDriverService = mock(Drive.class, Mockito.RETURNS_DEEP_STUBS);
+ when(mockDriverService.files()
+ .get(folderId)
+ .setSupportsAllDrives(true)
+ .setFields("name, driveId")
+ .execute()
+ ).thenReturn(new File()
+ .setName(folderName)
+ );
+
testSubject = new ListGoogleDrive() {
@Override
protected List<GoogleDriveFileInfo> performListing(ProcessContext
context, Long minTimestamp, ListingMode ignoredListingMode) throws IOException {
@@ -90,8 +117,12 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
Long createdTime = 123456L;
Long modifiedTime = null;
String mimeType = "mime_type_1";
+ String owner = "user1";
+ String lastModifyingUser = "user2";
+ String webViewLink = "http://web.view";
+ String webContentLink = "http://web.content";
- testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, createdTime);
+ testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, createdTime);
}
@Test
@@ -102,8 +133,12 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
Long createdTime = 123456L;
Long modifiedTime = 123456L + 1L;
String mimeType = "mime_type_1";
+ String owner = "user1";
+ String lastModifyingUser = "user2";
+ String webViewLink = "http://web.view";
+ String webContentLink = "http://web.content";
- testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, modifiedTime);
+ testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, modifiedTime);
}
@Test
@@ -114,8 +149,12 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
Long createdTime = 123456L;
Long modifiedTime = 123456L + 1L;
String mimeType = "mime_type_1";
+ String owner = "user1";
+ String lastModifyingUser = "user2";
+ String webViewLink = "http://web.view";
+ String webContentLink = "http://web.content";
- testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, modifiedTime);
+ testOutputAsAttributes(id, filename, size, createdTime, modifiedTime,
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, modifiedTime);
}
@Test
@@ -126,10 +165,14 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
Long createdTime = 123456L;
Long modifiedTime = 123456L + 1L;
String mimeType = "mime_type_1";
+ String owner = "user1";
+ String lastModifyingUser = "user2";
+ String webViewLink = "http://web.view";
+ String webContentLink = "http://web.content";
addJsonRecordWriterFactory();
- mockFetchedGoogleDriveFileList(id, filename, size, createdTime,
modifiedTime, mimeType);
+ mockFetchedGoogleDriveFileList(id, filename, size, createdTime,
modifiedTime, mimeType, owner, lastModifyingUser, webViewLink, webContentLink);
List<String> expectedContents = singletonList(
"[" +
@@ -139,7 +182,14 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
"\"drive.size\":" + size + "," +
"\"drive.size.available\":" + (size != null) + "," +
"\"drive.timestamp\":" + modifiedTime + "," +
- "\"mime.type\":\"" + mimeType + "\"" +
+ "\"drive.created.time\":\"" +
Instant.ofEpochMilli(createdTime) + "\"," +
+ "\"drive.modified.time\":\"" +
Instant.ofEpochMilli(modifiedTime) + "\"," +
+ "\"mime.type\":\"" + mimeType + "\"," +
+ "\"drive.path\":\"" + folderName + "\"," +
+ "\"drive.owner\":\"" + owner + "\"," +
+ "\"drive.last.modifying.user\":\"" + lastModifyingUser
+ "\"," +
+ "\"drive.web.view.link\":\"" + webViewLink + "\"," +
+ "\"drive.web.content.link\":\"" + webContentLink +
"\"" +
"}" +
"]");
@@ -154,14 +204,15 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
testRunner.setProperty(ListGoogleDrive.RECORD_WRITER, "record_writer");
}
- private void mockFetchedGoogleDriveFileList(String id, String filename,
Long size, Long createdTime, Long modifiedTime, String mimeType) throws
IOException {
+ private void mockFetchedGoogleDriveFileList(String id, String filename,
Long size, Long createdTime, Long modifiedTime, String mimeType,
+ String owner, String
lastModifyingUser, String webViewLink, String webContentLink) throws
IOException {
when(mockDriverService.files()
.list()
.setSupportsAllDrives(true)
.setIncludeItemsFromAllDrives(true)
.setQ("('" + folderId + "' in parents) and (mimeType !=
'application/vnd.google-apps.shortcut') and trashed = false")
.setPageToken(null)
- .setFields("nextPageToken, files(id, name, size, createdTime,
modifiedTime, mimeType)")
+ .setFields("nextPageToken, files(id, name, size, createdTime,
modifiedTime, mimeType, owners, lastModifyingUser, webViewLink,
webContentLink)")
.execute()
.getFiles()
).thenReturn(singletonList(
@@ -171,13 +222,19 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
size,
Optional.ofNullable(createdTime).map(DateTime::new).orElse(null),
Optional.ofNullable(modifiedTime).map(DateTime::new).orElse(null),
- mimeType
+ mimeType,
+ owner,
+ lastModifyingUser,
+ webViewLink,
+ webContentLink
)
));
}
- private void testOutputAsAttributes(String id, String filename, Long size,
Long createdTime, Long modifiedTime, String mimeType, Long expectedTimestamp)
throws IOException {
- mockFetchedGoogleDriveFileList(id, filename, size, createdTime,
modifiedTime, mimeType);
+ private void testOutputAsAttributes(String id, String filename, Long size,
Long createdTime, Long modifiedTime, String mimeType,
+ String owner, String
lastModifyingUser, String webViewLink, String webContentLink,
+ Long expectedTimestamp) throws
IOException {
+ mockFetchedGoogleDriveFileList(id, filename, size, createdTime,
modifiedTime, mimeType, owner, lastModifyingUser, webViewLink, webContentLink);
Map<String, String> inputFlowFileAttributes = new HashMap<>();
inputFlowFileAttributes.put(GoogleDriveAttributes.ID, id);
@@ -185,7 +242,14 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
inputFlowFileAttributes.put(GoogleDriveAttributes.SIZE, valueOf(size
!= null ? size : 0L));
inputFlowFileAttributes.put(GoogleDriveAttributes.SIZE_AVAILABLE,
valueOf(size != null));
inputFlowFileAttributes.put(GoogleDriveAttributes.TIMESTAMP,
valueOf(expectedTimestamp));
+ inputFlowFileAttributes.put(GoogleDriveAttributes.CREATED_TIME,
Instant.ofEpochMilli(createdTime != null ? createdTime : 0L).toString());
+ inputFlowFileAttributes.put(GoogleDriveAttributes.MODIFIED_TIME,
Instant.ofEpochMilli(modifiedTime != null ? modifiedTime : 0L).toString());
inputFlowFileAttributes.put(GoogleDriveAttributes.MIME_TYPE, mimeType);
+ inputFlowFileAttributes.put(GoogleDriveAttributes.PATH, folderName);
+ inputFlowFileAttributes.put(GoogleDriveAttributes.OWNER, owner);
+ inputFlowFileAttributes.put(GoogleDriveAttributes.LAST_MODIFYING_USER,
lastModifyingUser);
+ inputFlowFileAttributes.put(GoogleDriveAttributes.WEB_VIEW_LINK,
webViewLink);
+ inputFlowFileAttributes.put(GoogleDriveAttributes.WEB_CONTENT_LINK,
webContentLink);
HashSet<Map<String, String>> expectedAttributes = new
HashSet<>(singletonList(inputFlowFileAttributes));
@@ -200,7 +264,11 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
Long size,
DateTime createdTime,
DateTime modifiedTime,
- String mimeType
+ String mimeType,
+ String owner,
+ String lastModifyingUser,
+ String webViewLink,
+ String webContentLink
) {
File file = new File();
@@ -210,7 +278,11 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
.setMimeType(mimeType)
.setCreatedTime(createdTime)
.setModifiedTime(modifiedTime)
- .setSize(size);
+ .setSize(size)
+ .setOwners(List.of(new User().setDisplayName(owner)))
+ .setLastModifyingUser(new
User().setDisplayName(lastModifyingUser))
+ .setWebViewLink(webViewLink)
+ .setWebContentLink(webContentLink);
return file;
}
@@ -219,4 +291,9 @@ public class ListGoogleDriveTestRunnerTest implements
OutputChecker {
public TestRunner getTestRunner() {
return testRunner;
}
+
+ @Override
+ public Set<String> getCheckedAttributeNames() {
+ return Set.of(ID, FILENAME, SIZE, SIZE_AVAILABLE, TIMESTAMP,
CREATED_TIME, MODIFIED_TIME, MIME_TYPE, PATH, OWNER, LAST_MODIFYING_USER,
WEB_VIEW_LINK, WEB_CONTENT_LINK);
+ }
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/OutputChecker.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/OutputChecker.java
index 1c49f6ecfe..12ab6669c1 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/OutputChecker.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/OutputChecker.java
@@ -20,7 +20,6 @@ import org.apache.nifi.processor.Relationship;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,13 +48,7 @@ public interface OutputChecker {
assertEquals(expectedAttributes, actualAttributes);
}
- default Set<String> getCheckedAttributeNames() {
- Set<String> checkedAttributeNames =
Arrays.stream(GoogleDriveFlowFileAttribute.values())
- .map(GoogleDriveFlowFileAttribute::getName)
- .collect(Collectors.toSet());
-
- return checkedAttributeNames;
- }
+ Set<String> getCheckedAttributeNames();
default void checkContent(Relationship relationship, List<String>
expectedContent) {
getTestRunner().assertTransferCount(relationship,
expectedContent.size());
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveIT.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveIT.java
index 7912c67174..f9e01cdacc 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveIT.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveIT.java
@@ -24,6 +24,7 @@ import static
org.apache.nifi.processors.gcp.drive.PutGoogleDrive.FOLDER_ID;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
import org.junit.jupiter.api.BeforeEach;
@@ -32,7 +33,7 @@ import org.junit.jupiter.api.Test;
/**
* See Javadoc {@link AbstractGoogleDriveIT} for instructions how to run this
test.
*/
-public class PutGoogleDriveIT extends AbstractGoogleDriveIT<PutGoogleDrive>
implements OutputChecker {
+public class PutGoogleDriveIT extends AbstractGoogleDriveIT<PutGoogleDrive> {
public static final String TEST_FILENAME = "testFileName";
@@ -147,7 +148,10 @@ public class PutGoogleDriveIT extends
AbstractGoogleDriveIT<PutGoogleDrive> impl
flowFile.assertAttributeExists(GoogleDriveAttributes.ID);
flowFile.assertAttributeEquals(GoogleDriveAttributes.FILENAME,
TEST_FILENAME);
flowFile.assertAttributeExists(GoogleDriveAttributes.TIMESTAMP);
+ flowFile.assertAttributeExists(GoogleDriveAttributes.CREATED_TIME);
+ flowFile.assertAttributeExists(GoogleDriveAttributes.MODIFIED_TIME);
flowFile.assertAttributeEquals(GoogleDriveAttributes.SIZE,
String.valueOf(DEFAULT_FILE_CONTENT.length()));
+ flowFile.assertAttributeEquals(GoogleDriveAttributes.SIZE_AVAILABLE,
"true");
flowFile.assertAttributeEquals(GoogleDriveAttributes.MIME_TYPE,
"text/plain");
}
}
diff --git
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveTest.java
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveTest.java
index ecc5962951..128823106a 100644
---
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveTest.java
+++
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/PutGoogleDriveTest.java
@@ -194,7 +194,7 @@ public class PutGoogleDriveTest extends
AbstractGoogleDriveTest {
when(mockDriverService.files()
.create(any(File.class), any(InputStreamContent.class))
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size")
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size")
.execute())
.thenReturn(uploadedFile);
}
@@ -203,7 +203,7 @@ public class PutGoogleDriveTest extends
AbstractGoogleDriveTest {
when(mockDriverService.files()
.update(eq(uploadedFile.getId()), any(File.class),
any(InputStreamContent.class))
.setSupportsAllDrives(true)
- .setFields("id, name, createdTime, mimeType, size")
+ .setFields("id, name, createdTime, modifiedTime, mimeType,
size")
.execute())
.thenReturn(uploadedFile);
}