diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java index 5c5a79f0f..a1aba99d0 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java @@ -73,7 +73,8 @@ public HistoryService getHistoryService() * Returns all the calls made by all the contacts * in the supplied metacontact after the given date * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param startDate Date the start date of the calls * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException @@ -91,7 +92,7 @@ public Collection findByStartDate(MetaContact contact, Date startDate) * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - public Collection findByStartDate(Date startDate) throws RuntimeException + public Collection findByStartDate(Date startDate) { TreeSet result = new TreeSet(new CallRecordComparator()); try @@ -120,7 +121,8 @@ public Collection findByStartDate(Date startDate) throws RuntimeException * Returns all the calls made by all the contacts * in the supplied metacontact before the given date * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param endDate Date the end date of the calls * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException @@ -217,7 +219,8 @@ public Collection findByPeriod(Date startDate, Date endDate) throws * Returns the supplied number of calls by all the contacts * in the supplied metacontact * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param count calls count * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException @@ -257,6 +260,40 @@ public Collection findLast(int count) throws RuntimeException return result; } + /** + * Find the calls made by the supplied participant address + * @param address String the address of the participant + * @return Collection of CallRecords with CallParticipantRecord + * @throws RuntimeException + */ + public Collection findByParticipant(String address) + throws RuntimeException + { + TreeSet result = new TreeSet(new CallRecordComparator()); + try + { + // the default ones + History history = this.getHistory(null, null); + HistoryReader reader = history.getReader(); + addHistorySearchProgressListeners(reader, 1); + QueryResultSet rs = + reader.findByKeyword(address, "callParticipantIDs"); + while (rs.hasNext()) + { + HistoryRecord hr = (HistoryRecord) rs.next(); + result.add(convertHistoryRecordToCallRecord(hr)); + } + removeHistorySearchProgressListeners(reader); + } + catch (IOException ex) + { + logger.error("Could not read history", ex); + } + + return result; + } + + /** * Returns the history by specified local and remote contact * if one of them is null the default is used @@ -298,7 +335,7 @@ private History getHistory(Contact localContact, Contact remoteContact) */ private Object convertHistoryRecordToCallRecord(HistoryRecord hr) { - CallRecord result = new CallRecord(); + CallRecordImpl result = new CallRecordImpl(); LinkedList callParticipantIDs = null; LinkedList callParticipantStart = null; @@ -694,7 +731,7 @@ public void callEnded(CallEvent event) logger.info("callEnded"); Date endTime = new Date(); - CallRecord callRecord = findCallRecord(event.getSourceCall()); + CallRecordImpl callRecord = findCallRecord(event.getSourceCall()); // no such call if (callRecord == null) @@ -738,8 +775,8 @@ private void handleParticipantRemoved(CallParticipant callParticipant, CallRecord callRecord = findCallRecord(srcCall); String pAddress = callParticipant.getAddress(); - CallParticipantRecord cpRecord = - callRecord.findParticipantRecord(pAddress); + CallParticipantRecordImpl cpRecord = + (CallParticipantRecordImpl)callRecord.findParticipantRecord(pAddress); // no such participant if(cpRecord == null) @@ -753,12 +790,12 @@ private void handleParticipantRemoved(CallParticipant callParticipant, * @param call Call * @return CallRecord */ - private CallRecord findCallRecord(Call call) + private CallRecordImpl findCallRecord(Call call) { Iterator iter = currentCallRecords.iterator(); while (iter.hasNext()) { - CallRecord item = (CallRecord) iter.next(); + CallRecordImpl item = (CallRecordImpl) iter.next(); if(item.getSourceCall().equals(call)) return item; } @@ -777,11 +814,11 @@ private void handleNewCall(Call sourceCall, String direction) if(currentCallRecords.contains(sourceCall)) return; - CallRecord newRecord = new CallRecord( - sourceCall, + CallRecordImpl newRecord = new CallRecordImpl( direction, new Date(), null); + newRecord.setSourceCall(sourceCall); sourceCall.addCallChangeListener(historyCallChangeListener); @@ -862,8 +899,6 @@ void clear() } } - - /** * Used to compare CallRecords * and to be ordered in TreeSet according their timestamp @@ -873,8 +908,8 @@ private class CallRecordComparator { public int compare(Object o1, Object o2) { - return ((CallRecord)o1).getStartTime(). - compareTo(((CallRecord)o2).getStartTime()); + return ((CallRecord)o2).getStartTime(). + compareTo(((CallRecord)o1).getStartTime()); } } diff --git a/src/net/java/sip/communicator/impl/callhistory/CallParticipantRecordImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallParticipantRecordImpl.java new file mode 100644 index 000000000..3b7518897 --- /dev/null +++ b/src/net/java/sip/communicator/impl/callhistory/CallParticipantRecordImpl.java @@ -0,0 +1,54 @@ +package net.java.sip.communicator.impl.callhistory; + +import java.util.*; + +import net.java.sip.communicator.service.callhistory.*; + +/** + * Added some setters to CallParticipantRecord + * @author Damian Minkov + */ +public class CallParticipantRecordImpl + extends CallParticipantRecord +{ + /** + * Creates CallParticipantRecord + * @param participantAddress String + * @param startTime Date + * @param endTime Date + */ + public CallParticipantRecordImpl( + String participantAddress, + Date startTime, + Date endTime) + { + super(participantAddress, startTime, endTime); + } + + /** + * Sets the time the participant joined the call + * @param startTime Date + */ + public void setStartTime(Date startTime) + { + this.startTime = startTime; + } + + /** + * Sets the particiapnts address + * @param participantAddress String + */ + public void setParticipantAddress(String participantAddress) + { + this.participantAddress = participantAddress; + } + + /** + * Sets the time participant leaves the call + * @param endTime Date + */ + public void setEndTime(Date endTime) + { + this.endTime = endTime; + } +} diff --git a/src/net/java/sip/communicator/impl/callhistory/CallRecordImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallRecordImpl.java new file mode 100644 index 000000000..8723fdf26 --- /dev/null +++ b/src/net/java/sip/communicator/impl/callhistory/CallRecordImpl.java @@ -0,0 +1,93 @@ +package net.java.sip.communicator.impl.callhistory; + +import java.util.*; + +import net.java.sip.communicator.service.callhistory.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * Add Source call to the CallRecord + * @author Damian Minkov + */ +public class CallRecordImpl + extends CallRecord +{ + private Call sourceCall = null; + + /** + * Creates CallRecord + */ + public CallRecordImpl() + { + super(); + } + + /** + * Creates Call Record + * @param direction String + * @param startTime Date + * @param endTime Date + */ + public CallRecordImpl( + String direction, + Date startTime, + Date endTime) + { + super(direction, startTime, endTime); + } + + /** + * The Call source of this record + * @return Call + */ + public Call getSourceCall() + { + return sourceCall; + } + + /** + * Set the time when the call finishes + * If some participant has no end Time set we set it also + * @param endTime Date + */ + public void setEndTime(Date endTime) + { + this.endTime = endTime; + + Iterator iter = participantRecords.iterator(); + while (iter.hasNext()) + { + CallParticipantRecordImpl item = (CallParticipantRecordImpl) iter.next(); + if(item.getEndTime() == null) + item.setEndTime(endTime); + } + } + + /** + * Sets the time when the call begins + * @param startTime Date + */ + public void setStartTime(Date startTime) + { + this.startTime = startTime; + } + + /** + * The source call which this record servers + * @param sourceCall Call + */ + public void setSourceCall(Call sourceCall) + { + this.sourceCall = sourceCall; + } + + /** + * Sets the direction of the call + * IN or OUT + * @param direction String + */ + public void setDirection(String direction) + { + this.direction = direction; + } +} diff --git a/src/net/java/sip/communicator/service/callhistory/CallHistoryService.java b/src/net/java/sip/communicator/service/callhistory/CallHistoryService.java index 01153b940..a093e3245 100644 --- a/src/net/java/sip/communicator/service/callhistory/CallHistoryService.java +++ b/src/net/java/sip/communicator/service/callhistory/CallHistoryService.java @@ -23,37 +23,40 @@ public interface CallHistoryService * Returns all the calls made by all the contacts * in the supplied metacontact after the given date * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param startDate Date the start date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByStartDate(MetaContact contact, Date startDate) + public Collection findByStartDate(MetaContact contact, Date startDate) throws RuntimeException; /** * Returns all the calls made by all the contacts * in the supplied metacontact before the given date * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param endDate Date the end date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByEndDate(MetaContact contact, Date endDate) + public Collection findByEndDate(MetaContact contact, Date endDate) throws RuntimeException; /** * Returns all the calls made by all the contacts * in the supplied metacontact between the given dates * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param startDate Date the start date of the calls * @param endDate Date the end date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByPeriod(MetaContact contact, Date startDate, Date endDate) + public Collection findByPeriod(MetaContact contact, Date startDate, Date endDate) throws RuntimeException; @@ -61,20 +64,20 @@ Collection findByPeriod(MetaContact contact, Date startDate, Date endDate) * Returns all the calls made after the given date * * @param startDate Date the start date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByStartDate(Date startDate) + public Collection findByStartDate(Date startDate) throws RuntimeException; /** * Returns all the calls made before the given date * * @param endDate Date the end date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByEndDate(Date endDate) + public Collection findByEndDate(Date endDate) throws RuntimeException; /** @@ -82,22 +85,23 @@ Collection findByEndDate(Date endDate) * * @param startDate Date the start date of the calls * @param endDate Date the end date of the calls - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findByPeriod(Date startDate, Date endDate) + public Collection findByPeriod(Date startDate, Date endDate) throws RuntimeException; /** * Returns the supplied number of recent calls made by all the contacts * in the supplied metacontact * - * @param contact MetaContact + * @param contact MetaContact which contacts participate in + * the returned calls * @param count calls count - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findLast(MetaContact contact, int count) + public Collection findLast(MetaContact contact, int count) throws RuntimeException; /** @@ -105,24 +109,32 @@ Collection findLast(MetaContact contact, int count) * in the supplied metacontact * * @param count calls count - * @return Collection of CallReceivedEvent + * @return Collection of CallRecords with CallParticipantRecord * @throws RuntimeException */ - Collection findLast(int count) + public Collection findLast(int count) throws RuntimeException; + /** + * Find the calls made by the supplied participant address + * @param address String the address of the participant + * @return Collection of CallRecords with CallParticipantRecord + * @throws RuntimeException + */ + public Collection findByParticipant(String address) + throws RuntimeException; /** * Adding progress listener for monitoring progress of search process * * @param listener HistorySearchProgressListener */ - void addSearchProgressListener(CallHistorySearchProgressListener listener); + public void addSearchProgressListener(CallHistorySearchProgressListener listener); /** * Removing progress listener * * @param listener HistorySearchProgressListener */ - void removeSearchProgressListener(CallHistorySearchProgressListener listener); + public void removeSearchProgressListener(CallHistorySearchProgressListener listener); } diff --git a/src/net/java/sip/communicator/service/callhistory/CallParticipantRecord.java b/src/net/java/sip/communicator/service/callhistory/CallParticipantRecord.java index 942c92946..c2db4da12 100644 --- a/src/net/java/sip/communicator/service/callhistory/CallParticipantRecord.java +++ b/src/net/java/sip/communicator/service/callhistory/CallParticipantRecord.java @@ -11,9 +11,9 @@ */ public class CallParticipantRecord { - private String participantAddress = null; - private Date startTime = null; - private Date endTime = null; + protected String participantAddress = null; + protected Date startTime = null; + protected Date endTime = null; /** * Creates CallParticipantRecord @@ -58,31 +58,4 @@ public Date getStartTime() { return startTime; } - - /** - * Sets the time the participant joined the call - * @param startTime Date - */ - public void setStartTime(Date startTime) - { - this.startTime = startTime; - } - - /** - * Sets the particiapnts address - * @param participantAddress String - */ - public void setParticipantAddress(String participantAddress) - { - this.participantAddress = participantAddress; - } - - /** - * Sets the time participant leaves the call - * @param endTime Date - */ - public void setEndTime(Date endTime) - { - this.endTime = endTime; - } } diff --git a/src/net/java/sip/communicator/service/callhistory/CallRecord.java b/src/net/java/sip/communicator/service/callhistory/CallRecord.java index af6f069e5..4232fceac 100644 --- a/src/net/java/sip/communicator/service/callhistory/CallRecord.java +++ b/src/net/java/sip/communicator/service/callhistory/CallRecord.java @@ -2,8 +2,6 @@ import java.util.*; -import net.java.sip.communicator.service.protocol.*; - /** * Structure used for encapsulating data when writing or reading * Call History Data. Also These records are uesd for returning data @@ -19,11 +17,10 @@ public class CallRecord public final static String OUT = "out"; public final static String IN = "in"; - private Call sourceCall = null; - private String direction = null; - private Vector participantRecords = new Vector(); - private Date startTime = null; - private Date endTime = null; + protected String direction = null; + protected Vector participantRecords = new Vector(); + protected Date startTime = null; + protected Date endTime = null; /** * Creates CallRecord @@ -34,18 +31,15 @@ public CallRecord() /** * Creates Call Record - * @param sourceCall Call * @param direction String * @param startTime Date * @param endTime Date */ public CallRecord( - Call sourceCall, String direction, Date startTime, Date endTime) { - this.sourceCall = sourceCall; this.direction = direction; this.startTime = startTime; this.endTime = endTime; @@ -69,52 +63,6 @@ public CallParticipantRecord findParticipantRecord(String address) return null; } - /** - * Set the time when the call finishes - * If some participant has no end Time set we set it also - * @param endTime Date - */ - public void setEndTime(Date endTime) - { - this.endTime = endTime; - - Iterator iter = participantRecords.iterator(); - while (iter.hasNext()) - { - CallParticipantRecord item = (CallParticipantRecord) iter.next(); - if(item.getEndTime() == null) - item.setEndTime(endTime); - } - } - - /** - * Sets the time when the call begins - * @param startTime Date - */ - public void setStartTime(Date startTime) - { - this.startTime = startTime; - } - - /** - * The source call which this record servers - * @param sourceCall Call - */ - public void setSourceCall(Call sourceCall) - { - this.sourceCall = sourceCall; - } - - /** - * Sets the direction of the call - * IN or OUT - * @param direction String - */ - public void setDirection(String direction) - { - this.direction = direction; - } - /** * Returns the direction of the call * IN or OUT @@ -143,15 +91,6 @@ public Vector getParticipantRecords() return participantRecords; } - /** - * The Call source of this record - * @return Call - */ - public Call getSourceCall() - { - return sourceCall; - } - /** * The time when the call has began * @return Date