use of de.janrufmonitor.fritzbox.IPhonebookEntry 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.fritzbox.IPhonebookEntry in project janrufmonitor by tbrandt77.
the class FritzBoxMappingManager method toCallerList.
public ICallerList toCallerList(List l) {
ICallerList cl = getRuntime().getCallerFactory().createCallerList(l.size());
ICaller c = null;
for (int i = 0; i < l.size(); i++) {
try {
c = this.mapFritzBoxCallerToJam((IPhonebookEntry) l.get(i));
if (c != null)
cl.add(c);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return cl;
}
use of de.janrufmonitor.fritzbox.IPhonebookEntry in project janrufmonitor by tbrandt77.
the class FritzBoxMappingManager method toFritzBoxCallerList.
public List toFritzBoxCallerList(ICallerList l) {
List cl = new ArrayList(l.size());
IPhonebookEntry pe = null;
for (int i = 0; i < l.size(); i++) {
try {
pe = this.mapJamCallerToFritzBox((ICaller) l.get(i));
if (pe != null)
cl.add(pe);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return cl;
}
use of de.janrufmonitor.fritzbox.IPhonebookEntry in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method removeCaller.
public void removeCaller(ICaller caller) {
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
IPhonebookEntry pe = FritzBoxMappingManager.getInstance().mapJamCallerToFritzBox(caller);
fwm.deleteCaller(id, pe);
ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
cl.add(caller);
try {
getDatabaseHandler().deleteCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
} catch (FritzBoxLoginException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (DeleteCallerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (!this.isSyncing)
this.createCallerListFromFritzBoxPhonebook();
}
use of de.janrufmonitor.fritzbox.IPhonebookEntry in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method setCaller.
public void setCaller(ICaller caller) {
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
IPhonebookEntry pe = FritzBoxMappingManager.getInstance().mapJamCallerToFritzBox(caller);
fwm.setCaller(id, pe);
ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
cl.add(caller);
try {
getDatabaseHandler().insertOrUpdateCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
} catch (FritzBoxLoginException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (SetCallerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (!this.isSyncing)
this.createCallerListFromFritzBoxPhonebook();
}
Aggregations