Repository: nifi
Updated Branches:
  refs/heads/master 1597492fe -> 3b3d6d4eb


NIFI-5171: fixed Yandex Jersey issues by adding dependency to POM and modified 
API call to now detect for languages
Added license to YandexTranslate NOTICE file
Updated to use StringUtils.isBlank for detecting sourceLanguage field being 
blank and languages to file to align with new logic

Signed-off-by: Mark Payne <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/3b3d6d4e
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/3b3d6d4e
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/3b3d6d4e

Branch: refs/heads/master
Commit: 3b3d6d4eb2c9de250f22598f16b05811cf3ff17f
Parents: 1597492
Author: veteranbv <[email protected]>
Authored: Thu May 17 12:47:19 2018 -0400
Committer: Mark Payne <[email protected]>
Committed: Thu May 24 14:35:33 2018 -0400

----------------------------------------------------------------------
 .../src/main/resources/META-INF/NOTICE          |  1 +
 .../nifi-yandex-processors/pom.xml              |  7 +++++-
 .../nifi/processors/yandex/YandexTranslate.java | 26 +++++++++++++-------
 3 files changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/3b3d6d4e/nifi-nar-bundles/nifi-language-translation-bundle/nifi-language-translation-nar/src/main/resources/META-INF/NOTICE
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-language-translation-nar/src/main/resources/META-INF/NOTICE
 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-language-translation-nar/src/main/resources/META-INF/NOTICE
index ff3e180..93c10db 100644
--- 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-language-translation-nar/src/main/resources/META-INF/NOTICE
+++ 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-language-translation-nar/src/main/resources/META-INF/NOTICE
@@ -51,6 +51,7 @@ The following binary components are provided under the Common 
Development and Di
     (CDDL 1.1) (GPL2 w/ CPE) jersey-common 
