diff --git a/activiti-connector-model/pom.xml b/activiti-connector-model/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..ded4253661d3555cf788542c3fc7c385cd65ecd4 --- /dev/null +++ b/activiti-connector-model/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + activiti-root + org.activiti + 7.0.0-SNAPSHOT + + activiti-connector-model + Activiti :: Connector model + \ No newline at end of file diff --git a/activiti-connector-model/src/main/java/org/activiti/model/connector/ActionDefinition.java b/activiti-connector-model/src/main/java/org/activiti/model/connector/ActionDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..d2cdb1b799c84e32ba70d53572dcaefb11e6030d --- /dev/null +++ b/activiti-connector-model/src/main/java/org/activiti/model/connector/ActionDefinition.java @@ -0,0 +1,56 @@ +package org.activiti.model.connector; + +import java.util.List; + +public class ActionDefinition { + + private String id; + + private String name; + + private String description; + + private List input; + + private List output; + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public List getInput() { + return input; + } + + public List getOutput() { + return output; + } + + public void setId(String id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setInput(List input) { + this.input = input; + } + + public void setOutput(List output) { + this.output = output; + } +} diff --git a/activiti-connector-model/src/main/java/org/activiti/model/connector/ConnectorDefinition.java b/activiti-connector-model/src/main/java/org/activiti/model/connector/ConnectorDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..b6cb7c8f8a34cd098902dc413a0d61953d8d2c70 --- /dev/null +++ b/activiti-connector-model/src/main/java/org/activiti/model/connector/ConnectorDefinition.java @@ -0,0 +1,56 @@ +package org.activiti.model.connector; + +import java.util.Map; + +public class ConnectorDefinition { + + private String id; + + private String name; + + private String description; + + private String icon; + + private Map actions; + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getIcon() { + return icon; + } + + public Map getActions() { + return actions; + } + + public void setId(String id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public void setActions(Map actions) { + this.actions = actions; + } +} diff --git a/activiti-connector-model/src/main/java/org/activiti/model/connector/VariableDefinition.java b/activiti-connector-model/src/main/java/org/activiti/model/connector/VariableDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..336885c44a2865d2c1c9511523882591ba5d2f8a --- /dev/null +++ b/activiti-connector-model/src/main/java/org/activiti/model/connector/VariableDefinition.java @@ -0,0 +1,54 @@ +package org.activiti.model.connector; + +public class VariableDefinition { + + private String id; + + private String name; + + private String description; + + private String type; + + private boolean required; + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getType() { + return type; + } + + public boolean isRequired() { + return required; + } + + public void setId(String id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setType(String type) { + this.type = type; + } + + public void setRequired(boolean required) { + this.required = required; + } +} diff --git a/activiti-spring-connector/pom.xml b/activiti-spring-connector/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..28b4faebea67d7a9b7687426bf1210105f105612 --- /dev/null +++ b/activiti-spring-connector/pom.xml @@ -0,0 +1,45 @@ + + + + activiti-root + org.activiti + 7.0.0-SNAPSHOT + + 4.0.0 + + activiti-spring-connector + + + + org.activiti + activiti-connector-model + ${version} + + + org.springframework + spring-beans + + + org.springframework + spring-context + + + com.fasterxml.jackson.core + jackson-databind + + + + + junit + junit + test + + + org.springframework.boot + spring-boot-starter-test + test + + + \ No newline at end of file diff --git a/activiti-spring-connector/src/main/java/org/activiti/spring/connector/ConnectorService.java b/activiti-spring-connector/src/main/java/org/activiti/spring/connector/ConnectorService.java new file mode 100644 index 0000000000000000000000000000000000000000..1ec4e98241d5d3f1cff97dd7a05796c5810643d2 --- /dev/null +++ b/activiti-spring-connector/src/main/java/org/activiti/spring/connector/ConnectorService.java @@ -0,0 +1,77 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed 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.activiti.spring.connector; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.activiti.model.connector.ConnectorDefinition; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Service; + +@Service +public class ConnectorService { + + @Value("${activiti.connectors.dir:connectors}") + private String connectorRoot; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + private Optional retrieveFiles() throws IOException { + + Optional connectorFiles = Optional.empty(); + + Resource connectorRootPath = new ClassPathResource(connectorRoot); + if (connectorRootPath.exists()) { + connectorFiles = Optional.ofNullable(connectorRootPath.getFile().listFiles(new FilenameFilter() { + + @Override + public boolean accept(File dir, + String name) { + return (name.toLowerCase().endsWith(".json")); + } + }) + ); + } + return connectorFiles; + } + + private ConnectorDefinition read(File file) throws IOException { + return objectMapper.readValue(file, + ConnectorDefinition.class); + } + + public List get() throws IOException { + + List connectorDefinitions = new ArrayList<>(); + Optional files = retrieveFiles(); + if (files.isPresent()) { + for (File file : files.get()) { + connectorDefinitions.add(read(file)); + } + } + return connectorDefinitions; + } +} + diff --git a/activiti-spring-connector/src/main/java/org/activiti/spring/connector/autoconfigure/ConnectorAutoConfiguration.java b/activiti-spring-connector/src/main/java/org/activiti/spring/connector/autoconfigure/ConnectorAutoConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..0277b33b180d3130e91ddbac71e8149251f2bdbe --- /dev/null +++ b/activiti-spring-connector/src/main/java/org/activiti/spring/connector/autoconfigure/ConnectorAutoConfiguration.java @@ -0,0 +1,26 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed 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.activiti.spring.connector.autoconfigure; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan(basePackages = "org.activiti.spring.connector") +public class ConnectorAutoConfiguration { + +} diff --git a/activiti-spring-connector/src/main/resources/META-INF/spring.factories b/activiti-spring-connector/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000000000000000000000000000000000..db0ce04b0c98dfb4e0f7e29bc5dc74762a6881bd --- /dev/null +++ b/activiti-spring-connector/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.activiti.spring.connector.autoconfigure.ConnectorAutoConfiguration \ No newline at end of file diff --git a/activiti-spring-connector/src/test/java/org/activiti/spring/connector/ConnectorDefinitionServiceIT.java b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/ConnectorDefinitionServiceIT.java new file mode 100644 index 0000000000000000000000000000000000000000..a4c65ba8efb389bceda415ef03fa62ccbf5a4f22 --- /dev/null +++ b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/ConnectorDefinitionServiceIT.java @@ -0,0 +1,53 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed 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.activiti.spring.connector; + +import java.io.IOException; +import java.util.List; + +import org.activiti.model.connector.ConnectorDefinition; +import org.activiti.spring.connector.autoconfigure.ConnectorAutoConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.*; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ConnectorAutoConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) +@TestPropertySource(locations = "classpath:application-single-test.properties") +public class ConnectorDefinitionServiceIT { + + @Autowired + private ConnectorService connectorService; + + @Test + public void connector() throws IOException { + + List connectorDefinitions = connectorService.get(); + assertThat(connectorDefinitions).hasSize(1); + assertThat(connectorDefinitions.get(0).getId()).isEqualTo("connector-uuid"); + assertThat(connectorDefinitions.get(0).getName()).isEqualTo("Name-of-the-connector"); + assertThat(connectorDefinitions.get(0).getActions().size()).isEqualTo(2); + assertThat(connectorDefinitions.get(0).getActions().get("actionId1").getName()).isEqualTo("actionName1"); + assertThat(connectorDefinitions.get(0).getActions().get("actionId1").getInput().get(0).getName()).isEqualTo("input-variable-name-1"); + assertThat(connectorDefinitions.get(0).getActions().get("actionId1").getOutput().get(0).getName()).isEqualTo("output-variable-name-1"); + } +} diff --git a/activiti-spring-connector/src/test/java/org/activiti/spring/connector/EmptyConnectorDefinitionServiceIT.java b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/EmptyConnectorDefinitionServiceIT.java new file mode 100644 index 0000000000000000000000000000000000000000..76c0b1b240e5d70db65fa029626872564cc752f7 --- /dev/null +++ b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/EmptyConnectorDefinitionServiceIT.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed 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.activiti.spring.connector; + +import java.io.IOException; +import java.util.List; + +import org.activiti.model.connector.ConnectorDefinition; +import org.activiti.spring.connector.autoconfigure.ConnectorAutoConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.*; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ConnectorAutoConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) +@TestPropertySource(locations = "classpath:application-empty-test.properties") +public class EmptyConnectorDefinitionServiceIT { + + @Autowired + private ConnectorService connectorService; + + @Test + public void emptyConnectors() throws IOException { + + List connectorDefinitions = connectorService.get(); + + assertThat(connectorDefinitions).isEmpty(); + } +} diff --git a/activiti-spring-connector/src/test/java/org/activiti/spring/connector/MultipleConnectorDefinitionServiceIT.java b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/MultipleConnectorDefinitionServiceIT.java new file mode 100644 index 0000000000000000000000000000000000000000..5d77fcdfa791b29167aa332d8215caa3320dd6ae --- /dev/null +++ b/activiti-spring-connector/src/test/java/org/activiti/spring/connector/MultipleConnectorDefinitionServiceIT.java @@ -0,0 +1,50 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed 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.activiti.spring.connector; + +import java.io.IOException; +import java.util.List; + +import org.activiti.model.connector.ConnectorDefinition; +import org.activiti.spring.connector.autoconfigure.ConnectorAutoConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.*; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ConnectorAutoConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) +@TestPropertySource(locations = "classpath:application-multiple-test.properties") +public class MultipleConnectorDefinitionServiceIT { + + @Autowired + private ConnectorService connectorService; + + /** + * Three files have json extensions, one does not. + **/ + @Test + public void connectors() throws IOException { + + List connectorDefinitions = connectorService.get(); + assertThat(connectorDefinitions).hasSize(3); + } +} diff --git a/activiti-spring-connector/src/test/resources/application-empty-test.properties b/activiti-spring-connector/src/test/resources/application-empty-test.properties new file mode 100644 index 0000000000000000000000000000000000000000..8a34302d0c12b89ecfcc1b0b500a6006edb47c44 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/application-empty-test.properties @@ -0,0 +1 @@ +activiti.connectors.dir=empty_connector \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/application-multiple-test.properties b/activiti-spring-connector/src/test/resources/application-multiple-test.properties new file mode 100644 index 0000000000000000000000000000000000000000..ee2e19d1935b6fd22402505bd195321df56341d4 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/application-multiple-test.properties @@ -0,0 +1 @@ +activiti.connectors.dir=multiple_connectors \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/application-single-test.properties b/activiti-spring-connector/src/test/resources/application-single-test.properties new file mode 100644 index 0000000000000000000000000000000000000000..6b40556bc4603b6dd5a838d222e8344b9ec22879 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/application-single-test.properties @@ -0,0 +1 @@ +activiti.connectors.dir=connectors \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/connectors/connector.json b/activiti-spring-connector/src/test/resources/connectors/connector.json new file mode 100644 index 0000000000000000000000000000000000000000..4b94308ca21c62fe00c370f2ee7103ae2ab25123 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/connectors/connector.json @@ -0,0 +1,44 @@ +{ + "id": "connector-uuid", + "name": "Name-of-the-connector", + "description": "Description of the connector", + "icon": "path to icon", + "actions": { + "actionId1": { + "id": "actionId1", + "name": "actionName1", + "description": "description", + "input": [ + { + "id": "input-variable-1", + "name": "input-variable-name-1", + "type": "string", + "required": false, + "description": "description" + }, + { + "id": "input-variable-2", + "name": "input-variable-name-2", + "type": "boolean", + "required": false, + "description": "" + } + ], + "output": [ + { + "id": "output-variable-1", + "name": "output-variable-name-1", + "type": "string", + "description": "" + }, + { + "id": "output-variable-2", + "name": "output-variable-name-2", + "type": "string", + "description": "" + } + ] + }, + "actionName2": {} + } +} \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/multiple_connectors/connector.json b/activiti-spring-connector/src/test/resources/multiple_connectors/connector.json new file mode 100644 index 0000000000000000000000000000000000000000..83afc50858ecbf5143342e8a2eab6b856a795c96 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/multiple_connectors/connector.json @@ -0,0 +1,44 @@ +{ + "id": "connector-uuid", + "name": "Name-of-the-connector", + "description": "Description of the connector", + "icon": "path to icon", + "actions": { + "actionId1": { + "id": "actionId1", + "name": "actionName1", + "description": "description", + "input": [ + { + "id": "input-variable-1", + "name": "input-variable-name-1", + "type": "string", + "required": false, + "description": "description" + }, + { + "id": "input-variable-2", + "name": "input-variable-name-2", + "type": "boolean", + "required": false, + "description": "" + } + ], + "output": [ + { + "id": "output-variable-1", + "name": "output-variable-name-1", + "type": "string", + "description": "" + }, + { + "id": "output-variable-2", + "name": "output-variable-name-2", + "type": "string", + "description": "" + } + ] + }, + "actionName2": {} + } +} \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/multiple_connectors/connector2.json b/activiti-spring-connector/src/test/resources/multiple_connectors/connector2.json new file mode 100644 index 0000000000000000000000000000000000000000..e6e107f24f2697097dbc6b30b1733f56efa0adb1 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/multiple_connectors/connector2.json @@ -0,0 +1,44 @@ +{ + "id": "connector-uuid-2", + "name": "Name-of-the-connector-2", + "description": "Description of the connector", + "icon": "path to icon", + "actions": { + "actionId1": { + "id": "actionId1", + "name": "actionName1", + "description": "description", + "input": [ + { + "id": "input-variable-1", + "name": "input-variable-name-1", + "type": "string", + "required": false, + "description": "description" + }, + { + "id": "input-variable-2", + "name": "input-variable-name-2", + "type": "boolean", + "required": false, + "description": "" + } + ], + "output": [ + { + "id": "output-variable-1", + "name": "output-variable-name-1", + "type": "string", + "description": "" + }, + { + "id": "output-variable-2", + "name": "output-variable-name-2", + "type": "string", + "description": "" + } + ] + }, + "actionName2": {} + } +} \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/multiple_connectors/connector3.json b/activiti-spring-connector/src/test/resources/multiple_connectors/connector3.json new file mode 100644 index 0000000000000000000000000000000000000000..f0a90e4545f1caf824357319f00b896e488820d6 --- /dev/null +++ b/activiti-spring-connector/src/test/resources/multiple_connectors/connector3.json @@ -0,0 +1,44 @@ +{ + "id": "connector-uuid-3", + "name": "Name-of-the-connector-3", + "description": "Description of the connector", + "icon": "path to icon", + "actions": { + "actionId1": { + "id": "actionId1", + "name": "actionName1", + "description": "description", + "input": [ + { + "id": "input-variable-1", + "name": "input-variable-name-1", + "type": "string", + "required": false, + "description": "description" + }, + { + "id": "input-variable-2", + "name": "input-variable-name-2", + "type": "boolean", + "required": false, + "description": "" + } + ], + "output": [ + { + "id": "output-variable-1", + "name": "output-variable-name-1", + "type": "string", + "description": "" + }, + { + "id": "output-variable-2", + "name": "output-variable-name-2", + "type": "string", + "description": "" + } + ] + }, + "actionName2": {} + } +} \ No newline at end of file diff --git a/activiti-spring-connector/src/test/resources/multiple_connectors/connector_wrong.txt b/activiti-spring-connector/src/test/resources/multiple_connectors/connector_wrong.txt new file mode 100644 index 0000000000000000000000000000000000000000..1696b6bf2faff13b500c6363b93d6cac19b18deb --- /dev/null +++ b/activiti-spring-connector/src/test/resources/multiple_connectors/connector_wrong.txt @@ -0,0 +1 @@ +connector wrong file extension \ No newline at end of file diff --git a/pom.xml b/pom.xml index 545f0cbf0c4aac6e85fe413da2b774fb93ffb486..0b66170597dd88bef2019e313e63a28785b314c0 100644 --- a/pom.xml +++ b/pom.xml @@ -328,6 +328,8 @@ activiti-spring-security activiti-spring-security-policies activiti-spring-boot-starter + activiti-spring-connector + activiti-connector-model