Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 3 additions & 55 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
'use strict';

var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};

var fillTopics = function (data) {
if (data.topics) {
data.topics.forEach(function (entry) {
entry.id = entry.id || 9999;
entry.topics = entry.topics || [];
entry.questions = entry.questions || [];
});
}
};

var restMiddleware = function (req, res, next) {
if (req.method === 'PUT') {
var body = {};
req.on('data', function (chunk) {
body = JSON.parse(chunk.toString());
fillTopics(body);
});
req.on('end', function () {
res.writeHead(200, 'OK', {'Content-Type': 'application/json'});
res.end(JSON.stringify(body));
});
} else if (req.method === 'DELETE') {
res.writeHead(200, 'OK');
res.end();
} else {
return next();
}

};

module.exports = function (grunt) {

var protractorBrowserPort = grunt.option('p:port') || '8282';
var tomcatPort = grunt.option('p:port') || '8282';

grunt.initConfig({

Expand Down Expand Up @@ -101,23 +67,6 @@ module.exports = function (grunt) {
singleRun: true
}
},
connect: {
livereload: {
options: {
//keepalive: true,
port: protractorBrowserPort,
base: ['src/main/webapp', 'src/test/resources/json/root', 'src/test/resources/json'],
middleware: function (connect, options) {
return [
restMiddleware,
mountFolder(connect, options.base[0]),
mountFolder(connect, options.base[1]),
mountFolder(connect, options.base[2])
];
}
}
}
},
copy: {
lcov: {
expand: true,
Expand Down Expand Up @@ -167,7 +116,7 @@ module.exports = function (grunt) {
options : {
configFile : 'src/test/javascript/protractor.conf.js',
args : {
baseUrl : 'http://localhost:' + protractorBrowserPort
baseUrl : 'http://localhost:' + tomcatPort
}
}
},
Expand All @@ -177,7 +126,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-ngdocs');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
Expand All @@ -189,7 +137,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-protractor-runner');

grunt.registerTask('minify', ['clean:jsmin', 'removelogging', 'uglify', 'clean:cssmin', 'cssmin']);
grunt.registerTask('p:test', ['clean:e2etests','processhtml:e2eTests', 'connect', 'protractor', 'processhtml:production']);
grunt.registerTask('p:test', ['clean:e2etests','processhtml:e2eTests', 'protractor', 'processhtml:production']);
grunt.registerTask('k:test', ['processhtml:development', 'karma', 'copy:lcov']);

};
4 changes: 2 additions & 2 deletions commit_build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# "deploy: no deploy"
# "intent of using: production"
# "minification: yes"
# "we can modify server port for protractor e2e tests by passing argument "-Dprotractor.port=_port_number_"
# "we can modify port for embedded tomcat 7 server by passing argument "-Dtomcat.port=_port_number_"
# "this can be useful to suppress port conflict during executing 2 synchronous Jenkins jobs"
mvn clean verify -Pprod $1
mvn clean verify -Pprod -Dspring.profiles.active=test $1
4 changes: 2 additions & 2 deletions commit_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ rem code quality checks: yes (findbugs, pmd, checkstyle)
rem deploy: no deploy
rem intent of using: production
rem minification: yes
rem we can modify server port for protractor e2e tests by passing argument "-Dprotractor.port=_port_number_"
rem we can modify port for embedded tomcat 7 server by passing argument "-Dtomcat.port=_port_number_"
rem this can be useful to suppress port conflict during executing 2 synchronous Jenkins jobs
mvn clean verify -Pprod %1
mvn clean verify -Pprod -Dspring.profiles.active=test %1
7 changes: 4 additions & 3 deletions dirty_deploy.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rem test: no
rem code quality checks: no
rem deploy: deploy on local server tomcat 7
rem intent of using: development with deploy on local server tomcat 7 that should be started before deploy
rem deploy: deploy on embedded server tomcat 7
rem intent of using: development with starting embedded tomcat 7 server
rem minification: no
mvn clean package tomcat7:deploy -DskipTests -DskipITs -Dfindbugs.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true
rem we can modify port for embedded tomcat 7 server by passing argument "-Dtomcat.port=_port_number_"
mvn clean tomcat7:run-war -Pdev -DskipTests -Dspring.profiles.active=dev %1
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-connect": "^0.8.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-jshint": "latest",
"jshint-stylish": "latest",
Expand All @@ -31,6 +30,7 @@
"grunt-processhtml": "^0.3.3",
"grunt-open": "0.2.3",
"grunt-remove-logging": "latest",
"grunt-protractor-runner": "~1.2.1"
"grunt-protractor-runner": "~1.2.1",
"request": "~2.53.0"
}
}
42 changes: 30 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<sonar.javascript.lcov.reportPath>target/lcov.info</sonar.javascript.lcov.reportPath>
<sonar.exclusions>src/main/webapp/js/min/**/*</sonar.exclusions>
<sonar.cobertura.reportPath>target/site/cobertura/coverage.xml</sonar.cobertura.reportPath>
<protractor.port>8282</protractor.port>
<tomcat.port>8282</tomcat.port>
</properties>

<dependencies>
Expand Down Expand Up @@ -239,15 +239,6 @@
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>tomcat</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down Expand Up @@ -357,6 +348,16 @@
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<hostName>localhost</hostName>
<port>${tomcat.port}</port>
<path>/eighty</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down Expand Up @@ -429,7 +430,7 @@
<phase>integration-test</phase>
<configuration>
<arguments>--no-color</arguments>
<arguments>p:test --p:port=${protractor.port}</arguments>
<arguments>p:test --p:port=${tomcat.port}</arguments>
</configuration>
</execution>
<execution>
Expand All @@ -444,7 +445,24 @@
</execution>
</executions>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<path>/eightytest</path>
<fork>true</fork>
</configuration>
<executions>
<execution>
<id>tomcat-run-war-only</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war-only</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin}</version>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/epam/eighty/service/DBPopulatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface DBPopulatorService {

void populate() throws IOException;

void clean() throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.epam.eighty.service.impl;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import com.epam.eighty.service.DBPopulatorService;
Expand All @@ -16,13 +17,24 @@ public class DBPopulatorServiceImpl implements DBPopulatorService {

@Autowired
private GraphDatabaseService graphDatabaseService;

@Value("classpath:scripts/data.cypher")
private Resource createScriptResource;

private static final String DELETE_SCRIPT = "START n=node(*) OPTIONAL MATCH (n)-[r]-() delete n,r;";

@Override
public void populate() throws IOException {
String cypherScript = FileUtils.readFileToString(new File(getClass().getClassLoader().getResource("scripts/data.cypher").getFile()));
String cypherScript = FileUtils.readFileToString(createScriptResource.getFile());

ExecutionEngine engine = new ExecutionEngine(graphDatabaseService);
engine.execute(cypherScript);
}

@Override
public void clean() throws IOException {
ExecutionEngine engine = new ExecutionEngine(graphDatabaseService);
engine.execute(DELETE_SCRIPT);
}

}
47 changes: 47 additions & 0 deletions src/main/java/com/epam/eighty/web/api/DBPopulatorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.epam.eighty.web.api;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.codahale.metrics.annotation.Timed;
import com.epam.eighty.service.DBPopulatorService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;

@Api(value = "/db", description = "All operations for database population")
@Controller
@RequestMapping("/db")
@Profile({"dev", "test"})
public class DBPopulatorController {

@Autowired
private DBPopulatorService dbPopulatorService;

@ApiOperation(value = "Reload database", notes = "Reload database", httpMethod = "GET")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Request processing failed") })
@Timed
@RequestMapping(value = "/reload", method = RequestMethod.GET)
@Caching(evict = {
@CacheEvict(value = "topic", allEntries = true),
@CacheEvict(value = "question", allEntries = true),
@CacheEvict(value = "tag", allEntries = true),
@CacheEvict(value = "customer", allEntries = true)
})
public void reloadDataBase(final HttpServletResponse response) throws IOException {
dbPopulatorService.clean();
dbPopulatorService.populate();
response.setStatus(HttpServletResponse.SC_OK);
}

}
6 changes: 6 additions & 0 deletions src/main/resources/scripts/data.cypher
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ create (n4:Topic:_Topic {title:'SQL'})
create (n5:Topic:_Topic {title:'HQL'})
create (n6:Topic:_Topic {title:'Java'})
create (n7:Topic:_Topic {title:'Language basics'})
create (n8:Topic:_Topic {title:'Empty topic'})

create (t1:Topic:_Topic {title:'Object, class packaging'})
create (t2:Topic:_Topic {title:'Keywords'})
Expand All @@ -21,6 +22,7 @@ create (q3:Question:_Question {question:'What is Singleton class?'})
create (q4:Question:_Question {question:'List the three steps for creating an object for a class?'})
create (q5:Question:_Question {question:'What is the default value of float and double datatype in Java?'})
create (q6:Question:_Question {question:'What is a static variable?'})
create (q7:Question:_Question {question:'Fake question'})

create (tag1:Tag:_Tag {tag:'object'})
create (tag2:Tag:_Tag {tag:'variable'})
Expand All @@ -37,6 +39,7 @@ create (c2:Customer:_Customer {name:'Customer2'})

create (n0)-[:contains]->(n1)
create (n0)-[:contains]->(n2)
create (n0)-[:contains]->(n8)
create (n2)-[:contains]->(n3)
create (n3)-[:contains]->(n4)
create (n3)-[:contains]->(n5)
Expand All @@ -57,6 +60,7 @@ create (t1)-[:contains]->(q3)
create (t1)-[:contains]->(q4)
create (t1)-[:contains]->(q5)
create (t1)-[:contains]->(q6)
create (n2)-[:contains]->(q7)

create (q1)-[:has]->(tag1)
create (q2)-[:has]->(tag2)
Expand All @@ -70,8 +74,10 @@ create (q5)-[:has]->(tag7)
create (q5)-[:has]->(tag8)
create (q6)-[:has]->(tag9)
create (q6)-[:has]->(tag2)
create (q7)-[:has]->(tag1)

create (q1)-[:has]->(c1)
create (q2)-[:has]->(c1)
create (q3)-[:has]->(c2)
create (q3)-[:has]->(c2)
create (q7)-[:has]->(c2)
Loading