(org.glassfish.jersey.core:jersey-common:jar:2.26 - https://jersey.github.io/)
     (CDDL 1.1) (GPL2 w/ CPE) jersey-entity-filtering 
(org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.26 - 
https://jersey.github.io/)
     (CDDL 1.1) (GPL2 w/ CPE) jersey-media-json-jackson 
(org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.26 - 
https://jersey.github.io/)
+    (CDDL 1.1) (GPL2 w/ CPE) jersey-hk2 
(org.glassfish.jersey.inject:jersey-hk2:jar:2.26 - https://jersey.github.io/)
     (CDDL 1.1) (GPL2 w/ CPE) Old JAXB Runtime 
(com.sun.xml.bind:jaxb-impl:jar:2.2.3-1 - http://jaxb.java.net/)
     (CDDL 1.1) (GPL2 w/ CPE) Java Architecture For XML Binding 
(javax.xml.bind:jaxb-api:jar:2.2.2 - https://jaxb.dev.java.net/)
     (CDDL 1.1) (GPL2 w/ CPE) javax.ws.rs-api 
(javax.ws.rs:javax.ws.rs-api:jar:2.1 - http://jax-rs-spec.java.net)

http://git-wip-us.apache.org/repos/asf/nifi/blob/3b3d6d4e/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/pom.xml
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/pom.xml
 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/pom.xml
index d9a22d9..473a929 100644
--- 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/pom.xml
+++ 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/pom.xml
@@ -53,7 +53,12 @@
             <artifactId>jersey-media-json-jackson</artifactId>
             <version>${jersey.version}</version>
         </dependency>
-        
+        <dependency>
+            <groupId>org.glassfish.jersey.inject</groupId>
+            <artifactId>jersey-hk2</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.nifi</groupId>
             <artifactId>nifi-mock</artifactId>

http://git-wip-us.apache.org/repos/asf/nifi/blob/3b3d6d4e/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/src/main/java/org/apache/nifi/processors/yandex/YandexTranslate.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/src/main/java/org/apache/nifi/processors/yandex/YandexTranslate.java
 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/src/main/java/org/apache/nifi/processors/yandex/YandexTranslate.java
index 5f1ae88..f222cd9 100644
--- 
a/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/src/main/java/org/apache/nifi/processors/yandex/YandexTranslate.java
+++ 
b/nifi-nar-bundles/nifi-language-translation-bundle/nifi-yandex-processors/src/main/java/org/apache/nifi/processors/yandex/YandexTranslate.java
@@ -16,6 +16,7 @@
  */
 package org.apache.nifi.processors.yandex;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.annotation.behavior.DynamicProperty;
 import org.apache.nifi.annotation.behavior.InputRequirement;
 import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
@@ -71,8 +72,8 @@ import java.util.Set;
 @Tags({"yandex", "translate", "translation", "language"})
 @CapabilityDescription("Translates content and attributes from one language to 
another")
 @WritesAttributes({
-    @WritesAttribute(attribute = "yandex.translate.failure.reason", 
description = "If the text cannot be translated, this attribute will be set 
indicating the reason for the failure"),
-    @WritesAttribute(attribute = "language", description = "When the 
translation succeeds, if the content was translated, this attribute will be set 
indicating the new language of the content")
+        @WritesAttribute(attribute = "yandex.translate.failure.reason", 
description = "If the text cannot be translated, this attribute will be set 
indicating the reason for the failure"),
+        @WritesAttribute(attribute = "language", description = "When the 
translation succeeds, if the content was translated, this attribute will be set 
indicating the new language of the content")
 })
 @DynamicProperty(name = "The name of an attribute to set that will contain the 
translated text of the value",
         value = "The value to translate",
@@ -88,9 +89,8 @@ public class YandexTranslate extends AbstractProcessor {
             .build();
     public static final PropertyDescriptor SOURCE_LANGUAGE = new 
PropertyDescriptor.Builder()
             .name("Input Language")
-            .description("The language of incoming data")
-            .required(true)
-            .defaultValue("es")
+            .description("The language of incoming data. If no language is 
set, Yandex will attempt to detect the incoming language automatically.")
+            .required(false)
             
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
             .addValidator(new LanguageNameValidator())
             .build();
@@ -211,10 +211,14 @@ public class YandexTranslate extends AbstractProcessor {
     protected Invocation prepareResource(final String key, final List<String> 
text, final String sourceLanguage, final String destLanguage) {
         Invocation.Builder builder = 
client.target(URL).request(MediaType.APPLICATION_JSON);
 
-        final MultivaluedHashMap entity = new MultivaluedHashMap();;
+        final MultivaluedHashMap entity = new MultivaluedHashMap();
         entity.put("text", text);
         entity.add("key", key);
-        entity.add("lang", sourceLanguage + "-" + destLanguage);
+        if ((StringUtils.isBlank(sourceLanguage))) {
+            entity.add("lang", destLanguage);
+        } else {
+            entity.add("lang", sourceLanguage + "-" + destLanguage);
+        }
 
         return builder.buildPost(Entity.form(entity));
     }
@@ -266,7 +270,7 @@ public class YandexTranslate extends AbstractProcessor {
 
         if (response.getStatus() != Response.Status.OK.getStatusCode()) {
             getLogger().error("Failed to translate text using Yandex for {}; 
response was {}: {}; routing to {}", new Object[]{
-                flowFile, response.getStatus(), 
response.getStatusInfo().getReasonPhrase(), REL_TRANSLATION_FAILED.getName()});
+                    flowFile, response.getStatus(), 
response.getStatusInfo().getReasonPhrase(), REL_TRANSLATION_FAILED.getName()});
             flowFile = session.putAttribute(flowFile, 
"yandex.translate.failure.reason", response.getStatusInfo().getReasonPhrase());
             session.transfer(flowFile, REL_TRANSLATION_FAILED);
             return;
@@ -306,6 +310,10 @@ public class YandexTranslate extends AbstractProcessor {
 
         @Override
         public ValidationResult validate(final String subject, final String 
input, final ValidationContext context) {
+            if ((StringUtils.isBlank(input))) {
+                return new 
ValidationResult.Builder().subject(subject).input(input).valid(true).explanation("No
 Language Input Present").build();
+            }
+
             if (context.isExpressionLanguagePresent(input)) {
                 return new 
ValidationResult.Builder().subject(subject).input(input).valid(true).explanation("Expression
 Language Present").build();
             }
@@ -318,4 +326,4 @@ public class YandexTranslate extends AbstractProcessor {
         }
 
     }
-}
+}
\ No newline at end of file

Reply via email to