提交 56ce9b3d 编写于 作者: F Francesco Fazzini 提交者: salaboy

1972 add connector model (#1973)

* 1972 add connector model

* 1972 gitignore file not necessary as there is one at parent level

* Added spring module that reads connectors

* fixed a test and the pom version not to be hardcoded

* Autoconfiguration over componentscans

* Changes based on the PR comments and connector schema changes

* refactored pom to look similar to other projects

* Adding setters to model

* Rename from connector to connector definition

* Improved code readability
上级 4b5d96a4
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>activiti-root</artifactId>
<groupId>org.activiti</groupId>
<version>7.0.0-SNAPSHOT</version>
</parent>
<artifactId>activiti-connector-model</artifactId>
<name>Activiti :: Connector model</name>
</project>
\ No newline at end of file
package org.activiti.model.connector;
import java.util.List;
public class ActionDefinition {
private String id;
private String name;
private String description;
private List<VariableDefinition> input;
private List<VariableDefinition> output;
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public List<VariableDefinition> getInput() {
return input;
}
public List<VariableDefinition> 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<VariableDefinition> input) {
this.input = input;
}
public void setOutput(List<VariableDefinition> output) {
this.output = output;
}
}
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<String, ActionDefinition> actions;
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getIcon() {
return icon;
}
public Map<String, ActionDefinition> 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<String, ActionDefinition> actions) {
this.actions = actions;
}
}
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;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>activiti-root</artifactId>
<groupId>org.activiti</groupId>
<version>7.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>activiti-spring-connector</artifactId>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-connector-model</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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<File[]> retrieveFiles() throws IOException {
Optional<File[]> 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<ConnectorDefinition> get() throws IOException {
List<ConnectorDefinition> connectorDefinitions = new ArrayList<>();
Optional<File[]> files = retrieveFiles();
if (files.isPresent()) {
for (File file : files.get()) {
connectorDefinitions.add(read(file));
}
}
return connectorDefinitions;
}
}
/*
* 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 {
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.activiti.spring.connector.autoconfigure.ConnectorAutoConfiguration
\ No newline at end of file
/*
* 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<ConnectorDefinition> 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");
}
}
/*
* 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<ConnectorDefinition> connectorDefinitions = connectorService.get();
assertThat(connectorDefinitions).isEmpty();
}
}
/*
* 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<ConnectorDefinition> connectorDefinitions = connectorService.get();
assertThat(connectorDefinitions).hasSize(3);
}
}
activiti.connectors.dir=empty_connector
\ No newline at end of file
activiti.connectors.dir=multiple_connectors
\ No newline at end of file
activiti.connectors.dir=connectors
\ No newline at end of file
{
"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
{
"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
{
"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
{
"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
......@@ -328,6 +328,8 @@
<module>activiti-spring-security</module>
<module>activiti-spring-security-policies</module>
<module>activiti-spring-boot-starter</module>
<module>activiti-spring-connector</module>
<module>activiti-connector-model</module>
</modules>
<repositories>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册