diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/_main/cli/cmd/SSCCommands.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/_main/cli/cmd/SSCCommands.java index 643a5fe680..19f5747d79 100644 --- a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/_main/cli/cmd/SSCCommands.java +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/_main/cli/cmd/SSCCommands.java @@ -22,6 +22,7 @@ import com.fortify.cli.ssc.appversion_attribute.cli.cmd.SSCAppVersionAttributeCommands; import com.fortify.cli.ssc.appversion_filterset.cli.cmd.SSCAppVersionFilterSetCommands; import com.fortify.cli.ssc.appversion_groupset.cli.cmd.SSCAppVersionGroupSetCommands; +import com.fortify.cli.ssc.appversion_performanceindicator.cli.cmd.SSCAppVersionPerformanceIndicatorCommands; import com.fortify.cli.ssc.appversion_user.cli.cmd.SSCAppVersionUserCommands; import com.fortify.cli.ssc.artifact.cli.cmd.SSCArtifactCommands; import com.fortify.cli.ssc.attribute_definition.cli.cmd.SSCAttributeDefinitionCommands; @@ -62,6 +63,7 @@ SSCAppVersionAttributeCommands.class, SSCAppVersionFilterSetCommands.class, SSCAppVersionGroupSetCommands.class, + SSCAppVersionPerformanceIndicatorCommands.class, SSCAppVersionUserCommands.class, SSCArtifactCommands.class, SSCAttributeDefinitionCommands.class, diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorCommands.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorCommands.java new file mode 100644 index 0000000000..d69410a700 --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorCommands.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.cli.cmd; + +import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; +import picocli.CommandLine.Command; + +@Command( + name = "appversion-performanceindicator", + subcommands = { + SSCAppVersionPerformanceIndicatorGetCommand.class, + SSCAppVersionPerformanceIndicatorListCommand.class + } +) +public class SSCAppVersionPerformanceIndicatorCommands extends AbstractContainerCommand { +} \ No newline at end of file diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorGetCommand.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorGetCommand.java new file mode 100644 index 0000000000..907a61d28e --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorGetCommand.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.cli.cmd; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; +import com.fortify.cli.ssc._common.output.cli.cmd.AbstractSSCJsonNodeOutputCommand; +import com.fortify.cli.ssc.appversion.cli.mixin.SSCAppVersionResolverMixin; +import com.fortify.cli.ssc.appversion_performanceindicator.cli.mixin.SSCAppVersionPerformanceIndicatorResolverMixin; +import kong.unirest.UnirestInstance; +import lombok.Getter; +import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; + +@Command(name = OutputHelperMixins.Get.CMD_NAME) +public class SSCAppVersionPerformanceIndicatorGetCommand extends AbstractSSCJsonNodeOutputCommand { + @Getter @Mixin private OutputHelperMixins.Get outputHelper; + @Mixin SSCAppVersionPerformanceIndicatorResolverMixin.PositionalParameterSingle performanceIndicatorResolver; + @Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver; + + @Override + public JsonNode getJsonNode(UnirestInstance unirest) { + return performanceIndicatorResolver.getPerformanceIndicatorDescriptor(unirest, parentResolver.getAppVersionId(unirest)).asJsonNode(); + } + + @Override + public boolean isSingular() { + return true; + } +} diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorListCommand.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorListCommand.java new file mode 100644 index 0000000000..049676387e --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/cmd/SSCAppVersionPerformanceIndicatorListCommand.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.cli.cmd; + +import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; +import com.fortify.cli.ssc._common.output.cli.cmd.AbstractSSCBaseRequestOutputCommand; +import com.fortify.cli.ssc._common.rest.SSCUrls; +import com.fortify.cli.ssc.appversion.cli.mixin.SSCAppVersionResolverMixin; +import kong.unirest.HttpRequest; +import kong.unirest.UnirestInstance; +import lombok.Getter; +import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; + +@Command(name = OutputHelperMixins.List.CMD_NAME) +public class SSCAppVersionPerformanceIndicatorListCommand extends AbstractSSCBaseRequestOutputCommand { + @Getter @Mixin private OutputHelperMixins.List outputHelper; + @Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver; + + @Override + public HttpRequest getBaseRequest(UnirestInstance unirest) { + return unirest.get(SSCUrls.PROJECT_VERSION_PERFORMANCE_INDICATOR_HISTORIES(parentResolver.getAppVersionId(unirest))); + } + + @Override + public boolean isSingular() { + return false; + } +} diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/mixin/SSCAppVersionPerformanceIndicatorResolverMixin.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/mixin/SSCAppVersionPerformanceIndicatorResolverMixin.java new file mode 100644 index 0000000000..ab935e2aae --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/cli/mixin/SSCAppVersionPerformanceIndicatorResolverMixin.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.cli.mixin; + +import com.fortify.cli.ssc.appversion_performanceindicator.helper.SSCAppVersionPerformanceIndicatorDescriptor; +import com.fortify.cli.ssc.appversion_performanceindicator.helper.SSCAppVersionPerformanceIndicatorHelper; +import kong.unirest.UnirestInstance; +import lombok.Getter; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +public class SSCAppVersionPerformanceIndicatorResolverMixin { + private static abstract class AbstractSSCPerformanceIndicatorResolverMixin { + public abstract String getPerformanceIndicatorId(); + + public SSCAppVersionPerformanceIndicatorDescriptor getPerformanceIndicatorDescriptor(UnirestInstance unirest, String appVersionId) { + return new SSCAppVersionPerformanceIndicatorHelper(unirest, appVersionId).getDescriptorById(getPerformanceIndicatorId(), true); + } + } + + public static class PerformanceIndicatorOption extends AbstractSSCPerformanceIndicatorResolverMixin { + @Option(names="--performanceindicator", descriptionKey = "fcli.ssc.appversion-performance-indicator.resolver.id") + @Getter private String performanceIndicatorId; + } + + public static class PositionalParameterSingle extends AbstractSSCPerformanceIndicatorResolverMixin { + @Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.appversion-performance-indicator.resolver.id") + @Getter private String performanceIndicatorId; + } +} diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorDescriptor.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorDescriptor.java new file mode 100644 index 0000000000..489bdfbd9b --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorDescriptor.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.helper; + +import com.formkiq.graalvm.annotations.Reflectable; +import com.fortify.cli.common.json.JsonNodeHolder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Reflectable @NoArgsConstructor +@Data @EqualsAndHashCode(callSuper=true) +public class SSCAppVersionPerformanceIndicatorDescriptor extends JsonNodeHolder { + private String id; + private boolean defaultPerformanceIndicator; +} diff --git a/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorHelper.java b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorHelper.java new file mode 100644 index 0000000000..18f3007f53 --- /dev/null +++ b/fcli-core/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion_performanceindicator/helper/SSCAppVersionPerformanceIndicatorHelper.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.ssc.appversion_performanceindicator.helper; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fortify.cli.common.json.JsonHelper; +import com.fortify.cli.ssc._common.rest.SSCUrls; +import kong.unirest.UnirestInstance; +import lombok.Getter; + +import java.util.HashMap; +import java.util.Map; + +public final class SSCAppVersionPerformanceIndicatorHelper { + private final Map descriptorsById = new HashMap<>(); + @Getter private SSCAppVersionPerformanceIndicatorDescriptor defaultPerformanceIndicatorDescriptor; + + /** + * This constructor calls the SSC projectVersion filterSets endpoint to retrieve filter set data, + * then calls the {@link #processPerformanceIndicator(JsonNode)} method for each filter set to collect the + * relevant data. + * @param unirest + */ + public SSCAppVersionPerformanceIndicatorHelper(UnirestInstance unirest, String applicationVersionId) { + JsonNode body = unirest.get(SSCUrls.PROJECT_VERSION_PERFORMANCE_INDICATOR_HISTORIES(applicationVersionId)).queryString("limit","-1").asObject(JsonNode.class).getBody(); + body.get("data").forEach(this::processPerformanceIndicator); + } + + private void processPerformanceIndicator(JsonNode issueTemplate) { + SSCAppVersionPerformanceIndicatorDescriptor descriptor = JsonHelper.treeToValue(issueTemplate, SSCAppVersionPerformanceIndicatorDescriptor.class); + descriptorsById.put(descriptor.getId(), descriptor); + if ( descriptor.isDefaultPerformanceIndicator() ) { + this.defaultPerformanceIndicatorDescriptor = descriptor; + } + } + + public SSCAppVersionPerformanceIndicatorDescriptor getDescriptorById(String performanceIndicatorId, boolean failIfNotFound) { + if ( performanceIndicatorId==null ) { return defaultPerformanceIndicatorDescriptor; } + SSCAppVersionPerformanceIndicatorDescriptor descriptor = descriptorsById.get(performanceIndicatorId); + if ( failIfNotFound && descriptor==null ) { + throw new IllegalArgumentException("No Performance Indicator found with id "+performanceIndicatorId); + } + return descriptor; + } +} diff --git a/fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties b/fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties index c517c96259..894a886076 100644 --- a/fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties +++ b/fcli-core/fcli-ssc/src/main/resources/com/fortify/cli/ssc/i18n/SSCMessages.properties @@ -221,6 +221,12 @@ fcli.ssc.appversion-groupset.get.usage.header = Get group set details. fcli.ssc.appversion-groupset.list.usage.header = List application version group sets. fcli.ssc.appversion-group-set.resolver.displayNameOrId = Group set (groupBy) display name or id. +# fcli ssc appversion-performanceindicator +fcli.ssc.appversion-performanceindicator.usage.header = Manage SSC application version performance indicators. +fcli.ssc.appversion-performanceindicator.get.usage.header = Get performance indicator details. +fcli.ssc.appversion-performanceindicator.list.usage.header = List application version performance indicators. +fcli.ssc.appversion-performance-indicator.resolver.id = Performance indicator id. + # fcli ssc appversion-user fcli.ssc.appversion-user.usage.header = Manage SSC application version users. fcli.ssc.appversion-user.add.usage.header = Add users to an application version.