exceptionfactory commented on code in PR #7781:
URL: https://github.com/apache/nifi/pull/7781#discussion_r1364538488
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/IdentifyMimeType.java:
##########
@@ -231,8 +249,8 @@ public void process(final InputStream stream) throws
IOException {
MimeType mimetype;
mimetype = mimeTypes.forName(mimeType);
extension = mimetype.getExtension();
- } catch (MimeTypeException ex) {
- logger.warn("MIME type extension lookup failed: {}", new
Object[]{ex});
+ } catch (MimeTypeException e) {
+ logger.warn("MIME type extension lookup failed: ", e);
Review Comment:
```suggestion
logger.warn("MIME type extension lookup failed", e);
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/IdentifyMimeType.java:
##########
@@ -158,34 +173,37 @@ protected void init(final ProcessorInitializationContext
context) {
}
@OnScheduled
- public void setup(final ProcessContext context) {
- String configBody = context.getProperty(MIME_CONFIG_BODY).getValue();
- String configFile =
context.getProperty(MIME_CONFIG_FILE).evaluateAttributeExpressions().getValue();
+ public void setup(final ProcessContext context) throws IOException {
+ String configStrategy =
context.getProperty(CONFIG_STRATEGY).getValue();
- if (configBody == null && configFile == null){
+ if (configStrategy.equals(PRESET.getValue())){
this.detector = config.getDetector();
this.mimeTypes = config.getMimeRepository();
- } else if (configBody != null) {
- try {
- this.detector = MimeTypesFactory.create(new
ByteArrayInputStream(configBody.getBytes()));
- this.mimeTypes = (MimeTypes)this.detector;
- } catch (Exception e) {
- context.yield();
- throw new ProcessException("Failed to load config body", e);
- }
-
} else {
- try (final FileInputStream fis = new FileInputStream(configFile);
- final InputStream bis = new BufferedInputStream(fis)) {
- this.detector = MimeTypesFactory.create(bis);
- this.mimeTypes = (MimeTypes)this.detector;
- } catch (Exception e) {
- context.yield();
- throw new ProcessException("Failed to load config file", e);
- }
+ setCustomMimeTypes(configStrategy, context);
}
}
+ private void setCustomMimeTypes(String configStrategy, ProcessContext
context) throws IOException {
+ String configBody = context.getProperty(MIME_CONFIG_BODY).getValue();
+ String configFile =
context.getProperty(MIME_CONFIG_FILE).evaluateAttributeExpressions().getValue();
+
+ try (final InputStream customInputStream = configBody != null ? new
ByteArrayInputStream(configBody.getBytes()) : new FileInputStream(configFile);
+ final InputStream nifiInputStream =
getClass().getClassLoader().getResourceAsStream("org/apache/tika/mime/custom-mimetypes.xml");
+ final InputStream tikaInputStream =
MimeTypes.class.getClassLoader().getResourceAsStream("org/apache/tika/mime/tika-mimetypes.xml"))
{
Review Comment:
These lines should be moved into the `else` block since they are not used
for the `REPLACE` strategy.
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/IdentifyMimeType.java:
##########
@@ -259,13 +277,21 @@ protected Collection<ValidationResult>
customValidate(ValidationContext validati
Set<ValidationResult> results = new HashSet<>();
String body =
validationContext.getProperty(MIME_CONFIG_BODY).getValue();
String file =
validationContext.getProperty(MIME_CONFIG_FILE).getValue();
- if(body != null && file != null) {
- results.add(new ValidationResult.Builder()
- .input(MIME_CONFIG_FILE.getName())
- .subject(file)
- .valid(false)
- .explanation("Can only specify Config Body or Config File.
Not both.")
- .build());
+
if(!validationContext.getProperty(CONFIG_STRATEGY).getValue().equals(PRESET.getValue()))
{
+ if (body != null && file != null) {
+ results.add(new ValidationResult.Builder()
+ .subject(MIME_CONFIG_FILE.getDisplayName())
+ .input(file)
+ .valid(false)
+ .explanation("Can only specify Config Body or Config
File. Not both.")
+ .build());
+ } else if (body == null && file == null) {
+ results.add(new ValidationResult.Builder()
+ .subject(MIME_CONFIG_FILE.getDisplayName())
+ .valid(false)
+ .explanation("Either Config Body or Config File must
be set.")
Review Comment:
```suggestion
.explanation("Either [Config Body] or [Config File]
must be specified")
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/IdentifyMimeType.java:
##########
@@ -259,13 +277,21 @@ protected Collection<ValidationResult>
customValidate(ValidationContext validati
Set<ValidationResult> results = new HashSet<>();
String body =
validationContext.getProperty(MIME_CONFIG_BODY).getValue();
String file =
validationContext.getProperty(MIME_CONFIG_FILE).getValue();
- if(body != null && file != null) {
- results.add(new ValidationResult.Builder()
- .input(MIME_CONFIG_FILE.getName())
- .subject(file)
- .valid(false)
- .explanation("Can only specify Config Body or Config File.
Not both.")
- .build());
+
if(!validationContext.getProperty(CONFIG_STRATEGY).getValue().equals(PRESET.getValue()))
{
Review Comment:
```suggestion
if
(!validationContext.getProperty(CONFIG_STRATEGY).getValue().equals(PRESET.getValue()))
{
```
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/IdentifyMimeType.java:
##########
@@ -259,13 +277,21 @@ protected Collection<ValidationResult>
customValidate(ValidationContext validati
Set<ValidationResult> results = new HashSet<>();
String body =
validationContext.getProperty(MIME_CONFIG_BODY).getValue();
String file =
validationContext.getProperty(MIME_CONFIG_FILE).getValue();
- if(body != null && file != null) {
- results.add(new ValidationResult.Builder()
- .input(MIME_CONFIG_FILE.getName())
- .subject(file)
- .valid(false)
- .explanation("Can only specify Config Body or Config File.
Not both.")
- .build());
+
if(!validationContext.getProperty(CONFIG_STRATEGY).getValue().equals(PRESET.getValue()))
{
+ if (body != null && file != null) {
+ results.add(new ValidationResult.Builder()
+ .subject(MIME_CONFIG_FILE.getDisplayName())
+ .input(file)
+ .valid(false)
+ .explanation("Can only specify Config Body or Config
File. Not both.")
Review Comment:
```suggestion
.explanation("Either [Config Body] or [Config File]
can be specified, but not both properties.")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]