use of de.janrufmonitor.repository.ICallerManager 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);
}
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method parsePhone.
private IPhonenumber parsePhone(String caller) {
if (caller.indexOf("(0") > -1) {
IPhonenumber phone = null;
String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
if (pn.length() > 0) {
phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
try {
ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
return parsedCaller.getPhoneNumber();
} catch (CallerNotFoundException e) {
this.m_logger.warning(e.getMessage());
}
}
}
}
return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class OldDatFileCallerImporter method migrateCallerFromString.
private ICaller migrateCallerFromString(String scaller) {
if (scaller != null && scaller.trim().length() == 0)
return null;
StringTokenizer st = new StringTokenizer(scaller, ";");
String number = st.nextToken().trim();
String caller = st.nextToken().trim();
String reject = "0";
if (st.hasMoreTokens())
reject = st.nextToken().trim();
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(number.substring(1));
try {
ICaller migCaller = null;
ICallerManager def = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class)) {
migCaller = ((IIdentifyCallerRepository) def).getCaller(pn);
} else
throw new CallerNotFoundException();
StringTokenizer ctoken = new StringTokenizer(caller, " ");
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
if (ctoken.hasMoreTokens()) {
name.setFirstname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setLastname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setAdditional(ctoken.nextToken());
}
while (ctoken.hasMoreTokens()) {
name.setAdditional(name.getAdditional() + " " + ctoken.nextToken());
}
migCaller.setName(name);
if (reject.equalsIgnoreCase("1")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES);
migCaller.setAttribute(att);
}
if (reject.equalsIgnoreCase("0")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO);
migCaller.setAttribute(att);
}
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).info(migCaller.toString());
return migCaller;
} catch (CallerNotFoundException e) {
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).warning(e.getMessage());
}
return null;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class ConsoleImport method execute.
public void execute() throws Exception {
this.isExecuting = true;
if (this.getExecuteParams().length != 1) {
System.out.println("ERROR: Paramters are invalid. Please specify a valid module for installation.");
this.isExecuting = false;
return;
}
String filename = this.getExecuteParams()[0];
IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallerImporter");
if (imp != null && imp instanceof ICallerImporter) {
((ICallerImporter) imp).setFilename(filename);
ICallerList cl = ((ICallerImporter) imp).doImport();
ICallerManager mgr = this.getRuntime().getCallerManagerFactory().getCallerManager("CallerDirectory");
if (mgr != null && mgr.isActive() && mgr.isSupported(IWriteCallerRepository.class)) {
((IWriteCallerRepository) mgr).setCaller(cl);
System.out.println("INFO: Successfully imported " + cl.size() + " caller entries.");
} else {
System.out.println("ERROR: Caller manager is missing.");
}
} else {
System.out.println("ERROR: import filter for DAT files is missing.");
}
this.isExecuting = false;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class AbstractCallerDatabaseHandler method getCaller.
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();
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 {
return Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
} 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 {
ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
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());
}
for (int i = 0; i < p.length() - maxLength; i++) {
ps.setString(1, p.substring(0, p.length() - i) + "%");
rs = ps.executeQuery();
while (rs.next()) {
try {
ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
if (p.startsWith(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
// found extension phone
String extension = p.substring(c.getPhoneNumber().getTelephoneNumber().length(), p.length());
this.m_logger.info("Found call extension -" + extension + " for call number: " + p);
c.setUUID(new UUID().toString());
c.getPhoneNumber().setTelephoneNumber(p);
c.getPhoneNumber().setCallNumber(c.getPhoneNumber().getCallNumber() + extension);
// add attributes
IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, extension);
c.setAttribute(att);
att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, p.substring(0, p.length() - extension.length()));
c.setAttribute(att);
return c;
}
} catch (SerializerException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
return null;
}
Aggregations