Skip to content

Commit

Permalink
chore: SSC performance-indicator improvements, add variable commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Oct 19, 2023
1 parent b591ed2 commit dae7b57
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.fortify.cli.ssc.system_state.cli.cmd.SSCSystemStateCommands;
import com.fortify.cli.ssc.token.cli.cmd.SSCTokenCommands;
import com.fortify.cli.ssc.user.cli.cmd.SSCUserCommands;
import com.fortify.cli.ssc.variable.cli.cmd.SSCVariableCommands;

import picocli.CommandLine.Command;

Expand All @@ -53,6 +54,7 @@
SSCAttributeCommands.class,
SSCIssueCommands.class,
SSCPerformanceIndicatorCommands.class,
SSCVariableCommands.class,
SSCPluginCommands.class,
SSCReportCommands.class,
SSCRoleCommands.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

@Command(
name = "performance-indicator", aliases = "pi",
hidden = true,
subcommands = {
SSCPerformanceIndicatorDefinitionListCommand.class,
SSCPerformanceIndicatorGetCommand.class,
SSCPerformanceIndicatorListCommand.class
}
Expand Down
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.performance_indicator.cli.cmd;

import com.fortify.cli.common.cli.util.CommandGroup;
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 kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

@Command(name = OutputHelperMixins.ListDefinitions.CMD_NAME) @CommandGroup("definition")
public class SSCPerformanceIndicatorDefinitionListCommand extends AbstractSSCBaseRequestOutputCommand {
@Getter @Mixin private OutputHelperMixins.ListDefinitions outputHelper;

@Override
public HttpRequest<?> getBaseRequest(UnirestInstance unirest) {
return unirest.get(SSCUrls.PERFORMANCE_INDICATORS);
}

@Override
public boolean isSingular() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

public class SSCPerformanceIndicatorResolverMixin {
private static abstract class AbstractSSCPerformanceIndicatorResolverMixin {
public abstract String getPerformanceIndicatorNameOrId();
public abstract String getPerformanceIndicatorNameOrIdOrGuid();

public SSCPerformanceIndicatorDescriptor getPerformanceIndicatorDescriptor(UnirestInstance unirest, String appVersionId) {
return new SSCPerformanceIndicatorHelper(unirest, appVersionId).getDescriptorByNameOrId(getPerformanceIndicatorNameOrId(), true);
return new SSCPerformanceIndicatorHelper(unirest, appVersionId).getDescriptorByNameOrIdOrGuid(getPerformanceIndicatorNameOrIdOrGuid(), true);
}
}

public static class PerformanceIndicatorOption extends AbstractSSCPerformanceIndicatorResolverMixin {
@Option(names="--performanceindicator", descriptionKey = "fcli.ssc.performance-indicator.resolver.nameOrId")
@Getter private String performanceIndicatorNameOrId;
@Option(names="--performanceindicator", descriptionKey = "fcli.ssc.performance-indicator.resolver.NameOrIdOrGuid")
@Getter private String performanceIndicatorNameOrIdOrGuid;
}

public static class PositionalParameterSingle extends AbstractSSCPerformanceIndicatorResolverMixin {
@Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.performance-indicator.resolver.nameOrId")
@Getter private String performanceIndicatorNameOrId;
@Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.performance-indicator.resolver.NameOrIdOrGuid")
@Getter private String performanceIndicatorNameOrIdOrGuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
@Data @EqualsAndHashCode(callSuper=true)
public class SSCPerformanceIndicatorDescriptor extends JsonNodeHolder {
private String id;
private String guid;
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

public final class SSCPerformanceIndicatorHelper {
private final Map<String, SSCPerformanceIndicatorDescriptor> descriptorsById = new HashMap<>();
private final Map<String, SSCPerformanceIndicatorDescriptor> descriptorsByGuid = new HashMap<>();
private final Map<String, SSCPerformanceIndicatorDescriptor> descriptorsByName = new HashMap<>();

/**
Expand All @@ -41,16 +42,20 @@ public SSCPerformanceIndicatorHelper(UnirestInstance unirest, String application
private void processPerformanceIndicator(JsonNode issueTemplate) {
SSCPerformanceIndicatorDescriptor descriptor = JsonHelper.treeToValue(issueTemplate, SSCPerformanceIndicatorDescriptor.class);
descriptorsById.put(descriptor.getId(), descriptor);
descriptorsByGuid.put(descriptor.getGuid(), descriptor);
descriptorsByName.put(descriptor.getName(), descriptor);
}

public SSCPerformanceIndicatorDescriptor getDescriptorByNameOrId(String performanceIndicatorNameOrId, boolean failIfNotFound) {
SSCPerformanceIndicatorDescriptor descriptor = StringUtils.isBlank(performanceIndicatorNameOrId) ? null : descriptorsById.get(performanceIndicatorNameOrId);
public SSCPerformanceIndicatorDescriptor getDescriptorByNameOrIdOrGuid(String performanceIndicatorNameOrIdOrGuid, boolean failIfNotFound) {
SSCPerformanceIndicatorDescriptor descriptor = StringUtils.isBlank(performanceIndicatorNameOrIdOrGuid) ? null : descriptorsById.get(performanceIndicatorNameOrIdOrGuid);
if ( descriptor==null ) {
descriptor = descriptorsByName.get(performanceIndicatorNameOrId);
descriptor = descriptorsByGuid.get(performanceIndicatorNameOrIdOrGuid);
}
if ( descriptor==null ) {
descriptor = descriptorsByName.get(performanceIndicatorNameOrIdOrGuid);
}
if ( failIfNotFound && descriptor==null ) {
throw new IllegalArgumentException("No Performance Indicator found with name or id "+performanceIndicatorNameOrId);
throw new IllegalArgumentException("No Performance Indicator found with name, id or guid "+performanceIndicatorNameOrIdOrGuid);
}
return descriptor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.variable.cli.cmd;

import com.fortify.cli.common.cli.cmd.AbstractContainerCommand;

import picocli.CommandLine.Command;

@Command(
name = "variable", aliases = "var",
subcommands = {
SSCVariableDefinitionListCommand.class,
SSCVariableGetCommand.class,
SSCVariableListCommand.class
}
)
public class SSCVariableCommands extends AbstractContainerCommand {
}
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.variable.cli.cmd;

import com.fortify.cli.common.cli.util.CommandGroup;
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 kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

@Command(name = OutputHelperMixins.ListDefinitions.CMD_NAME) @CommandGroup("definition")
public class SSCVariableDefinitionListCommand extends AbstractSSCBaseRequestOutputCommand {
@Getter @Mixin private OutputHelperMixins.ListDefinitions outputHelper;

@Override
public HttpRequest<?> getBaseRequest(UnirestInstance unirest) {
return unirest.get(SSCUrls.VARIABLES);
}

@Override
public boolean isSingular() {
return false;
}
}
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.ssc.variable.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.variable.cli.mixin.SSCVariableResolverMixin;

import kong.unirest.UnirestInstance;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

@Command(name = OutputHelperMixins.Get.CMD_NAME)
public class SSCVariableGetCommand extends AbstractSSCJsonNodeOutputCommand {
@Getter @Mixin private OutputHelperMixins.Get outputHelper;
@Mixin SSCVariableResolverMixin.PositionalParameterSingle variableResolver;
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver;

@Override
public JsonNode getJsonNode(UnirestInstance unirest) {
return variableResolver.getVariableDescriptor(unirest, parentResolver.getAppVersionId(unirest)).asJsonNode();
}

@Override
public boolean isSingular() {
return true;
}
}
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.variable.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 SSCVariableListCommand 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_VARIABLE_HISTORIES(parentResolver.getAppVersionId(unirest)));
}

@Override
public boolean isSingular() {
return false;
}
}
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.ssc.variable.cli.mixin;

import com.fortify.cli.ssc.variable.helper.SSCVariableDescriptor;
import com.fortify.cli.ssc.variable.helper.SSCVariableHelper;

import kong.unirest.UnirestInstance;
import lombok.Getter;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

public class SSCVariableResolverMixin {
private static abstract class AbstractSSCVariableResolverMixin {
public abstract String getVariableNameOrIdOrGuid();

public SSCVariableDescriptor getVariableDescriptor(UnirestInstance unirest, String appVersionId) {
return new SSCVariableHelper(unirest, appVersionId).getDescriptorByNameOrIdOrGuid(getVariableNameOrIdOrGuid(), true);
}
}

public static class VariableOption extends AbstractSSCVariableResolverMixin {
@Option(names="--Variable", descriptionKey = "fcli.ssc.variable.resolver.NameOrIdOrGuid")
@Getter private String VariableNameOrIdOrGuid;
}

public static class PositionalParameterSingle extends AbstractSSCVariableResolverMixin {
@Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.variable.resolver.NameOrIdOrGuid")
@Getter private String VariableNameOrIdOrGuid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.variable.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 SSCVariableDescriptor extends JsonNodeHolder {
private String id;
private String guid;
private String name;
}
Loading

0 comments on commit dae7b57

Please sign in to comment.