[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6504: NIFI-10618: Add Asana connector

2022-11-23 Thread GitBox


exceptionfactory commented on code in PR #6504:
URL: https://github.com/apache/nifi/pull/6504#discussion_r1030605452


##
nifi-nar-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/AsanaObjectType.java:
##
@@ -0,0 +1,120 @@
+/*
+ * 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.processors.asana;
+
+import java.util.Arrays;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.DescribedValue;
+
+public enum AsanaObjectType implements DescribedValue {
+AV_COLLECT_TASKS(
+"asana-collect-tasks",
+"Tasks", ""
++ "Collect tasks matching to the specified conditions."
+),
+AV_COLLECT_TASK_ATTACHMENTS(
+"asana-collect-task-attachments",
+"Task Attachments",
+"Collect attached files of tasks matching to the specified 
conditions."
+),
+AV_COLLECT_PROJECTS(
+"asana-collect-projects",
+"Projects",
+"Collect projects of the workspace."
+),
+AV_COLLECT_TAGS(
+"asana-collect-tags",
+"Tags",
+"Collect tags of the workspace."
+),
+AV_COLLECT_USERS(
+"asana-collect-users",
+"Users",
+"Collect users assigned to the workspace."
+),
+AV_COLLECT_PROJECT_MEMBERS(
+"asana-collect-project-members",
+"Members of a Project",
+"Collect users assigned to the specified project."
+),
+AV_COLLECT_TEAMS(
+"asana-collect-teams",
+"Teams",
+"Collect teams of the workspace."
+),
+AV_COLLECT_TEAM_MEMBERS(
+"asana-collect-team-members",
+"Team Members",
+"Collect users assigned to the specified team."
+),
+AV_COLLECT_STORIES(
+"asana-collect-stories",
+"Stories of Tasks",
+"Collect stories (comments) of of tasks matching to the specified 
conditions."
+),
+AV_COLLECT_PROJECT_STATUS_UPDATES(
+"asana-collect-project-status-updates",
+"Status Updates of a Project",
+"Collect status updates of the specified project."
+),
+AV_COLLECT_PROJECT_STATUS_ATTACHMENTS(
+"asana-collect-project-status-attachments",
+"Attachments of Status Updates",
+"Collect attached files of project status updates."
+),
+AV_COLLECT_PROJECT_EVENTS(
+"asana-collect-project-events",
+"Events of a Project",
+"Collect various events happening on the specified project and on 
its' tasks."
+);
+
+private final String value;
+private final String displayName;
+private final String description;
+
+AsanaObjectType(String value, String displayName, String description) {
+this.value = value;
+this.displayName = displayName;
+this.description = description;
+}
+
+@Override
+public String getValue() {
+return value;
+}
+
+@Override
+public String getDisplayName() {
+return displayName;
+}
+
+@Override
+public String getDescription() {
+return description;
+}
+
+public AllowableValue createAllowableValue() {
+return new AllowableValue(value, displayName, description);
+}

Review Comment:
   This method should be unnecessary, since `getValue()` can be used directly.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6504: NIFI-10618: Add Asana connector

2022-11-02 Thread GitBox


exceptionfactory commented on code in PR #6504:
URL: https://github.com/apache/nifi/pull/6504#discussion_r1012402834


##
nifi-nar-bundles/nifi-asana-bundle/nifi-asana-processors/src/main/java/org/apache/nifi/processors/asana/GetAsanaObject.java:
##
@@ -0,0 +1,429 @@
+/*
+ * 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.processors.asana;
+
+import org.apache.http.entity.ContentType;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
+import org.apache.nifi.annotation.behavior.Stateful;
+import org.apache.nifi.annotation.behavior.TriggerSerially;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.components.state.StateMap;
+import org.apache.nifi.controller.asana.AsanaClient;
+import org.apache.nifi.controller.asana.AsanaClientProviderService;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.asana.utils.AsanaObject;
+import org.apache.nifi.processors.asana.utils.AsanaObjectFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaProjectEventFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaProjectFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaProjectMembershipFetcher;
+import 
org.apache.nifi.processors.asana.utils.AsanaProjectStatusAttachmentFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaProjectStatusFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaStoryFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaTagFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaTaskAttachmentFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaTaskFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaTeamFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaTeamMemberFetcher;
+import org.apache.nifi.processors.asana.utils.AsanaUserFetcher;
+import org.apache.nifi.reporting.InitializationException;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+@TriggerSerially
+@PrimaryNodeOnly
+@Stateful(scopes = {Scope.CLUSTER}, description = "Fingerprints of items in 
the last successful query are stored in order to enable incremental loading and 
change detection.")
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@WritesAttribute(attribute = GetAsanaObject.ASANA_GID, description = "Global 
ID of the object in Asana.")
+@Tags({"asana", "source", "ingest"})
+@CapabilityDescription("This processor collects data from Asana")
+public class GetAsanaObject extends AbstractProcessor {
+
+protected static final String ASANA_GID = "asana.gid";
+protected static final String AV_NAME_COLLECT_TASKS = 
"asana-collect-tasks";
+protected static final String AV_NAME_COLLECT_TASK_ATTACHMENTS = 
"asana-collect-task-attachments";
+protected static final String AV_NAME_COLLECT_PROJECTS = 
"asana-collect-projects";
+protected static final String AV_NAME_COLLECT_TAGS = "asana-collect-tags";
+protected static final String AV_NAME_COLLECT_USERS = 
"asana-collect-users";
+protected static final String AV_NAME_COLLECT_PROJECT_MEMBERS = 
"asana-collect-project-members

[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6504: NIFI-10618: Add Asana connector

2022-11-02 Thread GitBox


exceptionfactory commented on code in PR #6504:
URL: https://github.com/apache/nifi/pull/6504#discussion_r1012362913


##
nifi-nar-bundles/nifi-asana-bundle/nifi-asana-services/src/main/java/org/apache/nifi/controller/asana/StandardAsanaClientProviderService.java:
##
@@ -0,0 +1,104 @@
+/*
+ * 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.controller.asana;
+
+import com.asana.Client;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.resource.ResourceCardinality;
+import org.apache.nifi.components.resource.ResourceType;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static 
org.apache.nifi.controller.asana.StandardAsanaClient.ASANA_CLIENT_OPTION_BASE_URL;
+
+@CapabilityDescription("Common service to authenticate with Asana, and to work 
on a specified workspace.")
+@Tags({"asana", "service", "authentication"})
+public class StandardAsanaClientProviderService extends 
AbstractControllerService implements AsanaClientProviderService {
+
+protected static final String ASANA_API_URL = "asana-api-url";
+protected static final String ASANA_PERSONAL_ACCESS_TOKEN = 
"asana-personal-access-token";
+protected static final String ASANA_WORKSPACE_NAME = 
"asana-workspace-name";
+
+protected static final PropertyDescriptor PROP_ASANA_API_BASE_URL = new 
PropertyDescriptor.Builder()
+.name(ASANA_API_URL)
+.displayName("API URL")
+.description("Base URL of Asana API. Leave it as default, unless 
you have your own Asana instance "
++ "serving on a different URL. (typical for on-premise 
installations)")
+.required(true)
+
.defaultValue(Client.DEFAULTS.get(ASANA_CLIENT_OPTION_BASE_URL).toString())
+.identifiesExternalResource(ResourceCardinality.SINGLE, 
ResourceType.URL)

Review Comment:
   This attribute should be removed, as the External Resource feature is used 
for retrieving content, not for referencing a URL.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6504: NIFI-10618: Add Asana connector

2022-11-02 Thread GitBox


exceptionfactory commented on code in PR #6504:
URL: https://github.com/apache/nifi/pull/6504#discussion_r1012362369


##
nifi-nar-bundles/nifi-asana-bundle/nifi-asana-services/src/main/java/org/apache/nifi/controller/asana/StandardAsanaClient.java:
##
@@ -0,0 +1,303 @@
+/*
+ * 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.controller.asana;
+
+import com.asana.Client;
+import com.asana.errors.InvalidTokenError;
+import com.asana.models.Attachment;
+import com.asana.models.Event;
+import com.asana.models.Project;
+import com.asana.models.ProjectMembership;
+import com.asana.models.ProjectStatus;
+import com.asana.models.Resource;
+import com.asana.models.ResultBodyCollection;
+import com.asana.models.Section;
+import com.asana.models.Story;
+import com.asana.models.Tag;
+import com.asana.models.Task;
+import com.asana.models.Team;
+import com.asana.models.User;
+import com.asana.models.Workspace;
+import com.asana.requests.CollectionRequest;
+import com.asana.requests.EventsRequest;
+import com.google.gson.annotations.SerializedName;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+public class StandardAsanaClient implements AsanaClient {
+
+static final String ASANA_CLIENT_OPTION_BASE_URL = "base_url";
+
+private final Client client;
+private final Workspace workspace;
+
+public StandardAsanaClient(String personalAccessToken, String 
workspaceName, String baseUrl) {
+client = Client.accessToken(personalAccessToken);
+if (baseUrl != null) {
+client.options.put(ASANA_CLIENT_OPTION_BASE_URL, baseUrl);
+}
+workspace = getWorkspaceByName(workspaceName);
+}
+
+@Override
+public Project getProjectByName(String projectName) {
+return getProjects()
+.values()
+.stream()
+.filter(p -> p.name.equals(projectName))
+.findFirst()
+.orElseThrow(() -> new RuntimeException("No such project: " + 
projectName));
+}
+
+@Override
+public Map getProjects() {
+try {
+return collectionRequestToMap(
+client.projects.getProjects(null, null, workspace.gid, 
null, null, getSerializedFieldNames(Project.class), false)
+);
+} catch (IOException e) {
+throw new RuntimeException(e);

Review Comment:
   `RuntimeException` should be replaced with `UncheckedIOException` to provide 
a better representation of the wrapped exception.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org