use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class CombineAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Iterator i = selection.iterator();
ICallerList list = getRuntime().getCallerFactory().createCallerList();
ICallerList olist = getRuntime().getCallerFactory().createCallerList();
Object o = null;
while (i.hasNext()) {
o = i.next();
olist.add((ICaller) o);
if (o instanceof IMultiPhoneCaller) {
list.add((IMultiPhoneCaller) o);
} else if (o instanceof ICaller) {
list.add(getRuntime().getCallerFactory().toMultiPhoneCaller((ICaller) o));
}
}
if (list.size() < 2)
return;
Display display = DisplayManager.getDefaultDisplay();
Shell shell = new Shell(display);
WizardDialog.setDefaultImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
CallerCombineWizard callerWiz = new CallerCombineWizard(list);
WizardDialog dlg = new WizardDialog(shell, callerWiz);
dlg.open();
if (dlg.getReturnCode() == WizardDialog.OK) {
IMultiPhoneCaller c = callerWiz.getResult();
if (c != null) {
// remove merged contact from olist
ICaller ca, rmc = null;
for (int j = olist.size() - 1; j >= 0; j--) {
ca = olist.get(j);
if (ca.getUUID().equalsIgnoreCase(c.getUUID())) {
rmc = ca;
m_logger.info("Merged user detected: " + rmc);
}
}
if (rmc != null)
olist.remove(rmc);
this.m_app.getController().deleteElements(olist);
this.m_app.getController().updateElement(c);
this.m_app.updateViews(true);
}
}
}
}
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class TreeContentProvider method getChildren.
public Object[] getChildren(Object o) {
if (o instanceof IMultiPhoneCaller) {
List items = new ArrayList();
List pns = ((IMultiPhoneCaller) o).getPhonenumbers();
for (int i = 0, j = pns.size(); i < j; i++) {
items.add(new TreeItemCallerData(((IMultiPhoneCaller) o), ((IMultiPhoneCaller) o).getAttributes(), (IPhonenumber) pns.get(i)));
}
if (items.size() > 1)
items.remove(0);
return items.toArray();
}
return null;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class History method getConfiguration.
public Properties getConfiguration() {
Properties saved = super.getConfiguration();
Properties journalConfig = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Journal.NAMESPACE);
if (journalConfig != null && journalConfig.size() > 0) {
saved.setProperty(JournalConfigConst.CFG_REPOSITORY, journalConfig.getProperty(JournalConfigConst.CFG_REPOSITORY));
}
IFilter[] filters = null;
if (this.m_caller instanceof IMultiPhoneCaller) {
filters = new IFilter[((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size()];
for (int i = 0, j = ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size(); i < j; i++) {
filters[i] = new PhonenumberFilter((IPhonenumber) ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().get(i));
}
} else {
filters = new IFilter[1];
if (this.m_caller != null)
filters[0] = new PhonenumberFilter(this.m_caller.getPhoneNumber());
}
saved.setProperty("filter", new JournalFilterManager().getFiltersToString(filters));
return saved;
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class MacAddressBookProxy method addressBookChanged.
@SuppressWarnings("unchecked")
public void addressBookChanged(AddressBookNotification notification) {
this.m_logger.info("Mac Address Book update for UID " + notification.getUpdatedRecords());
Set updates = notification.getUpdatedRecords();
Iterator i = updates.iterator();
while (i.hasNext()) {
String uid = (String) i.next();
List uids = new ArrayList();
uids.add(uid);
List contacts = getRecordsByUIDs(uids);
if (contacts.size() > 0) {
final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
for (Object contact : contacts) {
if (contact instanceof Map<?, ?>) {
ICaller privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
ICaller businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
if (privateCaller == null && businessCaller != null) {
callers.add(businessCaller);
}
if (privateCaller != null && businessCaller == null) {
callers.add(privateCaller);
}
if (privateCaller != null && businessCaller != null) {
if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
businessCaller = null;
}
}
if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
privateCaller = null;
}
}
if (privateCaller != null) {
callers.add(privateCaller);
}
if (businessCaller != null) {
callers.add(businessCaller);
}
}
}
}
if (callers.size() > 0) {
Thread updateDbhThread = new Thread() {
public void run() {
updateProxyDatabase(callers);
}
};
updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
updateDbhThread.start();
}
}
}
}
use of de.janrufmonitor.framework.IMultiPhoneCaller in project janrufmonitor by tbrandt77.
the class MacAddressBookProxy method findContact.
@SuppressWarnings("unchecked")
public synchronized ICaller findContact(IPhonenumber pn) throws MacAddressBookProxyException {
ICaller c = Identifier.identifyDefault(getRuntime(), pn);
if (c == null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
c = getRuntime().getCallerFactory().createCaller(p);
}
if (c != null) {
if (PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
c.setPhoneNumber(p);
}
pn = c.getPhoneNumber();
try {
List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("List of found UUIDs: " + uuids);
}
if (uuids.size() > 0) {
String uuid = null;
for (int k = 0; k < uuids.size(); k++) {
uuid = (String) uuids.get(k);
List uids = new ArrayList();
uids.add(uuid);
List contacts = getRecordsByUIDs(uids);
if (contacts.size() > 0) {
Object contact = contacts.get(0);
ICallerList cl = getRuntime().getCallerFactory().createCallerList(2);
if (contact instanceof Map<?, ?>) {
ICaller businessCaller, privateCaller = null;
privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
if (privateCaller == null && businessCaller != null) {
cl.add(businessCaller);
}
if (privateCaller != null && businessCaller == null) {
cl.add(privateCaller);
}
if (privateCaller != null && businessCaller != null) {
if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
// only one entry available
IPhonenumber pn1 = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn1.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
businessCaller = null;
}
}
if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
// only one entry available
IPhonenumber pn1 = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn1.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
privateCaller = null;
}
}
if (privateCaller != null) {
cl.add(privateCaller);
}
if (businessCaller != null) {
cl.add(businessCaller);
}
}
}
if (cl.size() == 1) {
ICaller rc = cl.get(0);
rc.setUUID(new UUID().toString());
if (rc instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) rc).getPhonenumbers().clear();
}
rc.setPhoneNumber(pn);
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber());
rc.setAttribute(att);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Exact caller match: " + rc.toString());
}
return rc;
}
if (cl.size() == 2) {
ICaller rc = null;
for (int x = 0; x < cl.size(); x++) {
rc = cl.get(x);
if (rc instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) rc).getPhonenumbers();
IPhonenumber p = null;
for (int z = 0; z < phones.size(); z++) {
p = (IPhonenumber) phones.get(z);
if (p.getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && p.getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(p.getCallNumber())) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match (IMultiPhoneCaller): " + rc.toString());
}
rc.setUUID(new UUID().toString());
if (rc instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) rc).getPhonenumbers().clear();
}
rc.setPhoneNumber(p);
return rc;
}
}
} else {
if (rc.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && rc.getPhoneNumber().getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(rc.getPhoneNumber().getCallNumber())) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match (ICaller): " + rc.toString());
}
return rc;
}
}
}
}
}
}
} else {
Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
if (config.getProperty("keepextension", "false").equalsIgnoreCase("true")) {
// iterate down
String callnumber = pn.getCallNumber();
if (callnumber.length() > 1) {
pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
ICaller ca = this.findContact(pn);
if (ca != null) {
pn.setCallNumber(callnumber);
if (ca instanceof IMultiPhoneCaller) {
((IMultiPhoneCaller) ca).getPhonenumbers().clear();
}
ca.setPhoneNumber(pn);
// set extension
if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
if (pn.getTelephoneNumber().length() > centralnumber.length()) {
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
ca.setAttribute(att);
}
}
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Caller match by central number: " + ca.toString());
}
return ca;
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
}
this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
return null;
}
Aggregations