Skip to content

Commit

Permalink
Merge pull request #16 from adobe/filter
Browse files Browse the repository at this point in the history
Filter
  • Loading branch information
baubakg authored Apr 27, 2021
2 parents c7dd52e + a08c556 commit b9a6f74
Show file tree
Hide file tree
Showing 12 changed files with 833 additions and 173 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ Below is a diagram representing the class structure:
![The Class relationship](diagrams/Log_Parser-Classes.png)

## Release Notes

- 1.0.4 Snapshot
- #8 Added the filter function
- #13 Added copy constructors
- #13 Added a copy method in the StdLogEntry (#13)
- #14 Added a set method to LogData. This allows you to change a Log data given a key value and ParseDefinition entry title
- Renamed exception IncorrectParseDefinitionTitleException to IncorrectParseDefinitionException
- 1.0.3
- Introduced the LogData Top Class. This encapsulates all results.
- Introduced the LogDataFactory
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@
<founder>${project.organization.name}</founder>
<year>${project.inceptionYear}</year>
<website>${founder-website}</website>

</properties>
<includes>
<include>src/main/java/**</include>
<include>src/test/java/**</include>
</includes>
<strictCheck>true</strictCheck>
</configuration>
<executions>
<execution>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/adobe/campaign/tests/logparser/GenericEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public GenericEntry() {
super(new ParseDefinition("Created By Default"));
}

private GenericEntry(GenericEntry l_inputData) {
super(l_inputData);
}

@Override
public String makeKey() {
return String.join(getParseDefinition().getKeyPadding(), getParseDefinition().fetchKeyOrder().stream()
Expand All @@ -46,7 +50,6 @@ public Set<String> fetchHeaders() {
return getParseDefinition().fetchHeaders();

}


/**
* Returns the values map as it is without any manipulation
Expand All @@ -56,5 +59,11 @@ public Map<String, Object> fetchValueMap() {

return valuesMap;
}


@Override
public GenericEntry copy() {
return new GenericEntry(this);
}


}
143 changes: 127 additions & 16 deletions src/main/java/com/adobe/campaign/tests/logparser/LogData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionTitleException;
import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionException;

public class LogData<T extends StdLogEntry> {

Expand Down Expand Up @@ -95,18 +95,17 @@ public T get(String in_dataEntryKey) {
* @param in_valueKey
* The identity of the value.
* @return The key value for the given entry. null if not found
* @throws IncorrectParseDefinitionTitleException
* @throws IncorrectParseDefinitionException
* If the given valueKey was not found in the definition
*
*/
public Object get(String in_dataEntryKey, String in_valueKey)
throws IncorrectParseDefinitionTitleException {
public Object get(String in_dataEntryKey, String in_valueKey) throws IncorrectParseDefinitionException {

final T l_foundCubeEntry = this.get(in_dataEntryKey);

if (l_foundCubeEntry != null) {
if (!l_foundCubeEntry.fetchHeaders().contains(in_valueKey)) {
throw new IncorrectParseDefinitionTitleException("The key " + in_valueKey
throw new IncorrectParseDefinitionException("The key " + in_valueKey
+ " was not defined in the parse definition for the ParseDefinition "
+ l_foundCubeEntry.getParseDefinition().getTitle() + " you have configured.");
}
Expand All @@ -117,6 +116,37 @@ public Object get(String in_dataEntryKey, String in_valueKey)
return null;
}

/**
* This method allows you to change a specific value in the log data. For
* this, you need the key and the parse definition title to find the value
*
* Author : gandomi
*
* @param in_dataEntryKey
* The key with which the data has been stored
* @param in_valueKey
* The identity of the value.
* @param in_newValue
* The new value of the entry value
* @throws IncorrectParseDefinitionException
* When there is no entry for the given in_dataEntryKey and
* in_valueKey
*
*/
public void put(String in_dataEntryKey, String in_valueKey, Object in_newValue)
throws IncorrectParseDefinitionException {
if (get(in_dataEntryKey, in_valueKey) == null) {
throw new IncorrectParseDefinitionException("The given parse definition entry for key "
+ in_dataEntryKey + " and the ParsedefinitionEntry title " + in_valueKey
+ " could not be found. Operation failed.");
}

final T l_foundCubeEntry = this.get(in_dataEntryKey);

l_foundCubeEntry.fetchValueMap().put(in_valueKey, in_newValue);

}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down Expand Up @@ -145,20 +175,23 @@ public boolean equals(Object obj) {
* The key name of the parse definition perform the GroupBy on
* @param in_transformationClass
* The class to which we should transform the cube data
* @param <U> The return type of the group by cube.
* @param <U>
* The return type of the group by cube.
* @return a new LogData Object containing the groupBy values
* @throws IncorrectParseDefinitionTitleException
* @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
* @throws IllegalAccessException if the class or its nullary constructor is not accessible.
* @throws InstantiationException if this {@code Class} represents an abstract class, an interface,
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws InstantiationException
* if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
*
*/
public <U extends StdLogEntry> LogData<U> groupBy(String in_parseDefinitionEntryKey,
Class<U> in_transformationClass)
throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {

return groupBy(Arrays.asList(in_parseDefinitionEntryKey), in_transformationClass);
}
Expand All @@ -175,20 +208,23 @@ public <U extends StdLogEntry> LogData<U> groupBy(String in_parseDefinitionEntry
* on
* @param in_transformationClass
* The class to which we should transform the cube data
* @param <U> The return type of the group by cube.
* @param <U>
* The return type of the group by cube.
* @return a new LogData Object containing the groupBy values
* @throws IncorrectParseDefinitionTitleException
* @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
* @throws IllegalAccessException if the class or its nullary constructor is not accessible.
* @throws InstantiationException if this {@code Class} represents an abstract class, an interface,
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws InstantiationException
* if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
*
*/
public <U extends StdLogEntry> LogData<U> groupBy(List<String> in_parseDefinitionEntryKeyList,
Class<U> in_transformationClass)
throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
LogData<U> lr_cubeData = new LogData<U>();

//Creating new Definition
Expand All @@ -207,7 +243,7 @@ public <U extends StdLogEntry> LogData<U> groupBy(List<String> in_parseDefinitio

for (String lt_parseDefinitionEntryKey : in_parseDefinitionEntryKeyList) {
if (!lt_entry.getParseDefinition().fetchHeaders().contains(lt_parseDefinitionEntryKey)) {
throw new IncorrectParseDefinitionTitleException("The given header name "
throw new IncorrectParseDefinitionException("The given header name "
+ lt_parseDefinitionEntryKey + " was not among the stored data");
}

Expand All @@ -222,4 +258,79 @@ public <U extends StdLogEntry> LogData<U> groupBy(List<String> in_parseDefinitio
return lr_cubeData;
}

/**
* Here we create a new LogDataObject with the given ParseDefinitionEntry.
* This method performs a groupby for the given value. The frequence will
* also take into account the original frequence
*
* Author : gandomi
*
* @param in_parseDefinitionEntryKeyList
* The list of key names of the parse definition perform the GroupBy
* on
* @return a new LogData Object containing the groupBy values
* @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws InstantiationException
* if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
*
*/
public LogData<GenericEntry> groupBy(List<String> in_parseDefinitionEntryKeyList)
throws InstantiationException, IllegalAccessException, IncorrectParseDefinitionException {
return groupBy(in_parseDefinitionEntryKeyList, GenericEntry.class);
}

/**
* Here we create a new LogDataObject with the given ParseDefinitionEntry.
* This method performs a groupby for the given value. The frequence will
* also take into account the original frequence
*
* Author : gandomi
*
* @param in_parseDefinitionEntryKey
* The key name of the parse definition perform the GroupBy on
* @return a new LogData Object containing the groupBy values
* @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
* @throws IllegalAccessException
* if the class or its nullary constructor is not accessible.
* @throws InstantiationException
* if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
*
*/
public LogData<GenericEntry> groupBy(String in_parseDefinitionEntryKey)
throws InstantiationException, IllegalAccessException, IncorrectParseDefinitionException {
return groupBy(in_parseDefinitionEntryKey, GenericEntry.class);
}

/**
* This method filters the LogData with the given properties
*
* Author : gandomi
*
* @param in_filterKeyValues
* A map of &lt;String,Object&gt; representation the values we want to find
* @return a new LogDataObject containing only the filtered values
*
*/
public LogData<T> filter(Map<String, Object> in_filterKeyValues) {
LogData<T> lr_filteredLogData = new LogData<>();

for (String lt_logDataKey : this.getEntries().keySet()) {
if (this.get(lt_logDataKey).matches(in_filterKeyValues)) {
lr_filteredLogData.addEntry(this.get(lt_logDataKey));
}
}

return lr_filteredLogData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public ParseDefinition(String in_title) {
definitionEntries = new ArrayList<>();
keyOrder = new ArrayList<>();
}

public ParseDefinition(ParseDefinition in_oldParseDefinition) {
super();
this.title = in_oldParseDefinition.title;
this.definitionEntries = in_oldParseDefinition.definitionEntries;
this.keyPadding = in_oldParseDefinition.keyPadding;
this.keyOrder = in_oldParseDefinition.keyOrder;
this.printOutPadding = in_oldParseDefinition.printOutPadding;
}

/**
* This method adds a definition entry to the definition entries of this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public ParseDefinitionEntry() {

}

public ParseDefinitionEntry(ParseDefinitionEntry in_oldDefinitionEntry) {
this.title = in_oldDefinitionEntry.title;
this.start = in_oldDefinitionEntry.start;
this.end = in_oldDefinitionEntry.end;
this.caseSensitive = in_oldDefinitionEntry.caseSensitive;
this.trimQuotes = in_oldDefinitionEntry.trimQuotes;
this.toPreserve = in_oldDefinitionEntry.toPreserve;
}

public String getTitle() {
return title;
}
Expand Down Expand Up @@ -145,7 +154,8 @@ public int fetchEndPosition(String in_stringValue) {
*
* Author : gandomi
*
* @param in_logString The string/log line which we are searching through
* @param in_logString
* The string/log line which we are searching through
* @return A String that will be parsed by the subsequent
* ParseDefinitionEntry
*
Expand Down
Loading

0 comments on commit b9a6f74

Please sign in to comment.