use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class Serializer method toString.
private static String toString(ICaller caller, boolean includeImage) throws SerializerException {
if (caller instanceof IMultiPhoneCaller) {
return toString((IMultiPhoneCaller) caller, includeImage);
}
StringBuffer serialized = new StringBuffer(128);
try {
// add int area code
serialized.append(encode((caller.getPhoneNumber().getIntAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getIntAreaCode())));
serialized.append(m_token);
// add area code
serialized.append(encode((caller.getPhoneNumber().getAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getAreaCode())));
serialized.append(m_token);
// add call number
serialized.append(encode((caller.getPhoneNumber().getCallNumber().length() == 0 ? BLANK : caller.getPhoneNumber().getCallNumber())));
serialized.append(m_token);
// add firstname
serialized.append(encode((caller.getName().getFirstname().length() == 0 ? BLANK : caller.getName().getFirstname())));
serialized.append(m_token);
// add lastname
serialized.append(encode((caller.getName().getLastname().length() == 0 ? BLANK : caller.getName().getLastname())));
serialized.append(m_token);
// add additional
serialized.append(encode((caller.getName().getAdditional().length() == 0 ? BLANK : caller.getName().getAdditional())));
serialized.append(m_token);
// add caller UUID
serialized.append(encode((caller.getUUID().length() == 0 ? BLANK : caller.getUUID())));
serialized.append(m_token);
// add attributes
IAttributeMap al = caller.getAttributes();
if (al.size() == 0)
serialized.append(BLANK);
Iterator i = al.iterator();
IAttribute att = null;
while (i.hasNext()) {
att = (IAttribute) i.next();
serialized.append(encode(att.getName()));
serialized.append(EQUAL);
serialized.append(encodeAttributeValue(att.getValue()));
serialized.append(m_atoken);
}
} catch (Throwable t) {
throw new SerializerException(t.getMessage());
}
return serialized.toString();
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class FritzBoxMappingManager method mapJamCallerToFritzBox.
public IPhonebookEntry mapJamCallerToFritzBox(ICaller caller) throws IOException {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Processing JAM caller: " + caller.toString());
IPhonebookEntry pe = new FritzBoxPhonebookEntry();
IAttributeMap attributes = caller.getAttributes();
String name = "";
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME)) {
name += attributes.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue() + " ";
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, attributes.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME)) {
name += attributes.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue();
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_LASTNAME, attributes.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue());
}
pe.setName(name.trim());
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_STREET)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET, attributes.get(IJAMConst.ATTRIBUTE_NAME_STREET).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_STREET_NO)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_STREET_NO, attributes.get(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_CITY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_CITY, attributes.get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, attributes.get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_COUNTRY, attributes.get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
}
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
pe.addJamInfo(IJAMConst.ATTRIBUTE_NAME_CATEGORY, attributes.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY).getValue());
}
if (// hack, since FB only supports integer values
caller.getUUID().length() < 10)
pe.setUniqueID(caller.getUUID());
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_EMAIL))
pe.setEmail(attributes.get(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
if (attributes.contains("fb_entryID"))
pe.setEntryID(attributes.get("fb_entryID").getValue());
if (attributes.contains("fb_mod_time"))
pe.setModTime(attributes.get("fb_mod_time").getValue());
if (attributes.contains("fb_category"))
pe.setCategory(attributes.get("fb_category").getValue());
if (attributes.contains("fb_imageURL")) {
// replace /download.lua?path=/var by f
String nurl = attributes.get("fb_imageURL").getValue();
nurl = StringUtils.replaceString(nurl, "/download.lua?path=/var", "file:///var");
pe.setImageURL(nurl);
}
List phones = new ArrayList();
if (caller instanceof IMultiPhoneCaller) {
phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
} else {
phones.add(caller.getPhoneNumber());
}
for (int i = 0; i < phones.size(); i++) {
IPhonenumber pn = (IPhonenumber) phones.get(i);
String number = this.getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, pn);
if (attributes.contains("fb_number_type_" + pn.getTelephoneNumber())) {
pe.addNumber(number, attributes.get("fb_number_type_" + pn.getTelephoneNumber()).getValue());
pe.addNumberType(number, attributes.get("fb_number_type_" + pn.getTelephoneNumber()).getValue());
} else if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
if (attributes.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
pe.addNumber(number, "mobile");
pe.addNumberType(number, "mobile");
} else if (attributes.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
pe.addNumber(number, "fax_work");
pe.addNumberType(number, "fax_work");
} else {
pe.addNumber(number, "home");
pe.addNumberType(number, "home");
}
} else {
pe.addNumber(number, "home");
pe.addNumberType(number, "home");
}
if (attributes.contains("fb_number_id_" + pn.getTelephoneNumber())) {
pe.addNumberID(number, attributes.get("fb_number_id_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_prio_" + pn.getTelephoneNumber())) {
pe.addNumberPrio(number, attributes.get("fb_number_prio_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_quickdial_" + pn.getTelephoneNumber())) {
pe.addNumberQuickDial(number, attributes.get("fb_number_quickdial_" + pn.getTelephoneNumber()).getValue());
}
if (attributes.contains("fb_number_vanity_" + pn.getTelephoneNumber())) {
pe.addNumberVanity(number, attributes.get("fb_number_vanity_" + pn.getTelephoneNumber()).getValue());
}
}
return pe;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class AbstractPhonesPage method getResult.
public IPhonenumber[] getResult() {
if (all != null && all.getSelection())
return null;
if (this.m_selectedCallers != null && this.m_selectedCallers.size() > 0) {
List phoneList = new ArrayList();
ICaller c = null;
for (int i = 0, j = this.m_selectedCallers.size(); i < j; i++) {
c = ((ICaller) this.m_selectedCallers.get(i));
if (c instanceof IMultiPhoneCaller) {
phoneList.addAll(((IMultiPhoneCaller) c).getPhonenumbers());
} else {
phoneList.add(c.getPhoneNumber());
}
}
if (phoneList.size() > 0) {
this.m_phones = new IPhonenumber[phoneList.size()];
for (int i = 0, j = phoneList.size(); i < j; i++) {
this.m_phones[i] = (IPhonenumber) phoneList.get(i);
}
}
}
if (this.m_phones != null && this.m_phones.length == 0)
this.m_phones = null;
return this.m_phones;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class AbstractMultiPhoneCallerDatabaseHandler method insertOrUpdateCallerList.
/**
* Insert the callers in the list or update the callers if it already
* exists.
*
* @param cl
* @throws SQLException
*/
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
if (!isConnected())
try {
this.connect();
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
// check prepared statements
PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
PreparedStatement insert_phones = this.getStatement("INSERT_PHONE");
PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
PreparedStatement delete_phones = this.getStatement("DELETE_PHONE");
PreparedStatement delete_phones2 = this.getStatement("DELETE_PHONE2");
PreparedStatement delete_attributes = this.getStatement("DELETE_ATTRIBUTE");
// clean up prpared statements
insert_caller.clearBatch();
insert_attributes.clearBatch();
insert_phones.clearBatch();
update_caller.clearBatch();
delete_attributes.clearBatch();
delete_phones.clearBatch();
delete_phones2.clearBatch();
// list for redundant UUIDs checks
List uuid_check = new ArrayList(cl.size());
ICaller c = null;
String uuid = null;
List phones = new ArrayList(1);
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
if (this.m_logger.isLoggable(Level.INFO) && c != null)
this.m_logger.info("Adding to database: " + c.toString());
// check if redundant uuid could occure
uuid = c.getUUID();
if (uuid_check.contains(uuid)) {
this.m_logger.warning("Found duplicated UUID: " + c.toString());
c.setUUID(new UUID().toString());
uuid = c.getUUID();
}
uuid_check.add(uuid);
// check which type of Interface the caller object implements
if (!(c instanceof IMultiPhoneCaller)) {
if (this.m_logger.isLoggable(Level.INFO) && c != null)
this.m_logger.info("Caller is not type IMultiPhoneCaller. Transforming is triggered... : " + c.toString());
c = this.getRuntime().getCallerFactory().toMultiPhoneCaller(c);
// 2008/11/30: added to fix duplicated address book entries after category assignement
c.setUUID(uuid);
}
phones.clear();
phones.addAll(((IMultiPhoneCaller) c).getPhonenumbers());
// check if single caller (uuid) is already in DB
if (existsCaller(c)) {
internalUpdate(c);
if (this.m_logger.isLoggable(Level.INFO) && c != null)
this.m_logger.info("Caller already exists in database. Update is triggered: " + c.toString());
try {
// update caller table
this.updateCaller(update_caller, c.getUUID(), Serializer.toByteArray(c));
// update attributes table
this.deleteAttributes(delete_attributes, c.getUUID());
this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
// update phones table
this.deletePhone(delete_phones, c.getUUID());
IPhonenumber p = null;
for (int a = 0, b = phones.size(); a < b; a++) {
p = (IPhonenumber) phones.get(a);
this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
} else if (this.existsPhones(phones).size() > 0) {
internalInsert(c);
// check if phone numnbers are already in DB and overwrite them
List existingPhones = this.existsPhones(phones);
IPhonenumber pn = null;
for (int a = 0, b = existingPhones.size(); a < b; a++) {
pn = (IPhonenumber) existingPhones.get(a);
if (this.m_logger.isLoggable(Level.INFO) && c != null)
this.m_logger.info("Phone already exists in database. Update is triggered: " + pn.toString());
this.deletePhone(delete_phones2, pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber());
}
try {
this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
IPhonenumber p = null;
for (int a = 0, b = phones.size(); a < b; a++) {
p = (IPhonenumber) phones.get(a);
this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
} else {
internalInsert(c);
// insert new caller
try {
this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
IPhonenumber p = null;
for (int a = 0, b = phones.size(); a < b; a++) {
p = (IPhonenumber) phones.get(a);
this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
if (i % this.commit_count == 0) {
try {
delete_attributes.executeBatch();
delete_attributes.clearBatch();
this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
delete_phones.executeBatch();
delete_phones.clearBatch();
this.m_logger.info("Batch DELETE_PHONES executed...");
delete_phones2.executeBatch();
delete_phones2.clearBatch();
this.m_logger.info("Batch DELETE_PHONES2 executed...");
insert_caller.executeBatch();
insert_caller.clearBatch();
this.m_logger.info("Batch INSERT_CALLER executed...");
insert_attributes.executeBatch();
insert_attributes.clearBatch();
this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
insert_phones.executeBatch();
insert_phones.clearBatch();
this.m_logger.info("Batch INSERT_PHONES executed...");
update_caller.executeBatch();
update_caller.clearBatch();
this.m_logger.info("Batch UPDATE_CALLER executed...");
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage() + c.toString(), e);
// throw new SQLException("Batch execution failed: ");
}
}
}
// execute the rest batch content
delete_attributes.executeBatch();
delete_attributes.clearBatch();
this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
delete_phones.executeBatch();
delete_phones.clearBatch();
this.m_logger.info("Batch DELETE_PHONES executed...");
delete_phones2.executeBatch();
delete_phones2.clearBatch();
this.m_logger.info("Batch DELETE_PHONES2 executed...");
insert_caller.executeBatch();
insert_caller.clearBatch();
this.m_logger.info("Batch INSERT_CALLER executed...");
insert_attributes.executeBatch();
insert_attributes.clearBatch();
this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
insert_phones.executeBatch();
insert_phones.clearBatch();
this.m_logger.info("Batch INSERT_PHONES executed...");
update_caller.executeBatch();
update_caller.clearBatch();
this.m_logger.info("Batch UPDATE_CALLER executed...");
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class EabFileCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
Properties addressbook = new Properties();
FileOutputStream fo = new FileOutputStream(db);
ICaller c = null;
addressbook.setProperty("total", Integer.toString(this.m_callerList.size()));
for (int i = 0; i < this.m_callerList.size(); i++) {
c = this.m_callerList.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
addressbook.setProperty((i + 1) + ".phonecount", Integer.toString(phones.size()));
for (int a = 0, b = phones.size(); a < b; a++) {
addressbook.setProperty((i + 1) + ".intarea." + a, ((IPhonenumber) phones.get(a)).getIntAreaCode());
addressbook.setProperty((i + 1) + ".area." + a, ((IPhonenumber) phones.get(a)).getAreaCode());
addressbook.setProperty((i + 1) + ".phone." + a, ((IPhonenumber) phones.get(a)).getCallNumber());
}
} else {
addressbook.setProperty((i + 1) + ".intarea", c.getPhoneNumber().getIntAreaCode());
addressbook.setProperty((i + 1) + ".area", c.getPhoneNumber().getAreaCode());
addressbook.setProperty((i + 1) + ".phone", c.getPhoneNumber().getCallNumber());
}
IAttributeMap attributes = c.getAttributes();
Iterator iter = attributes.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
addressbook.setProperty((i + 1) + "." + a.getName(), a.getValue());
}
}
addressbook.store(fo, "");
fo.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
Aggregations