NIFI-12575 Updated nifi-asana-bundle using current API methods

This closes #8212

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
EndzeitBegins 2024-01-07 17:52:31 +01:00 committed by exceptionfactory
parent 726a930b01
commit 62d444ffc8
No known key found for this signature in database
9 changed files with 191 additions and 212 deletions

View File

@ -16,14 +16,13 @@
*/
package org.apache.nifi.processors.asana;
import java.util.Arrays;
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."
"Tasks",
"Collect tasks matching to the specified conditions."
),
AV_COLLECT_TASK_ATTACHMENTS(
"asana-collect-task-attachments",
@ -105,11 +104,4 @@ public enum AsanaObjectType implements DescribedValue {
public String getDescription() {
return description;
}
public static AsanaObjectType fromValue(String value) {
return Arrays.stream(AsanaObjectType.values())
.filter(asanaObjectType -> asanaObjectType.getValue().equals(value))
.findFirst()
.orElse(null);
}
}

View File

@ -16,33 +16,6 @@
*/
package org.apache.nifi.processors.asana;
import static java.lang.String.format;
import static java.lang.String.join;
import static java.util.Collections.singletonMap;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_EVENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_MEMBERS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_STATUS_ATTACHMENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_STATUS_UPDATES;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_STORIES;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TASKS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TASK_ATTACHMENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TEAM_MEMBERS;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
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.Map.Entry;
import java.util.Optional;
import java.util.Set;
import org.apache.http.entity.ContentType;
import org.apache.nifi.annotation.behavior.InputRequirement;
import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
@ -83,6 +56,32 @@ 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.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import static java.lang.String.format;
import static java.lang.String.join;
import static java.util.Collections.singletonMap;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_EVENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_MEMBERS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_STATUS_ATTACHMENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_STATUS_UPDATES;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_STORIES;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TASKS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TASK_ATTACHMENTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_TEAM_MEMBERS;
@TriggerSerially
@PrimaryNodeOnly
@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
@ -128,7 +127,7 @@ public class GetAsanaObject extends AbstractProcessor {
.description("Specify what kind of objects to be collected from Asana")
.required(true)
.allowableValues(AsanaObjectType.class)
.defaultValue(AV_COLLECT_TASKS.getValue())
.defaultValue(AV_COLLECT_TASKS)
.build();
protected static final PropertyDescriptor PROP_ASANA_PROJECT = new PropertyDescriptor.Builder()
@ -191,7 +190,7 @@ public class GetAsanaObject extends AbstractProcessor {
.addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
.build();
protected static final List<PropertyDescriptor> DESCRIPTORS = Collections.unmodifiableList(Arrays.asList(
protected static final List<PropertyDescriptor> DESCRIPTORS = List.of(
PROP_ASANA_CLIENT_SERVICE,
PROP_DISTRIBUTED_CACHE_SERVICE,
PROP_ASANA_OBJECT_TYPE,
@ -200,7 +199,7 @@ public class GetAsanaObject extends AbstractProcessor {
PROP_ASANA_TEAM_NAME,
PROP_ASANA_TAG,
PROP_ASANA_OUTPUT_BATCH_SIZE
));
);
protected static final Relationship REL_NEW = new Relationship.Builder()
.name(REL_NAME_NEW)
@ -219,11 +218,11 @@ public class GetAsanaObject extends AbstractProcessor {
+ "are carried by the asana.gid attribute of the generated FlowFiles.")
.build();
protected static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
protected static final Set<Relationship> RELATIONSHIPS = Set.of(
REL_NEW,
REL_UPDATED,
REL_REMOVED
)));
);
protected static final GenericObjectSerDe<String> STATE_MAP_KEY_SERIALIZER = new GenericObjectSerDe<>();
protected static final GenericObjectSerDe<Map<String, String>> STATE_MAP_VALUE_SERIALIZER = new GenericObjectSerDe<>();
@ -342,40 +341,26 @@ public class GetAsanaObject extends AbstractProcessor {
}
protected AsanaObjectFetcher createObjectFetcher(final ProcessContext context, AsanaClient client) {
final String objectType = context.getProperty(PROP_ASANA_OBJECT_TYPE).getValue();
final AsanaObjectType objectType = context.getProperty(PROP_ASANA_OBJECT_TYPE).asDescribedValue(AsanaObjectType.class);
final String projectName = context.getProperty(PROP_ASANA_PROJECT).getValue();
final String sectionName = context.getProperty(PROP_ASANA_SECTION).getValue();
final String teamName = context.getProperty(PROP_ASANA_TEAM_NAME).getValue();
final String tagName = context.getProperty(PROP_ASANA_TAG).getValue();
switch (AsanaObjectType.fromValue(objectType)) {
case AV_COLLECT_TASKS:
return new AsanaTaskFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_PROJECTS:
return new AsanaProjectFetcher(client);
case AV_COLLECT_PROJECT_EVENTS:
return new AsanaProjectEventFetcher(client, projectName);
case AV_COLLECT_PROJECT_MEMBERS:
return new AsanaProjectMembershipFetcher(client, projectName);
case AV_COLLECT_PROJECT_STATUS_ATTACHMENTS:
return new AsanaProjectStatusAttachmentFetcher(client, projectName);
case AV_COLLECT_PROJECT_STATUS_UPDATES:
return new AsanaProjectStatusFetcher(client, projectName);
case AV_COLLECT_STORIES:
return new AsanaStoryFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_TAGS:
return new AsanaTagFetcher(client);
case AV_COLLECT_TASK_ATTACHMENTS:
return new AsanaTaskAttachmentFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_TEAMS:
return new AsanaTeamFetcher(client);
case AV_COLLECT_TEAM_MEMBERS:
return new AsanaTeamMemberFetcher(client, teamName);
case AV_COLLECT_USERS:
return new AsanaUserFetcher(client);
}
throw new ProcessException("Cannot fetch objects of type: " + objectType);
return switch (objectType) {
case AV_COLLECT_TASKS -> new AsanaTaskFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_PROJECTS -> new AsanaProjectFetcher(client);
case AV_COLLECT_PROJECT_EVENTS -> new AsanaProjectEventFetcher(client, projectName);
case AV_COLLECT_PROJECT_MEMBERS -> new AsanaProjectMembershipFetcher(client, projectName);
case AV_COLLECT_PROJECT_STATUS_ATTACHMENTS -> new AsanaProjectStatusAttachmentFetcher(client, projectName);
case AV_COLLECT_PROJECT_STATUS_UPDATES -> new AsanaProjectStatusFetcher(client, projectName);
case AV_COLLECT_STORIES -> new AsanaStoryFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_TAGS -> new AsanaTagFetcher(client);
case AV_COLLECT_TASK_ATTACHMENTS -> new AsanaTaskAttachmentFetcher(client, projectName, sectionName, tagName);
case AV_COLLECT_TEAMS -> new AsanaTeamFetcher(client);
case AV_COLLECT_TEAM_MEMBERS -> new AsanaTeamMemberFetcher(client, teamName);
case AV_COLLECT_USERS -> new AsanaUserFetcher(client);
};
}
private Optional<Map<String, String>> recoverState(final ProcessContext context) {

View File

@ -59,8 +59,7 @@ public class AsanaObject {
@Override
public boolean equals(Object o) {
if (o instanceof AsanaObject) {
AsanaObject other = (AsanaObject) o;
if (o instanceof AsanaObject other) {
return state.equals(other.state)
&& Optional.ofNullable(gid).equals(Optional.ofNullable(other.gid))
&& Optional.ofNullable(content).equals(Optional.ofNullable(other.content))

View File

@ -16,11 +16,11 @@
*/
package org.apache.nifi.processors.asana.utils;
import static java.util.Collections.emptySet;
import com.asana.Json;
import com.asana.models.Resource;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.collections4.iterators.FilterIterator;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -40,7 +40,8 @@ import java.util.Set;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.collections4.iterators.FilterIterator;
import static java.util.Collections.emptySet;
public abstract class GenericAsanaObjectFetcher<T extends Resource> extends AbstractAsanaObjectFetcher {
private static final String LAST_FINGERPRINTS = ".lastFingerprints";
@ -163,7 +164,7 @@ public abstract class GenericAsanaObjectFetcher<T extends Resource> extends Abst
uncompressedBytes.write(buffer, 0, n);
}
}
return new String(uncompressedBytes.toByteArray(), StandardCharsets.UTF_8);
return uncompressedBytes.toString(StandardCharsets.UTF_8);
}
private String calculateSecureHash(String input) {

View File

@ -16,6 +16,26 @@
*/
package org.apache.nifi.processors.asana;
import com.asana.models.Project;
import com.asana.models.ProjectStatus;
import com.asana.models.Tag;
import com.asana.models.Task;
import com.asana.models.Team;
import com.asana.models.User;
import com.google.api.client.util.DateTime;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.controller.asana.AsanaClientProviderService;
import org.apache.nifi.controller.asana.AsanaEventsCollection;
import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockAsanaClientProviderService;
import org.apache.nifi.processors.asana.mocks.MockDistributedMapCacheClient;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.stream.Stream;
import static java.util.Collections.emptyList;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECTS;
import static org.apache.nifi.processors.asana.AsanaObjectType.AV_COLLECT_PROJECT_EVENTS;
@ -43,25 +63,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.asana.models.Project;
import com.asana.models.ProjectStatus;
import com.asana.models.Tag;
import com.asana.models.Task;
import com.asana.models.Team;
import com.asana.models.User;
import com.google.api.client.util.DateTime;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.controller.asana.AsanaClientProviderService;
import org.apache.nifi.controller.asana.AsanaEventsCollection;
import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockAsanaClientProviderService;
import org.apache.nifi.processors.asana.mocks.MockDistributedMapCacheClient;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class GetAsanaObjectConfigurationTest {
private TestRunner runner;
@ -77,14 +78,14 @@ public class GetAsanaObjectConfigurationTest {
@Test
public void testNotValidWithoutControllerService() {
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
runner.assertNotValid();
}
@Test
public void testNotValidWithoutDistributedMapCacheClient() throws InitializationException {
withMockAsanaClientService();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
runner.assertNotValid();
}
@ -92,7 +93,7 @@ public class GetAsanaObjectConfigurationTest {
public void testBatchSizeMustBePositiveInteger() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
runner.setProperty(PROP_ASANA_OUTPUT_BATCH_SIZE, StringUtils.EMPTY);
runner.assertNotValid();
@ -114,14 +115,14 @@ public class GetAsanaObjectConfigurationTest {
public void testValidConfigurations() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
runner.assertValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
runner.assertValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS);
runner.setProperty(PROP_ASANA_TEAM_NAME, "A team");
runner.assertValid();
}
@ -130,25 +131,25 @@ public class GetAsanaObjectConfigurationTest {
public void testConfigurationInvalidWithoutProjectName() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_MEMBERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_MEMBERS);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_STORIES.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_STORIES);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_EVENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_EVENTS);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_ATTACHMENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_ATTACHMENTS);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_UPDATES.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_UPDATES);
runner.assertNotValid();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASK_ATTACHMENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASK_ATTACHMENTS);
runner.assertNotValid();
}
@ -156,14 +157,14 @@ public class GetAsanaObjectConfigurationTest {
public void testConfigurationInvalidWithoutTeamName() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS);
}
@Test
public void testCollectProjects() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
final Project project = new Project();
project.gid = "12345";
@ -182,7 +183,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectTeams() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAMS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAMS);
final Team team = new Team();
team.gid = "12345";
@ -200,7 +201,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectTeamMembers() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TEAM_MEMBERS);
runner.setProperty(PROP_ASANA_TEAM_NAME, "A team");
final Team team = new Team();
@ -221,7 +222,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectUsers() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_USERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_USERS);
final User user = new User();
user.gid = "12345";
@ -239,7 +240,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectTags() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TAGS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TAGS);
final Tag tag = new Tag();
tag.gid = "12345";
@ -257,7 +258,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectProjectEvents() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_EVENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_EVENTS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -281,7 +282,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectProjectMembers() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_MEMBERS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_MEMBERS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -303,7 +304,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectProjectStatusUpdates() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_UPDATES.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_UPDATES);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -325,7 +326,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectProjectStatusAttachments() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_ATTACHMENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECT_STATUS_ATTACHMENTS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -352,7 +353,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectTasks() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASKS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -378,7 +379,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectTaskAttachments() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASK_ATTACHMENTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_TASK_ATTACHMENTS);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();
@ -406,7 +407,7 @@ public class GetAsanaObjectConfigurationTest {
public void testCollectStories() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_STORIES.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_STORIES);
runner.setProperty(PROP_ASANA_PROJECT, "My Project");
final Project project = new Project();

View File

@ -16,6 +16,27 @@
*/
package org.apache.nifi.processors.asana;
import com.google.gson.Gson;
import org.apache.nifi.controller.asana.AsanaClientProviderService;
import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockAsanaClientProviderService;
import org.apache.nifi.processors.asana.mocks.MockDistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockGetAsanaObject;
import org.apache.nifi.processors.asana.utils.AsanaObject;
import org.apache.nifi.processors.asana.utils.AsanaObjectFetcher;
import org.apache.nifi.processors.asana.utils.AsanaObjectFetcherException;
import org.apache.nifi.processors.asana.utils.AsanaObjectState;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
@ -38,27 +59,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.gson.Gson;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.nifi.controller.asana.AsanaClientProviderService;
import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockAsanaClientProviderService;
import org.apache.nifi.processors.asana.mocks.MockDistributedMapCacheClient;
import org.apache.nifi.processors.asana.mocks.MockGetAsanaObject;
import org.apache.nifi.processors.asana.utils.AsanaObject;
import org.apache.nifi.processors.asana.utils.AsanaObjectFetcher;
import org.apache.nifi.processors.asana.utils.AsanaObjectFetcherException;
import org.apache.nifi.processors.asana.utils.AsanaObjectState;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class GetAsanaObjectLifecycleTest {
private static final Gson GSON = new Gson();
@ -79,7 +79,7 @@ public class GetAsanaObjectLifecycleTest {
public void testYieldIsCalledWhenNoAsanaObjectsFetched() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
when(mockObjectFetcher.fetchNext()).thenReturn(null);
@ -98,7 +98,7 @@ public class GetAsanaObjectLifecycleTest {
public void testCollectObjectsFromAsanaThenYield() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
when(mockObjectFetcher.fetchNext())
.thenReturn(new AsanaObject(AsanaObjectState.NEW, "1", "Lorem ipsum"))
@ -139,19 +139,19 @@ public class GetAsanaObjectLifecycleTest {
final List<MockFlowFile> updatedFlowFiles = runner.getFlowFilesForRelationship(REL_UPDATED);
updatedFlowFiles.get(0).assertAttributeEquals(ASANA_GID, "1");
updatedFlowFiles.get(0).assertContentEquals("Lorem Ipsum");
updatedFlowFiles.getFirst().assertAttributeEquals(ASANA_GID, "1");
updatedFlowFiles.getFirst().assertContentEquals("Lorem Ipsum");
final List<MockFlowFile> removedFlowFiles = runner.getFlowFilesForRelationship(REL_REMOVED);
removedFlowFiles.get(0).assertAttributeEquals(ASANA_GID, "3");
removedFlowFiles.getFirst().assertAttributeEquals(ASANA_GID, "3");
}
@Test
public void testCollectObjectsFromAsanaWithBatchSizeConfigured() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
runner.setProperty(PROP_ASANA_OUTPUT_BATCH_SIZE, "2");
when(mockObjectFetcher.fetchNext())
@ -187,18 +187,18 @@ public class GetAsanaObjectLifecycleTest {
final List<MockFlowFile> updatedFlowFiles = runner.getFlowFilesForRelationship(REL_UPDATED);
updatedFlowFiles.get(0).assertContentEquals(GSON.toJson(singletonList("Lorem Ipsum")));
updatedFlowFiles.getFirst().assertContentEquals(GSON.toJson(singletonList("Lorem Ipsum")));
final List<MockFlowFile> removedFlowFiles = runner.getFlowFilesForRelationship(REL_REMOVED);
removedFlowFiles.get(0).assertContentEquals(GSON.toJson(singletonList("Some info about removal")));
removedFlowFiles.getFirst().assertContentEquals(GSON.toJson(singletonList("Some info about removal")));
}
@Test
public void testAttemptLoadStateButNoStatePresent() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
when(mockObjectFetcher.fetchNext()).thenReturn(null);
@ -212,7 +212,7 @@ public class GetAsanaObjectLifecycleTest {
public void testLoadValidState() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
final Map<String, String> validState = new LinkedHashMap<>();
validState.put("Key1", "Value1");
@ -232,7 +232,7 @@ public class GetAsanaObjectLifecycleTest {
public void testAttemptLoadInvalidStateThenClear() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
final Map<String, String> invalidState = singletonMap("Key", "Value");
@ -251,7 +251,7 @@ public class GetAsanaObjectLifecycleTest {
public void testStateIsSavedIfProcessorYields() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
final Map<String, String> state = singletonMap("Key", "Value");
@ -267,7 +267,7 @@ public class GetAsanaObjectLifecycleTest {
public void testStateIsSavedIfThereAreObjectsFetched() throws InitializationException {
withMockAsanaClientService();
withMockDistributedMapCacheClient();
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS.getValue());
runner.setProperty(PROP_ASANA_OBJECT_TYPE, AV_COLLECT_PROJECTS);
final Map<String, String> state = singletonMap("Key", "Value");

View File

@ -41,7 +41,6 @@ import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@ -242,7 +241,7 @@ public class StandardAsanaClient implements AsanaClient {
try {
results = collectionRequestToStream(client.workspaces.getWorkspaces(null, null, getSerializedFieldNames(Workspace.class), false))
.filter(w -> w.name.equals(workspaceName))
.collect(Collectors.toList());
.toList();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
@ -252,7 +251,7 @@ public class StandardAsanaClient implements AsanaClient {
} else if (results.size() > 1) {
throw new AsanaClientException("Multiple workspaces match: " + workspaceName);
}
return results.get(0);
return results.getFirst();
}
@Override

View File

@ -16,12 +16,7 @@
*/
package org.apache.nifi.controller.asana;
import static org.apache.nifi.controller.asana.StandardAsanaClient.ASANA_CLIENT_OPTION_BASE_URL;
import com.asana.Client;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.annotation.lifecycle.OnEnabled;
@ -30,6 +25,10 @@ import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.controller.ConfigurationContext;
import org.apache.nifi.processor.util.StandardValidators;
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 {
@ -72,11 +71,11 @@ public class StandardAsanaClientProviderService extends AbstractControllerServic
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
.build();
protected static final List<PropertyDescriptor> DESCRIPTORS = Collections.unmodifiableList(Arrays.asList(
protected static final List<PropertyDescriptor> DESCRIPTORS = List.of(
PROP_ASANA_API_BASE_URL,
PROP_ASANA_PERSONAL_ACCESS_TOKEN,
PROP_ASANA_WORKSPACE_NAME
));
);
private volatile String personalAccessToken;
private volatile String workspaceName;

View File

@ -16,18 +16,7 @@
*/
package org.apache.nifi.controller.asana;
import static java.util.stream.Collectors.toMap;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_API_BASE_URL;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_PERSONAL_ACCESS_TOKEN;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_WORKSPACE_NAME;
import static org.apache.nifi.util.TestRunners.newTestRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.asana.models.Project;
import java.io.IOException;
import java.util.Map;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.apache.nifi.reporting.InitializationException;
@ -38,46 +27,60 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_API_BASE_URL;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_PERSONAL_ACCESS_TOKEN;
import static org.apache.nifi.controller.asana.StandardAsanaClientProviderService.PROP_ASANA_WORKSPACE_NAME;
import static org.apache.nifi.util.TestRunners.newTestRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StandardAsanaClientProviderServiceTest {
private static final String LOCALHOST = "localhost";
private static final String WORKSPACES = "{\n" +
" \"data\": [\n" +
" {\n" +
" \"gid\": \"1202898619267352\",\n" +
" \"name\": \"My Workspace\",\n" +
" \"resource_type\": \"workspace\"\n" +
" },\n" +
" {\n" +
" \"gid\": \"1202939205399549\",\n" +
" \"name\": \"Company or Team Name\",\n" +
" \"resource_type\": \"workspace\"\n" +
" },\n" +
" {\n" +
" \"gid\": \"1202946450806837\",\n" +
" \"name\": \"Company or Team Name\",\n" +
" \"resource_type\": \"workspace\"\n" +
" }\n" +
" ],\n" +
" \"next_page\": null\n" +
"}";
private static final String WORKSPACES = """
{
"data": [
{
"gid": "1202898619267352",
"name": "My Workspace",
"resource_type": "workspace"
},
{
"gid": "1202939205399549",
"name": "Company or Team Name",
"resource_type": "workspace"
},
{
"gid": "1202946450806837",
"name": "Company or Team Name",
"resource_type": "workspace"
}
],
"next_page": null
}""";
private static final String PROJECTS = "{\n" +
" \"data\": [\n" +
" {\n" +
" \"gid\": \"1202898619637000\",\n" +
" \"name\": \"Our First Project\",\n" +
" \"resource_type\": \"project\"\n" +
" },\n" +
" {\n" +
" \"gid\": \"1202986168388325\",\n" +
" \"name\": \"Another Project Again\",\n" +
" \"resource_type\": \"project\"\n" +
" }\n" +
" ],\n" +
" \"next_page\": null\n" +
"}";
private static final String PROJECTS = """
{
"data": [
{
"gid": "1202898619637000",
"name": "Our First Project",
"resource_type": "project"
},
{
"gid": "1202986168388325",
"name": "Another Project Again",
"resource_type": "project"
}
],
"next_page": null
}""";
private TestRunner runner;
private StandardAsanaClientProviderService service;