Skip to content

Commit

Permalink
Added XML parser. Added user logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilatovM committed Dec 3, 2016
1 parent 67867f4 commit 3035997
Show file tree
Hide file tree
Showing 26 changed files with 324 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
*.iml
src/main/resources/jdbc.properties
45 changes: 21 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<name>FileAnalyser Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.8</java-version>
<spring.version>4.3.3.RELEASE</spring.version>
<org.aspectj-version>1.6.9</org.aspectj-version>
<org.slf4j-version>1.5.10</org.slf4j-version>
Expand All @@ -18,7 +19,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.3.RELEASE</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring Security-->
Expand All @@ -38,32 +44,16 @@
<version>4.1.3.RELEASE</version>
</dependency>

<!-- Spring JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>

<!-- postgresql -->
<!-- Hibernate -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>

<!--Persistence -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>

<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>

<!-- Logging -->
Expand Down Expand Up @@ -98,6 +88,13 @@
<version>1</version>
</dependency>

<!-- Javaee -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>

<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/mvcapp/DB_Utils/DAO/DB_DAO.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/mvcapp/DB_Utils/DAO/DB_PostgresImpl.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/mvcapp/DB_Utils/service/LoadService.java

This file was deleted.

19 changes: 16 additions & 3 deletions src/main/java/mvcapp/controllers/HomeMenuController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package mvcapp.controllers;

import mvcapp.dbutils.service.DBService;
import mvcapp.entities.Requirement;
import mvcapp.parser.service.FileService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;

@Controller
public class HomeMenuController {
@RequestMapping(value = "/search", method = RequestMethod.GET)
public String search() {
return "search";
}

@RequestMapping(value = "/load", method = RequestMethod.GET)
public String load() {
return "load";
}

@RequestMapping(value = "/search", method = RequestMethod.GET)
public String search() {
return "search";
@RequestMapping(value = "/load-file", method = RequestMethod.GET)
public String loadFile(String path) throws Exception {


return "load-completed";
}


}
22 changes: 21 additions & 1 deletion src/main/java/mvcapp/controllers/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package mvcapp.controllers;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LoginController {
@RequestMapping(value = {"/", "/login", "/loginfailed", "/logout"}, method = RequestMethod.GET)
@RequestMapping(value = {"/", "/login"}, method = RequestMethod.GET)
public String login() {
return "login";
}

@RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
public String loginFailed() {
return "login-failed";
}

@RequestMapping(value="/logout", method = RequestMethod.GET)
public String logoutPage (HttpServletRequest request, HttpServletResponse response) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null){
new SecurityContextLogoutHandler().logout(request, response, auth);
}
return "login";
}

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home() {
return "home";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/mvcapp/dbutils/dbconnection/DataBaseDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package mvcapp.dbutils.dbconnection;

import mvcapp.entities.Requirement;

import java.sql.SQLException;
import java.util.List;

public interface DataBaseDAO {
public void loadReqs(List<Requirement> reqs) throws SQLException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package mvcapp.dbutils.dbconnection;

import java.sql.SQLException;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import mvcapp.entities.Requirement;

import java.util.List;

@Component
public class DataBasePostgresImpl implements DataBaseDAO {
@Autowired
private SessionFactory sessionFactory;

@Transactional
public void loadReqs(List<Requirement> reqs) throws SQLException{
for (Requirement req: reqs) {
sessionFactory.getCurrentSession().save(req);
}

}

}
22 changes: 22 additions & 0 deletions src/main/java/mvcapp/dbutils/service/DBService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mvcapp.dbutils.service;

import java.sql.SQLException;
import java.util.List;

import mvcapp.dbutils.dbconnection.DataBaseDAO;
import mvcapp.entities.Requirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DBService {
@Autowired
private DataBaseDAO dataBase_dao;

@Transactional
public void loadReqs(List<Requirement> reqs) throws SQLException{
dataBase_dao.loadReqs(reqs);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package mvcapp.Entities;
package mvcapp.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "Requirements")
@Table(name = "requirements")
public class Requirement {
@Id
@Column(name = "id")
@GeneratedValue
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@Column(name = "title")
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mvcapp/parser/fileconnection/FileDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package mvcapp.parser.fileconnection;

import mvcapp.entities.Requirement;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

public interface FileDAO {
public List<Requirement> parseReqs(String path) throws ParserConfigurationException, IOException, SAXException, ParseException;
}
59 changes: 59 additions & 0 deletions src/main/java/mvcapp/parser/fileconnection/XmlImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package mvcapp.parser.fileconnection;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import mvcapp.entities.Requirement;
import org.xml.sax.SAXException;

public class XmlImpl implements FileDAO {
@Override
public List<Requirement> parseReqs(String path) throws ParserConfigurationException, IOException, SAXException, ParseException {
File xmlFile = new File(path);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(xmlFile);
document.getDocumentElement().normalize();

NodeList nodeList = document.getElementsByTagName(document.getDocumentElement().getChildNodes().item(1).getNodeName());

List<Requirement> reqs = new ArrayList<>();
for(int tmp = 0; tmp < nodeList.getLength(); tmp++)
{
Node node = nodeList.item(tmp);
if(node.getNodeType() == Node.ELEMENT_NODE)
{
Requirement req = new Requirement();

Element element = (Element)node;
req.setId(Integer.valueOf(element.getElementsByTagName("id").item(0).getChildNodes().item(0).getNodeValue()));
req.setTitle(element.getElementsByTagName("title").item(0).getChildNodes().item(0).getNodeValue());
req.setText(element.getElementsByTagName("text").item(0).getChildNodes().item(0).getNodeValue());
req.setComment(element.getElementsByTagName("comment").item(0).getChildNodes().item(0).getNodeValue());
String done = element.getElementsByTagName("done").item(0).getChildNodes().item(0).getNodeValue();
req.setDone(done.equals("yes"));
String dateStr = (element.getElementsByTagName("date").item(0).getChildNodes().item(0).getNodeValue());
SimpleDateFormat format = new SimpleDateFormat("dd.mm.yyyy");
Date date = format.parse(dateStr);
req.setDate(date);

reqs.add(req);
}
}
return reqs;
}
}
24 changes: 24 additions & 0 deletions src/main/java/mvcapp/parser/service/FileService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mvcapp.parser.service;

import mvcapp.entities.Requirement;
import mvcapp.parser.fileconnection.FileDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@Service
public class FileService {
@Autowired
private FileDAO fileDAO;

@Transactional
public List<Requirement> parseReqs(String path) throws ParserConfigurationException, SAXException, ParseException, IOException {
return fileDAO.parseReqs(path);
}
}
Loading

0 comments on commit 3035997

Please sign in to comment.