use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class AbstractMultiPhoneCallerDatabaseHandler method getCaller.
@SuppressWarnings("resource")
public ICaller getCaller(IPhonenumber pn) throws SQLException {
if (!isConnected())
try {
this.connect();
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
PreparedStatement ps = this.getStatement("SELECT_CALLER_PHONE");
String p = pn.getTelephoneNumber();
ICaller c = null;
ResultSet rs = null;
// check for internal telephone system numbers
if (this.isInternalNumber(pn)) {
ps.setString(1, p);
rs = ps.executeQuery();
while (rs.next()) {
this.m_logger.info("Found exact match of call number: " + p);
try {
c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
if (c instanceof IMultiPhoneCaller) {
IPhonenumber cp = null;
for (int i = 0, j = ((IMultiPhoneCaller) c).getPhonenumbers().size(); i < j; i++) {
cp = (IPhonenumber) ((IMultiPhoneCaller) c).getPhonenumbers().get(i);
if (cp.getTelephoneNumber().startsWith(p)) {
this.m_logger.info("Found correct phonenumber match: " + p + " = " + cp.getTelephoneNumber());
((IMultiPhoneCaller) c).getPhonenumbers().clear();
c.setPhoneNumber(cp);
return c;
}
}
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
int maxLength = this.maxInternalNumberLength();
// p must be an internal number but has no entry in this caller manager
if (p.length() < maxLength)
return null;
// check for international call
if (p.startsWith(this.getPrefix())) {
this.m_logger.info("Found international call number: " + p);
ICaller internationaCaller = null;
ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (cmg != null && cmg.isActive() && cmg.isSupported(IIdentifyCallerRepository.class)) {
try {
internationaCaller = ((IIdentifyCallerRepository) cmg).getCaller(pn);
} catch (CallerNotFoundException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
if (internationaCaller != null)
pn = internationaCaller.getPhoneNumber();
ps.setString(1, pn.getTelephoneNumber());
rs = ps.executeQuery();
while (rs.next()) {
try {
c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
if (c instanceof IMultiPhoneCaller) {
IPhonenumber cp = null;
for (int i = 0, j = ((IMultiPhoneCaller) c).getPhonenumbers().size(); i < j; i++) {
cp = (IPhonenumber) ((IMultiPhoneCaller) c).getPhonenumbers().get(i);
if (pn.getTelephoneNumber().equalsIgnoreCase(cp.getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(cp.getIntAreaCode())) {
this.m_logger.info("Found correct phonenumber match: " + p + " = " + cp.getTelephoneNumber());
((IMultiPhoneCaller) c).getPhonenumbers().clear();
c.setPhoneNumber(cp);
// found international number
return c;
}
}
} else if (c instanceof ICaller) {
if (pn.getTelephoneNumber().equalsIgnoreCase(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
// found international number
return c;
}
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
// check for extension
if (pn.getIntAreaCode() == null || pn.getIntAreaCode().length() == 0) {
pn.setIntAreaCode(this.getDefaultIntAreaCode());
}
PreparedStatement ps2 = this.getStatement("SELECT_PHONE_REF_COUNT");
if (ps2 == null)
return null;
boolean multiprocess = false;
for (int i = 0; i < p.length() - maxLength; i++) {
ps2.setString(1, p.substring(0, p.length() - i) + "%");
rs = ps2.executeQuery();
while (rs.next()) {
multiprocess = rs.getInt(1) > 1;
}
if (!multiprocess) {
ps.setString(1, p.substring(0, p.length() - i) + "%");
rs = ps.executeQuery();
while (rs.next()) {
try {
c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
ICaller nc = this.process(c, pn, p);
if (nc != null)
return nc;
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
} else {
// added 2008/04/18: processing of multiple callers is possible
PreparedStatement ps3 = this.getStatement("SELECT_PHONE_REF");
ps3.setString(1, p.substring(0, p.length() - i) + "%");
rs = ps3.executeQuery();
List uuids = new ArrayList(2);
while (rs.next()) {
uuids.add(rs.getString(1));
}
// process all UUIDs
String uuid = null;
ps3 = this.getStatement("SELECT_CALLER_PHONE2");
for (int j = 0; j < uuids.size(); j++) {
uuid = (String) uuids.get(j);
ps3.setString(1, uuid);
rs = ps3.executeQuery();
while (rs.next()) {
try {
c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
ICaller nc = this.process(c, pn, p);
if (nc != null)
return nc;
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
}
}
return null;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class AbstractPhonesPage method getCaller.
private ICaller getCaller(IPhonenumber pn, List managers) {
if (pn.isClired()) {
return this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), this.getRuntime().getCallerFactory().createPhonenumber(true));
}
if (pn.getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL) && pn.getCallNumber().equalsIgnoreCase(IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)) {
return (this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), this.getRuntime().getCallerFactory().createPhonenumber(IJAMConst.INTERNAL_CALL, "", IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)));
}
if (managers == null)
managers = this.getActiveCallerManagers();
ICallerManager man = null;
List remoteManagers = new ArrayList();
for (int i = 0; i < managers.size(); i++) {
man = (ICallerManager) managers.get(i);
// first only check local repository managers for performance
if (!(man instanceof ILocalRepository)) {
remoteManagers.add(man);
} else {
try {
if (man != null && man.isActive() && man.isSupported(IIdentifyCallerRepository.class))
return ((IIdentifyCallerRepository) man).getCaller(pn);
} catch (CallerNotFoundException e) {
this.m_logger.warning(e.getMessage());
}
}
}
// check for all non-local repositorymanagers
for (int i = 0; i < remoteManagers.size(); i++) {
man = (ICallerManager) remoteManagers.get(i);
try {
if (man != null && man.isActive() && man.isSupported(IIdentifyCallerRepository.class))
return ((IIdentifyCallerRepository) man).getCaller(pn);
} catch (CallerNotFoundException e) {
this.m_logger.warning(e.getMessage());
}
}
return null;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class CallerReaderFactory method getAllCallers.
public List getAllCallers() {
if (m_list == null) {
List managers = this.getActiveCallerManagers();
ICallerList list = PIMRuntime.getInstance().getCallerFactory().createCallerList();
ICallerList manList = null;
ICallerManager man = null;
for (int i = 0; i < managers.size(); i++) {
man = (ICallerManager) managers.get(i);
if (man != null && man.isActive() && man.isSupported(IReadCallerRepository.class)) {
this.m_currentCM = man;
manList = ((IReadCallerRepository) man).getCallers((IFilter) null);
list.add(unMultiPhoneCaller(manList, managers));
}
}
list.sort(CallerListComparator.ORDER_CALLERNAME, false);
m_list = new ArrayList();
m_list.add(PIMRuntime.getInstance().getCallerFactory().createCaller(PIMRuntime.getInstance().getCallerFactory().createName("", ""), PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true)));
// added 2009/04/18: added internal numbers
m_list.add(PIMRuntime.getInstance().getCallerFactory().createCaller(PIMRuntime.getInstance().getCallerFactory().createName("", ""), PIMRuntime.getInstance().getCallerFactory().createPhonenumber(IJAMConst.INTERNAL_CALL, "", IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)));
for (int i = list.size() - 1; i >= 0; i--) {
m_list.add(list.get(i));
}
}
this.m_currentCM = null;
return m_list;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class CallerReaderFactory method getActiveCallerManagers.
private List getActiveCallerManagers() {
List managers = PIMRuntime.getInstance().getCallerManagerFactory().getAllCallerManagers();
ICallerManager man = null;
for (int i = managers.size() - 1; i >= 0; i--) {
man = (ICallerManager) managers.get(i);
// removed: 2009/04/30: if (!man.isActive() || !(man.isSupported(IReadCallerRepository.class) && man.isSupported(IWriteCallerRepository.class))){
if (!man.isActive() || !man.isSupported(IReadCallerRepository.class)) {
managers.remove(i);
}
}
return managers;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class AssignAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null && v instanceof TableViewer) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
final ICall call = (ICall) selection.getFirstElement();
ICaller caller = call.getCaller();
final ICaller newCaller = openCallerWizard(caller);
if (newCaller != null) {
int l_status = SWT.NO;
if (!newCaller.getPhoneNumber().isClired()) {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(getI18nManager().getString(getNamespace(), "setall", "label", getLanguage()));
l_status = messageBox.open();
}
final int status = l_status;
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
call.setCaller(newCaller);
if (status == SWT.NO && m_app.getController() instanceof IExtendedApplicationController) {
// added 2009/12/31: only update single entry
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignprogress", "label", getLanguage()));
((IExtendedApplicationController) m_app.getController()).updateElement(call, false);
} else {
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "assignall", "label", getLanguage()));
m_app.getController().updateElement(call);
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(),
// DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
if (!newCaller.getPhoneNumber().isClired()) {
new SWTExecuter() {
protected void execute() {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(getI18nManager().getString(getNamespace(), "addressbookconfirm", "label", getLanguage()));
if (messageBox.open() == SWT.YES) {
List cpms = getRuntime().getCallerManagerFactory().getTypedCallerManagers(IWriteCallerRepository.class);
ICallerManager cmgr = null;
for (int i = 0; i < cpms.size(); i++) {
cmgr = (ICallerManager) cpms.get(i);
if (cmgr.isActive() && cmgr.isSupported(IWriteCallerRepository.class))
((IWriteCallerRepository) cmgr).updateCaller(newCaller);
}
}
m_app.updateViews(true);
}
}.start();
} else {
m_app.updateViews(true);
}
// this.m_app.updateViews(true);
}
}
}
}
Aggregations