Skip to content

Commit 37c9148

Browse files
Merge pull request #27 from piplcom/APPS-491-support-voip-vehicle-fields
support voip and vin fields
2 parents 576a234 + 5e18444 commit 37c9148

File tree

10 files changed

+339
-54
lines changed

10 files changed

+339
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Library Requirements
1010
--------------------
1111

1212
* Google Gson, you can find it inside this project under `lib/google/` or download from [here](http://code.google.com/p/google-gson/downloads/list).
13-
* The library was tested on Java 7 but will probably work on earlier versions as well.
13+
* The library SDK version 5.1.0 is compatible with Java 8 and above.
1414

1515
Installation
1616
------------

pom.xml

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,51 @@
44

55
<groupId>com.pipl.api</groupId>
66
<artifactId>piplapis</artifactId>
7-
<version>5.0.16-SNAPSHOT</version><!-- `-SNAPSHOT` is replaced during build -->
7+
<version>5.1.0-SNAPSHOT</version><!-- `-SNAPSHOT` is replaced during build -->
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>
1111
<description>Java client library for the Pipl search API.</description>
1212
<url>https://pipl.com/api/</url>
13-
13+
14+
<profiles>
15+
<profile>
16+
<id>production</id>
17+
18+
<activation>
19+
<activeByDefault>true</activeByDefault>
20+
</activation>
21+
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>org.apache.maven.plugins</groupId>
26+
<artifactId>maven-gpg-plugin</artifactId>
27+
<version>1.6</version>
28+
<executions>
29+
<execution>
30+
<id>sign-artifacts</id>
31+
<phase>verify</phase>
32+
<goals>
33+
<goal>sign</goal>
34+
</goals>
35+
<configuration>
36+
<gpgArguments>
37+
<arg>--pinentry-mode</arg>
38+
<arg>loopback</arg>
39+
</gpgArguments>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
</profile>
47+
<profile>
48+
<id>skip-pgp-signing</id>
49+
</profile>
50+
</profiles>
51+
1452
<scm>
1553
<connection>scm:git:git@github.com:piplcom/piplapis-java.git</connection>
1654
<developerConnection>scm:git:git@github.com:piplcom/piplapis-java.git</developerConnection>
@@ -88,28 +126,23 @@
88126
</execution>
89127
</executions>
90128
</plugin>
91-
<plugin>
92-
<groupId>org.apache.maven.plugins</groupId>
93-
<artifactId>maven-gpg-plugin</artifactId>
94-
<version>1.6</version>
95-
<executions>
96-
<execution>
97-
<id>sign-artifacts</id>
98-
<phase>verify</phase>
99-
<goals>
100-
<goal>sign</goal>
101-
</goals>
102-
<configuration>
103-
<gpgArguments>
104-
<arg>--pinentry-mode</arg>
105-
<arg>loopback</arg>
106-
</gpgArguments>
107-
</configuration>
108-
</execution>
109-
</executions>
110-
</plugin>
111129
<!-- RELEASE PLUGIN PLACEHOLDER -->
112130
</plugins>
131+
<pluginManagement>
132+
<plugins>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-surefire-plugin</artifactId>
136+
<version>3.0.0</version>
137+
<configuration>
138+
<argLine>
139+
--illegal-access=permit
140+
--add-opens java.base/java.lang=ALL-UNNAMED
141+
</argLine>
142+
</configuration>
143+
</plugin>
144+
</plugins>
145+
</pluginManagement>
113146
</build>
114147

115148
<dependencies>

src/main/java/com/pipl/api/data/containers/FieldsContainer.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,7 @@
77

88
import com.google.gson.annotations.Expose;
99
import com.google.gson.annotations.SerializedName;
10-
import com.pipl.api.data.fields.Address;
11-
import com.pipl.api.data.fields.DOB;
12-
import com.pipl.api.data.fields.Education;
13-
import com.pipl.api.data.fields.Email;
14-
import com.pipl.api.data.fields.Ethnicity;
15-
import com.pipl.api.data.fields.Field;
16-
import com.pipl.api.data.fields.Gender;
17-
import com.pipl.api.data.fields.Image;
18-
import com.pipl.api.data.fields.Job;
19-
import com.pipl.api.data.fields.Language;
20-
import com.pipl.api.data.fields.Name;
21-
import com.pipl.api.data.fields.OriginCountry;
22-
import com.pipl.api.data.fields.Phone;
23-
import com.pipl.api.data.fields.Tag;
24-
import com.pipl.api.data.fields.Url;
25-
import com.pipl.api.data.fields.UserID;
26-
import com.pipl.api.data.fields.Username;
10+
import com.pipl.api.data.fields.*;
2711

2812
/**
2913
* The base class of Record and Person, made only for inheritance.
@@ -66,6 +50,10 @@ public class FieldsContainer implements Serializable {
6650
public ArrayList<Relationship> relationships;
6751
@Expose
6852
public ArrayList<Tag> tags;
53+
54+
@Expose
55+
public ArrayList<Vehicle> vehicles;
56+
6957
@Expose
7058
public DOB dob;
7159
@Expose
@@ -87,6 +75,7 @@ public FieldsContainer() {
8775
urls = new ArrayList<Url>();
8876
relationships = new ArrayList<Relationship>();
8977
tags = new ArrayList<Tag>();
78+
vehicles = new ArrayList<Vehicle>();
9079
}
9180

9281
public FieldsContainer(Collection<Field> fields) {
@@ -135,6 +124,8 @@ public void addFields(Collection<Field> fields) {
135124
relationships.add((Relationship) field);
136125
} else if (field instanceof Tag) {
137126
tags.add((Tag) field);
127+
} else if (field instanceof Vehicle) {
128+
vehicles.add((Vehicle) field);
138129
}
139130
}
140131
}
@@ -163,6 +154,8 @@ public ArrayList<Field> allFields() {
163154
fields.addAll(urls);
164155
fields.addAll(relationships);
165156
fields.addAll(tags);
157+
fields.addAll(vehicles);
158+
166159
return fields;
167160
}
168161

@@ -233,6 +226,9 @@ public ArrayList<Relationship> getRelationships() {
233226
public ArrayList<Tag> getTags() {
234227
return tags;
235228
}
229+
public ArrayList<Vehicle> getVehicles() {
230+
return vehicles;
231+
}
236232

237233
public void setNames(ArrayList<Name> names) {
238234
this.names = names;
@@ -318,6 +314,12 @@ public boolean isSearchable() {
318314
return true;
319315
}
320316
}
317+
318+
for (Vehicle vehicle : getVehicles()) {
319+
if (vehicle.isSearchable()) {
320+
return true;
321+
}
322+
}
321323
return false;
322324
}
323325

src/main/java/com/pipl/api/data/fields/Phone.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class Phone extends AbstractField {
3232
@SerializedName("@do_not_call")
3333
public Boolean doNotCall;
3434

35+
@Expose
36+
public Boolean voip;
37+
3538
public Phone() {
3639
}
3740

@@ -132,6 +135,9 @@ public String getType() {
132135
public Boolean getDoNotCall() {
133136
return doNotCall;
134137
}
138+
public Boolean getVoip() {
139+
return voip;
140+
}
135141

136142
public String getDisplay() {
137143
return display;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.pipl.api.data.fields;
2+
3+
import com.google.gson.annotations.Expose;
4+
5+
import java.util.Arrays;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Objects;
10+
import java.util.regex.Pattern;
11+
12+
public class Vehicle extends AbstractField {
13+
14+
private static final long serialVersionUID = 1L;
15+
@Expose
16+
public String vin;
17+
18+
@Expose
19+
public Integer year;
20+
21+
@Expose
22+
public String make;
23+
24+
@Expose
25+
public String model;
26+
27+
// TODO: redundant since it is not suppoerted by the API
28+
@Expose
29+
public String color;
30+
31+
@Expose
32+
public String vehicleType;
33+
34+
public Vehicle(String vin) {
35+
this.vin = vin;
36+
}
37+
public Vehicle(String vin, Integer year, String make, String model, String color, String vehicleType) {
38+
this.vin = vin;
39+
this.year = year;
40+
this.make = make;
41+
this.model = model;
42+
this.color = color;
43+
this.vehicleType = vehicleType;
44+
}
45+
46+
public String getDisplay() {
47+
String make = (this.make != null) ? this.make.substring(0, 1).toUpperCase() + this.make.substring(1) + " " : "";
48+
String model = (this.model != null) ? this.model.substring(0, 1).toUpperCase() + this.model.substring(1) + " " : "";
49+
String make_and_model = (!make.isEmpty() || !model.isEmpty()) ? make + model : "";
50+
String year = (this.year != null) ? this.year + " " : "";
51+
String vin = (this.vin != null) ? this.vin : "";
52+
String color = (this.color != null) ? ", " + this.color.substring(0, 1).toUpperCase() + this.color.substring(1) : "";
53+
String vehicle_type = (this.vehicleType != null) ? "(" + this.vehicleType.substring(0, 1).toUpperCase() + this.vehicleType.substring(1) + ")" : "";
54+
String type_and_color = (!vehicle_type.isEmpty() || !color.isEmpty()) ? vehicle_type + color + " " : "";
55+
String hyphen = (!year.isEmpty() || !make_and_model.isEmpty() || !vehicle_type.isEmpty() || !color.isEmpty()) ? "- " : "";
56+
return year + make_and_model + type_and_color + hyphen + "VIN " + vin;
57+
}
58+
59+
public boolean isVinValid() {
60+
boolean vinValid = true;
61+
if (vin != null) {
62+
vinValid = vin.length() == 17
63+
&& !Pattern.compile("[ioqIOQ]").matcher(vin).find()
64+
&& !Pattern.compile("[uzUZ0]").matcher(Character.toString(vin.charAt(8))).find()
65+
&& vin.matches("[a-zA-Z0-9]+");
66+
if (vinValid) {
67+
vinValid = isVinChecksumValid();
68+
}
69+
}
70+
return vinValid;
71+
}
72+
73+
public boolean isVinChecksumValid() {
74+
String vinLC = vin.toLowerCase();
75+
char checkDigit = vinLC.charAt(8);
76+
HashMap<String, List<String>> replaceMap = new HashMap<>();
77+
replaceMap.put("1", Arrays.asList("a", "j"));
78+
replaceMap.put("2", Arrays.asList("b", "k", "s"));
79+
replaceMap.put("3", Arrays.asList("c", "l", "t"));
80+
replaceMap.put("4", Arrays.asList("d", "m", "u"));
81+
replaceMap.put("5", Arrays.asList("e", "n", "v"));
82+
replaceMap.put("6", Arrays.asList("f", "w"));
83+
replaceMap.put("7", Arrays.asList("g", "p", "x"));
84+
replaceMap.put("8", Arrays.asList("h", "y"));
85+
replaceMap.put("9", Arrays.asList("r", "z"));
86+
87+
int[] positionalWeights = {8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2};
88+
89+
for (Map.Entry<String, List<String>> entry : replaceMap.entrySet()) {
90+
String digit = entry.getKey();
91+
List<String> replacements = entry.getValue();
92+
for (String c : replacements) {
93+
vinLC = vinLC.replace(c, digit);
94+
}
95+
}
96+
int checksum = 0;
97+
98+
for (int i = 0; i < vinLC.length(); i++) {
99+
char num = vinLC.charAt(i);
100+
if (i != 8) {
101+
checksum += Integer.parseInt(String.valueOf(num)) * positionalWeights[i];
102+
}
103+
}
104+
checksum %= 11;
105+
if (checksum == 10) {
106+
checksum = 'x';
107+
}
108+
return Objects.equals(String.valueOf(checksum), String.valueOf(checkDigit));
109+
}
110+
111+
/**
112+
* A bool value that indicates whether it's possible to search using the data in this vehicle field
113+
*
114+
* @return boolean
115+
*/
116+
@Override
117+
public boolean isSearchable() {
118+
return this.isVinValid();
119+
}
120+
}

0 commit comments

Comments
 (0)