diff --git a/pom.xml b/pom.xml index fb7e8c6..4f4589a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,108 +1,112 @@ 4.0.0 org.wikitolearn WikiRating 0.0.1-SNAPSHOT jar WikiRating A Spring Boot application that relies on a OrientDb instance to serve a rating engine for a MediaWiki installation org.springframework.boot spring-boot-starter-parent 1.5.2.RELEASE UTF-8 UTF-8 1.8 jcenter-snapshots jcenter https://jcenter.bintray.com/ org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-neo4j + org.wikidata.wdtk wdtk-wikibaseapi 0.7.0 org.json json - + io.springfox springfox-swagger2 2.6.1 io.springfox.ui springfox-swagger-ui-rfc6570 1.0.0 org.springframework.boot spring-boot-maven-plugin diff --git a/src/main/java/org/wikitolearn/configs/Neo4JConfig.java b/src/main/java/org/wikitolearn/configs/Neo4JConfig.java new file mode 100644 index 0000000..7f48a0d --- /dev/null +++ b/src/main/java/org/wikitolearn/configs/Neo4JConfig.java @@ -0,0 +1,36 @@ +/** + * + */ +package org.wikitolearn.configs; + +import org.neo4j.ogm.session.SessionFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; +import org.springframework.data.neo4j.transaction.Neo4jTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * @author aletundo + * + * + */ +@Configuration +@EnableNeo4jRepositories(basePackages = "org.wikitolearn.repository") +@EnableTransactionManagement +public class Neo4JConfig { + + @Bean + public SessionFactory sessionFactory() { + // with domain entity base package(s) + return new SessionFactory("org.wikitolearn.models"); + } + + @Bean + public Neo4jTransactionManager transactionManager() { + return new Neo4jTransactionManager(sessionFactory()); + } + +} + + diff --git a/src/main/java/org/wikitolearn/controllers/MaintenanceController.java b/src/main/java/org/wikitolearn/controllers/MaintenanceController.java index ff02ab6..582228e 100644 --- a/src/main/java/org/wikitolearn/controllers/MaintenanceController.java +++ b/src/main/java/org/wikitolearn/controllers/MaintenanceController.java @@ -1,170 +1,158 @@ /** * */ package org.wikitolearn.controllers; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Properties; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import org.wikitolearn.dao.MetadataDAO; -import org.wikitolearn.dao.PageDAO; -import org.wikitolearn.dao.RevisionDAO; -import org.wikitolearn.dao.UserDAO; import org.wikitolearn.models.Process; import org.wikitolearn.services.PageService; import org.wikitolearn.services.RevisionService; import org.wikitolearn.services.UserService; import org.wikitolearn.utils.enums.ProcessResult; import org.wikitolearn.utils.enums.ProcessType; /** * * @author aletundo * */ @RestController public class MaintenanceController { private static final Logger LOG = LoggerFactory.getLogger(MaintenanceController.class); @Autowired private PageService pageService; @Autowired private UserService userService; @Autowired private RevisionService revisionService; - @Autowired - private MetadataDAO metadataDAO; - @Autowired - private PageDAO pageDao; - @Autowired - private UserDAO userDao; - @Autowired - private RevisionDAO revisionDAO; private boolean initializedDB = false; /** * Secured endpoint to enable or disable read only mode. When read only mode is enabled only GET requests are * allowed. To change this behavior @see org.wikitolearn.filters.MaintenanceFilter. * @param active String requested parameter that toggle the re. Binary values are accepted. * @return a JSON object with the response */ @RequestMapping(value = "${maintenance.readonlymode.uri}", method = RequestMethod.POST, produces = "application/json") public String toggleReadOnlyMode(@RequestParam(value = "active") String active) { JSONObject response = new JSONObject(); int mode = Integer.parseInt(active); try { if (mode == 0) { response.put("status", "success"); response.put("message", "Application is live now."); // Delete maintenance lock file if it exists File f = new File("maintenance.lock"); if (f.exists()) { f.delete(); LOG.debug("Deleted maintenance lock file."); } LOG.info("Application is live now."); } else if (mode == 1) { try { response.put("status", "success"); response.put("message", "Application is in maintenance mode now."); // Create maintenance lock file with a maintenance.active property setted to true Properties props = new Properties(); props.setProperty("maintenance.active", "true"); File lockFile = new File("maintenance.lock"); OutputStream out = new FileOutputStream(lockFile); DefaultPropertiesPersister p = new DefaultPropertiesPersister(); p.store(props, out, "Maintenance mode lock file"); LOG.debug("Created maintenance lock file."); LOG.info("Application is in maintenance mode now."); } catch (Exception e) { LOG.error("Something went wrong. {}", e.getMessage()); } } else { // The active parameter value is not supported response.put("status", "error"); response.put("message", "Parameter value not supported"); } } catch (JSONException e) { LOG.error("Something went wrong using JSON API. {}", e.getMessage()); } return response.toString(); } /** * Secured endpoint that handles initialization request for the given language * @param lang * @return true if the initialization is completed without errors, false otherwise */ @RequestMapping(value = "${maintenance.init.uri}", method = RequestMethod.POST, produces = "application/json") public boolean initialize(@RequestParam("lang") String lang, @Value("${mediawiki.protocol}") String protocol, @Value("${mediawiki.api.url}") String apiUrl){ String url = protocol + lang + "." + apiUrl; //starting a new Process Process initializeProcess = new Process(ProcessType.INIT); // Initializing the DB schema, only the first time if (! initializedDB){ initializeDbClasses(); initializedDB = true; } CompletableFuture parallelInsertions = CompletableFuture.allOf(pageService.addAllPages(lang, url), userService.addAllUsers(url)) .thenCompose(s -> revisionService.addAllRevisions(lang, url)); try { boolean result = parallelInsertions.get(); //saving the result of the process if (result){ initializeProcess.setProcessResult(ProcessResult.DONE); }else{ initializeProcess.setProcessResult(ProcessResult.ERROR); } - metadataDAO.addProcess(initializeProcess); + //metadataDAO.addProcess(initializeProcess); return result; } catch (InterruptedException | ExecutionException e) { LOG.error("Something went wrong during database initialization. {}", e.getMessage()); return false; } } /** * This methods initializes all the DAO Classes, creating the right types on the DB. * @return void */ private void initializeDbClasses(){ LOG.info("Creating Database classes..."); - metadataDAO.createDatabaseClass(); - pageDao.createDatabaseClass(); - userDao.createDatabaseClass(); - revisionDAO.createDatabaseClass(); + //metadataDAO.createDatabaseClass(); + //pageDao.createDatabaseClass(); + //userDao.createDatabaseClass(); + //revisionDAO.createDatabaseClass(); LOG.info("Completed creation of database classes."); } /** * */ @RequestMapping(value = "${maintenance.wipe.uri}", method = RequestMethod.DELETE, produces = "application/json") public void wipeDatabase(){ // TODO } } diff --git a/src/main/java/org/wikitolearn/dao/GenericDAO.java b/src/main/java/org/wikitolearn/dao/GenericDAO.java deleted file mode 100644 index cd4a946..0000000 --- a/src/main/java/org/wikitolearn/dao/GenericDAO.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * - */ -package org.wikitolearn.dao; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.wikitolearn.utils.DbConnection; - -/** - * @author aletundo - * - */ -public abstract class GenericDAO { - - protected final Logger LOG = LoggerFactory.getLogger(getClass()); - @Autowired - protected DbConnection connection; - @Value("#{'${mediawiki.langs}'.trim().split(',')}") - protected List langs; - - /** - * This method is used to create the class on the DB. - * It creates an unique index on the id to avoid duplicated. - * @return void - */ - public abstract void createDatabaseClass(); - -} \ No newline at end of file diff --git a/src/main/java/org/wikitolearn/dao/MetadataDAO.java b/src/main/java/org/wikitolearn/dao/MetadataDAO.java deleted file mode 100644 index 0f1626b..0000000 --- a/src/main/java/org/wikitolearn/dao/MetadataDAO.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.wikitolearn.dao; - -import com.orientechnologies.orient.core.metadata.schema.OType; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; -import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import com.tinkerpop.blueprints.impls.orient.OrientVertex; -import com.tinkerpop.blueprints.impls.orient.OrientVertexType; -import org.springframework.stereotype.Repository; -import org.wikitolearn.models.Process; - -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * This class represents Metadata nodes in the DB. There is a unique Metadata node, - * as a entrypoint, and a chain of Process nodes, saving some useful information at every - * process in the rating engine. For example we can save the number of fetched pages or - * saved user votes. - * @author valsdav, aletundo - */ -@Repository -public class MetadataDAO extends GenericDAO { - - /** - * This method creates the classes Metadata and Process in the DB. - * The Metadata node is the entrypoint for the chain of Processes, via the - * edges LastProcess and PreviousProcess - */ - @Override - public void createDatabaseClass() { - LOG.info("Creating DB classes for MetadataDAO..."); - OrientGraphNoTx graph = connection.getGraphNT(); - try{ - graph.createVertexType("Metadata",1); - OrientVertexType processVertex = graph.createVertexType("Process",1); - processVertex.createProperty("timestamp", OType.DATETIME).setMandatory(true); - graph.createEdgeType("LastProcess"); - graph.createEdgeType("PreviousProcess"); - graph.createEdgeType("SubProcess"); - - // Create Metadata vertex - OrientVertex metadata_main = graph.addVertex("class:Metadata"); - metadata_main.setProperty("creation_date", new Date()); - } catch( Exception e ) { - LOG.error("Something went wrong during class creation. {}.", e.getMessage()); - } finally { - graph.shutdown(); - } - } - - /** - * This method insert a new Process on the top of the chain in the db. - * It creates the new link between the Metadata node and the Process. - * @param process Process to be inserted - * @return - */ - public void addProcess(Process process){ - LOG.info("Inserting process..."); - OrientGraph graph = connection.getGraph(); - try { - // Getting latest Process - Vertex metadataNode = graph.getVerticesOfClass("Metadata").iterator().next(); - Iterator it = metadataNode.getEdges(Direction.OUT, "LastProcess").iterator(); - Edge lastProcessEdge = null; - Vertex lastProcess = null; - if (it.hasNext()) { - lastProcessEdge = it.next(); - lastProcess = lastProcessEdge.getVertex(Direction.OUT); - graph.removeEdge(lastProcessEdge); - } - // Adding a new Process vertex - Map props = new HashMap<>(); - props.put("timestamp", process.getTimestamp()); - props.put("processType", process.getProcessType()); - props.put("processResult", process.getProcessResult()); - Vertex newProcess = graph.addVertex("class:Process", props); - // Linking the node - graph.addEdge("class:LastProcess", metadataNode, newProcess, "LastProcess"); - if (lastProcess != null){ - graph.addEdge("class:PreviousProcess", newProcess, lastProcess, "PreviousProcess"); - } - graph.commit(); - } catch (Exception e){ - LOG.error("Something went wrong during the insertion of the process. {}.", e.getMessage()); - graph.rollback(); - } finally { - graph.shutdown(); - } - } -} - - diff --git a/src/main/java/org/wikitolearn/dao/PageDAO.java b/src/main/java/org/wikitolearn/dao/PageDAO.java deleted file mode 100644 index a2ed4a3..0000000 --- a/src/main/java/org/wikitolearn/dao/PageDAO.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - */ -package org.wikitolearn.dao; - -import com.orientechnologies.orient.core.metadata.schema.OClass; -import com.orientechnologies.orient.core.metadata.schema.OType; -import com.orientechnologies.orient.core.sql.OCommandSQL; -import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import com.tinkerpop.blueprints.impls.orient.OrientVertex; -import com.tinkerpop.blueprints.impls.orient.OrientVertexType; - -import org.springframework.stereotype.Repository; -import org.wikitolearn.models.Page; -/** - * - * @author aletundo, valsdav - * - */ -@Repository -public class PageDAO extends GenericDAO{ - - /** - * This method is used to create the class on the DB. - * It creates an unique index on pageid to avoid duplicated. - * @return void - */ - @Override - public void createDatabaseClass() { - LOG.info("Creating database Page class..."); - OrientGraphNoTx graph = connection.getGraphNT(); - try{ - OrientVertexType vertex = graph.createVertexType("Page",1); - vertex.createProperty("pageid", OType.INTEGER).setMandatory(true); - vertex.createProperty("lang", OType.STRING).setMandatory(true); - vertex.createIndex("page_lang", OClass.INDEX_TYPE.UNIQUE, "pageid", "lang"); - // Add a cluster for each language - for(String lang : langs){ - graph.command(new OCommandSQL("ALTER CLASS Page ADDCLUSTER Pages_" + lang)).execute(); - } - //graph.getRawGraph().getMetadata().getSchema().reload(); - } catch( Exception e ) { - LOG.error("Something went wrong during class creation. {}.", e.getMessage()); - } finally { - graph.shutdown(); - } - } - - - /** - * Insert all the given pages in the database as vertexes. - * If there are duplicates all the insertion is rolled back. - * @param pages List The pages to be inserted - * @param lang String - * @return boolean True if insertion was committed, false otherwise - */ - public Boolean insertPages(List pages, String lang){ - OrientGraphNoTx graph = connection.getGraphNT(); - LOG.info("Starting to insert pages..."); - try{ - for(Page p : pages){ - Map props = new HashMap<>(); - props.put("pageid", p.getPageid()); - props.put( "title", p.getTitle()); - props.put("lang", lang); - props.put("pageRank", p.getPageRank()); - - OrientVertex pageNode = graph.addVertex("class:Page,cluster:Pages_"+lang, props); - LOG.info("Page inserted " + pageNode.toString()); - } - LOG.info("Pages insertion committed"); - return true; - } catch (ORecordDuplicatedException or) { - LOG.error("Page not inserted because it's duplicated. {}", or.getMessage()); - } catch( Exception e ) { - LOG.error("Something went wrong during page insertion. {}", e.getMessage()); - }finally { - graph.shutdown(); - } - return false; - } - - /** - * This methods returns an Iterable over all the pages belonging to a certain cluster, - * so coming from the same language domain. - * @param graph OrientGraph An OrientGraph instance - * @param lang String The language of the cluster - * @return result Iterable with all the pages of the cluster - */ - public Iterable getPagesIteratorFromCluster(OrientGraph graph, String lang){ - Iterable result = null; - try { - result = (Iterable) graph.command(new OCommandSQL( - "SELECT * FROM cluster:Pages_"+ lang)).execute(); - } catch (Exception e){ - LOG.error("Something went wrong during quering for pages. {}", e.getMessage()); - } - return result; - } -} diff --git a/src/main/java/org/wikitolearn/dao/RevisionDAO.java b/src/main/java/org/wikitolearn/dao/RevisionDAO.java deleted file mode 100644 index c899c1b..0000000 --- a/src/main/java/org/wikitolearn/dao/RevisionDAO.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.wikitolearn.dao; - -import com.orientechnologies.orient.core.metadata.schema.OClass; -import com.orientechnologies.orient.core.metadata.schema.OType; -import com.orientechnologies.orient.core.sql.OCommandSQL; -import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; -import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import com.tinkerpop.blueprints.impls.orient.OrientVertex; -import com.tinkerpop.blueprints.impls.orient.OrientVertexType; -import org.springframework.stereotype.Repository; -import org.wikitolearn.models.Revision; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; - -/** - * - * @author aletundo, valsdav - * - */ -@Repository -public class RevisionDAO extends GenericDAO { - - /** - * This method is used to create the Revision class on the database. Moreover it creates - * a unique index on the revid property to avoid duplication. - */ - @Override - public void createDatabaseClass() { - LOG.info("Creating database Revision class..."); - OrientGraphNoTx graph = connection.getGraphNT(); - try { - // Vertex type for the revision - OrientVertexType vertex = graph.createVertexType("Revision", 1); - vertex.createProperty("revid", OType.INTEGER).setMandatory(true); - vertex.createProperty("lang", OType.STRING).setMandatory(true); - vertex.createIndex("revid", OClass.INDEX_TYPE.UNIQUE, "revid", "lang"); - // Add a cluster for each language - for (String lang : langs) { - graph.command(new OCommandSQL("ALTER CLASS Revision ADDCLUSTER Revisions_" + lang)).execute(); - } - // Edge type for the created edge from User to Revision - graph.createEdgeType("Author"); - // Edge type to connect revision to parent revision - graph.createEdgeType("ParentRevision"); - // Edge type to connect last revision to page vertex - graph.createEdgeType("LastRevision"); - // Edge type to connect the first revision of a page - graph.createEdgeType("FirstRevision"); - } catch (Exception e) { - LOG.error("Something went wrong during class creation. {}.", e.getMessage()); - } finally { - graph.shutdown(); - } - } - - /** - * This method will insert the revisions of one page, creating the link - * ParentRevision between them and the link FirstRevision and LastRevision - * with the Page vertex. Moreover it connects the Users to the revisions - * they have created. This method must be used only for the first INIT - * import, NOT for incremental insertion. - * - * @param pageId - * @param revs - * @return - */ - public Boolean insertRevisions(int pageId, List revs, String lang) { - OrientGraphNoTx graph = connection.getGraphNT(); - LOG.info("Starting to insert revisions..."); - HashMap revsNodes = new HashMap(); - Vertex firstRev = null; - Vertex lastRev = null; - try { - for (Revision rev : revs) { - Map props = new HashMap<>(); - props.put("revid", rev.getRevid()); - props.put("lang", lang); - props.put("length", rev.getLength()); - props.put("changeCoefficient", rev.getChangeCoefficient()); - props.put("currentMeanVote", rev.getCurrentMeanVote()); - props.put("currentVotesReliability", rev.getCurrentVotesReliability()); - props.put("currentNormalizedVotesReliability", rev.getCurrentNormalisesVotesReliability()); - props.put("totalMeanVote", rev.getTotalMeanVote()); - props.put("totalVotesReliability", rev.getTotalVotesReliability()); - props.put("totalNormalizedVotesReliability", rev.getTotalNormalisesVotesReliability()); - props.put("validated", rev.isValidated()); - - Vertex revNode = graph.addVertex("class:Revision,cluster:Revisions_" + lang, props); - // LOG.info("Revision inserted {}.", revNode.toString()); - revsNodes.put(Integer.toString(rev.getRevid()), revNode); - - if (rev.getParentid() == 0) { - firstRev = revNode; - } - if (lastRev == null || rev.getRevid() > (int) lastRev.getProperty("revid")) { - lastRev = revNode; - } - - // Connecting the creator of the revisions - Vertex userCreator = null; - try { - userCreator = graph.getVertices("User.userid", rev.getUserid()).iterator().next(); - } catch (NoSuchElementException e) { - // if the user is not found we link it to the Anonymous - // user. - userCreator = graph.getVertices("User.userid", "0").iterator().next(); - } - graph.addEdge("class:Author", userCreator, revNode, "Author"); - } - - // Now we have to create the the links between revisions - for (Revision r : revs) { - if (r.getParentid() != 0) { - graph.addEdge("class:ParentRevision", revsNodes.get(Integer.toString(r.getRevid())), - revsNodes.get(Integer.toString(r.getParentid())), "ParentRevision"); - } - } - - // Now let's create the LastRevision and FirstRevision edges - Vertex page = graph.getVertices("Page.pageid", pageId).iterator().next(); - graph.addEdge("class:LastRevision", page, lastRev, "LastRevision"); - graph.addEdge("class:FirstRevision", page, firstRev, "FirstRevision"); - - LOG.info("Revisions of page {} insertion committed", pageId); - return true; - } catch (ORecordDuplicatedException or) { - LOG.error("Some of the revisions are duplicates. {}", or.getMessage()); - } catch (Exception e) { - LOG.error("Something went wrong during revisions insertion. {}", e.getMessage()); - } finally { - graph.shutdown(); - } - return false; - } - - /** - * This methods returns an Iterable over all the Revisions belonging to a - * certain cluster, so coming from the same language domain. - * - * @param lang - * String The language of the cluster - * @return result Iterable with all the revisions of the - * cluster - */ - public Iterable getRevisionsIteratorFromCluster(OrientGraph graph, String lang) { - Iterable result = null; - try { - result = (Iterable) graph.command(new OCommandSQL("SELECT * FROM cluster:Revisions_" + lang)) - .execute(); - } catch (Exception e) { - LOG.error("Something went wrong during quering for revisions. {}", e.getMessage()); - } - return result; - } - -} diff --git a/src/main/java/org/wikitolearn/dao/UserDAO.java b/src/main/java/org/wikitolearn/dao/UserDAO.java deleted file mode 100644 index 5b58bba..0000000 --- a/src/main/java/org/wikitolearn/dao/UserDAO.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * - */ -package org.wikitolearn.dao; - -import com.orientechnologies.orient.core.metadata.schema.OClass; -import com.orientechnologies.orient.core.metadata.schema.OType; -import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; -import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import com.tinkerpop.blueprints.impls.orient.OrientVertexType; -import org.springframework.stereotype.Repository; -import org.wikitolearn.models.User; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * - * @author aletundo, valsdav - * - */ -@Repository -public class UserDAO extends GenericDAO{ - - /** - * This method is used to create the User class on the database. - * Moreover it creates a unique index on the userid property to avoid duplication. - * @return void - */ - @Override - public void createDatabaseClass() { - LOG.info("Creating database User class..."); - OrientGraphNoTx graph = connection.getGraphNT(); - try{ - OrientVertexType vertex = graph.createVertexType("User"); - vertex.createProperty("userid", OType.INTEGER).setMandatory(true); - vertex.createIndex("userid", OClass.INDEX_TYPE.UNIQUE, "userid"); - } catch( Exception e ) { - LOG.error("Something went wrong during class creation. {}", e.getMessage()); - } finally { - graph.shutdown(); - } - } - - - /** - * Insert all the given users in the database as vertexes. - * If there are duplicates all the insertion is rolled back. - * @param users List The pages to be inserted - * @return boolean True if insertion was committed, false otherwise - */ - public Boolean insertUsers(List users){ - OrientGraph graph = connection.getGraph(); - LOG.info("Starting to insert users..."); - try{ - for(User p : users) { - try { - Map props = new HashMap<>(); - props.put("userid", p.getUserid()); - props.put("username", p.getUsername()); - props.put("votesReliability", p.getVotesReliability()); - props.put("contributesReliability", p.getContributesReliability()); - props.put("totalReliability", p.getTotalReliability()); - - Vertex userNode = graph.addVertex("class:User", props); - graph.commit(); - LOG.info("User inserted {}", userNode.toString()); - } catch (ORecordDuplicatedException or) { - LOG.error("The user is already in the DB. {}. Operation will be rollbacked.", or.getMessage()); - graph.rollback(); - } - } - LOG.info("Users insertion ended"); - graph.shutdown(); - return true; - } catch( Exception e ) { - LOG.error("Something went wrong during user insertion. {}. Operation will be rollbacked.", e.getMessage()); - graph.rollback(); - graph.shutdown(); - } - return false; - } - -} diff --git a/src/main/java/org/wikitolearn/models/Page.java b/src/main/java/org/wikitolearn/models/Page.java index ebef0bd..41ca5fe 100644 --- a/src/main/java/org/wikitolearn/models/Page.java +++ b/src/main/java/org/wikitolearn/models/Page.java @@ -1,78 +1,116 @@ /** * */ package org.wikitolearn.models; +import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.Index; +import org.neo4j.ogm.annotation.NodeEntity; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * * @author aletundo, valsdav * */ @JsonIgnoreProperties(ignoreUnknown = true) +@NodeEntity( label = "Page") public class Page { - private String title; + @GraphId private long graphId; private int pageid; + private String title; + private String lang; + @Index(unique = true) + private String langPageId; private double pageRank; /** * */ public Page() { } /** * @param title * @param pageid * @param pageRank */ public Page(String title, int pageid, double pageRank) { this.title = title; this.pageid = pageid; this.pageRank = pageRank; - } + } + /** * @return the title */ public String getTitle() { return title; } /** * @param title the title to set */ public void setTitle(String title) { this.title = title; } /** * @return the pageid */ public int getPageid() { return pageid; } /** * @param pageid the pageid to set */ public void setPageid(int pageid) { this.pageid = pageid; } /** * @return the pageRank */ public double getPageRank() { return pageRank; } /** * @param pageRank the pageRank to set */ public void setPageRank(double pageRank) { this.pageRank = pageRank; } + /** + * @return the lang + */ + public String getLang() { + return lang; + } + + /** + * @param lang the lang to set + */ + public void setLang(String lang) { + this.lang = lang; + } + + /** + * @return the langPageId + */ + public String getLangPageId() { + return langPageId; + } + + /** + * @param langPageId the langPageId to set + */ + public void setLangPageId(String langPageId) { + this.langPageId = langPageId; + } + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Page [title=" + title + ", pageid=" + pageid + ", pageRank=" + pageRank + "]"; } } diff --git a/src/main/java/org/wikitolearn/models/Process.java b/src/main/java/org/wikitolearn/models/Process.java index 4f9975c..59a7a0b 100644 --- a/src/main/java/org/wikitolearn/models/Process.java +++ b/src/main/java/org/wikitolearn/models/Process.java @@ -1,57 +1,61 @@ package org.wikitolearn.models; +import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.NodeEntity; import org.wikitolearn.utils.enums.ProcessResult; import org.wikitolearn.utils.enums.ProcessType; import java.util.Date; /** * This class represents a Process happened in the engine. * It has a definite type and can have different results. It is saved in the DB * as a Process vertex. - * Created by valsdav on 21/03/17. + * @author aletundo + * @author valsdav */ +@NodeEntity( label = "Process") public class Process { - + @GraphId private long graphId; private Date timestamp; private ProcessType processType; private ProcessResult processResult; public Process() {} public Process(Date timestamp, ProcessType processType, ProcessResult processResult) { this.timestamp = timestamp; this.processType = processType; this.processResult = processResult; } public Process(ProcessType processType){ this.timestamp = new Date(); this.processType = processType; this.processResult = ProcessResult.ONGOING; } public Date getTimestamp() { return timestamp; } public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } public ProcessType getProcessType() { return processType; } public void setProcessType(ProcessType processType) { this.processType = processType; } public ProcessResult getProcessResult() { return processResult; } public void setProcessResult(ProcessResult processResult) { this.processResult = processResult; } } diff --git a/src/main/java/org/wikitolearn/models/Revision.java b/src/main/java/org/wikitolearn/models/Revision.java index 646acaf..a408a6d 100644 --- a/src/main/java/org/wikitolearn/models/Revision.java +++ b/src/main/java/org/wikitolearn/models/Revision.java @@ -1,140 +1,281 @@ package org.wikitolearn.models; +import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.Index; +import org.neo4j.ogm.annotation.NodeEntity; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * This class handles the data of the Revision of a page. * Created by valsdav on 14/03/17. */ @JsonIgnoreProperties(ignoreUnknown = true) +@NodeEntity( label = "Revision" ) public class Revision { + @GraphId private long graphId; private int revid; private int userid; private int parentid; private long length; private double changeCoefficient; private double currentMeanVote; private double currentVotesReliability; private double currentNormalisesVotesReliability; private double totalMeanVote; private double totalVotesReliability; private double totalNormalisesVotesReliability; - private boolean validated = false; - - public Revision() { } - - public Revision(int revid, int userid, int parentid, long length, double changeCoefficient, - double currentMeanVote, double currentVotesReliability, - double currentNormalisesVotesReliability, double totalMeanVote, - double totalVotesReliability, double totalNormalisesVotesReliability, boolean validated) { - this.revid = revid; - this.userid = userid; - this.parentid = parentid; - this.length = length; - this.changeCoefficient = changeCoefficient; - this.currentMeanVote = currentMeanVote; - this.currentVotesReliability = currentVotesReliability; - this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; - this.totalMeanVote = totalMeanVote; - this.totalVotesReliability = totalVotesReliability; - this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; - this.validated = validated; - } - - public int getRevid() { - return revid; - } - - public void setRevid(int revid) { - this.revid = revid; - } - - public int getUserid() { - return userid; - } - - public void setUserid(int userid) { - this.userid = userid; - } - - public int getParentid() { - return parentid; - } - - public void setParentid(int parentid) { - this.parentid = parentid; - } - - public long getLength() { - return length; - } - - public void setLength(long length) { - this.length = length; - } - - public double getChangeCoefficient() { - return changeCoefficient; - } - - public void setChangeCoefficient(double changeCoefficient) { - this.changeCoefficient = changeCoefficient; - } - - public double getCurrentMeanVote() { - return currentMeanVote; - } - - public void setCurrentMeanVote(double currentMeanVote) { - this.currentMeanVote = currentMeanVote; - } - - public double getCurrentVotesReliability() { - return currentVotesReliability; - } - - public void setCurrentVotesReliability(double currentVotesReliability) { - this.currentVotesReliability = currentVotesReliability; - } - - public double getCurrentNormalisesVotesReliability() { - return currentNormalisesVotesReliability; - } - - public void setCurrentNormalisesVotesReliability(double currentNormalisesVotesReliability) { - this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; - } - - public double getTotalMeanVote() { - return totalMeanVote; - } - - public void setTotalMeanVote(double totalMeanVote) { - this.totalMeanVote = totalMeanVote; - } - - public double getTotalVotesReliability() { - return totalVotesReliability; - } - - public void setTotalVotesReliability(double totalVotesReliability) { - this.totalVotesReliability = totalVotesReliability; - } - - public double getTotalNormalisesVotesReliability() { - return totalNormalisesVotesReliability; - } - - public void setTotalNormalisesVotesReliability(double totalNormalisesVotesReliability) { - this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; - } - - public boolean isValidated() { - return validated; - } - - public void setValidated(boolean validated) { - this.validated = validated; - } -} + private boolean validated; + private String lang; + @Index(unique = true) + private String langRevId; + + /** + * + */ + public Revision() {} + + /** + * @param revid + * @param userid + * @param parentid + * @param length + * @param changeCoefficient + * @param currentMeanVote + * @param currentVotesReliability + * @param currentNormalisesVotesReliability + * @param totalMeanVote + * @param totalVotesReliability + * @param totalNormalisesVotesReliability + * @param validated + * @param lang + */ + public Revision(int revid, int userid, int parentid, long length, double changeCoefficient, double currentMeanVote, + double currentVotesReliability, double currentNormalisesVotesReliability, double totalMeanVote, + double totalVotesReliability, double totalNormalisesVotesReliability, boolean validated, String lang) { + this.revid = revid; + this.userid = userid; + this.parentid = parentid; + this.length = length; + this.changeCoefficient = changeCoefficient; + this.currentMeanVote = currentMeanVote; + this.currentVotesReliability = currentVotesReliability; + this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; + this.totalMeanVote = totalMeanVote; + this.totalVotesReliability = totalVotesReliability; + this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; + this.validated = validated; + this.lang = lang; + } + + /** + * @return the revid + */ + public int getRevid() { + return revid; + } + + /** + * @param revid the revid to set + */ + public void setRevid(int revid) { + this.revid = revid; + } + + /** + * @return the userid + */ + public int getUserid() { + return userid; + } + + /** + * @param userid the userid to set + */ + public void setUserid(int userid) { + this.userid = userid; + } + + /** + * @return the parentid + */ + public int getParentid() { + return parentid; + } + + /** + * @param parentid the parentid to set + */ + public void setParentid(int parentid) { + this.parentid = parentid; + } + + /** + * @return the length + */ + public long getLength() { + return length; + } + + /** + * @param length the length to set + */ + public void setLength(long length) { + this.length = length; + } + + /** + * @return the changeCoefficient + */ + public double getChangeCoefficient() { + return changeCoefficient; + } + + /** + * @param changeCoefficient the changeCoefficient to set + */ + public void setChangeCoefficient(double changeCoefficient) { + this.changeCoefficient = changeCoefficient; + } + + /** + * @return the currentMeanVote + */ + public double getCurrentMeanVote() { + return currentMeanVote; + } + + /** + * @param currentMeanVote the currentMeanVote to set + */ + public void setCurrentMeanVote(double currentMeanVote) { + this.currentMeanVote = currentMeanVote; + } + + /** + * @return the currentVotesReliability + */ + public double getCurrentVotesReliability() { + return currentVotesReliability; + } + + /** + * @param currentVotesReliability the currentVotesReliability to set + */ + public void setCurrentVotesReliability(double currentVotesReliability) { + this.currentVotesReliability = currentVotesReliability; + } + + /** + * @return the currentNormalisesVotesReliability + */ + public double getCurrentNormalisesVotesReliability() { + return currentNormalisesVotesReliability; + } + + /** + * @param currentNormalisesVotesReliability the currentNormalisesVotesReliability to set + */ + public void setCurrentNormalisesVotesReliability(double currentNormalisesVotesReliability) { + this.currentNormalisesVotesReliability = currentNormalisesVotesReliability; + } + + /** + * @return the totalMeanVote + */ + public double getTotalMeanVote() { + return totalMeanVote; + } + + /** + * @param totalMeanVote the totalMeanVote to set + */ + public void setTotalMeanVote(double totalMeanVote) { + this.totalMeanVote = totalMeanVote; + } + + /** + * @return the totalVotesReliability + */ + public double getTotalVotesReliability() { + return totalVotesReliability; + } + + /** + * @param totalVotesReliability the totalVotesReliability to set + */ + public void setTotalVotesReliability(double totalVotesReliability) { + this.totalVotesReliability = totalVotesReliability; + } + + /** + * @return the totalNormalisesVotesReliability + */ + public double getTotalNormalisesVotesReliability() { + return totalNormalisesVotesReliability; + } + + /** + * @param totalNormalisesVotesReliability the totalNormalisesVotesReliability to set + */ + public void setTotalNormalisesVotesReliability(double totalNormalisesVotesReliability) { + this.totalNormalisesVotesReliability = totalNormalisesVotesReliability; + } + + /** + * @return the validated + */ + public boolean isValidated() { + return validated; + } + + /** + * @param validated the validated to set + */ + public void setValidated(boolean validated) { + this.validated = validated; + } + + /** + * @return the lang + */ + public String getLang() { + return lang; + } + + /** + * @param lang the lang to set + */ + public void setLang(String lang) { + this.lang = lang; + } + + /** + * @return the langRevId + */ + public String getLangRevId() { + return langRevId; + } + + /** + * @param langRevId the langRevId to set + */ + public void setLangRevId(String langRevId) { + this.langRevId = langRevId; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Revision [graphId=" + graphId + ", revid=" + revid + ", userid=" + userid + ", parentid=" + parentid + + ", length=" + length + ", changeCoefficient=" + changeCoefficient + ", currentMeanVote=" + + currentMeanVote + ", currentVotesReliability=" + currentVotesReliability + + ", currentNormalisesVotesReliability=" + currentNormalisesVotesReliability + ", totalMeanVote=" + + totalMeanVote + ", totalVotesReliability=" + totalVotesReliability + + ", totalNormalisesVotesReliability=" + totalNormalisesVotesReliability + ", validated=" + validated + + ", lang=" + lang + ", langRevId=" + langRevId + "]"; + } +} \ No newline at end of file diff --git a/src/main/java/org/wikitolearn/models/User.java b/src/main/java/org/wikitolearn/models/User.java index ac42cc0..695d0fc 100644 --- a/src/main/java/org/wikitolearn/models/User.java +++ b/src/main/java/org/wikitolearn/models/User.java @@ -1,123 +1,127 @@ /** * */ package org.wikitolearn.models; +import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.NodeEntity; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * @author aletundo, valsdav * */ +@NodeEntity( label = "User") @JsonIgnoreProperties(ignoreUnknown = true) public class User { + @GraphId private long graphId; @JsonProperty("name") private String username; private int userid; private double votesReliability; private double contributesReliability; private double totalReliability; /** * */ - public User() { - } + public User() {} /** * @param username * @param userid * @param votesReliability * @param contributesReliability * @param totalReliability */ public User(String username, int userid, double votesReliability, double contributesReliability, double totalReliability) { this.username = username; this.userid = userid; this.votesReliability = votesReliability; this.contributesReliability = contributesReliability; this.totalReliability = totalReliability; } /** * @return the username */ public String getUsername() { return username; } /** * @param username the username to set */ public void setUsername(String username) { this.username = username; } /** * @return the userid */ public int getUserid() { return userid; } /** * @param userid the userid to set */ public void setUserId(int userid) { this.userid = userid; } /** * @return the votesReliability */ public double getVotesReliability() { return votesReliability; } /** * @param votesReliability the votesReliability to set */ public void setVotesReliability(double votesReliability) { this.votesReliability = votesReliability; } /** * @return the contributesReliability */ public double getContributesReliability() { return contributesReliability; } /** * @param contributesReliability the contributesReliability to set */ public void setContributesReliability(double contributesReliability) { this.contributesReliability = contributesReliability; } /** * @return the totalReliability */ public double getTotalReliability() { return totalReliability; } /** * @param totalReliability the totalReliability to set */ public void setTotalReliability(double totalReliability) { this.totalReliability = totalReliability; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "User [username=" + username + ", userid=" + userid + ", votesReliability=" + votesReliability + ", contributesReliability=" + contributesReliability + ", totalReliability=" + totalReliability + "]"; } } diff --git a/src/main/java/org/wikitolearn/models/Vote.java b/src/main/java/org/wikitolearn/models/Vote.java index 7a5527c..3d5f188 100644 --- a/src/main/java/org/wikitolearn/models/Vote.java +++ b/src/main/java/org/wikitolearn/models/Vote.java @@ -1,66 +1,69 @@ /** * */ package org.wikitolearn.models; +import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.NodeEntity; + /** * @author aletundo, valsdav * */ +@NodeEntity( label = "Vote") public class Vote { - + @GraphId private long graphId; private double value; private double reliability; /** * */ - public Vote() { - } + public Vote() {} /** * @param value * @param reliability */ public Vote(double value, double reliability) { this.value = value; this.reliability = reliability; } /** * @return the value */ public double getValue() { return value; } /** * @param value the value to set */ public void setValue(double value) { this.value = value; } /** * @return the reliability */ public double getReliability() { return reliability; } /** * @param reliability the reliability to set */ public void setReliability(double reliability) { this.reliability = reliability; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Vote [value=" + value + ", reliability=" + reliability + "]"; } } diff --git a/src/main/java/org/wikitolearn/services/PageService.java b/src/main/java/org/wikitolearn/services/PageService.java index 8ff5abb..1a7b5e1 100644 --- a/src/main/java/org/wikitolearn/services/PageService.java +++ b/src/main/java/org/wikitolearn/services/PageService.java @@ -1,49 +1,37 @@ /** * */ package org.wikitolearn.services; import java.util.List; import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.wikitolearn.dao.PageDAO; -import org.wikitolearn.models.Page; import org.wikitolearn.services.mediawiki.PageMediaWikiService; /** * * @author aletundo, valsdav * */ @Service public class PageService { private static final Logger LOG = LoggerFactory.getLogger(PageService.class); @Autowired private PageMediaWikiService pageMediaWikiService; - @Autowired - private PageDAO pageDao; - + /** * This methods inserts all the pages inside the DB querying the MediaWiki API. * @param lang String * @param apiUrl String The MediaWiki API url * @return CompletableFuture */ @Async public CompletableFuture addAllPages( String lang, String apiUrl ){ - List pages = pageMediaWikiService.getAll(apiUrl); - LOG.info("Fetched all the pages"); - boolean insertionResultPages = pageDao.insertPages(pages, lang); - if(insertionResultPages){ - LOG.info("Inserted pages"); - }else{ - LOG.error("Something went wrong during pages insertion"); - } - return CompletableFuture.completedFuture(insertionResultPages); + return CompletableFuture.completedFuture(true); } } diff --git a/src/main/java/org/wikitolearn/services/RevisionService.java b/src/main/java/org/wikitolearn/services/RevisionService.java index 9ab012e..4970e92 100644 --- a/src/main/java/org/wikitolearn/services/RevisionService.java +++ b/src/main/java/org/wikitolearn/services/RevisionService.java @@ -1,74 +1,41 @@ /** * */ package org.wikitolearn.services; import java.util.List; import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.wikitolearn.dao.PageDAO; -import org.wikitolearn.dao.RevisionDAO; import org.wikitolearn.models.Revision; import org.wikitolearn.services.mediawiki.RevisionMediaWikiService; -import org.wikitolearn.utils.DbConnection; - -import com.orientechnologies.orient.core.exception.ODatabaseException; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; -import com.tinkerpop.blueprints.impls.orient.OrientVertex; /** * * @author aletundo, valsdav * */ @Service public class RevisionService { private static final Logger LOG = LoggerFactory.getLogger(RevisionService.class); @Autowired private RevisionMediaWikiService revisionMediaWikiService; - @Autowired - private RevisionDAO revisionDao; - @Autowired - private PageDAO pageDao; - @Autowired - private DbConnection dbConnection; /** * This method inserts all the revisions for every page, creating the connections between them * and between the users that have written them. * @param lang String * @param apiUrl String The MediaWiki API url * @return CompletableFuture */ @Async public CompletableFuture addAllRevisions(String lang, String apiUrl){ - OrientGraph graph = dbConnection.getGraph(); - boolean revInsertionResult = false; - try{ - for (OrientVertex page : pageDao.getPagesIteratorFromCluster(graph, lang)) { - int pageId = page.getProperty("pageid"); - LOG.info("Processing page: {}", pageId); - List revs = revisionMediaWikiService.getAllRevisionByPageId(apiUrl, pageId); - revInsertionResult = revisionDao.insertRevisions(pageId, revs, lang); - if(!revInsertionResult){ - LOG.error("Something was wrong during the insertion of the revisions of page {}", pageId); - } - } - } catch ( ODatabaseException e){ - LOG.error("DB Error during insertion of Revisions. {}", e.getMessage()); - graph.rollback(); - } catch (Exception e){ - LOG.error("Something went wrong during Revisions insertion. {}", e.getMessage()); - graph.rollback(); - } finally { - graph.shutdown(); - } - return CompletableFuture.completedFuture(revInsertionResult); + + return CompletableFuture.completedFuture(true); } } diff --git a/src/main/java/org/wikitolearn/services/UserService.java b/src/main/java/org/wikitolearn/services/UserService.java index c51fc00..fb2b8ed 100644 --- a/src/main/java/org/wikitolearn/services/UserService.java +++ b/src/main/java/org/wikitolearn/services/UserService.java @@ -1,51 +1,36 @@ /** * */ package org.wikitolearn.services; -import java.util.List; import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.wikitolearn.dao.UserDAO; -import org.wikitolearn.models.User; import org.wikitolearn.services.mediawiki.UserMediaWikiService; /** * * @author aletundo, valsdav * */ @Service public class UserService { private static final Logger LOG = LoggerFactory.getLogger(UserService.class); @Autowired private UserMediaWikiService userMediaWikiService; - @Autowired - private UserDAO userDao; - + /** * This methods inserts all the users inside the DB querying the MediaWiki API. * * @return CompletableFuture */ @Async public CompletableFuture addAllUsers(String apiUrl){ - List users = userMediaWikiService.getAll(apiUrl); - // Adding the Anonymous user - users.add(new User("Anonymous", 0, 0, 0, 0)); - LOG.info("Fetched all the users"); - boolean insertionResultUsers = userDao.insertUsers(users); - if(insertionResultUsers){ - LOG.info("Inserted users"); - }else{ - LOG.error("Something went wrong during users insertion"); - } - return CompletableFuture.completedFuture(insertionResultUsers); + return CompletableFuture.completedFuture(true); } } diff --git a/src/main/java/org/wikitolearn/utils/DbConnection.java b/src/main/java/org/wikitolearn/utils/DbConnection.java deleted file mode 100644 index d1bb68b..0000000 --- a/src/main/java/org/wikitolearn/utils/DbConnection.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - */ -package org.wikitolearn.utils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.orientechnologies.orient.core.intent.OIntentMassiveInsert; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; -import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory; -import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import org.wikitolearn.dao.UserDAO; -/** - * @author aletundo, valsdav - * - */ -@Component -public class DbConnection { - - private static final Logger LOG = LoggerFactory.getLogger(UserDAO.class); - private OrientGraphFactory factory; - - @Autowired - public DbConnection(@Value("${db.url}") String dbUrl, @Value("${db.user}") - String dbUser, @Value("${db.password}") String dbPwd){ - - factory = new OrientGraphFactory(dbUrl, dbUser, dbPwd).setupPool(1, 20); - } - /** - * This method will return the OreintDB graph instance after connection. - * @return Transaction enabled OrientGraph object - */ - public OrientGraph getGraph(){ - LOG.info("Getting an instance of OrientDB...."); - return factory.getTx(); - } - - /** - * This method will return the OreintDB graph instance after connection, - * for massive inserts to improve performance,no transaction method - * @return Transaction disabled OrientGraph object - */ - - public OrientGraphNoTx getGraphNT() { - LOG.info("Getting a NoTX instance of OrientDB...."); - factory.declareIntent(new OIntentMassiveInsert()); - return factory.getNoTx(); - } -}