-
Notifications
You must be signed in to change notification settings - Fork 39
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 #675 from IBM/INS-49047-v2
INS-49047: Adding JSON/Leef parser
- Loading branch information
Showing
16 changed files
with
1,420 additions
and
83 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
13 changes: 8 additions & 5 deletions
13
...c/main/java/com/ibm/guardium/universalconnector/commons/custom_parsing/ParserFactory.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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.ibm.guardium.universalconnector.commons.custom_parsing; | ||
|
||
import com.ibm.guardium.universalconnector.commons.custom_parsing.parsers.IParser; | ||
import com.ibm.guardium.universalconnector.commons.custom_parsing.parsers.JsonParser; | ||
import com.ibm.guardium.universalconnector.commons.custom_parsing.parsers.LeefParser; | ||
import com.ibm.guardium.universalconnector.commons.custom_parsing.parsers.RegexParser; | ||
|
||
public class ParserFactory { | ||
IParser parser; | ||
|
||
public ParserFactory() { | ||
} | ||
|
||
public IParser getParser(ParserType parserType) { | ||
//For now we only support Regex | ||
//if(parserType.equals(ParserType.regex)) | ||
if (parserType.equals(ParserType.json)) | ||
return new JsonParser(); | ||
else if (parserType.equals(ParserType.leef)) | ||
return new LeefParser(); | ||
|
||
return new RegexParser(); | ||
} | ||
|
||
public enum ParserType { | ||
regex, | ||
json, | ||
xml | ||
leef | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
...ium/universalconnector/commons/custom_parsing/excepton/InvalidConfigurationException.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,7 @@ | ||
package com.ibm.guardium.universalconnector.commons.custom_parsing.excepton; | ||
|
||
public class InvalidConfigurationException extends Exception { | ||
public InvalidConfigurationException(String msg) { | ||
super(msg); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
|
||
public interface IParser { | ||
String parse(String payload, String key); | ||
|
||
boolean isPayloadValid(String payload); | ||
} |
31 changes: 31 additions & 0 deletions
31
...n/java/com/ibm/guardium/universalconnector/commons/custom_parsing/parsers/JsonParser.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,31 @@ | ||
package com.ibm.guardium.universalconnector.commons.custom_parsing.parsers; | ||
|
||
import com.ibm.guardium.universalconnector.commons.custom_parsing.parsers.json_parser.JsonUtil; | ||
|
||
import java.util.Map; | ||
|
||
public class JsonParser implements IParser { | ||
|
||
private final JsonUtil util = new JsonUtil(); | ||
Map<String, String> extractedProperties; | ||
|
||
@Override | ||
public String parse(String payload, String key) { | ||
if (key == null) | ||
return null; | ||
return extractedProperties.get(key); | ||
} | ||
|
||
@Override | ||
public boolean isPayloadValid(String payload) { | ||
if (payload == null) | ||
return false; | ||
|
||
extractedProperties = parsePayload(payload); | ||
return extractedProperties != null && !extractedProperties.isEmpty(); | ||
} | ||
|
||
public Map<String, String> parsePayload(String payload) { | ||
return util.getMap(payload); | ||
} | ||
} |
Oops, something went wrong.