-
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.
Merge pull request #433 from wtfacoconut/list-group
feat: Add `fcli ssc appversion-groupset` command and add group by mixin ...
- Loading branch information
Showing
9 changed files
with
234 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
...n/java/com/fortify/cli/ssc/appversion_groupset/cli/cmd/SSCAppVersionGroupSetCommands.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,27 @@ | ||
/******************************************************************************* | ||
* 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_groupset.cli.cmd; | ||
|
||
import com.fortify.cli.common.cli.cmd.*; | ||
import picocli.CommandLine.*; | ||
|
||
@Command( | ||
hidden = true, | ||
name = "appversion-groupset", | ||
subcommands = { | ||
SSCAppVersionGroupSetGetCommand.class, | ||
SSCAppVersionGroupSetListCommand.class, | ||
} | ||
) | ||
public class SSCAppVersionGroupSetCommands extends AbstractContainerCommand { | ||
} |
39 changes: 39 additions & 0 deletions
39
...java/com/fortify/cli/ssc/appversion_groupset/cli/cmd/SSCAppVersionGroupSetGetCommand.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,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_groupset.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.mixin.*; | ||
import com.fortify.cli.ssc._common.output.cli.cmd.*; | ||
import com.fortify.cli.ssc.appversion.cli.mixin.*; | ||
import com.fortify.cli.ssc.appversion_groupset.cli.mixin.*; | ||
import kong.unirest.*; | ||
import lombok.*; | ||
import picocli.CommandLine.*; | ||
|
||
@Command(name = OutputHelperMixins.Get.CMD_NAME) | ||
public class SSCAppVersionGroupSetGetCommand extends AbstractSSCJsonNodeOutputCommand { | ||
@Getter @Mixin private OutputHelperMixins.Get outputHelper; | ||
@Mixin SSCAppVersionGroupSetResolverMixin.PositionalParameterSingle groupSetResolver; | ||
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
return groupSetResolver.getGroupSetDescriptor(unirest, parentResolver.getAppVersionId(unirest)).asJsonNode(); | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ava/com/fortify/cli/ssc/appversion_groupset/cli/cmd/SSCAppVersionGroupSetListCommand.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.ssc.appversion_groupset.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.mixin.*; | ||
import com.fortify.cli.ssc._common.output.cli.cmd.*; | ||
import com.fortify.cli.ssc._common.rest.*; | ||
import com.fortify.cli.ssc.appversion.cli.mixin.*; | ||
import kong.unirest.*; | ||
import lombok.*; | ||
import picocli.CommandLine.*; | ||
|
||
@Command(name = OutputHelperMixins.List.CMD_NAME) | ||
public class SSCAppVersionGroupSetListCommand extends AbstractSSCJsonNodeOutputCommand { | ||
@Getter @Mixin private OutputHelperMixins.List outputHelper; | ||
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
return unirest.get(SSCUrls.PROJECT_VERSION_ISSUE_SELECTOR_SET(parentResolver.getAppVersionId(unirest))) | ||
.asObject(JsonNode.class).getBody() | ||
.get("data") | ||
.get("groupBySet"); | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return false; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...com/fortify/cli/ssc/appversion_groupset/cli/mixin/SSCAppVersionGroupSetResolverMixin.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,38 @@ | ||
/******************************************************************************* | ||
* 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_groupset.cli.mixin; | ||
|
||
import com.fortify.cli.ssc.appversion_groupset.helper.*; | ||
import kong.unirest.*; | ||
import lombok.*; | ||
import picocli.CommandLine.*; | ||
|
||
public class SSCAppVersionGroupSetResolverMixin { | ||
private static abstract class AbstractSSCGroupSetResolverMixin { | ||
public abstract String getGroupSetDisplayNameOrId(); | ||
|
||
public SSCAppVersionGroupSetDescriptor getGroupSetDescriptor(UnirestInstance unirest, String appVersionId) { | ||
return new SSCAppVersionGroupSetHelper(unirest, appVersionId).getDescriptorByDisplayNameOrId(getGroupSetDisplayNameOrId(), true); | ||
} | ||
} | ||
|
||
public static class GroupByOption extends AbstractSSCGroupSetResolverMixin { | ||
@Option(names="--by", defaultValue = "FOLDER", descriptionKey = "fcli.ssc.appversion-group-set.resolver.displayNameOrId") | ||
@Getter public String groupSetDisplayNameOrId; | ||
} | ||
|
||
public static class PositionalParameterSingle extends AbstractSSCGroupSetResolverMixin { | ||
@Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.appversion-group-set.resolver.displayNameOrId") | ||
@Getter private String groupSetDisplayNameOrId; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../java/com/fortify/cli/ssc/appversion_groupset/helper/SSCAppVersionGroupSetDescriptor.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,25 @@ | ||
/******************************************************************************* | ||
* 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_groupset.helper; | ||
|
||
import com.formkiq.graalvm.annotations.*; | ||
import com.fortify.cli.common.json.*; | ||
import lombok.*; | ||
|
||
@Reflectable @NoArgsConstructor | ||
@Data @EqualsAndHashCode(callSuper=true) | ||
public class SSCAppVersionGroupSetDescriptor extends JsonNodeHolder { | ||
private String guid; | ||
private String displayName; | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...main/java/com/fortify/cli/ssc/appversion_groupset/helper/SSCAppVersionGroupSetHelper.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,51 @@ | ||
/******************************************************************************* | ||
* 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_groupset.helper; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.json.*; | ||
import com.fortify.cli.ssc._common.rest.*; | ||
import kong.unirest.*; | ||
|
||
import java.util.*; | ||
|
||
public final class SSCAppVersionGroupSetHelper { | ||
private final Map<String, SSCAppVersionGroupSetDescriptor> descriptorsByGuid = new HashMap<>(); | ||
private final Map<String, SSCAppVersionGroupSetDescriptor> descriptorsByDisplayName = new HashMap<>(); | ||
|
||
/** | ||
* This constructor calls the SSC projectVersion issueSelectorSet endpoint to retrieve filter and grouping data. | ||
* As we are only interested in the grouping data, we then call the {@link #processGroupSet(JsonNode)} method for | ||
* each grouping to collect the relevant data. | ||
* @param unirest | ||
*/ | ||
public SSCAppVersionGroupSetHelper(UnirestInstance unirest, String applicationVersionId) { | ||
JsonNode body = unirest.get(SSCUrls.PROJECT_VERSION_ISSUE_SELECTOR_SET(applicationVersionId)).asObject(JsonNode.class).getBody(); | ||
body.get("data").get("groupBySet").forEach(this::processGroupSet); | ||
} | ||
|
||
private void processGroupSet(JsonNode issueTemplate) { | ||
SSCAppVersionGroupSetDescriptor descriptor = JsonHelper.treeToValue(issueTemplate, SSCAppVersionGroupSetDescriptor.class); | ||
descriptorsByGuid.put(descriptor.getGuid(), descriptor); | ||
descriptorsByDisplayName.put(descriptor.getDisplayName(), descriptor); | ||
} | ||
|
||
public SSCAppVersionGroupSetDescriptor getDescriptorByDisplayNameOrId(String groupBySetDisplayNameOrId, boolean failIfNotFound) { | ||
SSCAppVersionGroupSetDescriptor descriptor = descriptorsByGuid.get(groupBySetDisplayNameOrId); | ||
descriptor = descriptor!=null ? descriptor : descriptorsByDisplayName.get(groupBySetDisplayNameOrId); | ||
if ( failIfNotFound && descriptor==null ) { | ||
throw new IllegalArgumentException("No grouping found with display name or id "+groupBySetDisplayNameOrId); | ||
} | ||
return descriptor; | ||
} | ||
} |
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