-
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.
chore: Add support for copying SSC appversions/state
feat: `fcli ssc appversion create`: Add options for copying existing application version feat: Add `fcli ssc appversion copy-state` command feat: Add `fcli system-state wait-for-job` command
- Loading branch information
Showing
16 changed files
with
544 additions
and
22 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
90 changes: 90 additions & 0 deletions
90
...c/src/main/java/com/fortify/cli/ssc/appversion/cli/cmd/SSCAppVersionCopyStateCommand.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,90 @@ | ||
/******************************************************************************* | ||
* 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.cli.cmd; | ||
|
||
import java.util.HashMap; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; | ||
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.ssc._common.output.cli.cmd.AbstractSSCJsonNodeOutputCommand; | ||
import com.fortify.cli.ssc._common.rest.SSCUrls; | ||
import com.fortify.cli.ssc.appversion.cli.mixin.SSCDelimiterMixin; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionDescriptor; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionHelper; | ||
|
||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "copy-state") | ||
public class SSCAppVersionCopyStateCommand extends AbstractSSCJsonNodeOutputCommand implements IJsonNodeSupplier, IRecordTransformer, IActionCommandResultSupplier { | ||
@Getter | ||
@Mixin | ||
private OutputHelperMixins.TableNoQuery outputHelper; | ||
|
||
@Getter | ||
@Mixin | ||
private SSCDelimiterMixin delimiterMixin; | ||
|
||
@Option(names = {"--copy-from", "--from"}, required = true, descriptionKey = "fcli.ssc.appversion.resolver.copy-from.nameOrId") | ||
@Getter | ||
private String fromAppVersionNameOrId; | ||
|
||
@Option(names = {"--copy-to", "--to"}, required = true, descriptionKey = "fcli.ssc.appversion.resolver.copy-to.nameOrId") | ||
@Getter | ||
private String toAppVersionNameOrId; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
SSCAppVersionDescriptor fromAppVersionDescriptor = SSCAppVersionHelper.getRequiredAppVersion(unirest, getFromAppVersionNameOrId(), delimiterMixin.getDelimiter()); | ||
SSCAppVersionDescriptor toAppVersionDescriptor = SSCAppVersionHelper.getRequiredAppVersion(unirest, getToAppVersionNameOrId(), delimiterMixin.getDelimiter()); | ||
|
||
return mapper.valueToTree(copyState(unirest, fromAppVersionDescriptor, toAppVersionDescriptor)); | ||
|
||
} | ||
|
||
@Override | ||
public JsonNode transformRecord(JsonNode record) { | ||
return SSCAppVersionHelper.renameFields(record); | ||
} | ||
|
||
@Override | ||
public String getActionCommandResult() { | ||
return "COPY_REQUESTED"; | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
|
||
private static final HashMap<String, String> copyState(UnirestInstance unirest, SSCAppVersionDescriptor sourceAppVersion, SSCAppVersionDescriptor targetAppVersion) { | ||
HashMap<String, String> appVersionIds = new HashMap<String, String>(); | ||
appVersionIds.put("previousProjectVersionId", sourceAppVersion.getVersionId()); | ||
appVersionIds.put("projectVersionId", targetAppVersion.getVersionId()); | ||
|
||
unirest.post(SSCUrls.PROJECT_VERSIONS_ACTION_COPY_CURRENT_STATE) | ||
.body(appVersionIds) | ||
.asObject(JsonNode.class).getBody(); | ||
|
||
return appVersionIds; | ||
} | ||
|
||
} |
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
51 changes: 51 additions & 0 deletions
51
...sc/src/main/java/com/fortify/cli/ssc/appversion/cli/mixin/SSCAppVersionCopyFromMixin.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.cli.mixin; | ||
|
||
import com.fortify.cli.common.util.DisableTest; | ||
import com.fortify.cli.common.util.DisableTest.TestType; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionDescriptor; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionHelper; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionCopyType; | ||
|
||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Option; | ||
|
||
public class SSCAppVersionCopyFromMixin { | ||
|
||
@ArgGroup(exclusive=false, multiplicity = "0..1") | ||
private SSCAppVersionCopyFromArgGroup argGroup; | ||
|
||
public boolean isCopyRequested() { return argGroup!=null; } | ||
public String getAppVersionNameOrId() { | ||
return argGroup==null ? null : argGroup.getAppVersionNameOrId(); | ||
} | ||
|
||
public final SSCAppVersionCopyType[] getCopyOptions(){ | ||
return this.argGroup.getCopyOptions(); | ||
} | ||
|
||
public SSCAppVersionDescriptor getAppVersionDescriptor(UnirestInstance unirest,String delimiter, String... fields){ | ||
return SSCAppVersionHelper.getRequiredAppVersion(unirest, getAppVersionNameOrId(), delimiter, fields); | ||
} | ||
|
||
private static class SSCAppVersionCopyFromArgGroup { | ||
@Option(names = {"--copy-from", "--from"}, required = true, descriptionKey = "fcli.ssc.appversion.resolver.copy-from.nameOrId") | ||
@Getter private String appVersionNameOrId; | ||
@DisableTest(TestType.MULTI_OPT_PLURAL_NAME) | ||
@Option(names = {"--copy"}, required = false, split = ",", descriptionKey = "fcli.ssc.appversion.create.copy-options") | ||
@Getter private SSCAppVersionCopyType[] copyOptions; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...e/fcli-ssc/src/main/java/com/fortify/cli/ssc/appversion/helper/SSCAppVersionCopyType.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,44 @@ | ||
/******************************************************************************* | ||
* 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.helper; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This enumeration defines the items that can be copied from an existing application version | ||
*/ | ||
public enum SSCAppVersionCopyType { | ||
AnalysisProcessingRules("copyAnalysisProcessingRules"), | ||
BugTrackerConfiguration("copyBugTrackerConfiguration"), | ||
CustomTags("copyCustomTags"), | ||
State("copyState"); | ||
|
||
private final String sscValue; | ||
|
||
private SSCAppVersionCopyType(String sscValue) { | ||
this.sscValue = sscValue; | ||
} | ||
|
||
public String getSscValue() { | ||
return this.sscValue; | ||
} | ||
|
||
public static final SSCAppVersionCopyType fromSscValue(String sscValue) { | ||
return Stream.of(SSCAppVersionCopyType.values()) | ||
.filter(v->v.getSscValue().equals(sscValue)) | ||
.findFirst() | ||
.orElseThrow(()->new IllegalStateException("Unknown SSC copyFrom option: "+sscValue)); | ||
} | ||
|
||
} |
Oops, something went wrong.