-
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: Partial data-extract implementation
- Loading branch information
Showing
37 changed files
with
2,338 additions
and
21 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
55 changes: 55 additions & 0 deletions
55
...in/java/com/fortify/cli/common/data_extract/cli/cmd/AbstractDataExtractCreateCommand.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,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.common.data_extract.cli.cmd; | ||
|
||
import java.util.List; | ||
|
||
import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; | ||
import com.fortify.cli.common.cli.mixin.CommonOptionMixins.OptionParametersMixin; | ||
import com.fortify.cli.common.data_extract.helper.DataExtractTemplateExecutor; | ||
import com.fortify.cli.common.data_extract.helper.DataExtractTemplateHelper; | ||
import com.fortify.cli.common.progress.cli.mixin.ProgressWriterFactoryMixin; | ||
import com.fortify.cli.common.util.DisableTest; | ||
import com.fortify.cli.common.util.DisableTest.TestType; | ||
|
||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
|
||
public abstract class AbstractDataExtractCreateCommand extends AbstractRunnableCommand implements Runnable { | ||
@Option(names={"-t", "--template"}, required=true) private String template; | ||
@DisableTest({TestType.MULTI_OPT_SPLIT, TestType.MULTI_OPT_PLURAL_NAME, TestType.OPT_LONG_NAME}) | ||
@Option(names="--<template-parameter>", paramLabel="<value>", descriptionKey="fcli.data-extract.create.template-parameter") | ||
private List<String> dummyForSynopsis; | ||
@Mixin private OptionParametersMixin templateParameters; | ||
@Mixin private ProgressWriterFactoryMixin progressWriterFactory; | ||
|
||
@Override | ||
public final void run() { | ||
initMixins(); | ||
try ( var progressWriter = progressWriterFactory.create() ) { | ||
progressWriter.writeProgress("Loading template %s", template); | ||
var templateDescriptor = DataExtractTemplateHelper.load(getType(), template); | ||
progressWriter.writeProgress("Executing template %s", template); | ||
var templateExecutor = DataExtractTemplateExecutor.builder() | ||
.template(templateDescriptor) | ||
.inputParameters(templateParameters.getOptions()) | ||
.progressWriter(progressWriter) | ||
.build(); | ||
configure(templateExecutor); | ||
templateExecutor.execute(); | ||
} | ||
} | ||
|
||
protected abstract String getType(); | ||
protected abstract void configure(DataExtractTemplateExecutor templateExecutor); | ||
} |
32 changes: 32 additions & 0 deletions
32
.../com/fortify/cli/common/data_extract/cli/cmd/AbstractDataExtractListTemplatesCommand.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,32 @@ | ||
/******************************************************************************* | ||
* 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.common.data_extract.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; | ||
import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; | ||
|
||
public abstract class AbstractDataExtractListTemplatesCommand extends AbstractOutputCommand implements IJsonNodeSupplier { | ||
@Override | ||
public final JsonNode getJsonNode() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
@Override | ||
public final boolean isSingular() { | ||
return false; | ||
} | ||
protected abstract String getType(); | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ommon/src/main/java/com/fortify/cli/common/data_extract/helper/DataExtractRestHelper.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,55 @@ | ||
/** | ||
* Copyright 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.common.data_extract.helper; | ||
|
||
import com.fortify.cli.common.output.product.IProductHelper; | ||
import com.fortify.cli.common.output.transform.IInputTransformer; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.common.rest.paging.INextPageUrlProducer; | ||
import com.fortify.cli.common.rest.paging.INextPageUrlProducerSupplier; | ||
import com.fortify.cli.common.rest.unirest.IUnirestInstanceSupplier; | ||
import com.fortify.cli.common.util.JavaHelper; | ||
|
||
import kong.unirest.UnirestInstance; | ||
import lombok.Data; | ||
|
||
@Data | ||
public final class DataExtractRestHelper implements AutoCloseable { | ||
private final String name; | ||
private final IUnirestInstanceSupplier unirestInstanceSupplier; | ||
private final IProductHelper productHelper; | ||
private UnirestInstance unirestInstance; | ||
public final UnirestInstance getUnirestInstance() { | ||
if ( unirestInstance==null ) { | ||
unirestInstance = unirestInstanceSupplier.getUnirestInstance(); | ||
} | ||
return unirestInstance; | ||
} | ||
public final IInputTransformer getInputTransformer() { | ||
return JavaHelper.as(productHelper, IInputTransformer.class).orElse(i->i); | ||
} | ||
public final IRecordTransformer getRecordTransformer() { | ||
return JavaHelper.as(productHelper, IRecordTransformer.class).orElse(r->r); | ||
} | ||
public final INextPageUrlProducer getNextPageUrlProducer() { | ||
return JavaHelper.as(productHelper, INextPageUrlProducerSupplier.class) | ||
.map(s->s.getNextPageUrlProducer()) | ||
.orElse(null); | ||
} | ||
@Override | ||
public void close() throws Exception { | ||
if ( unirestInstance!=null ) { | ||
unirestInstance.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.