001/* 002 * Copyright 2020 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.insight; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 020import com.fasterxml.jackson.annotation.JsonProperty; 021import com.fasterxml.jackson.databind.ObjectMapper; 022import com.vonage.client.VonageUnexpectedException; 023 024import java.io.IOException; 025import java.util.HashMap; 026import java.util.Map; 027 028@JsonIgnoreProperties(ignoreUnknown = true) 029public class AdvancedInsightResponse extends StandardInsightResponse { 030 private Validity validNumber; 031 private Reachability reachability; 032 private PortedStatus ported; 033 private Integer lookupOutcome; 034 private String lookupOutcomeMessage; 035 private RoamingDetails roaming; 036 private String callerName; 037 private String firstName; 038 private String lastName; 039 private CallerType callerType; 040 041 042 public static AdvancedInsightResponse fromJson(String json) { 043 try { 044 ObjectMapper mapper = new ObjectMapper(); 045 return mapper.readValue(json, AdvancedInsightResponse.class); 046 } catch (IOException jpe) { 047 throw new VonageUnexpectedException("Failed to produce AdvancedInsightResponse from json.", jpe); 048 } 049 } 050 051 @JsonProperty("valid_number") 052 public Validity getValidNumber() { 053 return validNumber; 054 } 055 056 @JsonProperty("reachable") 057 public Reachability getReachability() { 058 return reachability; 059 } 060 061 public PortedStatus getPorted() { 062 return ported; 063 } 064 065 @JsonProperty("lookup_outcome") 066 public Integer getLookupOutcome() { 067 return lookupOutcome; 068 } 069 070 @JsonProperty("lookup_outcome_message") 071 public String getLookupOutcomeMessage() { 072 return lookupOutcomeMessage; 073 } 074 075 public RoamingDetails getRoaming() { 076 return roaming; 077 } 078 079 @JsonProperty("caller_name") 080 public String getCallerName() { 081 return callerName; 082 } 083 084 @JsonProperty("first_name") 085 public String getFirstName() { 086 return firstName; 087 } 088 089 @JsonProperty("last_name") 090 public String getLastName() { 091 return lastName; 092 } 093 094 @JsonProperty("caller_type") 095 public CallerType getCallerType() { 096 return callerType; 097 } 098 099 public enum PortedStatus { 100 UNKNOWN, PORTED, NOT_PORTED, ASSUMED_NOT_PORTED, ASSUMED_PORTED; 101 102 private static final Map<String, PortedStatus> PORTED_STATUS_INDEX = new HashMap<>(); 103 104 static { 105 for (PortedStatus portedStatus : PortedStatus.values()) { 106 PORTED_STATUS_INDEX.put(portedStatus.name(), portedStatus); 107 } 108 } 109 110 @JsonCreator 111 public static PortedStatus fromString(String name) { 112 PortedStatus foundPortedStatus = PORTED_STATUS_INDEX.get(name.toUpperCase()); 113 return (foundPortedStatus != null) ? foundPortedStatus : UNKNOWN; 114 } 115 116 } 117 118 public enum Validity { 119 UNKNOWN, VALID, NOT_VALID; 120 121 private static final Map<String, Validity> VALIDITY_INDEX = new HashMap<>(); 122 123 static { 124 for (Validity validity : Validity.values()) { 125 VALIDITY_INDEX.put(validity.name(), validity); 126 } 127 } 128 129 @JsonCreator 130 public static Validity fromString(String name) { 131 Validity foundValidity = VALIDITY_INDEX.get(name.toUpperCase()); 132 return (foundValidity != null) ? foundValidity : Validity.UNKNOWN; 133 } 134 } 135 136 public enum Reachability { 137 UNKNOWN, REACHABLE, UNDELIVERABLE, ABSENT, BAD_NUMBER, BLACKLISTED; 138 139 private static final Map<String, Reachability> REACHABILITY_INDEX = new HashMap<>(); 140 141 static { 142 for (Reachability reachability : Reachability.values()) { 143 REACHABILITY_INDEX.put(reachability.name(), reachability); 144 } 145 } 146 147 @JsonCreator 148 public static Reachability fromString(String name) { 149 Reachability foundReachability = REACHABILITY_INDEX.get(name.toUpperCase()); 150 return (foundReachability != null) ? foundReachability : UNKNOWN; 151 } 152 } 153}