-
Notifications
You must be signed in to change notification settings - Fork 23
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
17 changed files
with
1,022 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...mmon/src/main/java/com/fortify/cli/common/spring/expression/wrapper/SimpleExpression.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,47 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2020 Micro Focus or one of its affiliates, a Micro Focus company | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including without | ||
* limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to | ||
* whom the Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
******************************************************************************/ | ||
package com.fortify.cli.common.spring.expression.wrapper; | ||
|
||
import org.springframework.expression.Expression; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
/** | ||
* <p>This is a simple wrapper class for a Spring {@link Expression} | ||
* instance. It's main use is in combination with | ||
* {@link SimpleExpressionDeserializer} to allow automatic | ||
* conversion from String values to simple {@link Expression} | ||
* instances in JSON/YAML documents.</p> | ||
* | ||
* <p>The reason for needing this wrapper class is to differentiate | ||
* with templated {@link Expression} instances that are handled | ||
* by {@link TemplateExpressionDeserializer}.</p> | ||
*/ | ||
@JsonDeserialize(using = SimpleExpressionDeserializer.class) | ||
public class SimpleExpression extends WrappedExpression { | ||
public SimpleExpression(Expression target) { | ||
super(target); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...n/java/com/fortify/cli/common/spring/expression/wrapper/SimpleExpressionDeserializer.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 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2020 Micro Focus or one of its affiliates, a Micro Focus company | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including without | ||
* limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to | ||
* whom the Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
******************************************************************************/ | ||
package com.fortify.cli.common.spring.expression.wrapper; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
/** | ||
* This Jackson deserializer allows parsing String values into an | ||
* SpEL Expression object. | ||
*/ | ||
@Component | ||
public final class SimpleExpressionDeserializer extends StdDeserializer<SimpleExpression> { | ||
private static final long serialVersionUID = 1L; | ||
private static final SpelExpressionParser parser = new SpelExpressionParser(); | ||
public SimpleExpressionDeserializer() { this(null); } | ||
public SimpleExpressionDeserializer(Class<?> vc) { super(vc); } | ||
|
||
@Override | ||
public SimpleExpression deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
return node==null || node.isNull() ? null : new SimpleExpression(parser.parseExpression(node.asText())); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...on/src/main/java/com/fortify/cli/common/spring/expression/wrapper/TemplateExpression.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,47 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2020 Micro Focus or one of its affiliates, a Micro Focus company | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including without | ||
* limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to | ||
* whom the Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
******************************************************************************/ | ||
package com.fortify.cli.common.spring.expression.wrapper; | ||
|
||
import org.springframework.expression.Expression; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
/** | ||
* <p>This is a simple wrapper class for a Spring {@link Expression} | ||
* instance. It's main use is in combination with | ||
* {@link TemplateExpressionDeserializer} to allow automatic | ||
* conversion from String values to templated {@link Expression} | ||
* instances.</p> | ||
* | ||
* <p>The reason for needing this wrapper class is to differentiate | ||
* with non-templated {@link Expression} instances that are | ||
* handled by {@link SimpleExpressionDeserializer}.</p> | ||
*/ | ||
@JsonDeserialize(using = TemplateExpressionDeserializer.class) | ||
public class TemplateExpression extends WrappedExpression { | ||
public TemplateExpression(Expression target) { | ||
super(target); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...java/com/fortify/cli/common/spring/expression/wrapper/TemplateExpressionDeserializer.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,58 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2020 Micro Focus or one of its affiliates, a Micro Focus company | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including without | ||
* limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to | ||
* whom the Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
******************************************************************************/ | ||
package com.fortify.cli.common.spring.expression.wrapper; | ||
|
||
import java.beans.PropertyEditor; | ||
import java.io.IOException; | ||
|
||
import org.springframework.expression.common.TemplateParserContext; | ||
import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
/** | ||
* This {@link PropertyEditor} allows parsing String values into a | ||
* TemplateExpression object. | ||
*/ | ||
@Component | ||
public final class TemplateExpressionDeserializer extends StdDeserializer<TemplateExpression> { | ||
private static final long serialVersionUID = 1L; | ||
private static final SpelExpressionParser parser = new SpelExpressionParser(); | ||
private static final TemplateParserContext templateContext = new TemplateParserContext("${","}"); | ||
public TemplateExpressionDeserializer() { this(null); } | ||
public TemplateExpressionDeserializer(Class<?> vc) { super(vc); } | ||
|
||
@Override | ||
public TemplateExpression deserialize(JsonParser jp, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode node = jp.getCodec().readTree(jp); | ||
return node==null || node.isNull() ? null : new TemplateExpression(parser.parseExpression(node.asText(), templateContext)); | ||
} | ||
} |
Oops, something went wrong.