Skip to content

Commit

Permalink
Panchenko. Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyantynPanchenko committed Nov 5, 2016
1 parent 9dafd93 commit ea719d3
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 20 deletions.
10 changes: 7 additions & 3 deletions WebContent/WEB-INF/views/guides/guides.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<spring:url value="/guides/position" var="position" />
<spring:url value="/guides/available" var="available" />
<spring:url value="/guides/statistics" var="statistics" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
Expand All @@ -28,9 +29,12 @@
</c:forEach>
</table>
</c:if>
<br/><br/>
<div class="w3-third"><a href="${position}" class="w3-btn-block w3-black">Find guides by position</a></div>
<div class="w3-third w3-right"><a href="${available}" class="w3-btn-block w3-black">Find available guides</a></div>
<br/><br/>
<div class="w3-container w3-content w3-center w3-padding-32" style="max-width: 280px">
<p><a href="${position}" class="w3-btn-block w3-black">Find guides by position</a></p>
<p><a href="${available}" class="w3-btn-block w3-black">Find available guides</a></p>
<p><a href="${statistics}" class="w3-btn-block w3-black">Statistics per guide</a></p>
</div>
</div>

<!-- Footer -->
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/views/guides/guidesAvailableResults.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- Page content -->
<div class="w3-content" style="max-width: 2000px; margin-top: 46px">
<div class="w3-container w3-content w3-center w3-padding-64" style="max-width: 800px" >
<h3 class="w3-wide">Guides available</h3>
<h2 class="w3-wide">Guides available</h2>
<div class="w3-container w3-content w3-center">
<h3 class="w3-wide">from ${start}</h3>
<h3 class="w3-wide">to ${end}</h3>
Expand Down
33 changes: 33 additions & 0 deletions WebContent/WEB-INF/views/guides/guidesStatistics.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%@ page session="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<spring:url value="/guides/statistics" var="statistics"></spring:url>

<html>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<jsp:include page="../menu.jsp"></jsp:include>

<!-- Page content -->
<div class="w3-container w3-content w3-center w3-padding-64 w3-card-8" style="max-width: 800px; margin-top: 100px" >
<h2 class="w3-wide">Find statistics in time slot:</h2>
<div class="w3-container w3-content w3-center" style="max-width:280px">
<form method="POST" action="${statistics}">
<p>From: <input type="datetime-local" name="start" value="${start}" class="w3-input w3-border" required="required"/></p>
<p>To: <input type="datetime-local" name="end" value="${end}"class="w3-input w3-border" required="required"/></p>
<p><input type="submit" class="w3-btn-block w3-blue"/></p>
</form>
</div>
</div>

<!-- Footer -->
<footer
class="w3-container w3-padding-64 w3-center w3-opacity w3-light-grey w3-xlarge">
</footer>

</body>
</html>

60 changes: 60 additions & 0 deletions WebContent/WEB-INF/views/guides/guidesStatisticsResults.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<%@ page session="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<spring:url value="/guides" var="all" />
<spring:url value="/guides/position" var="pos" />
<spring:url value="/guides/available" var="available" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<jsp:include page="../menu.jsp"></jsp:include>

<!-- Page content -->
<div class="w3-content" style="max-width: 2000px; margin-top: 46px">
<div class="w3-container w3-content w3-center w3-padding-64"
style="max-width: 800px" >
<h2 class="w3-wide">Guides' statistics</h2>

<c:choose>
<c:when test="${not empty statistics}">
<table class="w3-table w3-striped w3-border w3-bordered w3-hoverable">
<thead>
<tr class="w3-light-grey"><th>Guide</th><th>Total tours</th><th>Total tours' duration</th></tr>
</thead>
<c:forEach items="${statistics}" var="current">
<tr>
<td>${current.firstName} ${current.lastName}</td>
<td>${current.totalExcursions}</td>
<td>${current.excursionsTotalDuration}</td>
</tr>
</c:forEach>
</table>
</c:when>
<c:otherwise>
<h2 class="w3-wide">not found!</h2>
<p>Try one more time</p>
</c:otherwise>
</c:choose>
<div class="w3-container w3-content w3-center w3-row" style="max-width: 260px">
<p><a href="${all}" class="w3-btn-block w3-black">Our guides</a></p>
<p><a href="${pos}" class="w3-btn-block w3-black">Find guides by position</a></p>
<p><a href="${available}" class="w3-btn-block w3-black">Find available guides</a></p>
</div>
</div>
</div>


<br />

<!-- Footer -->
<footer
class="w3-container w3-padding-64 w3-center w3-opacity w3-light-grey w3-xlarge">
</footer>

</body>
</html>

