[Client] [Cli] Support data source info

This commit is contained in:
qianmoQ 2022-12-26 21:10:34 +08:00
parent f463b99445
commit 34541b3d52
8 changed files with 98 additions and 0 deletions

1
.gitignore vendored
View File

@ -40,3 +40,4 @@ tmp/
# vscode #
.vscode
dist/datacap/
list

View File

@ -65,6 +65,35 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly-plugin.version}</version>
<configuration>
<finalName>datacap-cli</finalName>
<archive>
<manifest>
<mainClass>io.edurt.datacap.client.cli.DataCapCli</mainClass>
</manifest>
</archive>
<!-- <descriptorRefs>-->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
<!-- </descriptorRefs>-->
<descriptors>
<descriptor>../../configure/assembly/assembly-cli.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -13,6 +13,7 @@ public class DataCapCli
SpringApplication application = new SpringApplication(DataCapCli.class);
application.setBannerMode(Banner.Mode.OFF);
application.setWebApplicationType(WebApplicationType.NONE);
application.setLogStartupInfo(false);
application.run(args);
}

View File

@ -5,4 +5,6 @@ import org.springframework.shell.table.Table;
public interface DataSourceService
{
Table showList();
Table getInfo();
}

View File

@ -13,9 +13,12 @@ import org.springframework.shell.table.TableModel;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import static java.lang.Math.toIntExact;
@Service
public class DataSourceServiceImpl
implements DataSourceService
@ -57,4 +60,28 @@ public class DataSourceServiceImpl
TableUtils.applyStyle(tableBuilder);
return tableBuilder.build();
}
@Override
public Table getInfo()
{
HttpConfigure configure = this.cacheService.getConfigure();
configure.setUrl(url + "/" + configure.getSourceId());
HttpCommon httpCommon = new HttpCommon(configure);
ServerResponse serverResponse = httpCommon.withTokenForGet();
LinkedTreeMap<String, Object> map = (LinkedTreeMap) serverResponse.getData();
LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
headers.put("id", "Id");
headers.put("name", "Name");
headers.put("type", "Type");
headers.put("description", "Description");
DataSource dataSource = new DataSource();
dataSource.setId(toIntExact(configure.getSourceId()));
dataSource.setName(String.valueOf(map.get("name")));
dataSource.setType(String.valueOf(map.get("type")));
dataSource.setDescription(String.valueOf(map.get("description")));
TableModel model = new BeanListTableModel<>(Collections.singleton(dataSource), headers);
TableBuilder tableBuilder = new TableBuilder(model);
TableUtils.applyStyle(tableBuilder);
return tableBuilder.build();
}
}

View File

@ -42,6 +42,13 @@ public class DataSourceShell
System.out.println("Use successful!");
}
@ShellMethod(value = "Get data source details", key = {"source info"})
@ShellMethodAvailability(value = "availabilityCheck")
public Table getInfo()
{
return this.dataSourceService.getInfo();
}
public Availability availabilityCheck()
{
return this.checkService.availabilityCheck();

View File

@ -0,0 +1 @@
logging.level.root=OFF

View File

@ -0,0 +1,30 @@
<assembly>
<id>jar-with-dependencies-and-exclude-classes</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>org.apache.logging.*:log4j</exclude>
<exclude>ch.qos.logback:logback-classic</exclude>
<exclude>ch.qos.logback:logback-core</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>