Skip to content

Commit

Permalink
feat: Application Version's Performance Indicator (list & get)
Browse files Browse the repository at this point in the history
  • Loading branch information
gendry-gh committed Sep 21, 2023
1 parent aa8cb43 commit 23d3c96
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,7 @@
SSCAppVersionAttributeCommands.class,
SSCAppVersionFilterSetCommands.class,
SSCAppVersionGroupSetCommands.class,
SSCAppVersionPerformanceIndicatorCommands.class,
SSCAppVersionUserCommands.class,
SSCArtifactCommands.class,
SSCAttributeDefinitionCommands.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<String, SSCAppVersionPerformanceIndicatorDescriptor> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 23d3c96

Please sign in to comment.