Skip to content

Commit

Permalink
Code refractored + Logging level added.
Browse files Browse the repository at this point in the history
  • Loading branch information
gitorko committed Feb 11, 2016
1 parent 7caadd5 commit ca99e1c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ If you are using DB authentication insert this row.
INSERT INTO `excord`.`ec_user` (`id`, `username`, `name`, `password`, `role`, `enabled`, `created_date`,`email`)
VALUES ('1', 'admin', 'admin', 'manager', 'USER', '1', NOW(),'test@blackhole.com');
```
### Log Monitoring
tail -f excord.log
grep 'GET' access_log.*.log | egrep -v "(.gif|.jpg|.png|.swf|.ico|.txt|.xml|.css|.js|.rss)"

### Screenshots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ public String requirementDelete(Model model, HttpSession session, HttpServletReq

Long parentId = reqObj.getParentId().getId();
String reqName = reqObj.getName();
String reqSlug = reqObj.getSlug();
rDao.delete(reqObj);
historyUtil.addHistory("Deleted requirement: [" + reqName + "]", reqObj.getSlug(), request, session);
historyUtil.addHistory("Deleted requirement: [" + reqName + "]", reqSlug, request, session);
session.setAttribute("flashMsg", "Successfully deleted requirement!");
return "redirect:/requirement?reqId=" + parentId;

Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/deem/excord/controller/TestCaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ public String testCaseAddFolder(Model model, HttpSession session, HttpServletReq
childFolder.setSlug(BizUtil.INSTANCE.getSlug());
childFolder.setName(folderName);
childFolder.setParentId(parentFolder);
historyUtil.addHistory("Added folder: [" + folderName + "] under [" + parentFolder.getName() + "]", parentFolder.getSlug(), request, session);
tfDao.save(childFolder);
historyUtil.addHistory("Added folder: [" + folderName + "] under [" + parentFolder.getName() + "]", parentFolder.getSlug(), request, session);
return "redirect:/testcase?nodeId=" + parentFolder.getId();
}

Expand All @@ -247,8 +247,8 @@ public String testCaseTestPlanLink(Model model, HttpServletRequest request, Http
if (tcObj.getEnabled()) {
//Dont map disabled test cases.
enabledTcPresent = true;
historyUtil.addHistory("Linked TestPlan : [" + tpObj.getName() + "] with TestCase: [" + tcObj.getName() + "]", tpObj.getSlug(), request, session);
tptcDao.save(tptcMap);
historyUtil.addHistory("Linked TestPlan : [" + tpObj.getName() + "] with TestCase: [" + tcObj.getName() + "]", tpObj.getSlug(), request, session);
} else {
disabledTcPresent = true;
LOGGER.info("Cant link disabled test case: [{}:{}] to test plan: [{}:{}]", tcObj.getId(), tcObj.getName(), tpObj.getId(), tpObj.getName());
Expand Down Expand Up @@ -277,8 +277,8 @@ public String testcaseEnable(Model model, HttpServletRequest request, HttpSessio
for (Long testCaseId : testcaseChkLst) {
EcTestcase tcObj = tcDao.findOne(testCaseId);
tcObj.setEnabled(true);
historyUtil.addHistory("Enabled testcase : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
tcDao.save(tcObj);
historyUtil.addHistory("Enabled testcase : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
}
session.setAttribute("flashMsg", "Successfully enabled testcase!");
return "redirect:/testcase?nodeId=" + nodeId;
Expand All @@ -290,8 +290,8 @@ public String testcaseDisable(Model model, HttpServletRequest request, HttpSessi
for (Long testCaseId : testcaseChkLst) {
EcTestcase tcObj = tcDao.findOne(testCaseId);
tcObj.setEnabled(false);
historyUtil.addHistory("Disabled testcase : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
tcDao.save(tcObj);
historyUtil.addHistory("Disabled testcase : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
}
session.setAttribute("flashMsg", "Successfully disabled testcase!");
return "redirect:/testcase?nodeId=" + nodeId;
Expand All @@ -302,8 +302,10 @@ public String testcaseDelete(Model model, HttpServletRequest request, HttpSessio

for (Long testCaseId : testcaseChkLst) {
EcTestcase tcObj = tcDao.findOne(testCaseId);
historyUtil.addHistory("Deleted testcase : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
String testcaseName = tcObj.getName();
String testcaseSlug = tcObj.getSlug();
tcDao.delete(tcObj);
historyUtil.addHistory("Deleted testcase : [" + testcaseName + "]", testcaseSlug, request, session);
}
session.setAttribute("flashMsg", "Successfully deleted testcase!");
return "redirect:/testcase?nodeId=" + nodeId;
Expand Down Expand Up @@ -331,8 +333,10 @@ public String testcaseDeleteFolder(Model model, HttpServletRequest request, Http

if (currentNode.getParentId() != null) {
Long parentId = currentNode.getParentId().getId();
historyUtil.addHistory("Folder Deleted : [" + currentNode.getName() + "]", currentNode.getSlug(), request, session);
String folderName = currentNode.getName();
String folderSlug = currentNode.getSlug();
tfDao.delete(currentNode);
historyUtil.addHistory("Folder Deleted : [" + folderName + "]", folderSlug, request, session);
session.setAttribute("flashMsg", "Successfully deleted folder!");
return "redirect:/testcase?nodeId=" + parentId;
} else {
Expand Down Expand Up @@ -391,8 +395,8 @@ public String testcaseBulkSave(Model model, HttpServletRequest request, HttpSess
if (tproduct != null) {
tcObj.setProduct(tproduct);
}
historyUtil.addHistory("Testcase Bulk Updated : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
tcDao.save(tcObj);
historyUtil.addHistory("Testcase Bulk Updated : [" + tcObj.getName() + "]", tcObj.getSlug(), request, session);
}
return "redirect:/testcase?nodeId=" + nodeId;
}
Expand All @@ -414,9 +418,11 @@ public String testcasePaste(Model model, HttpServletRequest request, HttpSession
for (String tc : clipboardTcLst) {
EcTestcase tcObj = tcDao.findOne(Long.parseLong(tc));
EcTestfolder newNode = tfDao.findOne(nodeId);
historyUtil.addHistory("Moved testcase : [" + tcObj.getName() + "] from [" + tcObj.getFolderId().getName() + " ] to [" + newNode.getName() + " ]", tcObj.getSlug(), request, session);
tcObj.setFolderId(newNode);
String oldFolder = tcObj.getFolderId().getName();
String newFolder = newNode.getName();
tcDao.save(tcObj);
historyUtil.addHistory("Moved testcase : [" + tcObj.getName() + "] from [" + oldFolder + " ] to [" + newFolder + " ]", tcObj.getSlug(), request, session);
}
session.setAttribute("clipboardTc", null);
session.setAttribute("flashMsg", "Testcases moved successfully!");
Expand All @@ -430,9 +436,12 @@ public String testcaseRenameFolder(Model model, HttpServletRequest request, Http

EcTestfolder currenNode = tfDao.findOne(nodeId);
if (currenNode.getParentId() != null) {
String currentName = currenNode.getName();
String currentSlug = currenNode.getSlug();
String newName = newNodeName;
currenNode.setName(newNodeName);
historyUtil.addHistory("Folder Renamed from : [" + currenNode.getName() + "] to [" + newNodeName + "]", currenNode.getSlug(), request, session);
tfDao.save(currenNode);
historyUtil.addHistory("Folder Renamed from : [" + currentName + "] to [" + newName + "]", currentSlug, request, session);
session.setAttribute("flashMsg", "Successfully renamed folder!");
} else {
session.setAttribute("flashMsg", "Cant rename root folder!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ public String editTestplan(Model model, @RequestParam(value = "testplanId", requ
public String deleteTestplan(HttpSession session, HttpServletRequest request, Model model, @RequestParam(value = "testplanId", required = true) Long testplanId) {

EcTestplan tpObj = tpDao.findOne(testplanId);
String tpName = tpObj.getName();
String tpSlug = tpObj.getSlug();
tpDao.delete(tpObj);
historyUtil.addHistory("Deleted testplan: [" + tpObj.getName() + "]", tpObj.getSlug(), request, session);
historyUtil.addHistory("Deleted testplan: [" + tpName + "]", tpSlug, request, session);
return "redirect:/testplan";
}

Expand Down Expand Up @@ -281,8 +283,8 @@ public String testCaseTestPlanMapRemove(Model model, HttpServletRequest request,
EcTestcase tc = tcDao.findOne(testCaseId);
EcTestplan tp = tpDao.findOne(testPlanId);
EcTestplanTestcaseMapping tptcMap = tptcDao.findByTestplanIdAndTestcaseId(tp, tc);
historyUtil.addHistory("UnLinked TestPlan : [" + tp.getName() + "] with TestCase: [" + tc.getName() + "] ", tp.getSlug(), request, session);
tptcDao.delete(tptcMap);
historyUtil.addHistory("UnLinked TestPlan : [" + tp.getName() + "] with TestCase: [" + tc.getName() + "] ", tp.getSlug(), request, session);
}
session.setAttribute("flashMsg", "Successfully Unlinked!");
return "redirect:/testplan_view?testplanId=" + testPlanId;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ spring.freemarker.check-template-location=true
spring.freemarker.enabled=true
spring.freemarker.prefer-file-system-access=true

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=common
server.tomcat.basedir=.
server.tomcat.accesslog.directory=.

#spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=false
Expand Down
28 changes: 15 additions & 13 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
<property name="LOG_PATH" value="." />
<property name="LOG_FILE" value="excord.log" />

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>excord.log</file>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>excord.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

<root level="info">
<appender-ref ref="FILE" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ROLLING" />
</root>

</configuration>

0 comments on commit ca99e1c

Please sign in to comment.