Author: JirkaM Date: 2010-02-16 16:41:02 +0100 (Tue, 16 Feb 2010) New Revision: 1742 Modified: trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/StatisticWorkerImpl.java trunk/server/dispatcher/JavaSource/cz/elvys/xsd/stats-data.xsd Log: * add action for elvys restart modified JavaSource/cz/elvys/dispatcher/impl/StatisticWorkerImpl.java modified JavaSource/cz/elvys/xsd/stats-data.xsd Modified: trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/StatisticWorkerImpl.java =================================================================== --- trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/StatisticWorkerImpl.java 2010-02-16 12:10:31 UTC (rev 1741) +++ trunk/server/dispatcher/JavaSource/cz/elvys/dispatcher/impl/StatisticWorkerImpl.java 2010-02-16 15:41:02 UTC (rev 1742) @@ -82,15 +82,50 @@ log.error("Error while parsing xml:" + str); throw new SAXException(message, e); } + + Session sess = InitSessionFactory.getInstance().getCurrentSession(); + Transaction tx = HibUtils.startTx(sess); + + // at first, try to detect elvys down timestamp + Timestamp elvysDown = parser.getElvysDown(); + + if(elvysDown != null){ + // we have time of elvys down, make ending + + // delete all events with non-ending download + String deleteHql = "DELETE FROM Statistics WHERE action_end IS NULL AND elvys =:elvysId AND action_type = 'download' "; + Query query = sess.createQuery(deleteHql); + query.setInteger("elvysId", elvysID); + try { + query.executeUpdate(); + } catch (Exception e) { + String message = "Downloaded action with non-ending time were not deleted after elvys down."; + log.error(message); + } + + // set new end for exhibit + String updateHql = "UPDATE Statistics SET action_end = :newActionEnd WHERE action_end IS NULL AND elvys =:elvysId AND action_type = 'exhibit' "; + Query updateQuery = sess.createQuery(updateHql); + updateQuery.setDate("newActionEnd", elvysDown); + updateQuery.setInteger("elvysId", elvysID); + + try { + updateQuery.executeUpdate(); + } catch (Exception e) { + String message = "Exhibit actions without ending time were not update."; + log.error(message); + } + + } + + // update old data: // - get from input xml data with action_type = 'exhibit' and // action_start = 0 // - update data in db - select by document id, elvys id, layout id, - // action_end = 0, position + // action_end = 0, position - List<Statistics> statsUpdate = parser.getStatsForUpdate(); - Session sess = InitSessionFactory.getInstance().getCurrentSession(); - Transaction tx = HibUtils.startTx(sess); + List<Statistics> statsUpdate = parser.getStatsForUpdate(); try { for (Statistics stat : statsUpdate) { @@ -140,8 +175,7 @@ } } catch (Exception e) { - String message = CommonUtils.prepareErrorMessage( - "Error while inserting new statistics data."); + String message = "Error while inserting new statistics data."; log.error(message); } @@ -185,6 +219,8 @@ private Integer tempPosition; private CategoryDefinition tempCategory; private Integer tempPanelOrder; + + private Timestamp elvysDown; private boolean isStatsForUpdate; @@ -194,6 +230,10 @@ } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (qName.equals("elvys_down")) { + + } + if (qName.equals("elvys_event")) { } @@ -230,6 +270,14 @@ } public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equals("elvys_down")) { + this.elvysDown = new Timestamp((Long.parseLong(this.tempValue)) * 1000); + if (this.tempValue.equals("0")) { + this.elvysDown = null; + } + } + + // save bean to db if (qName.equals("elvys_event")) { this.tempStats = new Statistics(); @@ -356,5 +404,10 @@ public void setStatsForUpdate(List<Statistics> statsForUpdate) { this.statsForUpdate = statsForUpdate; } + + public Timestamp getElvysDown() { + return elvysDown; + } + } } Modified: trunk/server/dispatcher/JavaSource/cz/elvys/xsd/stats-data.xsd =================================================================== --- trunk/server/dispatcher/JavaSource/cz/elvys/xsd/stats-data.xsd 2010-02-16 12:10:31 UTC (rev 1741) +++ trunk/server/dispatcher/JavaSource/cz/elvys/xsd/stats-data.xsd 2010-02-16 15:41:02 UTC (rev 1742) @@ -4,6 +4,7 @@ <xs:complexType> <xs:sequence> <xs:element ref="elvys_event" /> + <xs:element name="elvys_down" type="xs:int"></xs:element> </xs:sequence> </xs:complexType> </xs:element>