-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added XML parser. Added user logout.
- Loading branch information
Showing
26 changed files
with
324 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
*.iml | ||
src/main/resources/jdbc.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/mvcapp/dbutils/dbconnection/DataBaseDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/mvcapp/dbutils/dbconnection/DataBasePostgresImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
12 changes: 4 additions & 8 deletions
12
...ain/java/mvcapp/Entities/Requirement.java → ...ain/java/mvcapp/entities/Requirement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.