Skip to content

Commit

Permalink
Merge pull request #983 from sania-16/working
Browse files Browse the repository at this point in the history
ZIP Changes - Draft PR
  • Loading branch information
sania-16 authored Jan 10, 2025
2 parents 4a02faa + 4f3b065 commit 0909688
Show file tree
Hide file tree
Showing 115 changed files with 1,442 additions and 751 deletions.
32 changes: 26 additions & 6 deletions assembly/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>byte-buddy</artifactId>
<groupId>net.bytebuddy</groupId>
</exclusion>
<exclusion>
<artifactId>byte-buddy-agent</artifactId>
<groupId>net.bytebuddy</groupId>
</exclusion>
<exclusion>
<artifactId>objenesis</artifactId>
<groupId>org.objenesis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down Expand Up @@ -113,12 +139,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void setLabelDataSampleSize(float labelDataSampleSize) throws ZinggClient
*/
@Override
public List<? extends FieldDefinition> getFieldDefinition() {
return fieldDefinition;
return this.fieldDefinition;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class FieldDefUtil implements Serializable{

public List<? extends FieldDefinition> getFieldDefinitionDontUse(List<? extends FieldDefinition> fieldDefinition) {
return fieldDefinition.stream()
.filter(x->x.matchType.contains(MatchType.DONT_USE))
.filter(x->x.matchType.contains(MatchTypes.DONT_USE))
.collect(Collectors.toList());
}

public List<? extends FieldDefinition> getFieldDefinitionToUse(List<? extends FieldDefinition> fieldDefinition) {
return fieldDefinition.stream()
.filter(x->!x.matchType.contains(MatchType.DONT_USE))
.filter(x->!x.matchType.contains(MatchTypes.DONT_USE))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@
* @author sgoyal
*
*/
public class FieldDefinition implements Named,
Serializable {
public class FieldDefinition implements Named, Serializable {

private static final long serialVersionUID = 1L;

public static final Log LOG = LogFactory.getLog(FieldDefinition.class);

@JsonDeserialize(using = MatchTypeDeserializer.class)
@JsonSerialize(using = MatchTypeSerializer.class)
public List<MatchType> matchType;
public List<? extends IMatchType> matchType;

//@JsonSerialize(using = DataTypeSerializer.class)
public String dataType;
Expand All @@ -52,17 +51,21 @@ public class FieldDefinition implements Named,
public FieldDefinition() {
}

public String getFields() { return fields; }
public String getFields() {
return fields;
}

public void setFields(String fields) { this.fields = fields;}
public void setFields(String fields) {
this.fields = fields;
}

/**
* Get the field type of the class
*
* @return the type
*/
public List<MatchType> getMatchType() {
return matchType;
public List<? extends IMatchType> getMatchType() {
return this.matchType;
}

/**
Expand All @@ -73,7 +76,7 @@ public List<MatchType> getMatchType() {
* the type to set
*/
@JsonDeserialize(using = MatchTypeDeserializer.class)
public void setMatchType(List<MatchType> type) {
public void setMatchType(List<? extends IMatchType> type) {
this.matchType = type; //MatchTypeDeserializer.getMatchTypeFromString(type);
}

Expand Down Expand Up @@ -113,7 +116,7 @@ public void setAbbreviations(String abbreviations) {
}

public String getFieldName() {
return fieldName;
return this.fieldName;
}

public void setFieldName(String fieldName) {
Expand All @@ -122,7 +125,7 @@ public void setFieldName(String fieldName) {

@JsonIgnore
public boolean isDontUse() {
return (matchType != null && matchType.contains(MatchType.DONT_USE));
return (matchType != null && matchType.contains(MatchTypes.DONT_USE));
}

@Override
Expand Down Expand Up @@ -185,34 +188,34 @@ public void serialize(DataType dType, JsonGenerator jsonGenerator,
}
}*/

public static class MatchTypeSerializer extends StdSerializer<List<MatchType>> {
public static class MatchTypeSerializer extends StdSerializer<List<IMatchType>> {
public MatchTypeSerializer() {
this(null);
}

public MatchTypeSerializer(Class<List<MatchType>> t) {
public MatchTypeSerializer(Class<List<IMatchType>> t) {
super(t);
}

@Override
public void serialize(List<MatchType> matchType, JsonGenerator jsonGen, SerializerProvider provider)
public void serialize(List<IMatchType> matchType, JsonGenerator jsonGen, SerializerProvider provider)
throws IOException, JsonProcessingException {
try {
jsonGen.writeObject(getStringFromMatchType(matchType));
jsonGen.writeObject(getStringFromMatchType((List<IMatchType>) matchType));
LOG.debug("Serializing custom type");
} catch (ZinggClientException e) {
throw new IOException(e);
}
}

public static String getStringFromMatchType(List<MatchType> matchType) throws ZinggClientException {
public static String getStringFromMatchType(List<IMatchType> matchType) throws ZinggClientException {
return String.join(",", matchType.stream()
.map(p -> p.value())
.map(p -> p.getName())
.collect(Collectors.toList()));
}
}

public static class MatchTypeDeserializer extends StdDeserializer<List<MatchType>> {
public static class MatchTypeDeserializer extends StdDeserializer<List<IMatchType>> {
private static final long serialVersionUID = 1L;

public MatchTypeDeserializer() {
Expand All @@ -222,24 +225,24 @@ public MatchTypeDeserializer(Class<String> t) {
super(t);
}
@Override
public List<MatchType> deserialize(JsonParser parser, DeserializationContext context)
public List<IMatchType> deserialize(JsonParser parser, DeserializationContext context)
throws IOException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
try{
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
LOG.debug("Deserializing custom type");
return getMatchTypeFromString(mapper.readValue(parser, String.class));
}
catch(ZinggClientException e) {
catch(Exception | ZinggClientException e) {
throw new IOException(e);
}
}

public static List<MatchType> getMatchTypeFromString(String m) throws ZinggClientException{
List<MatchType> matchTypes = new ArrayList<MatchType>();
public static List<IMatchType> getMatchTypeFromString(String m) throws ZinggClientException, Exception{
List<IMatchType> matchTypes = new ArrayList<IMatchType>();
String[] matchTypeFromConfig = m.split(",");
for (String s: matchTypeFromConfig) {
MatchType mt = MatchType.getMatchType(s);
IMatchType mt = MatchTypes.getByName(s);
matchTypes.add(mt);
}
return matchTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package zingg.common.client;

public interface IMatchType extends Named {

public String toString();

}

106 changes: 44 additions & 62 deletions common/client/src/main/java/zingg/common/client/MatchType.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,68 @@
package zingg.common.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* Field types used in defining the types of fields for matching. See the field
* definitions and the user guide for more details
*/

public enum MatchType implements Serializable {
/**
* Short words like first names and organizations with focus on first
* characters matching
*/
FUZZY("FUZZY"),

/**
* Fields needing exact matches
*/
EXACT("EXACT"),
public class MatchType implements IMatchType, Serializable{


/**
* Many times pin code is xxxxx-xxxx and has to be matched with xxxxx.
*/
PINCODE("PINCODE"),
private static final long serialVersionUID = 1L;
public String name;

/**
* an email type which is supposed to look at only the first part of the email and ignore the domain.
*/
EMAIL("EMAIL"),

/**
* Long descriptive text, usually more than a couple of words for example
* product descriptions
*/
TEXT("TEXT"),
public MatchType(){

}

/**
* Strings containing numbers which need to be same. Example in addresses,
* we dont want 4th street to match 5th street
* Matching numbers with deviations
*/
NUMERIC("NUMERIC"),
/*eg P301d, P00231*/
NUMERIC_WITH_UNITS("NUMBER_WITH_UNITS"),
NULL_OR_BLANK("NULL_OR_BLANK"),
ONLY_ALPHABETS_EXACT("ONLY_ALPHABETS_EXACT"),
ONLY_ALPHABETS_FUZZY("ONLY_ALPHABETS_FUZZY"),
DONT_USE("DONT_USE");
public MatchType(String n){
this.name = n;
MatchTypes.put(this);
}

private String value;
private static Map<String, MatchType> types;
@Override
public String getName() {
return this.name;
}

MatchType(String type) {
this.value = type;
@Override
public void setName(String name) {
this.name = name;
}

private static void init() {
types = new HashMap<String, MatchType>();
for (MatchType f : MatchType.values()) {
types.put(f.value, f);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}

@JsonCreator
public static MatchType getMatchType(String t) throws ZinggClientException{
if (types == null) {
init();
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MatchType other = (MatchType) obj;
if (name == null) {
if (other.name != null){
return false;
}
}
else if (!name.equalsIgnoreCase(other.name)){
return false;
}
MatchType type = types.get(t.trim().toUpperCase());
if (type == null) throw new ZinggClientException("Unsupported Match Type: " + t);
return type;
return true;
}

@JsonValue
public String value() {
return value;
@Override
public String toString() {
return name;
}

}
Loading

0 comments on commit 0909688

Please sign in to comment.