Skip to content

Commit

Permalink
NashTech-Labs#27 conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushil committed Mar 31, 2015
2 parents 6e5d239 + 61cbdba commit 0c769f5
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 146 deletions.
43 changes: 23 additions & 20 deletions app/Global.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import java.io.File
import java.sql.Date
import scala.slick.driver.PostgresDriver.simple._
import com.typesafe.config.ConfigFactory
import play.api._
import java.io.File
import utils.Connection
Expand All @@ -9,6 +13,13 @@ import model.repository.ModelRepository.models
import model.repository.BrandRepository.brands
import model.repository.MobileRepository.mobiles
import model.repository.AuditRepository.audits
import play.api.mvc.RequestHeader
import play.mvc._
import org.omg.CosNaming.NamingContextPackage.NotFound
import views.html.defaultpages.notFound
import play.api.mvc.Action
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

object Global extends GlobalSettings {

Expand All @@ -25,33 +36,25 @@ object Global extends GlobalSettings {
val secretKey = Play.application.configuration.getString("aws_secret_key")
val userId = Play.application.configuration.getString("smtp.user")
val password = Play.application.configuration.getString("smtp.password")

Connection.databaseObject.withSession { implicit session: Session =>
if (MTable.getTables("brands").list.isEmpty) {
brands.ddl.create
Logger.info("Table brand created in database")
}

if (MTable.getTables("models").list.isEmpty) {
models.ddl.create
Logger.info("Table brand created in database")
try {
Connection.databaseObject.withSession { implicit session: Session =>
(brands.ddl ++ models.ddl ++ mobiles.ddl ++ audits.ddl).create
Logger.info("All tables have been created")
}

if (MTable.getTables("mobiles").list.isEmpty) {
mobiles.ddl.create
Logger.info("Table brand created in database")
}
if (MTable.getTables("audits").list.isEmpty) {
audits.ddl.create
Logger.info("Table brand created in database")
} else
} catch {
case ex: Exception => Logger.info("please provide csvs in conf" + ex.printStackTrace())

Logger.info("Table already exists in database")

}
}

override def onStop(app: Application): Unit = {
Logger.info("Application shutdown.......")

}
override def onHandlerNotFound(request: RequestHeader) = {
Future{
play.api.mvc.Results.Ok(views.html.errorPage("page not found"))
}
}
}
1 change: 0 additions & 1 deletion app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ def javascriptRoutes: Action[play.api.mvc.AnyContent] = Action { implicit reques
routes.javascript.AdminController.changeMobileRegType)).as("text/javascript")
}
}

