Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-11059 PutBoxFile processor #6892

Closed

Conversation

krisztina-zsihovszki
Copy link
Contributor

Summary

NIFI-11059

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-11059
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-11059

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 8
    • JDK 11
    • JDK 17

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

@turcsanyip turcsanyip self-requested a review January 26, 2023 09:47
Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this new Processor @krisztina-zsihovszki! I will defer to others for a more thorough code and functionality review, but I noted a handful of minor stylistic recommendations.

final BoxFile.Info fetchedFileInfo = createFileInfo(TEST_PATH, MODIFIED_TIME);
doReturn(fetchedFileInfo).when(mockBoxFile).getInfo();

// WHEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of WHEN and THEN comments should be avoided.

public static final String ID = "box.id";
public static final String ID_DESC = "The id of the file";

public static final String FILENAME = CoreAttributes.FILENAME.key();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend avoiding reproducing the FILENAME and PATH attributes and using the CoreAttributes enum directly.

}

public static Map<String, String> createAttributeMap(Info fileInfo) {
final Map<String, String> attributes = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend using LinkedHashMap instead of HashMap for deterministic ordering of attributes added.

outFlowFile = session.putAttribute(outFlowFile, ERROR_MESSAGE_ATTRIBUTE, e.getMessage());

session.transfer(outFlowFile, REL_FAILURE);
flowFile = session.putAttribute(flowFile, ERROR_CODE, "" + e.getResponseCode());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good opportunity to adjust this approach. String.valueOf(e.getResponseCode()) should be used instead of concatenating an empty string to the response code.

REL_FAILURE
)));

public static final int CONFLICT_RESPONSE_CODE = 409;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this variable be protected or private?

getLogger().error("Exception occurred while uploading file '{}' to Box folder '{}'", filename, fullPath, e);
handleExpectedError(session, flowFile, e);
} catch (Exception e) {
getLogger().error("Unexpected exception occurred while uploading file '{}' to Box folder '{}'", filename, fullPath, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getLogger().error("Unexpected exception occurred while uploading file '{}' to Box folder '{}'", filename, fullPath, e);
getLogger().error("Upload failed: File [{}] folder [{}]", filename, fullPath, e);

}

if (createFolder) {
getLogger().debug("Create folder " + folderName + " parent id: " + parentFolderId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log statements should use placeholders:

Suggested change
getLogger().debug("Create folder " + folderName + " parent id: " + parentFolderId);
getLogger().debug("Creating Folder [{}] Parent [{}]", folderName, parentFolderId);

getLogger().info("File with the same name '{}' already exists in '%s'. Remote file is not modified due to {} being set to '{}'.",
filename, path, CONFLICT_RESOLUTION.getDisplayName(), conflictResolution);
} else if (FAIL_RESOLUTION.equals(conflictResolution)) {
throw new ProcessException(format("File with the same name '%s' already exists in '%s'.", filename, path), e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend avoiding periods at the end of messages:

Suggested change
throw new ProcessException(format("File with the same name '%s' already exists in '%s'.", filename, path), e);
throw new ProcessException(format("File with the same name [%s] already exists in [%s]", filename, path), e);

final String path = BoxFileUtils.getPath(folder.getInfo());

if (IGNORE_RESOLUTION.equals(conflictResolution)) {
getLogger().info("File with the same name '{}' already exists in '%s'. Remote file is not modified due to {} being set to '{}'.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getLogger().info("File with the same name '{}' already exists in '%s'. Remote file is not modified due to {} being set to '{}'.",
getLogger().info("File with the same name [{}] already exists in [%s] Remote file is not modified due to [{}] being set to [{}]",

Comment on lines 92 to 94
public static final String IGNORE_RESOLUTION = "ignore";
public static final String REPLACE_RESOLUTION = "replace";
public static final String FAIL_RESOLUTION = "fail";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your work for NIFI-11068 in PR #6861, it looks like these variables can be replaced with the new ConflictResolutionStrategy.

Copy link
Contributor

@turcsanyip turcsanyip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krisztina-zsihovszki Thanks for the latest changes!
I found only some minor issues / improvements. Pls. see my comments below.

Copy link
Contributor

@turcsanyip turcsanyip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @krisztina-zsihovszki!

+1 LGTM

@exceptionfactory Do you have any further comments or can we merge it?

Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @krisztina-zsihovszki, looks good! No further comments @turcsanyip, feel free to merge!

@turcsanyip
Copy link
Contributor

@exceptionfactory Thanks for your review!
Merging to main...

@asfgit asfgit closed this in 653631c Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants