-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
fcli fod report
commands for creating and downloading FoD…
… reports (resolves #263)
- Loading branch information
Showing
22 changed files
with
969 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/report/cli/cmd/FoDReportCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.report.cli.cmd; | ||
|
||
import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; | ||
import com.fortify.cli.common.variable.DefaultVariablePropertyName; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "report", | ||
subcommands = { | ||
FoDReportListCommand.class, | ||
FoDReportGetCommand.class, | ||
FoDReportCreateCommand.class, | ||
FoDReportDeleteCommand.class, | ||
FoDReportWaitForCommand.class, | ||
FoDReportDownloadCommand.class, | ||
FoDReportTemplateListCommand.class | ||
} | ||
) | ||
@DefaultVariablePropertyName("reportId") | ||
public class FoDReportCommands extends AbstractContainerCommand { | ||
} |
81 changes: 81 additions & 0 deletions
81
...ore/fcli-fod/src/main/java/com/fortify/cli/fod/report/cli/cmd/FoDReportCreateCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.report.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.cli.util.EnvSuffix; | ||
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; | ||
import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.common.util.StringUtils; | ||
import com.fortify.cli.fod._common.cli.mixin.FoDDelimiterMixin; | ||
import com.fortify.cli.fod._common.output.cli.AbstractFoDJsonNodeOutputCommand; | ||
import com.fortify.cli.fod.release.cli.mixin.FoDReleaseByQualifiedNameOrIdResolverMixin; | ||
import com.fortify.cli.fod.release.helper.FoDReleaseDescriptor; | ||
import com.fortify.cli.fod.report.cli.mixin.FoDReportTemplateByNameOrIdResolverMixin; | ||
import com.fortify.cli.fod.report.helper.FoDReportCreateRequest; | ||
import com.fortify.cli.fod.report.helper.FoDReportFormatType; | ||
import com.fortify.cli.fod.report.helper.FoDReportHelper; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = OutputHelperMixins.Create.CMD_NAME) | ||
public class FoDReportCreateCommand extends AbstractFoDJsonNodeOutputCommand implements IActionCommandResultSupplier { | ||
@Getter @Mixin private OutputHelperMixins.Create outputHelper; | ||
|
||
@Mixin private FoDDelimiterMixin delimiterMixin; // Is automatically injected in resolver mixins | ||
@Mixin private FoDReleaseByQualifiedNameOrIdResolverMixin.RequiredOption releaseResolver; | ||
|
||
@Mixin private FoDReportTemplateByNameOrIdResolverMixin.RequiredOption reportTemplateResolver; | ||
|
||
@EnvSuffix("NAME") @Parameters(index = "0", arity = "1", descriptionKey = "fcli.fod.report.create.name") | ||
protected String reportName; | ||
|
||
@Option(names = {"--format"}, required = true) | ||
protected FoDReportFormatType format; | ||
|
||
@Option(names = {"--notes"}) | ||
protected String notes; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
FoDReleaseDescriptor releaseDescriptor = releaseResolver.getReleaseDescriptor(unirest); | ||
int reportTemplateId = Integer.parseInt(reportTemplateResolver.getReportTemplateId(unirest)); | ||
|
||
FoDReportCreateRequest reportCreateRequest = FoDReportCreateRequest.builder() | ||
.applicationId(Integer.valueOf(releaseDescriptor.getApplicationId())) | ||
.releaseId(Integer.valueOf(releaseDescriptor.getReleaseId())) | ||
.reportTemplateTypeId(reportTemplateId) | ||
.reportName(reportName) | ||
.reportFormat(StringUtils.capitalize(format.name().toLowerCase())) | ||
.notes((notes == null || notes.isEmpty() ? "Generated by fcli" : notes)) | ||
.build(); | ||
|
||
return FoDReportHelper.createReport(unirest, reportCreateRequest).asJsonNode(); | ||
} | ||
|
||
@Override | ||
public String getActionCommandResult() { | ||
return "CREATED"; | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...ore/fcli-fod/src/main/java/com/fortify/cli/fod/report/cli/cmd/FoDReportDeleteCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.report.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; | ||
import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.fod._common.output.cli.AbstractFoDJsonNodeOutputCommand; | ||
import com.fortify.cli.fod._common.rest.FoDUrls; | ||
import com.fortify.cli.fod.report.cli.mixin.FoDReportResolverMixin; | ||
import com.fortify.cli.fod.report.helper.FoDReportDescriptor; | ||
import com.fortify.cli.fod.report.helper.FoDReportHelper; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
|
||
@Command(name = OutputHelperMixins.Delete.CMD_NAME) | ||
public class FoDReportDeleteCommand extends AbstractFoDJsonNodeOutputCommand implements IActionCommandResultSupplier { | ||
@Getter @Mixin private OutputHelperMixins.Delete outputHelper; | ||
@Mixin private FoDReportResolverMixin.PositionalParameter reportResolver; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
FoDReportDescriptor reportDescriptor = FoDReportHelper.getReportDescriptor(unirest, reportResolver.getReportId()); | ||
unirest.delete(FoDUrls.REPORT) | ||
.routeParam("reportId", reportResolver.getReportId()) | ||
.asObject(JsonNode.class).getBody(); | ||
return reportDescriptor.asObjectNode(); | ||
} | ||
|
||
@Override | ||
public String getActionCommandResult() { | ||
return "DELETED"; | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...e/fcli-fod/src/main/java/com/fortify/cli/fod/report/cli/cmd/FoDReportDownloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.report.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.cli.mixin.CommonOptionMixins; | ||
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; | ||
import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.fod._common.output.cli.AbstractFoDJsonNodeOutputCommand; | ||
import com.fortify.cli.fod._common.rest.FoDUrls; | ||
import com.fortify.cli.fod.report.cli.mixin.FoDReportResolverMixin; | ||
import com.fortify.cli.fod.report.helper.FoDReportDescriptor; | ||
import com.fortify.cli.fod.report.helper.FoDReportHelper; | ||
import kong.unirest.GetRequest; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import lombok.SneakyThrows; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
|
||
import java.nio.file.StandardCopyOption; | ||
|
||
@Command(name = OutputHelperMixins.Download.CMD_NAME) | ||
public class FoDReportDownloadCommand extends AbstractFoDJsonNodeOutputCommand implements IActionCommandResultSupplier { | ||
@Getter @Mixin private OutputHelperMixins.Download outputHelper; | ||
@Mixin private FoDReportResolverMixin.PositionalParameter reportResolver; | ||
|
||
@Mixin private CommonOptionMixins.RequiredFile outputFileMixin; | ||
|
||
@Override @SneakyThrows | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
FoDReportDescriptor reportDescriptor = FoDReportHelper.getReportDescriptor(unirest, reportResolver.getReportId()); | ||
var file = outputFileMixin.getFile().getAbsolutePath(); | ||
GetRequest request = unirest.get(FoDUrls.REPORT + "/download") | ||
.routeParam("reportId", reportResolver.getReportId()) | ||
.accept("application/octet-stream"); | ||
int status = 202; | ||
while ( status==202 ) { | ||
status = request | ||
.asFile(file, StandardCopyOption.REPLACE_EXISTING) | ||
.getStatus(); | ||
if ( status==202 ) { Thread.sleep(30000L); } | ||
} | ||
return reportDescriptor.asObjectNode().put("file", file); | ||
} | ||
|
||
@Override | ||
public String getActionCommandResult() { | ||
return "REPORT_DOWNLOADED"; | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/report/cli/cmd/FoDReportGetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.report.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.fod._common.output.cli.AbstractFoDJsonNodeOutputCommand; | ||
import com.fortify.cli.fod.report.cli.mixin.FoDReportResolverMixin; | ||
import com.fortify.cli.fod.report.helper.FoDReportHelper; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
|
||
@Command(name = OutputHelperMixins.Get.CMD_NAME) | ||
public class FoDReportGetCommand extends AbstractFoDJsonNodeOutputCommand { | ||
@Getter @Mixin private OutputHelperMixins.Get outputHelper; | ||
@Mixin private FoDReportResolverMixin.PositionalParameter reportResolver; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
return reportResolver.getReportDescriptor(unirest).asJsonNode(); | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.