2 changes: 1 addition & 1 deletion src/com/softserve/museum/dao/impl/GuideDAOimpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public List<Guide> findByTime(LocalDateTime start, LocalDateTime end) {
public List<GuideStatisticDTO> getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end) {
StringBuilder query = new StringBuilder(
"SELECT XS.guide.firstName AS firstName, XS.guide.lastName AS lastName, COUNT(id) AS totalExcursions, "
+ "SUM(XS.details.durationsec) AS excursionsTotalDuration " + "FROM Excursion AS XS "
+ "SUM(XS.details.durationSec) AS excursionsTotalDuration " + "FROM Excursion AS XS "
+ "WHERE (XS.start >= :startDate AND XS.end <= :endDate) GROUP BY XS.guide");
System.out.println(query.toString());
Query result = sessionFactory.getCurrentSession().createQuery(query.toString());
Expand Down
2 changes: 2 additions & 0 deletions src/com/softserve/museum/service/GuideService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public interface GuideService {
public abstract List<Guide> findByTime(String start, String end);

public abstract List<GuideStatisticDTO> getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end);

public abstract List<GuideStatisticDTO> getGuidesStatisticByPeriod(String start, String end);

/* @SuppressWarnings("rawtypes")
public abstract List getCountGuidesByPeriod(LocalDateTime start, LocalDateTime end);
Expand Down
29 changes: 16 additions & 13 deletions src/com/softserve/museum/service/impl/GuideServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.softserve.museum.dao.generic.ExcursionDAO;
import com.softserve.museum.dao.generic.GuideDAO;
import com.softserve.museum.domain.Excursion;
import com.softserve.museum.domain.Guide;
import com.softserve.museum.domain.GuideStatisticDTO;
import com.softserve.museum.domain.Position;
Expand All @@ -38,9 +36,6 @@ public class GuideServiceImpl implements GuideService {
@Autowired
private GuideDAO guides;

@Autowired
private ExcursionDAO excursions;

/**
* Finds all guides.
* @return list of all guides
Expand All @@ -58,14 +53,7 @@ public List<Guide> listGuides() {
*/
@Override
public List<Guide> findByTime(LocalDateTime start, LocalDateTime end) {
List<Excursion> eList = excursions.findInPeriod(start, end);
List<Guide> gList = guides.getAll();

for (Excursion e: eList) {
gList.remove(e.getGuide());
}

return gList;
return guides.findByTime(start, end);
}


Expand Down Expand Up @@ -95,6 +83,21 @@ public List<Guide> findByTime(String start, String end) {
public List<GuideStatisticDTO> getGuidesStatisticByPeriod(LocalDateTime start, LocalDateTime end) {
return guides.getGuidesStatisticByPeriod(start, end);
}

/**
* Return statistic about all guides excursions in given time slot.
* @param start start of time slot
* @param end end of time slot
* @return list of proxy object GuideStatisticDTO
*/
@Override
public List<GuideStatisticDTO> getGuidesStatisticByPeriod(String start, String end) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime startTime = LocalDateTime.parse(start, formatter);
LocalDateTime endTime = LocalDateTime.parse(end, formatter);

return guides.getGuidesStatisticByPeriod(startTime, endTime);
}

@SuppressWarnings("rawtypes")
@Override
Expand Down
28 changes: 26 additions & 2 deletions src/com/softserve/museum/web/controller/GuidesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ModelAndView findAvailable(
@RequestParam(name="end") String end) {

ModelAndView model = new ModelAndView("guides/guidesAvailableResults");
// trim milliseconds and delimiters
// trim seconds, milliseconds and delimiters
start = start.replace('T', ' ').substring(0, (start.length() - 7));
end = end.replace('T', ' ').substring(0, (end.length() - 7));
model.addObject("start", start);
Expand Down Expand Up @@ -115,6 +115,30 @@ public ModelAndView showGuideByPosition(@PathVariable("position") String positio
model.addObject("position", position);
model.addObject("guides", guideService.findByPosition(position));
return model;
}
}

@GetMapping("/statistics")
public ModelAndView showStatisticsFindForm() {
ModelAndView model = new ModelAndView("guides/guidesStatistics");
model.addObject("start", LocalDateTime.now());
model.addObject("end", LocalDateTime.now().plusHours(2));
return model;
}

@PostMapping("/statistics")
public ModelAndView showStatisticsResults(
@RequestParam(name="start") String start,
@RequestParam(name="end") String end) {

ModelAndView model = new ModelAndView("guides/guidesStatisticsResults");
// trim seconds, milliseconds and delimiters
start = start.replace('T', ' ').substring(0, (start.length() - 7));
end = end.replace('T', ' ').substring(0, (end.length() - 7));
model.addObject("start", start);
model.addObject("end", end);
model.addObject("statistics", guideService.getGuidesStatisticByPeriod(start, end));

return model;
}

}

0 comments on commit ea719d3

Please sign in to comment.