object Application extends Application
2 changes: 1 addition & 1 deletion app/controllers/MobileController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class MobileController(mobileRepo: MobileRepository, brandRepo: BrandRepository,
case Right(Some(id)) =>
Redirect(routes.MobileController.modelRegistrationForm).flashing("SUCCESS" -> Messages("messages.mobile.model.added.success"))
case Right(None) =>
Redirect(routes.MobileController.modelRegistrationForm).flashing("SUCCESS" -> Messages("messages.mobile.model.added.error"))
Redirect(routes.MobileController.modelRegistrationForm).flashing("ERROR" -> Messages("messages.mobile.model.added.error"))
case _ =>
Redirect(routes.MobileController.modelRegistrationForm).flashing("ERROR" -> Messages("messages.mobile.model.added.error"))
}
Expand Down
17 changes: 9 additions & 8 deletions app/utils/S3Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ trait S3UtilComponent {
* Store file to standard bucket on S3
*/
def store(documentName: String, fileToSave: File) = {
try {
amazonS3Client.putObject(bucketName, documentName, fileToSave)
} catch {
case ex: Exception => Logger.error(ex.getMessage(), ex); false
}
try {
amazonS3Client.putObject(bucketName, documentName, fileToSave)
} catch {
case ex: Exception => Logger.error(ex.getMessage(), ex); false
}
}

/**
* Delete file from standard bucket on S3
*/
def delete(fileKeyName: String):Boolean = {
def delete(fileKeyName: String): Boolean = {
try {
amazonS3Client.deleteObject(bucketName, fileKeyName)
true
} catch {
case ex: Exception => Logger.error(ex.getMessage(), ex)
false
case ex: Exception =>
Logger.error(ex.getMessage(), ex)
false
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/views/errorPage.scala.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@(message: String)
@main("Welcome to Play",user=None) {

<div >
<div class ="container">
<div class="page">
<h3 class="alert-error">@message</h3>
<h1> 404: Page Not Found</h1>
<a class="navbar-brand" href="/">MCWS Home</a>
</div>
</div>
}
59 changes: 40 additions & 19 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=436035873185298";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=436035873185298";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Wrap all page content here -->
<div id="wrap" class="margin">
Expand All @@ -43,35 +45,54 @@

<!-- Place this tag after the last share tag. -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
(function() {
var po = document
.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document
.getElementsByTagName('script')[0];
s.parentNode
.insertBefore(
po,
s);
})();
</script>
<!-- Place this tag where you want the widget to render. -->
<div class="g-follow" data-annotation="bubble" data-height="24" data-href="//plus.google.com/101596762455378096324" data-rel="publisher">
</div>

<!-- Place this tag after the last widget tag. -->
<script type="text/javascript">
(function() {
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
})();
</script>
<script src="//platform.linkedin.com/in.js" type="text/javascript">
lang: en_US
</script>
lang: en_US
</script>
<script type="IN/Share" data-url="http://www.mycellwasstolen.com/" data-counter="right">
</script>
<span class="fb-like" data-href="https://www.facebook.com/mycellwasstolen.mcws" data-width="200" data-show-faces="false" data-send="true"></span>
<a href="https://twitter.com/mycellwasstolen" class="twitter-follow-button" data-show-count="true" data-size="large">Follow @{"@MCWS"}</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<script>
!function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/
.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + '://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'twitter-wjs');
</script>
</div>
}

Expand Down
4 changes: 2 additions & 2 deletions conf/dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ db.default.password="postgres"
smtp.password="my_password"

# Enable Email and Twitter Posts
tweetsWithEmail.post=false

Tweet.post=false
Email.send = false
#AWS_CREDENTIALS
aws_bucket_name="my_bucket_name"
aws_access_key="my_access_key"
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ POST /createMobileModel controllers.MobileController.saveModel

#audit
GET /registrationRecord controllers.AuditController.getRegistrationRecordsByYear(date:String)
GET /auditpage controllers.AuditController.auditPage
GET /auditpage controllers.AuditController.auditPage
POST /admin/auditIMEID controllers.AuditController.getTimestampByIMEI
GET /admin/auditAllRecords controllers.AuditController.getAllTimestamp
# Map static resources from the /public folder to the /assets URL path
Expand Down
8 changes: 4 additions & 4 deletions conf/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ db.default.password=""
smtp.host=mock

#AWS_CREDENTIALS
aws_bucket_name="my_bucket_name"
aws_access_key="my_access_key"
aws_secret_key="my_secret_key"
aws_bucket_name="aws_bucket_name"
aws_access_key="aws_access_key"
aws_secret_key="aws_secret_key"

#Disable twitter and email
tweetsWithEmail.post=false
tweetsWithEmail.post=false
2 changes: 1 addition & 1 deletion test/Router/RouterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ redirectLocation(result) must beSome.which(_ == "/admin/mobiles?status=pending")

"redirect to audit page" in {
running(FakeApplication()) {
val Some(result) = route(FakeRequest(GET, "/admin/auditpage"))
val Some(result) = route(FakeRequest(GET, "/auditpage"))
status(result) must equalTo(303)
}
}
Expand Down
43 changes: 3 additions & 40 deletions test/controllers/AdminControllerTestCases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import play.api.test.Helpers._
import play.api.test.FakeRequest
import play.api.mvc.Security
import utils._
import play.api.mvc.Security
import java.util.Date
import java.util.Calendar

class AdminControllerTestCases extends Specification with Mockito {

Expand All @@ -34,7 +37,6 @@ class AdminControllerTestCases extends Specification with Mockito {
val getAllMobilesWithBrand: List[(Mobile, String, String)] = List(mobileWithBrand)
val audit = List(Audit("864465028854206", new java.sql.Timestamp(new java.util.Date().getTime), Some(1)))
val user = User("admin", "knol2013")

val mockedMail = mock[MailUtil]
val mockedS3Util = mock[S3UtilComponent]
val mockedMobilRepo = mock[MobileRepository]
Expand Down Expand Up @@ -208,43 +210,4 @@ class AdminControllerTestCases extends Specification with Mockito {
contentType(result) must beSome("text/plain")
}
}

"AdminControllerTesting: auditPage" in {
running(FakeApplication()) {
Cache.set("admin", user)
val result = adminController.auditPage(FakeRequest().withSession(Security.username -> "admin"))
status(result) must equalTo(200)
contentType(result) must beSome("text/html")
}
}

"AdminControllerTesting: getTimestampByIMEI -> with invalid form data" in {
running(FakeApplication()) {
Cache.set("admin", user)
when(mockedAuditRepo.getAllTimestampsByIMEID("864465028854206")).thenReturn(audit)
val result = adminController.getTimestampByIMEI(FakeRequest())
status(result) must equalTo(200)
contentType(result) must beSome("text/html")
}
}

"AdminControllerTesting: getTimestampByIMEI -> with valid form data" in {
running(FakeApplication()) {
Cache.set("admin", user)
when(mockedAuditRepo.getAllTimestampsByIMEID("864465028854206")).thenReturn(List())
val result = adminController.getTimestampByIMEI(FakeRequest().withFormUrlEncodedBody("imeiMeid" -> "864465028854206").withSession(Security.username -> "admin"))
status(result) must equalTo(200)
contentType(result) must beSome("text/html")
}
}

"AdminControllerTesting: getAllTimestamp" in {
running(FakeApplication()) {
Cache.set("admin", user)
when(mockedAuditRepo.getAllTimestamps).thenReturn(audit)
val result = adminController.getAllTimestamp(FakeRequest().withSession(Security.username -> "admin"))
status(result) must equalTo(200)
contentType(result) must beSome("text/html")
}
}
}
14 changes: 9 additions & 5 deletions test/repository/RepositoryTest/AuditRepoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import model.repository.Audit
import play.api.test.FakeApplication
import play.api.test.Helpers._
import model.repository.AuditRepository
import java.util.Calendar
class AuditRepoTest extends FunSuite {
val calender = Calendar.getInstance
val now: java.util.Date = calender.getTime
val timeStamp = new java.sql.Timestamp(now.getTime())
val auditTimestamp = Audit("123456789012345", "25/03/15 23:50", Some(1))
val auditTimestamp = Audit("123456789012345", timeStamp, Some(1))
//Tests insertion of a timeStamp
test("AuditRepository: insert an Audit Record with Imeid and timestamp") {
Expand All @@ -27,15 +31,15 @@ class AuditRepoTest extends FunSuite {
assert(returnedValue === List(auditTimestamp))
}
}
//Test listing of all TimeStamps
test("AuditRepository: list all timestamps") {
test("AuditRepository: list all timestamps") {
running(FakeApplication()) {
AuditRepository.insertTimestamp(auditTimestamp)
AuditRepository.insertTimestamp(auditTimestamp)
val returnedValue = AuditRepository.getAllTimestamps
assert(returnedValue === List(auditTimestamp,Audit("123456789012345", "25/03/15 23:50", Some(2))))
assert(returnedValue === List(auditTimestamp, Audit("123456789012345", timeStamp, Some(2))))
}
}
}*/
}*/
4 changes: 2 additions & 2 deletions test/repository/RepositoryTest/BrandRepoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.scalatest.BeforeAndAfterAll
class BrandRepoTest extends FunSuite {
val brand = Brand("nokia", "12-17-2013",Some(1))
val brand = Brand("nokia",Some(1))
//Tests Brand Insertion
test("BrandRepository: insert a brand successfully") {
Expand Down Expand Up @@ -60,4 +60,4 @@ class BrandRepoTest extends FunSuite {
}
}
*/
*/
Loading

0 comments on commit 0c769f5

Please sign in to comment.