use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.
the class IsdnMoniCallImporter method doImport.
public ICallList doImport() {
this.m_callerList = null;
boolean doNotShowmessage = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(this.getNamespace(), CFG_SHOW_ENTRY_WARNING).equalsIgnoreCase("true");
if (!doNotShowmessage) {
new SWTExecuter() {
protected void execute() {
String message = getI18nManager().getString(getNamespace(), "message", "description", getLanguage());
MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "message", "label", getLanguage()), message, getI18nManager().getString(getNamespace(), "confirmmessage", "label", getLanguage()), false, null, null);
if (d.getReturnCode() == 2) {
m_callerList = getRuntime().getCallerFactory().createCallerList();
}
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), CFG_SHOW_ENTRY_WARNING, (d.getToggleState() ? "true" : "false"));
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
isDialogFinished = true;
}
}.start();
} else {
isDialogFinished = true;
}
while (!isDialogFinished) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
Date startDate = new Date();
File db = new File(m_filename);
int size = (int) db.length() / 64;
size = Math.abs(size);
ThreadGroup g = new ThreadGroup("JAM- HeuerMigrator-ThreadGroup");
m_callList = getRuntime().getCallFactory().createCallList(size);
m_pnList = new ArrayList(size);
try {
FileReader dbReader = new FileReader(db);
BufferedReader bufReader = new BufferedReader(dbReader);
int i = 0;
while (bufReader.ready()) {
String line = bufReader.readLine();
if (line.indexOf("->") > 0) {
try {
Thread t = new Thread(g, new MigratorThread(this.m_callList, (this.m_callerList != null ? this.m_callerList : null), line, this.m_pnList));
t.setName("JAM-HeuerMigrator#" + (i++) + "-Thread-(non-deamon)");
t.start();
if (g.activeCount() > 100) {
Thread.sleep(1000);
}
} catch (Exception ex) {
this.m_logger.severe("Unexpected error during migration: " + ex);
}
}
}
bufReader.close();
dbReader.close();
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find call backup file " + m_filename);
return this.m_callList;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return this.m_callList;
}
while (g.activeCount() > 0) {
try {
Thread.sleep(1000);
this.m_logger.info("Waiting for " + g.activeCount() + " Migrator threads.");
} catch (InterruptedException e) {
this.m_logger.severe(e.getMessage());
}
}
if (this.m_callerList != null) {
this.m_logger.info("Commiting detected callers to default caller manager.");
String cm = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "repository");
ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getCallerManager(cm);
if (cmg != null && cmg.isActive() && cmg.isSupported(IWriteCallerRepository.class)) {
((IWriteCallerRepository) cmg).setCaller(this.m_callerList);
}
}
Date endDate = new Date();
this.m_logger.info("Successfully imported call file " + m_filename);
this.m_logger.info("Found " + new Integer(this.m_callList.size()).toString() + " call items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
return m_callList;
}
use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.
the class EditorController method deleteElements.
public synchronized void deleteElements(Object list) {
if (list != null && list instanceof ICallerList) {
Map cms = new HashMap();
ICallerList tmplist = null;
ICaller c = null;
for (int i = 0; i < ((ICallerList) list).size(); i++) {
c = ((ICallerList) list).get(i);
IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
String cname = (att == null ? "all" : att.getValue());
if (cms.containsKey(cname)) {
tmplist = (ICallerList) cms.get(cname);
tmplist.add(c);
} else {
tmplist = this.getRuntime().getCallerFactory().createCallerList(1);
tmplist.add(c);
cms.put(cname, tmplist);
}
}
List managers = this.getActiveCallerManagers();
ICallerManager mgr = null;
for (int i = 0; i < managers.size(); i++) {
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
tmplist = (ICallerList) cms.get("all");
if (tmplist != null) {
this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
((IWriteCallerRepository) mgr).removeCaller(tmplist);
}
tmplist = (ICallerList) cms.get(mgr.getManagerID());
if (tmplist != null) {
this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
((IWriteCallerRepository) mgr).removeCaller(tmplist);
}
}
}
}
}
}
use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.
the class EditorController method updateElement.
public synchronized void updateElement(Object element) {
if (element != null && element instanceof ICallerList) {
ICallerManager mgr = this._getRepository();
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
for (int i = 0, j = ((ICallerList) element).size(); i < j; i++) {
((IWriteCallerRepository) mgr).updateCaller(((ICallerList) element).get(i));
}
}
}
}
if (element != null && element instanceof ICaller) {
List managers = this.getActiveCallerManagers();
ICallerManager mgr = null;
IAttribute att = ((ICaller) element).getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
for (int i = 0; i < managers.size(); i++) {
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
if (att == null || att.getValue().equalsIgnoreCase(mgr.getManagerID()))
((IWriteCallerRepository) mgr).updateCaller((ICaller) element);
}
}
}
}
}
use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.
the class RemoveCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(RemoveCallerList.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Removing caller list with " + l.size() + " entries.");
((IWriteCallerRepository) mgr).removeCaller(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.repository.types.IWriteCallerRepository in project janrufmonitor by tbrandt77.
the class SetCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(SetCallerList.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Setting caller list with " + l.size() + " entries.");
((IWriteCallerRepository) mgr).setCaller(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations