turcsanyip commented on code in PR #7644: URL: https://github.com/apache/nifi/pull/7644#discussion_r1396967921
########## nifi-nar-bundles/nifi-zendesk-bundle/nifi-zendesk-nar/src/main/resources/META-INF/NOTICE: ########## @@ -4,36 +4,12 @@ Copyright 2015-2022 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). -=========================================== -Apache Software License v2 -=========================================== +************************ +BSD License +************************ -The following binary components are provided under the Apache Software License v2 - - (ASLv2) Apache Commons IO - The following NOTICE information applies: - Apache Commons IO - Copyright 2002-2017 The Apache Software Foundation - - (ASLv2) Jackson JSON processor + (BSD) ANTLR 3 Runtime (org.antlr:antlr-runtime:3.5.3) Review Comment: Based on other nar modules using Antlr, the license entry needs to be added in the `LICENSE` file instead of `NOTICE`. Please use [nifi-framework-nar](https://github.com/apache/nifi/blob/63364687d8bbe2af2d0031f745ca3c61144f8b4f/nifi-nar-bundles/nifi-framework-bundle/nifi-framework-nar/src/main/resources/META-INF/LICENSE#L204-L238) as a template. ########## nifi-nar-bundles/nifi-zendesk-bundle/nifi-zendesk-services/src/main/java/org/apache/nifi/services/zendesk/ZendeskRecordSink.java: ########## @@ -0,0 +1,239 @@ +/* + * 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.services.zendesk; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnDisabled; +import org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.common.zendesk.ZendeskAuthenticationContext; +import org.apache.nifi.common.zendesk.ZendeskAuthenticationType; +import org.apache.nifi.common.zendesk.ZendeskClient; +import org.apache.nifi.common.zendesk.validation.JsonPointerPropertyNameValidator; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.record.sink.RecordSinkService; +import org.apache.nifi.schema.access.SchemaNotFoundException; +import org.apache.nifi.serialization.RecordSetWriter; +import org.apache.nifi.serialization.RecordSetWriterFactory; +import org.apache.nifi.serialization.WriteResult; +import org.apache.nifi.serialization.record.Record; +import org.apache.nifi.serialization.record.RecordSet; +import org.apache.nifi.web.client.api.HttpResponseEntity; +import org.apache.nifi.web.client.api.HttpResponseStatus; +import org.apache.nifi.web.client.api.HttpUriBuilder; +import org.apache.nifi.web.client.provider.api.WebClientServiceProvider; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static java.lang.String.format; +import static org.apache.nifi.common.zendesk.ZendeskProperties.WEB_CLIENT_SERVICE_PROVIDER; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_AUTHENTICATION_CREDENTIAL; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_AUTHENTICATION_TYPE; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_CREATE_TICKETS_RESOURCE; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_CREATE_TICKET_RESOURCE; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_SUBDOMAIN; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_TICKET_COMMENT_BODY; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_TICKET_PRIORITY; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_TICKET_SUBJECT; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_TICKET_TYPE; +import static org.apache.nifi.common.zendesk.ZendeskProperties.ZENDESK_USER; +import static org.apache.nifi.common.zendesk.util.ZendeskRecordPathUtils.addDynamicField; +import static org.apache.nifi.common.zendesk.util.ZendeskRecordPathUtils.addField; +import static org.apache.nifi.common.zendesk.util.ZendeskUtils.createRequestObject; +import static org.apache.nifi.common.zendesk.util.ZendeskUtils.getDynamicProperties; +import static org.apache.nifi.common.zendesk.util.ZendeskUtils.getResponseBody; + +@Tags({"zendesk", "record", "sink"}) +@CapabilityDescription("Create Zendesk tickets using the Zendesk API." + + "The service requires a Zendesk account with configured access.") +public class ZendeskRecordSink extends AbstractControllerService implements RecordSinkService { + + private final ObjectMapper mapper = new ObjectMapper(); + private Map<String, String> dynamicProperties; + private volatile RecordSetWriterFactory writerFactory; + private Cache<String, ObjectNode> recordCache; + private ZendeskClient zendeskClient; + + private String commentBody; + private String subject; + private String priority; + private String type; + + static final PropertyDescriptor CACHE_SIZE = new PropertyDescriptor.Builder() + .name("cache-size") + .displayName("Cache Size") + .description("Specifies how many Zendesk ticket should be cached.") + .addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR) + .defaultValue("1000") + .required(true) + .build(); + + static final PropertyDescriptor CACHE_EXPIRATION = new PropertyDescriptor.Builder() + .name("cache-expiration") + .displayName("Cache Expiration") + .description("Specifies how long a Zendesk ticket that is cached should remain in the cache.") + .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR) + .defaultValue("1 hour") + .required(true) + .build(); + + private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList( + RecordSinkService.RECORD_WRITER_FACTORY, Review Comment: The Zendesk API accepts only Json input so it does not really need a configurable record writer. It should be removed and the request json can simply be created in the service without the writer. ########## nifi-nar-bundles/nifi-extension-utils/nifi-record-path-property/src/main/java/org/apache/nifi/record/path/property/RecordPathPropertyUtil.java: ########## @@ -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 value property value to be resolved + * @param record record to receive the value from if the field value is a record path + */ + public static String resolvePropertyValue(String value, Record record) { Review Comment: Minor correction in wording but it is a common utility method so it is worth being more precise: ```suggestion * @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) { ``` -- 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]
