Author: DavidK Date: 2010-02-10 00:57:06 +0100 (Wed, 10 Feb 2010) New Revision: 1693 Modified: trunk/server/dispatcher/JavaSource/com/elvys/properties/PropertyManager.java trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/FilecacheConfigWorkerImpl.java trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBL.java trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLImpl.java trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java Log: filecacheConfig upgraded - newly, it looks ahead.. Modified: trunk/server/dispatcher/JavaSource/com/elvys/properties/PropertyManager.java =================================================================== --- trunk/server/dispatcher/JavaSource/com/elvys/properties/PropertyManager.java 2010-02-09 23:42:42 UTC (rev 1692) +++ trunk/server/dispatcher/JavaSource/com/elvys/properties/PropertyManager.java 2010-02-09 23:57:06 UTC (rev 1693) @@ -5,9 +5,6 @@ import java.net.URL; import java.util.Properties; -import javax.servlet.http.HttpServlet; - - public class PropertyManager { private static Properties prop = null; private static final String CONF_PROPERTY_FILE = "/conf.properties"; @@ -50,4 +47,16 @@ String value = prop.getProperty("dispatcherDocumentsContextUrl"); return value; } + + + + /** + * Gets filecacheConfig value of view in the future (in minutes) + * @return + */ + public static Integer getFilecacheConfigViewInMinutes() { + Integer value = 1440; + return value; + } + } Modified: trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/FilecacheConfigWorkerImpl.java =================================================================== --- trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/FilecacheConfigWorkerImpl.java 2010-02-09 23:42:42 UTC (rev 1692) +++ trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/FilecacheConfigWorkerImpl.java 2010-02-09 23:57:06 UTC (rev 1693) @@ -1,9 +1,14 @@ package cz.elvys.dispatcher.impl; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.xml.XMLConstants; import javax.xml.transform.stream.StreamSource; @@ -14,6 +19,7 @@ import org.hibernate.Transaction; import org.xml.sax.SAXException; +import com.elvys.properties.PropertyManager; import com.sun.xml.bind.marshaller.NamespacePrefixMapper; import cz.elvys.commons.def.Constants; @@ -28,6 +34,7 @@ import cz.elvys.webServer.HIBgen.Timeline; import cz.elvys.webServer.HIBgen.VideoContent; import cz.elvys.webServer.db.InitSessionFactory; +import cz.elvys.webServer.toSpring.exception.ExecuteException; import elvys.server.bl.Fact; import elvys.server.bl.categrel.CategoryBL; import elvys.server.bl.elvysrel.ElvysBL; @@ -71,38 +78,10 @@ } Integer groupId = elvys.getElvysGroup().getId(); - // get Categories assigned to that ElvysGroup - List<cz.elvys.webServer.HIBgen.Category> categories = cbl.listCategoriesForGroup(groupId, sess); + // list of files to be displayed for the next XY minutes + List<File> files = getFilesLookAhead(groupId, sess); - // list of actually displayed files - List<File> files = new ArrayList<File>(); - - // iterate through categories - for (cz.elvys.webServer.HIBgen.Category cat: categories) { - List<Map<Integer, Timeline>> categoryTimelines = pbl.getActualPlanningForCategory( - cat.getCategoryPlanning().getId(), sess); - // iterate through layout positions - for(Map<Integer, Timeline> posTimelines: categoryTimelines) { - Collection<Timeline> tls = posTimelines.values(); - for(Timeline tl: tls) { - String type = tl.getFrameContent().getContentType().getType(); - // TODO tohle oddelat! udelat spolecneho predka FrameContentWithFile.. - - if (type.equals("video")) { - VideoContent vc = (VideoContent) tl.getFrameContent(); - File file = vc.getVideo(); - files.add(file); - continue; - } else if (type.equals("document")) { - DocumentContent dc = (DocumentContent) tl.getFrameContent(); - File file = dc.getDocument(); - files.add(file); - continue; - } - } - } - } - + // fill data FileCacheConfig fcConfig = of.createFileCacheConfig(); { // elvysId @@ -136,6 +115,75 @@ return generatedXML; } + + /** + * returns planned files for the given company + * @param groupId + * @param sess + * @return + * @throws ExecuteException + */ + private List<File> getFilesLookAhead(Integer groupId, Session sess) throws ExecuteException { + List<File> files = new ArrayList<File>(); + + // get Categories assigned to that ElvysGroup + List<cz.elvys.webServer.HIBgen.Category> categories = cbl.listCategoriesForGroup(groupId, sess); + + // prepare time window for getting files + Integer viewInMinutes = PropertyManager.getFilecacheConfigViewInMinutes(); + Date timeWindowFrom = new Date(); + Calendar calendar = new GregorianCalendar(); + calendar.setTime(timeWindowFrom); + calendar.add(Calendar.MINUTE, viewInMinutes); + Date timeWindowTo = calendar.getTime(); + + // iterate through categories + for (cz.elvys.webServer.HIBgen.Category cat: categories) { + + List<Map<Integer, List<Timeline>>> categoryTimelines = + pbl.getTimelinesForCategory(timeWindowFrom, timeWindowTo, + cat.getCategoryPlanning().getId(), sess); + // iterate through layout positions + for(Map<Integer, List<Timeline>> posTimelines: categoryTimelines) { + Collection<List<Timeline>> panelInstancesOfPosition = posTimelines.values(); + for(List<Timeline> timelines: panelInstancesOfPosition) { + for(Timeline tl: timelines) { + String type = tl.getFrameContent().getContentType().getType(); + // TODO tohle oddelat! udelat spolecneho predka FrameContentWithFile.. + + if (type.equals("video")) { + VideoContent vc = (VideoContent) tl.getFrameContent(); + File file = vc.getVideo(); + files.add(file); + continue; + } else if (type.equals("document")) { + DocumentContent dc = (DocumentContent) tl.getFrameContent(); + File file = dc.getDocument(); + files.add(file); + continue; + } + } + } + } + } + List<File> uniqListOfFiles = new ArrayList<File>(); + Set<Integer> idSet = new HashSet<Integer>(); + for (File file: files) { + if (idSet.contains(file.getId())) { + // file has already been added to the uniqListOfFiles + // do nothing + } else { + // hasn't been processed yet + // add it to the result + uniqListOfFiles.add(file); + idSet.add(file.getId()); + } + } + + return uniqListOfFiles; + } + + @Override protected String getSchemaPath() { return FILECACHE_CONFIG_XSD_PATH; Modified: trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBL.java =================================================================== --- trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBL.java 2010-02-09 23:42:42 UTC (rev 1692) +++ trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBL.java 2010-02-09 23:57:06 UTC (rev 1693) @@ -138,7 +138,22 @@ public List<Map<Integer,Timeline>> getActualPlanningForCategory(Integer catPlanningId, Session sess) throws ExecuteException; + /** + * Returns plannings for chosen category that cross(or are inside) + * time boundaries <br/> + * Fetches type-specific frame_content + * @param from the beginning of the time period + * @param to the end of the time period + * @param catPlanningId id of category planning + * @return list {@link PlanningBL#getActualPlanningForCategoryMakeSession(Integer)} + * @throws ExecuteException + */ + public List<Map<Integer,List<Timeline>>> getTimelinesForCategoryMakeSession(Date from, Date to, Integer catPlanningId) throws ExecuteException; + /** + * @see PlanningBL#getTimelinesForCategory(Date, Date, Integer) + */ + public List<Map<Integer,List<Timeline>>> getTimelinesForCategory(Date from, Date to, Integer catPlanningId, Session sess) throws ExecuteException; /** * loads list of permitted content type for one position @@ -146,4 +161,5 @@ * @param lineId id of the position */ public List<ContentType> loadPermittedTypesForThisPosition(int layoutID, int position) throws Exception; + } Modified: trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLImpl.java =================================================================== --- trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLImpl.java 2010-02-09 23:42:42 UTC (rev 1692) +++ trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLImpl.java 2010-02-09 23:57:06 UTC (rev 1693) @@ -36,7 +36,6 @@ private static final String ERROR_OVERLAYING_PLANNING = "Overlaying planning found"; private static final String UNABLE_TO_LOAD_TYPES = "Unable to load permitted content types. "; private static final String CANNOT_GET_RID_OF_TIMELINES = "Couldn't get rid of Timelines. "; - private static final String CANNOT_DELETE_PROPERLY = "Couldn't properly delete timelines.."; private static final String CANNOT_LIST_FUTURE_TIMELINES = "Couldn't list future timelines!"; private static final String CANNOT_REPLICATE_TIMELINE = "Couldn't replicate timeline."; @@ -448,18 +447,67 @@ return result; } + @Override + public List<Map<Integer, List<Timeline>>> getTimelinesForCategoryMakeSession( + Date from, Date to, Integer catPlanningId) throws ExecuteException { + Session sess = InitSessionFactory.getInstance().getCurrentSession(); + Transaction tx = HibUtils.startTx(sess); + List<Map<Integer,List<Timeline>>> timelines = null; + try { + timelines = getTimelinesForCategory(from, to, catPlanningId, sess); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + throw new ExecuteException(e); + } + return timelines; + } + - - - - - - - - - - + @Override + public List<Map<Integer, List<Timeline>>> getTimelinesForCategory(Date from, + Date to, Integer catPlanningId, Session sess) + throws ExecuteException { + List<Map<Integer,List<Timeline>>> result = null; + try { + // actual timelines of selected panel + List<Timeline> timelines = getTimelinesGeneric( + from, to, catPlanningId, null, null, sess); + + // layout position count + Layout layout = lbl.getLayoutByCategoryPlanningId(catPlanningId, sess); + Integer layoutPosCount = layout.getSectCount(); + + result = new ArrayList<Map<Integer,List<Timeline>>>(); + for (int i=0; i<layoutPosCount; i++) { + result.add(new HashMap<Integer,List<Timeline>>()); + } + + // create list of position records + for (Timeline tl : timelines) { + int posIndex = tl.getLayoutPos(); + int panIndex = tl.getPanel().getId().getOrderNum(); + Map<Integer,List<Timeline>> positionMapOfPanels = result.get(posIndex-1); + if (positionMapOfPanels.get(panIndex) == null) { + // first timeline on the panel and the position + positionMapOfPanels.put(panIndex, new ArrayList<Timeline>()); + positionMapOfPanels.get(panIndex).add(tl); + } else { + // some timelines for panel, position exists, just add + positionMapOfPanels.get(panIndex).add(tl); + } + } + } catch (Exception e) { + String message = CommonUtils.prepareErrorMessage( + CANT_LOAD_PLANNING_LIST, "catPlanningId", catPlanningId, + "panelOrd", null); + throw new ExecuteException(message,e); + } + return result; + } + + /** * Generic method for getting list of timelines. <br/> * tip1: scheduleFrom == scheduleTo - get actual planning <br/> Modified: trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java =================================================================== --- trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java 2010-02-09 23:42:42 UTC (rev 1692) +++ trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java 2010-02-09 23:57:06 UTC (rev 1693) @@ -1,5 +1,8 @@ package elvys.server.bl.planning; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -200,6 +203,56 @@ } @Test + public void testGetPlanningForCategory() throws Exception { + // count of existing timelines inside time window + int found = 0; + + Date start = new Date(); + Calendar cal = new GregorianCalendar(); + cal.setTime(start); + cal.add(Calendar.MINUTE, 24*60); + Date end = cal.getTime(); + + + // get list of groups + List<ElvysGroup> groups = ebl.listGroupByCompany(companyId); + for (ElvysGroup group: groups) { + Integer groupId = group.getId(); + + // categories + List<Category> categories = cbl.listCategoriesForGroupMakeSession(groupId); + for (Category cat: categories) { + Integer planningId = cat.getCategoryPlanning().getId(); + Layout layout = lbl.getActiveLayoutByIdMakeSess(cat.getCategoryDefinition().getLayout().getId()); + int sectCount = layout.getSectCount(); + + // category's plannings + List<Map<Integer, List<Timeline>>> categoryTimelines = pbl.getTimelinesForCategoryMakeSession( + start, end, planningId); + assertTrue(categoryTimelines.size() == sectCount); + + // iterate through positions + for (int posIndex=0; posIndex < categoryTimelines.size(); posIndex++) { + Map<Integer, List<Timeline>> posMap = categoryTimelines.get(posIndex); + Set<Integer> panIndices = posMap.keySet(); + // iterate through panels + for (Integer panIndex: panIndices) { + List<Timeline> listTl = posMap.get(panIndex); + for (Timeline tl: listTl) { + assertTrue(tl.getShowStart()!=null); + } + found++; + } + } + } + } + assertTrue(found >0); + + + + } + + @Test public void loadPermittedTypesTest() throws Exception { // number of permitted ContentType assignment int found = 0;