forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-11992: Processor and sink service for filing tickets in Zendesk
This closes apache#7644. Signed-off-by: Peter Turcsanyi <[email protected]>
- Loading branch information
1 parent
3b0d810
commit 7770a17
Showing
33 changed files
with
2,998 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
nifi-nar-bundles/nifi-extension-utils/nifi-record-path-property/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-extension-utils</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>nifi-record-path-property</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-record-path</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
117 changes: 117 additions & 0 deletions
117
...h-property/src/main/java/org/apache/nifi/record/path/property/RecordPathPropertyUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* 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.record.path.property; | ||
|
||
import org.apache.nifi.processor.exception.ProcessException; | ||
import org.apache.nifi.record.path.FieldValue; | ||
import org.apache.nifi.record.path.RecordPath; | ||
import org.apache.nifi.record.path.RecordPathResult; | ||
import org.apache.nifi.serialization.record.DataType; | ||
import org.apache.nifi.serialization.record.Record; | ||
import org.apache.nifi.serialization.record.RecordFieldType; | ||
import org.apache.nifi.serialization.record.type.ChoiceDataType; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
public final class RecordPathPropertyUtil { | ||
|
||
private static final String NULL_VALUE = "null"; | ||
private static final Pattern RECORD_PATH_PATTERN = Pattern.compile("@\\{(/.*?)\\}"); | ||
|
||
private RecordPathPropertyUtil() { | ||
} | ||
|
||
/** | ||
* Resolves the property value to be handled as a record path or a constant value. | ||
* | ||
* @param propertyValue property value to be resolved | ||
* @param record record to resolve the value from if the property value is a record path | ||
*/ | ||
public static String resolvePropertyValue(String propertyValue, Record record) { | ||
if (propertyValue != null && !propertyValue.isBlank()) { | ||
final Matcher matcher = RECORD_PATH_PATTERN.matcher(propertyValue); | ||
if (matcher.matches()) { | ||
return resolveRecordState(matcher.group(1), record); | ||
} else { | ||
return propertyValue; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static String resolveRecordState(String pathValue, final Record record) { | ||
final RecordPath recordPath = RecordPath.compile(pathValue); | ||
final RecordPathResult result = recordPath.evaluate(record); | ||
final List<FieldValue> fieldValues = result.getSelectedFields().collect(toList()); | ||
final FieldValue fieldValue = getMatchingFieldValue(recordPath, fieldValues); | ||
|
||
if (fieldValue.getValue() == null || fieldValue.getValue() == NULL_VALUE) { | ||
return null; | ||
} | ||
|
||
return getFieldValue(recordPath, fieldValue); | ||
} | ||
|
||
/** | ||
* The method checks if only one result were received for the give record path. | ||
* | ||
* @param recordPath path to the requested field | ||
* @param resultList result list | ||
* @return matching field | ||
*/ | ||
private static FieldValue getMatchingFieldValue(final RecordPath recordPath, final List<FieldValue> resultList) { | ||
if (resultList.isEmpty()) { | ||
throw new ProcessException(String.format("Evaluated RecordPath [%s] against Record but got no results", recordPath)); | ||
} | ||
|
||
if (resultList.size() > 1) { | ||
throw new ProcessException(String.format("Evaluated RecordPath [%s] against Record and received multiple distinct results [%s]", recordPath, resultList)); | ||
} | ||
|
||
return resultList.get(0); | ||
} | ||
|
||
/** | ||
* The method checks the field's type and filters out every non-compatible type. | ||
* | ||
* @param recordPath path to the requested field | ||
* @param fieldValue record field | ||
* @return value of the record field | ||
*/ | ||
private static String getFieldValue(final RecordPath recordPath, FieldValue fieldValue) { | ||
final RecordFieldType fieldType = fieldValue.getField().getDataType().getFieldType(); | ||
|
||
if (fieldType == RecordFieldType.RECORD || fieldType == RecordFieldType.ARRAY || fieldType == RecordFieldType.MAP) { | ||
throw new ProcessException(String.format("The provided RecordPath [%s] points to a [%s] type value", recordPath, fieldType)); | ||
} | ||
|
||
if (fieldType == RecordFieldType.CHOICE) { | ||
final ChoiceDataType choiceDataType = (ChoiceDataType) fieldValue.getField().getDataType(); | ||
final List<DataType> possibleTypes = choiceDataType.getPossibleSubTypes(); | ||
if (possibleTypes.stream().anyMatch(type -> type.getFieldType() == RecordFieldType.RECORD)) { | ||
throw new ProcessException(String.format("The provided RecordPath [%s] points to a [CHOICE] type value with Record subtype", recordPath)); | ||
} | ||
} | ||
|
||
return String.valueOf(fieldValue.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
nifi-nar-bundles/nifi-zendesk-bundle/nifi-zendesk-common/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-zendesk-bundle</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>nifi-zendesk-common</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<!-- Internal dependencies --> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-utils</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-web-client-provider-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-record-path-property</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- External dependencies --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-ssl-context-service-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
48 changes: 48 additions & 0 deletions
48
...esk-common/src/main/java/org/apache/nifi/common/zendesk/ZendeskAuthenticationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.common.zendesk; | ||
|
||
public class ZendeskAuthenticationContext { | ||
|
||
private final String subdomain; | ||
private final String user; | ||
private final ZendeskAuthenticationType authenticationType; | ||
private final String authenticationCredentials; | ||
|
||
public ZendeskAuthenticationContext(String subdomain, String user, ZendeskAuthenticationType authenticationType, String authenticationCredentials) { | ||
this.subdomain = subdomain; | ||
this.user = user; | ||
this.authenticationType = authenticationType; | ||
this.authenticationCredentials =authenticationCredentials; | ||
} | ||
|
||
public String getSubdomain() { | ||
return subdomain; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public ZendeskAuthenticationType getAuthenticationType() { | ||
return authenticationType; | ||
} | ||
|
||
public String getAuthenticationCredentials() { | ||
return authenticationCredentials; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.