diff options
author | Henri Herscher <henri@oreka.org> | 2005-10-20 13:46:56 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-10-20 13:46:56 +0000 |
commit | 25c5446b5e0ab6d534203097b351699b1a769c6a (patch) | |
tree | 460bce79c944aa65151a358df5bd3c26af35513c /orkweb/src/net/sf/oreka/services | |
parent | 7e1d63dd9fd149e4934bf77095c8610fac786b04 (diff) |
first checkin
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@3 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkweb/src/net/sf/oreka/services')
7 files changed, 695 insertions, 0 deletions
diff --git a/orkweb/src/net/sf/oreka/services/FormFilter.java b/orkweb/src/net/sf/oreka/services/FormFilter.java new file mode 100644 index 0000000..94723d3 --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/FormFilter.java @@ -0,0 +1,39 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +public abstract class FormFilter { + + boolean isValid = true; + + /** + * @return Returns the isValid. + */ + public boolean isValid() { + return isValid; + } + + + /** + * @param isValid The isValid to set. + */ + public void setValid(boolean isValid) { + this.isValid = isValid; + } + + +} diff --git a/orkweb/src/net/sf/oreka/services/RecSegmentFilter.java b/orkweb/src/net/sf/oreka/services/RecSegmentFilter.java new file mode 100644 index 0000000..20b12ef --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/RecSegmentFilter.java @@ -0,0 +1,274 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +import java.util.Date; + +import net.sf.oreka.Direction; +import net.sf.oreka.orkweb.ContextListener; + +import org.apache.log4j.Logger; + +public class RecSegmentFilter extends FormFilter { + + static Logger logger = Logger.getLogger(RecSegmentFilter.class); + + private String minDuration = ""; + private String minDurationError; + private String maxDuration = ""; + private String maxDurationError; + private String localParty = ""; + private String localPartyError; + private String remoteParty = ""; + private String remotePartyError; + private Date startDate = null; + private Date endDate = null; + private Direction direction; + + private final String UNALLOWED_CHARACTER = "Unallowed character"; + private final String ENTER_A_NUMBER = "Enter a number"; + + private boolean isStringInvalidParty(String party) { + // See if there are any characters not listed here + return (party.matches(".*[^A-Za-z0-9#\\*@].*")); + } + + public String getErrorStyle(){ + return "error"; + } + public String getOkStyle(){ + return ""; + } + + /** + * @return Returns the durationError. + */ + public String getMinDurationError() { + return minDurationError; + } + + + + /** + * @param durationError The durationError to set. + */ + public void setMinDurationError(String durationError) { + this.minDurationError = durationError; + } + + + + /** + * @return Returns the localPartyError. + */ + public String getLocalPartyError() { + return localPartyError; + } + + + + /** + * @param localPartyError The localPartyError to set. + */ + public void setLocalPartyError(String localPartyError) { + this.localPartyError = localPartyError; + } + + + + /** + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + + if(localParty == null) { + this.localParty = ""; + } + else { + localParty.trim(); + this.localParty = localParty; + } + if (isStringInvalidParty(this.localParty)) { + setLocalPartyError(UNALLOWED_CHARACTER); + } + else { + setLocalPartyError(null); + } + } + + + public RecSegmentFilter() { + + minDuration = new String(); + localParty = new String(); + direction = Direction.ALL; + + long millisIn24hours = 24 * 3600 * 1000; + endDate = new Date(); + + // For now, retrieve 24 hours worth of records by default + if (ContextListener.debugSwitch == false) { + startDate = new Date(endDate.getTime() - millisIn24hours); + } + else { + startDate = new Date(0); + } + + /* + // Read properties file. + Properties properties = new Properties(); + try { + properties.load(new FileInputStream("RecSegmentFilter.properties")); + } catch (IOException e) { + System.out.println("@@@@@@@@@@"); + } + */ + + } + + + /** + * @return Returns the duration. + */ + public String getMinDuration() { + return minDuration; + } + + + + /** + * @param minDuration The duration to set. + */ + public void setMinDuration(String minDuration) { + + if(minDuration == null) { + this.minDuration = ""; + } + else { + minDuration.trim(); + this.minDuration = minDuration; + } + if (this.minDuration.matches(".*[^0-9].*")) { + // there is a funny character here ... + setMinDurationError(ENTER_A_NUMBER); + } + else { + setMinDurationError(null); + } + } + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public String getRemoteParty() { + return remoteParty; + } + + + public void setRemoteParty(String remoteParty) { + if(remoteParty == null) { + this.remoteParty = ""; + } + else { + remoteParty.trim(); + this.remoteParty = remoteParty; + } + if (isStringInvalidParty(this.remoteParty)) { + setRemotePartyError(UNALLOWED_CHARACTER); + } + else { + setRemotePartyError(null); + } + } + + + public String getRemotePartyError() { + return remotePartyError; + } + + + public void setRemotePartyError(String remotePartyError) { + this.remotePartyError = remotePartyError; + } + + public Direction getDirection() { + return direction; + } + + + public void setDirection(Direction direction) { + this.direction = direction; + } + + public String getMaxDuration() { + return maxDuration; + } + + + public void setMaxDuration(String maxDuration) { + if(maxDuration == null) { + this.maxDuration = ""; + } + else { + maxDuration.trim(); + this.maxDuration = maxDuration; + } + if (this.maxDuration.matches(".*[^0-9].*")) { + // there is a funny character here ... + setMaxDurationError(ENTER_A_NUMBER); + } + else { + setMaxDurationError(null); + } + } + + + public String getMaxDurationError() { + return maxDurationError; + } + + + public void setMaxDurationError(String maxDurationError) { + this.maxDurationError = maxDurationError; + } + + + + + + +} diff --git a/orkweb/src/net/sf/oreka/services/RecSegmentFilter.properties b/orkweb/src/net/sf/oreka/services/RecSegmentFilter.properties new file mode 100644 index 0000000..a6e5ec3 --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/RecSegmentFilter.properties @@ -0,0 +1,2 @@ +duration=0 +localParty=8948
\ No newline at end of file diff --git a/orkweb/src/net/sf/oreka/services/RecSegmentResult.java b/orkweb/src/net/sf/oreka/services/RecSegmentResult.java new file mode 100644 index 0000000..fd43ad5 --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/RecSegmentResult.java @@ -0,0 +1,83 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +import net.sf.oreka.persistent.*; + + +public class RecSegmentResult { + + private RecSegment RecSegment; + private RecTape RecTape; + + private String foo = "henri"; + + public RecSegmentResult() { + RecSegment = new RecSegment(); + RecTape = new RecTape(); + } + + /** + * @return Returns the recSegment. + */ + public RecSegment getRecSegment() { + return RecSegment; + } + + + /** + * @param recSegment The recSegment to set. + */ + public void setRecSegment(RecSegment recSegment) { + RecSegment = recSegment; + } + + /** + * @return Returns the recTape. + */ + public RecTape getRecTape() { + return RecTape; + } + + + /** + * @param recTape The recTape to set. + */ + public void setRecTape(RecTape recTape) { + RecTape = recTape; + } + + /** + * @return Returns the foo. + */ + public String getFoo() { + return foo; + } + + + /** + * @param foo The foo to set. + */ + public void setFoo(String foo) { + this.foo = foo; + } + + + + + +} diff --git a/orkweb/src/net/sf/oreka/services/RecSegmentService.java b/orkweb/src/net/sf/oreka/services/RecSegmentService.java new file mode 100644 index 0000000..cdaa6fc --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/RecSegmentService.java @@ -0,0 +1,25 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +import java.util.*; + + +public interface RecSegmentService { + + public int getResults(RecSegmentFilter filter, int offset, int number, String orderBy, boolean ascending, List results); +} diff --git a/orkweb/src/net/sf/oreka/services/RecSegmentServiceHbn.java b/orkweb/src/net/sf/oreka/services/RecSegmentServiceHbn.java new file mode 100644 index 0000000..26a3746 --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/RecSegmentServiceHbn.java @@ -0,0 +1,206 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +import java.text.SimpleDateFormat; +import java.util.List; + +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.persistent.RecSegment; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.hibernate.HibernateException; +import org.hibernate.Query; +import org.hibernate.ScrollableResults; +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class RecSegmentServiceHbn implements RecSegmentService{ + + private boolean firstCriterium = true; + + static Logger logger = Logger.getLogger(RecSegmentServiceHbn.class); + /** + * + */ + public RecSegmentServiceHbn() { + + } + +// private void addCriteriumPrefix (StringBuffer query) { +// if(firstCriterium){ +// query.append(" where "); +// firstCriterium = false; +// } +// else { +// query.append(" and "); +// } +// } + + public int getResults(RecSegmentFilter filter, int offset, int number, String orderBy, boolean ascending, List results) + { + firstCriterium = true; + int numResults = 0; + logger.log(Level.DEBUG, "Entering getResults"); + //logger.log(Level.INFO, System.getProperty("java.class.path")); + + //RecSegment seg1 = new RecSegment(); + //RecSegment seg2 = new RecSegment(); + + //RecTape tape1 = new RecTape(); + //RecTape tape2 = new RecTape(); + /* + RecSegmentResult result1 = new RecSegmentResult(); + RecSegmentResult result2 = new RecSegmentResult(); + + result1.getRecSegment().setDuration(10); + result1.getRecSegment().setLocalParty("01223"); + results.add(result1); + result2.getRecSegment().setDuration(11); + result2.getRecSegment().setLocalParty("01440"); + results.add(result2); +*/ + /* + for (int i=0; i<number; i++) + { + RecSegmentResult result = new RecSegmentResult(); + result.getRecSegment().setDuration(offset + i); + result.getRecSegment().setLocalParty(orderBy); + result.getRecTape().setId(ascending ? 0:1); + results.add(result); + } + numResults = 502; + */ + + Transaction tx = null; + Session session = null; + try + { + session = HibernateManager.getSession(); + + StringBuffer queryString = new StringBuffer("from RecSegment as seg left join seg.recTape as tape left join tape.service as srv "); + //StringBuffer queryString = new StringBuffer("from RecSegment as seg "); + + //boolean firstCriterium = false; + + queryString.append(" where seg.timestamp between :startDate and :endDate "); + + if(filter.getLocalParty().length() > 0) { + queryString.append(" and seg.localParty=:localParty "); + } + if(filter.getRemoteParty().length() > 0) { + queryString.append(" and seg.remoteParty=:remoteParty "); + } + if(filter.getMinDuration().length() > 0) { + queryString.append(" and seg.duration>:minDuration "); + } + if(filter.getMaxDuration().length() > 0) { + queryString.append(" and seg.duration<:maxDuration "); + } + if(filter.getDirection() != Direction.ALL){ + queryString.append(" and seg.direction=:direction "); + } + + if(orderBy.length() == 0) { + orderBy = "seg.timestamp"; + } + queryString.append(" order by "); + queryString.append(orderBy); + if (ascending) { + queryString.append(" asc"); + } + else { + queryString.append(" desc"); + } + + Query query = session.createQuery(queryString.toString()); + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + logger.debug("Filter start date:" + dateFormat.format(filter.getStartDate())); + query.setTimestamp("startDate", filter.getStartDate()); + logger.debug("Filter end date:" + dateFormat.format(filter.getEndDate())); + query.setTimestamp("endDate", filter.getEndDate()); + + + if(filter.getLocalParty().length() > 0) { + query.setString("localParty", filter.getLocalParty()); + } + if(filter.getRemoteParty().length() > 0) { + query.setString("remoteParty", filter.getRemoteParty()); + } + if(filter.getMinDuration().length() > 0) { + query.setString("minDuration", filter.getMinDuration()); + } + if(filter.getMaxDuration().length() > 0) { + query.setString("maxDuration", filter.getMaxDuration()); + } + if(filter.getDirection() != Direction.ALL){ + query.setParameter( "direction", filter.getDirection().ordinal() ); + //query.setParameter( "direction", filter.getDirection().name() ); + } + +// Criteria crit = session.createCriteria(RecSegment.class); +// //crit.setFetchMode("RecTape",FetchMode.EAGER); +// crit.setFetchMode(null, FetchMode.LAZY); + + ScrollableResults scrollDocs = query.scroll(); + + + if ( scrollDocs.last() ) { + numResults = scrollDocs.getRowNumber()+1; + logger.debug("Num res:" + numResults); + } + + //scrollDocs.beforeFirst(); + scrollDocs.setRowNumber(offset); + int rowsSoFar = 0; + + while (scrollDocs.get()!= null && rowsSoFar<number) + { + rowsSoFar++; + RecSegment seg = (RecSegment)scrollDocs.get(0); + + //logger.log(Level.ERROR, seg.getRecTape().getUrl()); + + //RecTape tape = (RecTape)scrollDocs.get(1); + //RecTape tape = new RecTape(); + RecSegmentResult res = new RecSegmentResult(); + res.setRecSegment(seg); + //res.setRecTape(tape); + results.add(res); + scrollDocs.next(); + } + } + catch ( HibernateException he ) { + if ( tx != null ) tx.rollback(); + logger.log(Level.ERROR, he.toString()); + he.printStackTrace(); + } + catch (Exception e) + { + logger.error(e); + e.printStackTrace(); + } + finally { + session.close(); + } + return numResults; + } + +} diff --git a/orkweb/src/net/sf/oreka/services/Startup.java b/orkweb/src/net/sf/oreka/services/Startup.java new file mode 100644 index 0000000..337734f --- /dev/null +++ b/orkweb/src/net/sf/oreka/services/Startup.java @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.services; + +import java.util.*; +import java.io.*; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +public class Startup { + + static Logger logger = Logger.getLogger(Startup.class); + + public Startup() { + + logger.log(Level.WARN, "Initializing orkweb"); + + InputStream is = this.getClass().getClassLoader().getResourceAsStream("log4j.properties"); + if (is != null) + { + Properties properties = new Properties(); + try + { + properties.load(is); + PropertyConfigurator.configure(properties); + } + catch (IOException e) + { + logger.log(Level.INFO, "log4j.properties not found"); + } + } + + //PropertyConfigurator.configure("log4j.properties"); + + /* + //InputStream s = ClassLoader.getSystemResourceAsStream("toto.txt"); + InputStream s = this.getClass().getClassLoader().getResourceAsStream("toto.txt"); + if (s != null) + { + logger.log(Level.INFO, "~~~~~~~~ yes"); + } + else + { + logger.log(Level.INFO, "~~~~~~~~ no"); + } + */ + + + } + +} |