Skip to content
This repository was archived by the owner on Aug 4, 2020. It is now read-only.

Commit 7b9db8b

Browse files
author
Chris Wiechmann
committed
Merge branch 'develop'
2 parents 509f4ea + 092dd0d commit 7b9db8b

File tree

14 files changed

+408
-18
lines changed

14 files changed

+408
-18
lines changed

.github/workflows/maven.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Java CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Set up JDK 1.8
13+
uses: actions/setup-java@v1
14+
with:
15+
java-version: 1.8
16+
- name: Build with Maven
17+
run: mvn -B package --file pom.xml

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# apimanager-report-tool
2-
Tool allowing you to create different reports about your API-Registry
2+
Create reports on top of you API-Manager to get insights.
3+
4+
This readme will be updated soon, for now please read more information [here](https://github.com/Axway-API-Management-Plus/apimanager-swagger-promote/wiki/8.-API-Manager-Report-tool)

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@
2323
<tag>@${project.version}</tag>
2424
</scm>
2525

26+
<distributionManagement>
27+
<repository>
28+
<id>github</id>
29+
<name>Axway-API-Management-Plus Apache Maven Packages</name>
30+
<url>https://maven.pkg.github.com/Axway-API-Management-Plus/apimanager-report-tool</url>
31+
</repository>
32+
</distributionManagement>
33+
2634
<dependencies>
2735
<dependency>
2836
<artifactId>axway-swagger-promote-core</artifactId>
2937
<groupId>com.github.axway-api-management-plus.swagger-promote</groupId>
30-
<version>1.6.0</version>
38+
<version>1.6.4</version>
3139
</dependency>
3240
<dependency>
3341
<groupId>org.apache.commons</groupId>

src/main/assembly/assembly.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<id>1.0.0</id>
33
<formats>
44
<format>tar.gz</format>
5+
<format>zip</format>
56
</formats>
67
<includeBaseDirectory>true</includeBaseDirectory>
78
<includeSiteDirectory>false</includeSiteDirectory>

src/main/java/com/axway/apim/report/APIManagerMetadataExport.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import com.axway.apim.lib.ErrorCode;
1818
import com.axway.apim.lib.ErrorState;
1919
import com.axway.apim.lib.RelaxedParser;
20+
import com.axway.apim.report.formats.CSVAPISubscriptionReport;
2021
import com.axway.apim.report.formats.CSVCustomPolicyDependencyReport;
2122
import com.axway.apim.report.formats.CSVEmbeddedAnalyticsReport;
23+
import com.axway.apim.report.formats.ExcelAPISubscriptionReport;
2224
import com.axway.apim.report.formats.ExcelCustomPolicyDependencyReport;
2325
import com.axway.apim.swagger.APIManagerAdapter;
2426

@@ -84,8 +86,11 @@ public static int run(String args[]) {
8486
printUsage(options, e.getMessage());
8587
System.exit(99);
8688
}
89+
// Try workaround issue #219 we also have to provide some internal-commands - This can be removed with version 1.6.5
90+
// We just give cmd a second time!
8791

88-
params = new CommandParameters(cmd);
92+
params = new CommandParameters(cmd, cmd, null);
93+
//params = new CommandParameters(cmd);
8994

9095
APIManagerAdapter apimAdapter = APIManagerAdapter.getInstance();
9196
APIExportMetadataHandler exportHandler = new APIExportMetadataHandler(apimAdapter, params.getValue("report"));
@@ -124,6 +129,8 @@ private static void printUsage(Options options, String message) {
124129
System.out.println(CSVEmbeddedAnalyticsReport.class.getSimpleName()+":\nGenerates a report with APIs, Applications, Orgs and their relation to each other. (CSV-Format)");
125130
System.out.println(CSVCustomPolicyDependencyReport.class.getSimpleName()+":\nTells you which APIs are using which Custom-Policies (CSV-Format)");
126131
System.out.println(ExcelCustomPolicyDependencyReport.class.getSimpleName()+":\nTells you which APIs are using which Custom-Policies (Excel-Format)");
132+
System.out.println(CSVAPISubscriptionReport.class.getSimpleName()+":\nReports application subscriptions to APIs (CSV-Format)");
133+
System.out.println(ExcelAPISubscriptionReport.class.getSimpleName()+":\nReports application subscriptions to APIs (Excel-Format)");
127134
System.out.println("\n");
128135
System.out.println("ERROR: " + message);
129136
System.out.println("\n");

src/main/java/com/axway/apim/report/beans/MetadataClientApplication.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.axway.apim.report.formats;
2+
3+
import java.io.File;
4+
import java.io.FileWriter;
5+
import java.io.IOException;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import org.apache.commons.csv.CSVFormat;
11+
import org.apache.commons.csv.CSVPrinter;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
import com.axway.apim.lib.AppException;
16+
import com.axway.apim.lib.CommandParameters;
17+
import com.axway.apim.lib.ErrorCode;
18+
import com.axway.apim.report.utils.APIComparator;
19+
import com.axway.apim.report.utils.ClientAppComparator;
20+
import com.axway.apim.swagger.APIManagerAdapter;
21+
import com.axway.apim.swagger.api.properties.applications.ClientApplication;
22+
import com.axway.apim.swagger.api.state.IAPI;
23+
24+
public class CSVAPISubscriptionReport extends AbstractReportFormat implements IReportFormat {
25+
private static Logger LOG = LoggerFactory.getLogger(CSVAPISubscriptionReport.class);
26+
27+
protected Map<String, List<ClientApplication>> subscribedApplications = new HashMap<String, List<ClientApplication>>();
28+
29+
@Override
30+
public void preProcessMetadata() throws AppException {
31+
// We need to know the API-Access for each Application
32+
initApplicationAPISubcription();
33+
LOG.info("Successfully loaded application subscriptions.");
34+
}
35+
36+
@Override
37+
public void exportMetadata() throws AppException {
38+
String filename = CommandParameters.getInstance().getValue("filename");
39+
Appendable appendable;
40+
CSVPrinter csvPrinter = null;
41+
try {
42+
File cvsFile = new File(filename);
43+
if(cvsFile.exists()) {
44+
LOG.info("Going to overwrite existing file: '"+cvsFile.getCanonicalPath()+"'");
45+
}
46+
appendable = new FileWriter(cvsFile);
47+
csvPrinter = new CSVPrinter(appendable, CSVFormat.DEFAULT.withHeader(
48+
"APIOrgName",
49+
"APIName",
50+
"APIVersion",
51+
"APIStatus",
52+
//"APIId",
53+
"ApplicationOrganization",
54+
"ApplicationName"
55+
));
56+
writeAPIUsageLineToCSV(csvPrinter);
57+
LOG.info("API Subscription report exported into file: '"+cvsFile.getCanonicalPath()+"'");
58+
} catch (IOException e) {
59+
throw new AppException("Cant open CSV-File for writing", ErrorCode.UNXPECTED_ERROR);
60+
} finally {
61+
if(csvPrinter!=null)
62+
try {
63+
csvPrinter.close(true);
64+
} catch (Exception ignore) {
65+
throw new AppException("Unable to close CSVWriter", ErrorCode.UNXPECTED_ERROR, ignore);
66+
}
67+
}
68+
}
69+
70+
private void writeAPIUsageLineToCSV(CSVPrinter csvPrinter) throws IOException, AppException {
71+
int i=0;
72+
metaData.getAllAPIs().sort(new APIComparator());
73+
for(IAPI api : metaData.getAllAPIs()) {
74+
if(api.getApplications()==null) {
75+
csvPrinter.printRecord(
76+
APIManagerAdapter.getInstance().getOrg(api.getOrganizationId()).getName(),
77+
api.getName(),
78+
api.getVersion(),
79+
api.getState(),
80+
"Not subscribed!",
81+
"Not subscribed!"
82+
);
83+
} else {
84+
api.getApplications().sort(new ClientAppComparator());
85+
for(ClientApplication app : api.getApplications()) {
86+
i++;
87+
csvPrinter.printRecord(
88+
APIManagerAdapter.getInstance().getOrg(api.getOrganizationId()).getName(),
89+
api.getName(),
90+
api.getVersion(),
91+
api.getState(),
92+
APIManagerAdapter.getInstance().getOrg(app.getOrganizationId()).getName(),
93+
app.getName()
94+
);
95+
if( i % 50 == 0 ){
96+
csvPrinter.flush();
97+
}
98+
}
99+
}
100+
}
101+
csvPrinter.flush();
102+
}
103+
}

src/main/java/com/axway/apim/report/formats/CSVCustomPolicyDependencyReport.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public void exportMetadata() throws AppException {
9898
throw new AppException("Unable to close CSVWriter", ErrorCode.UNXPECTED_ERROR, ignore);
9999
}
100100
}
101-
102101
}
103102

104103
private void writePolicyTypeToCSV(CSVPrinter csvPrinter, Map<String, List<IAPI>> policies, String type) throws IOException, AppException {

src/main/java/com/axway/apim/report/formats/CSVEmbeddedAnalyticsReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void exportMetadata() throws AppException {
8888
method.getName(),
8989
"Front-End",
9090
app.getOrganizationId(),
91-
APIManagerAdapter.getInstance().getOrgName(app.getOrganizationId()),
91+
APIManagerAdapter.getInstance().getOrg(app.getOrganizationId()).getName(),
9292
df.format(getMidnight()
9393
));
9494
if( i % 50 == 0 ){
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.axway.apim.report.formats;
2+
3+
import java.io.File;
4+
import java.io.FileOutputStream;
5+
import java.io.IOException;
6+
7+
import org.apache.poi.ss.usermodel.Cell;
8+
import org.apache.poi.ss.usermodel.Row;
9+
import org.apache.poi.xssf.usermodel.XSSFSheet;
10+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import com.axway.apim.lib.AppException;
15+
import com.axway.apim.lib.CommandParameters;
16+
import com.axway.apim.lib.ErrorCode;
17+
import com.axway.apim.report.utils.APIComparator;
18+
import com.axway.apim.report.utils.ClientAppComparator;
19+
import com.axway.apim.swagger.APIManagerAdapter;
20+
import com.axway.apim.swagger.api.properties.applications.ClientApplication;
21+
import com.axway.apim.swagger.api.state.IAPI;
22+
23+
public class ExcelAPISubscriptionReport extends CSVAPISubscriptionReport {
24+
private static Logger LOG = LoggerFactory.getLogger(ExcelAPISubscriptionReport.class);
25+
26+
@Override
27+
public void exportMetadata() throws AppException {
28+
String filename = CommandParameters.getInstance().getValue("filename");
29+
30+
if(!filename.endsWith(".xlsx")) {
31+
filename = filename + ".xlsx";
32+
}
33+
34+
XSSFWorkbook workbook = new XSSFWorkbook();
35+
XSSFSheet sheet = workbook.createSheet("API Subscriptions");
36+
37+
Row row = sheet.createRow(0);
38+
Cell cell = row.createCell(0);
39+
cell.setCellValue("API Organization");
40+
cell = row.createCell(1);
41+
cell.setCellValue("API Name");
42+
cell = row.createCell(2);
43+
cell.setCellValue("API Version");
44+
cell = row.createCell(3);
45+
cell.setCellValue("API Status");
46+
cell = row.createCell(4);
47+
cell.setCellValue("Application organization");
48+
cell = row.createCell(5);
49+
cell.setCellValue("Application name");
50+
51+
createExcelReport(sheet);
52+
try {
53+
File targetFile = new File(filename);
54+
FileOutputStream outputStream = new FileOutputStream(targetFile);
55+
workbook.write(outputStream);
56+
LOG.info("API Subscription report exported into file: '"+targetFile.getCanonicalPath()+"'");
57+
} catch (IOException e) {
58+
throw new AppException("Cant open Excel-File for writing", ErrorCode.UNXPECTED_ERROR);
59+
} finally {
60+
try {
61+
workbook.close();
62+
} catch (IOException ignore) {}
63+
}
64+
}
65+
66+
private void createExcelReport(XSSFSheet sheet) throws AppException {
67+
int rowNum = 1;
68+
Cell cell;
69+
metaData.getAllAPIs().sort(new APIComparator());
70+
for(IAPI api : metaData.getAllAPIs()) {
71+
if(api.getApplications()==null) {
72+
Row row = sheet.createRow(rowNum++);
73+
cell = row.createCell(0);
74+
cell.setCellValue(APIManagerAdapter.getInstance().getOrg(api.getOrganizationId()).getName());
75+
cell = row.createCell(1);
76+
cell.setCellValue(api.getName());
77+
cell = row.createCell(2);
78+
cell.setCellValue(api.getVersion());
79+
cell = row.createCell(3);
80+
cell.setCellValue(api.getState());
81+
cell = row.createCell(4);
82+
cell.setCellValue("Not subscribed!");
83+
cell = row.createCell(5);
84+
cell.setCellValue("Not subscribed!");
85+
} else {
86+
api.getApplications().sort(new ClientAppComparator());
87+
for(ClientApplication app : api.getApplications()) {
88+
Row row = sheet.createRow(rowNum++);
89+
cell = row.createCell(0);
90+
cell.setCellValue(APIManagerAdapter.getInstance().getOrg(api.getOrganizationId()).getName());
91+
cell = row.createCell(1);
92+
cell.setCellValue(api.getName());
93+
cell = row.createCell(2);
94+
cell.setCellValue(api.getVersion());
95+
cell = row.createCell(3);
96+
cell.setCellValue(api.getState());
97+
cell = row.createCell(4);
98+
cell.setCellValue(APIManagerAdapter.getInstance().getOrg(app.getOrganizationId()).getName());
99+
cell = row.createCell(5);
100+
cell.setCellValue(app.getName());
101+
}
102+
}
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)