HtmlUtil.java
public static String testableHtml (
PageData pageData,
boolean includeSuiteSetup
) throws Exception {
WikiPage wikiPage = pageData.getWikiPage();
StringBuffer buffer = new StringBuffer();
if (pageData.hasAttribute("Test")) {
if (includeSuiteSetup) {
WikiPage suiteSetup =
PageCrawlerImpl.getInheritedPage(
SuiteResponder.SUITE_SETUP_NAME, wikiPage
);
if (suiteSetup != null) {
WikiPagePath pagePath = suiteSetup.getPageCrawler().getFullPath(suiteSetup);
String pagePathName = PathParser.render(pagePath);
buffer.append("!include -setup .")
.append(pagePathName)
.append("\n");
}
}
WikiPage setup = PageCrawlerImpl.getInheritedPage("SetUp", wikiPage);
if (setup != null) {
WikiPagePath setupPath = wikiPage.getPageCrawler().getFullPath(setup);
String setupPathName = PathParser.render(setupPath);
buffer.append("!include -setup .")
.append(setupPathName)
.append("\n");
}
}
buffer.append(pageData.getContent());
if (pageData.hasAttribute("Test")) {
WikiPage teardown = PageCrawlerImpl.getInheritedPage("TearDown", wikiPage);
if (teardown != null) {
WikiPagePath tearDownPath = wikiPage.getPageCrawler().getFullPath(teardown);
String tearDownPathName = PathParser.render(tearDownPath);
buffer.append("\n")
.append("!include -teardown .")
.append(tearDownPathName)
.append("\n");
}
if (includeSuiteSetup) {
WikiPage suiteTeardown = PageCrawlerImpl.getInheritedPage(SuiteResponder.SUITE_TEARDOWN_NAME, wikiPage);
if (suiteTeardown != null) {
WikiPagePath pagePath = suiteTeardown.getPageCrawler().getFullPath (suiteTeardown);
String pagePathName = PathParser.render(pagePath);
buffer.append("!include -teardown .")
.append(pagePathName)
.append("\n");
}
}
}
pageData.setContent(buffer.toString());
return pageData.getHtml();
}
์ ์ฝ๋๋ ์ถ์ํ ์์ค๋ ๋๋ฌด ๋ค์ํ๊ณ , ์ฝ๋๋ ๋๋ฌด ๊ธธ๋ค. ๋ ๊ฒน์ผ๋ก ์ค์ฒฉ๋ if๋ฌธ์ ์ด์ํ ํ๋๊ทธ๋ฅผ ํ์ธํ๊ณ , ์ด์ํ ๋ฌธ์์ด์ ์ฌ์ฉํ๋ฉฐ, ์ด์ํ ํจ์๋ฅผ ํธ์ถํ๋ค.
๋๋ฌด ์ดํดํ๊ธฐ ์ด๋ ต๋ค!!
์ ์ฝ๋๋ฅผ ๋ฆฌํฉํฐ๋งํด๋ณด์.
public static String renderPageWithSetupsAndTeardowns (
PageData pageData, boolean isSuite
) throws Exception {
boolean isTestPage = pageData.hasAttribute("Test");
if (isTestPage) {
WikiPage testPage = pageData.getWikiPage();
StringBuffer newPageContent = new StringBuffer();
includeSetupPages(testPage, newPageContent, isSuite);
pageData.setContent(newPageContent.toString());
}
return pageData.getHtml();
}
์ ์ฝ๋๋ฅผ ๋ณด๊ณ 100% ์ดํดํ์ง๋ ๋ชปํด๋, ํจ์๊ฐ ์ค์ (setup) ํ์ด์ง์ ํด์ (teardown) ํ์ด์ง๋ฅผ ํ ์คํธ ํ์ด์ง์ ๋ฃ์ ํ ํด๋น ํ ์คํธ ํ์ด์ง๋ฅผ HTML๋ก ๋ ๋๋งํ๋ค๋ ์ฌ์ค์ ์ง์ํ ์ ์๋ค.
์ ํจ์๊ฐ ์ดํดํ๊ธฐ ์ฌ์ด ์ด์ ๊ฐ ๋ฌด์์ผ๊น? ์๋๋ฅผ ๋ถ๋ช ํ ํํํ๋ ํจ์๋ฅผ ์ด๋ป๊ฒ ๊ตฌํํ ์ ์์๊น? ํจ์์ ์ด๋ค ์์ฑ์ ๋ถ์ฌํด์ผ ์ฒ์ ์ฝ๋ ์ฌ๋์ด ํ๋ก๊ทธ๋จ ๋ด๋ถ๋ฅผ ์ง๊ด์ ์ผ๋ก ํ์ ํ ์ ์์๊น?
- ํจ์๋ ์งง๊ณ ๊ฐ๊ฒฐํ ์๋ก ์ข๋ค.
HtmlUtil.java re-refactoring
public static String renderPageWithSetupsAndTeardowns(
PageData pageData, boolean isSuite) throws Exception {
if (isTestPage(pageData))
includeSetupAndTeardownPages(pageData, isSuite);
return pageData.getHtml();
}
)
HtmlUtils๋ฅผ ๋ฆฌํฉํ ๋งํ ์ฝ๋๋ ์์ ๊ฐ์ด ๋ ๊ฐ๊ฒฐํ๊ฒ ๋ง๋ค ์ ์๋ค!
- ์์ฆ์ ํ ํ๋ฉด์ ๊ธ๊ผด์ ์กฐ์ ํ๋ฉด ๊ฐ๋ก 150์ ์ธ๋ก 100์ค๋ ๋ค์ด๊ฐ๋ค. ๋ฐ๋ผ์ ๊ฐ๋ก 150์๋ฅผ ๋์ด์๋ ์๋๋ค. (๋ฐ๋์ ํ ํ๋ฉด์ ๋ค์ด๊ฐ์ผ ํ๋ค.)
- ํจ์๋ 100์ค์ ๋์ด์๋ ์๋๋ค. ์๋, 20์ค๋ ๊ธธ๋ค!
If ๋ฌธ / else ๋ฌธ / while๋ฌธ์ ๋ค์ด๊ฐ๋ ๋ธ๋ก์ ํ ์ค์ด์ด์ผ ํ๋ค.
- ๋ธ๋ก ์์์ ํธ์ถํ๋ ํจ์ ์ด๋ฆ์ ์ ์ ํ ์ง๋๋ค๋ฉด, ์ฝ๋๋ฅผ ์ดํดํ๊ธฐ๋ ์ฌ์์ง๋ค.
์ค์ฒฉ ๊ตฌ์กฐ๊ฐ ์๊ธธ๋งํผ ํจ์๊ฐ ์ปค์ ธ์๋ ์๋๋ค.
๊ทธ๋ฌ๋ฏ๋ก ํจ์์์ ๋ค์ฌ์ฐ๊ธฐ ์์ค์ 1๋จ์ด๋ 2๋จ์ ๋์ด์๋ฉด ์๋๋ค. ๊ทธ๋์ผ ํจ์๋ ์ฝ๊ณ ์ดํดํ๊ธฐ ์ฌ์์ง๋ค.
ํจ์๋ ํ ๊ฐ์ง๋ฅผ ํด์ผ ํ๋ค. ๊ทธ ํ ๊ฐ์ง๋ฅผ ์ ํด์ผ ํ๋ค. ๊ทธ ํ ๊ฐ์ง๋ง์ ํด์ผ ํ๋ค.
- ์ด๋ป๊ฒ ํจ์๊ฐ ํ ๊ฐ์ง๋ง ํ๊ณ ์๋์ง ํ๋จํ ์ ์์๊น?
- ๋จ์ํ ๋ค๋ฅธ ํํ์ด ์๋๋ผ ์๋ฏธ ์๋ ์ด๋ฆ์ผ๋ก ๋ค๋ฅธ ํจ์๋ฅผ ์ถ์ถํ ์ ์๋ค๋ฉด ๊ทธ ํจ์๋ ์ฌ๋ฌ ์์ ์ ํ๋ ์ ์ด๋ค.
- ํ ๊ฐ์ง ์์ ๋ง ํ๋ ํจ์๋ ์์ฐ์ค๋ฝ๊ฒ ์ฌ๋ฌ ์น์ ์ผ๋ก ๋๋๊ธฐ ์ด๋ ต๋ค.
- ํจ์๊ฐ ํ์คํ 'ํ ๊ฐ์ง' ์์ ๋ง ํ๋ ค๋ฉด ํจ์ ๋ด ๋ชจ๋ ๋ฌธ์ฅ์ ์ถ์ํ ์์ค์ด ๋์ผํด์ผ ํ๋ค.
- ํ ํจ์ ๋ด ์ ์ถ์ํ ์์ค์ ์์ผ๋ฉด ์ฝ๋๋ฅผ ์ฝ๋ ์ฌ๋์ด ํท๊ฐ๋ฆฐ๋ค. ํน์ ํํ์ด ๊ทผ๋ณธ ๊ฐ๋ ์ธ์ง ์๋๋ฉด ์ธ๋ถ ์ฌํญ์ธ์ง ๊ตฌ๋ถํ๊ธฐ ์ด๋ ค์ด ํ์ด๋ค.
- ๊ทผ๋ณธ ๊ฐ๋ ๊ณผ ์ธ๋ถ ์ฌํญ์ ๋ค์๊ธฐ ์์ํ๋ฉด, ๊นจ์ด์ง ์ฐฝ๋ฌธ์ฒ๋ผ ์ฌ๋๋ค์ด ํจ์์ ์ธ๋ถ์ฌํญ์ ์ ์ ๋ ์ถ๊ฐํ๋ค.
- ์ฝ๋๋ ์์์ ์๋๋ก ์ด์ผ๊ธฐ์ฒ๋ผ ์ฝํ์ผ ์ข๋ค. ํ ํจ์ ๋ค์์๋ ์ถ์ํ ์์ค์ด ํ ๋จ๊ณ ๋ฎ์ ํจ์๊ฐ ์จ๋ค. ์ฆ, ์์์ ์๋๋ก ํ๋ก๊ทธ๋จ์ ์ฝ์ผ๋ฉด ํจ์ ์ถ์ํ ์์ค์ด ํ ๋ฒ์ ํ ๋จ๊ณ์ฉ ๋ฎ์์ง๋ค.
- Switch ๋ฌธ์ ์๊ฒ ๋ง๋ค๊ธฐ ์ด๋ ต๋ค.
-
case ๋ถ๊ธฐ๊ฐ ๋จ ๋ ๊ฐ์ธ switch ๋ฌธ๋ ๊ธธ๊ณ , ๋จ์ผ ๋ธ๋ก์ด๋ ํจ์๊ฐ ์ข๋ค.(์๊ฐ์ ์ทจํฅ)
-
๋ํ 'ํ ๊ฐ์ง' ์์ ๋ง ํ๋ switch ๋ฌธ๋ ๋ง๋ค๊ธฐ ์ด๋ ต๋ค. ๋ณธ์ง์ ์ผ๋ก switch ๋ฌธ์ N๊ฐ์ง๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ๋๋ฌธ์ด๋ค.
-
๊ฐ switch ๋ฌธ์ ์จ๊ธฐ๊ณ ์ ๋๋ก ๋ฐ๋ณตํ์ง ์๋ ๋ฐฉ๋ฒ์ ์๋ค. ๋ฌผ๋ก ๋คํ์ฑ์ ์ด์ฉํ๋ค.
public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } }
์ ํจ์๋
ํจ์๊ฐ ๊ธธ๊ณ
,ํ ๊ฐ์ง ์์ ๋ง ์ํํ์ง ์๊ณ
,SRP(Single Responsibility Principle)๋ฅผ ์๋ฐ
ํ๊ณ ,OCP(Open Closeed Principle)
๋ฅผ ์๋ฐํ๋ค๋ ๋ฌธ์ ๊ฐ ์๋ค. ์ฆ, ์๋ก์ด ์ง์ ์ ํ์ ์ถ๊ฐํ ๋๋ง๋ค ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๊ณ ๊ตฌ์กฐ๊ฐ ๋์ผํ ํจ์๊ฐ ๋ฌดํ์ ์กด์ฌํ ์ ์๋ค๋ ๋ฌธ์ ๊ฐ ์๋ค. (ex. isPayday(Employee e, Date date), deliverPay(Employee e, Mone pay) ๋ฑ) ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ switch ๋ฌธ์ ์ถ์ ํฉํ ๋ฆฌ์ ๊ฝ๊ฝ ์จ๊ธด๋ค. ํฉํ ๋ฆฌ๋ switch ๋ฌธ์ ์ฌ์ฉํด ์ ์ ํ Employee ํ์ ํด๋์ค์ ์ธ์คํด์ค๋ฅผ ์์ฑํ๋ค. calculatePay, isPayday, deliverPay ๋ฑ๊ณผ ๊ฐ์ ํจ์๋ Employee ์ธํฐํ์ด์ค๋ฅผ ๊ฑฐ์ณ ํธ์ถ๋๋ค.public abstract class Employee { public abstract boolean isPayday(); public abstract Money calculatePay(); public abstract void deliverPay(Money pay); }
public interface EmployeeFactory { public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType; }
public class EmployeeFactoryImpl { public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType { switch (r.type) { case COMMISSIONED: return new CommissionedEmployee(r); case HOURLY: return new HourlyEmployee(r); case SALARIED: return new SalariedEmployee(r); default: throw new InvalidEmployeeType(r.type); } } }
-
- ex)
testableHtml
->SetupTeardownIncluder.render
- ํจ์๊ฐ ํ๋ ์ผ์ ๋ ์ ํํํ๋ ๊ฒ์ด ํจ์ฌ ์ข์ ์ด๋ฆ์ด๋ค.
- ์ฝ๋๋ฅผ ์ฝ์ผ๋ฉด์ ์ง์ํ๋ ๊ธฐ๋ฅ์ ๊ฐ ๋ฃจํด์ด ๊ทธ๋๋ก ์ํํ๋ค๋ฉด ๊นจ๋ํ ์ฝ๋๋ผ ๋ถ๋ฌ๋ ๋๊ฒ ๋ค.
- ๊ธธ๊ณ ์์ ์ ์ธ ์ด๋ฆ์ด ์งง๊ณ ์ด๋ ค์ด ์ด๋ฆ๋ณด๋ค ์ข๋ค.
- ๊ธธ๊ณ ์์ ์ ์ธ ์ด๋ฆ์ด ๊ธธ๊ณ ์์ ์ ์ธ ์ฃผ์๋ณด๋ค ์ข๋ค.
- ์ด๋ฆ์ ๋ถ์ผ ๋๋ ์ผ๊ด์ฑ์ด ์์ด์ผ ํ๋ค. ๋ชจ๋ ๋ด์์ ํจ์ ์ด๋ฆ์ ๊ฐ์ ๋ฌธ๊ตฌ, ๋ช
์ฌ, ๋์ฌ๋ฅผ ์ฌ์ฉํ๋ค.
- ์) includeSetupAndTeardownPages, includeSetupPages, includeSuiteSetupPage, includeSetupPage ๋ฑ
- ํจ์์์ ์ด์์ ์ธ ์ธ์ ๊ฐ์๋ 0๊ฐ (๋ฌดํญ)์ด๋ค. ๋ค์์ 1๊ฐ(๋จํญ), ๋ค์์ 2๊ฐ(์ดํญ)๋ค. 3๊ฐ(์ผํญ)์ ๊ฐ๋ฅํ ํผํ๋ ํธ์ด ์ข๋ค. 4๊ฐ ์ด์(๋คํญ)์ ํน๋ณํ ์ด์ ๊ฐ ํ์ํ๋ค. ํน๋ณํ ์ด์ ๊ฐ ์์ด๋ ์ฌ์ฉํ๋ฉด ์๋๋ค.
- ํ ์คํธ ๊ด์ ์์ ๋ณด๋ฉด ์ธ์๋ ๋ ์ด๋ ต๋ค. ๊ฐ๊ฐ์ง ์ธ์ ์กฐํฉ์ผ๋ก ํจ์๋ฅผ ๊ฒ์ฆํ๋ ํ ์คํธ ์ผ์ด์ค๋ฅผ ์์ฑํ๋ค๊ณ ํ์ ๋, ์ธ์๊ฐ ์์ผ๋ฉด ๊ฐ๋จํ์ง๋ง ์ธ์๊ฐ 2๊ฐ, 3๊ฐ ๋์ด๊ฐ๋ฉด ์ธ์๋ง๋ค ์ ํจํ ๊ฐ์ผ๋ก ๋ชจ๋ ์กฐํฉ์ ์์ฑํด์ผํ๋ฏ๋ก ํ ์คํธํ๊ธฐ ์๋นํ ๋ถ๋ด์ค๋ฌ์ ์ง๋ค.
- ํจ์์ ์ธ์ 1๊ฐ๋ฅผ ๋๊ธฐ๋ ์ด์ ๋ก ๊ฐ์ฅ ํํ ๊ฒฝ์ฐ๋ ๋ ๊ฐ์ง๋ค.
-
- ์ธ์์ ์ง๋ฌธ์ ๋์ง๋ ๊ฒฝ์ฐ
- ์)
boolean fileExists("MyFile")
-
- ์ธ์๋ฅผ ๋ญ๊ฐ๋ก ๋ณํํด ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ๊ฒฝ์ฐ
- ์)
InputStream fileOpen("Myfile")
-
- ํจ์์ ์ธ์ 1๊ฐ๋ฅผ ๋๊ธฐ์ง๋ง ์ถ๋ ฅ ์ธ์๊ฐ ์๋ ๊ฒฝ์ฐ (์ด๋ฒคํธ)
passwordAttemptFailedNtimes(int attempts)
- ์ด๋ฐ ์ด๋ฒคํธ ์ฑ์ด ์๋ ๊ฒฝ์ฐ ๋จํญ ํจ์์ธ๋ฐ ๋ฐํ ๊ฐ์ด ์๋ ๊ฒฝ์ฐ๋ ๊ฐ๊ธ์ ํผํ๋ค.
- ํ๋๊ทธ ์ธ์๋ฅผ ๋๊ธฐ๋ ๊ด๋ก๋ ํจ์๊ฐ ํ๊บผ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง๋ฅผ ์ฒ๋ฆฌํ๋ค๊ณ ๋๋๊ณ ์๊ธฐํ๋ ๊ฑฐ๋ผ ์ข์ง ์๋ค.
- ์ธ์๊ฐ 2๊ฐ์ธ ํจ์๋ ์ธ์๊ฐ 1๊ฐ์ธ ํจ์๋ณด๋ค ์ดํดํ๊ธฐ ์ด๋ ต๋ค.
- ๋ฌผ๋ก ์ดํญ ํจ์๊ฐ ์ ์ ํ ๊ฒฝ์ฐ๋ ์๋ค. ์)
Point p = new Point(0, 0)
- ์ฆ, ์ธ์ 2๊ฐ๊ฐ ํ ๊ฐ์ ํํํ๋ ๋ ์์์ผ ๊ฒฝ์ฐ ์ ํฉํ๋ค.
- ์ดํญ ํจ์๊ฐ ๋ฌด์กฐ๊ฑด ๋์๋ค๋ ์๋ฆฌ๋ ์๋๋ค. ๋ถ๊ฐํผํ ๊ฒฝ์ฐ๋ ์๊ธฐ์ง๋ง ๊ทธ๋งํผ ์ํ์ด ๋ฐ๋ฅธ๋ค๋ ์ฌ์ค์ ์ดํดํ๊ณ ๊ฐ๋ฅํ๋ฉด ๋จํญํจ์๋ก ๋ฐ๊พธ๋๋ก ์ ์จ์ผ ํ๋ค.
- ์ธ์๊ฐ 3๊ฐ์ธ ํจ์๋ ์ธ์๊ฐ 2๊ฐ์ธ ํจ์๋ณด๋ค ํจ์ฌ ๋ ์ดํดํ๊ธฐ ์ด๋ ต๋ค.
- ์์, ์ฃผ์ถคํ๋ ๊ฒฝ์ฐ, ๋ฌด์๋ก ์ผ๊ธฐ๋๋ ๋ฌธ์ ๊ฐ ๋ ๋ฐฐ ์ด์ ๋์ด๋๋ค.
- ์ธ์๊ฐ 2-3๊ฐ ํ์ํ๋ค๋ฉด ์ผ๋ถ๋ฅผ ๋ ์์ ์ธ ํด๋์ค ๋ณ์๋ก ์ ์ธํ ๊ฐ๋ฅ์ฑ์ ์ง์ด๋ณธ๋ค.
- ์
Circle makeCircle(double x, double y, double radius);
Circle makeCircle(Point center, double radius);
- ๋๋ก๋ ์ธ์ ๊ฐ์๊ฐ ๊ฐ๋ณ์ ์ธ ํจ์๋ ํ์ํ๋ค. String.format ๋ฉ์๋๊ฐ ์ข์ ์๋ค.
String.format("%s worked %.2f hours.", name, hours);
- ํจ์์ ์๋๋ ์ธ์์ ์์์ ์๋๋ฅผ ์ ๋๋ก ํํํ๋ ค๋ฉด ์ข์ ํจ์ ์ด๋ฆ์ด ํ์๋ค.
- ๋จํญ ํจ์๋ ํจ์์ ์ธ์๊ฐ ๋์ฌ/๋ช
์ฌ ์์ ์ด๋ค์ผ ํ๋ค.
- ์)
write(name)
,writeField(name)
- ์)
- ํจ์ ์ด๋ฆ์ ํค์๋๋ฅผ ์ถ๊ฐํ๋ ํ์ (ํจ์ ์ด๋ฆ์ ์ธ์ ์ด๋ฆ์ ๋ฃ๋๋ค.)
- ์)
assertEquals
๋ณด๋คassertExpectedEqualsActual(expected, actual)
์ด ๋ ์ข๋ค. (์ธ์ ์์๋ฅผ ๊ธฐ์ตํ ํ์๊ฐ ์์ด์ง๋ค.)
- ์)
- ๋ถ์ ํจ๊ณผ๋ ๊ฑฐ์ง๋ง์ด๋ค.
- ํจ์์์ ํ ๊ฐ์ง๋ฅผ ํ๊ฒ ๋ค๊ณ ์ฝ์ํ๊ณ ์ ๋จ๋ชฐ๋ ๋ค๋ฅธ ์ง์ ํ๋ ๊ฒ์ ํด๋ก์ด ๊ฑฐ์ง๋ง์ด๋ค.
- ํจ์๋ก ๋์ด์จ ์ธ์๋ ์์คํ ์ ์ญ ๋ณ์๋ฅผ ์์ ํ๋ ๋ฑ
- ๋ง์ ๊ฒฝ์ฐ ์๊ฐ์ ์ธ ๊ฒฐํฉ(temporal coupling)์ด๋ ์์ ์ข ์์ฑ(order dependency)๋ฅผ ์ด๋ํ๋ค.
public class UserValidator {
private Cryptographer cryptographer;
public boolean checkPassword(String userName, String password) {
User user = UserGateway.findByName(userName);
if (user != User.NULL) {
String codedPhrase = user.getPhraseEncodedByPassword();
String phrase = cryptographer.decrypt(codedPhrase, password);
if ("Valid Password".equals(phrase)) {
Session.initialize();
return true;
}
}
return false;
}
}
์ฌ๊ธฐ์ ํจ์๊ฐ ์ผ์ผํค๋ ๋ถ์ ํจ๊ณผ๋ Session.initialize()
ํธ์ถ์ด๋ค. ์ด ํจ์๋ฅผ ํธ์ถํ๋ ์ฌ์ฉ์๋ ์ฌ์ฉ์๋ฅผ ์ธ์ฆํ๋ฉด์ ๊ธฐ์กด ์ธ์
์ ๋ณด๋ฅผ ์ง์๋ฒ๋ฆด ์ํ์ ์ฒํ๋ค.
์ด๋ฐ ๋ถ์ํจ๊ณผ๊ฐ ์๊ฐ์ ์ธ ๊ฒฐํฉ์ ์ด๋ํ๋ค. (์ฆ, ์ธ์
์ ์ด๊ธฐํํด๋ ๊ด์ฐฎ์ ๊ฒฝ์ฐ์๋ง ํธ์ถ์ด ๊ฐ๋ฅํ๋ค.)
๋ฐ๋ผ์ checkPassword
๋ฉ์๋๋ checkPasswordAndInitializeSession
์ด๋ผ๋ ์ด๋ฆ์ด ํจ์ฌ ์ข๋ค.
- ์ธ์๋ฅผ ์ถ๋ ฅ์ผ๋ก ์ฌ์ฉํ๋ ํจ์
- ์)
appendFooter(s);
: ์ธ์ s์ ๋ฐ๋ฅ๊ธ์ ์ฒจ๋ถํ๋ค. (return void)
- ์)
- ๊ฐ์ฒด ์งํฅ ์ธ์ด์์๋ ์ถ๋ ฅ ์ธ์๋ฅผ ์ฌ์ฉํ ํ์๊ฐ ๊ฑฐ์ ์๋ค. ์ถ๋ ฅ ์ธ์๋ก ์ฌ์ฉํ๋ผ๊ณ ์ค๊ณ๋ ๋ณ์๊ฐ
this
์ด๊ธฐ ๋๋ฌธ์ด๋ค. ๋ค์ ๋งํด, ์ ํจ์๋report.appendFooter()
๋ก ํธ์ถํ๋ ๋ฐฉ์์ด ๋ ์ข๋ค. - ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ ฅ ์ธ์๋ฅผ ํผํด์ผ ํ๋ค. ํจ์์์ ์ํ๋ฅผ ๋ณ๊ฒฝํด์ผ ํ๋ค๋ฉด ํจ์๊ฐ ์ํ ๊ฐ์ฒด ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฐฉ์์ ํํ๋ค.
- ํจ์๋ ๋ญ๊ฐ๋ฅผ ์ํํ๊ฑฐ๋ ๋ญ๊ฐ์ ๋ตํ๊ฑฐ๋ ๋ ์ค ํ๋๋ง ํด์ผ ํ๋ค.
- ๊ฐ์ฒด ์ํ๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์๋๋ฉด ๊ฐ์ฒด ์ ๋ณด๋ฅผ ๋ฐํํ๊ฑฐ๋ ๋ ์ค ํ๋๋ค. ๋ ๋ค ํ๋ฉด ํผ๋์ ์ด๋ํ๋ค.
- ์)
public boolean set(String attribute, String value)
: ์ด๋ฆ์ด attribute์ธ ์์ฑ์ ์ฐพ์ ๊ฐ์ value๋ก ์ค์ ํ ํ ์ฑ๊ณตํ๋ฉด true๋ฅผ ๋ฐํํ๊ณ ์คํจํ๋ฉด false๋ฅผ ๋ฐํํ๋ค.- ์ค์ ๋ก ํจ์๋ฅผ ์ฌ์ฉํ ๋
if (set("username", "unclebob"))...
์ ๊ฐ์ ๊ดด์ํ ํ์์ผ๋ก ์ฌ์ฉํ๋ค. ๋ง์น if๋ฌธ๊ณผ ํจ๊ป ์ฝํ์ username ์์ฑ์ด unclebob์ผ๋ก ์ค์ ๋์ด ์๋ค๋ฉด ์ด๋ผ๋ ๋ด์ฉ์ผ๋ก ํด์๋๋ค. - ์์ ๋ช ๋ น์ ์กฐํ๋ฅผ ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ข๋ค.
if (attributeExists("username")) { setAttribute("username", "unclebob"); }
- ์ค์ ๋ก ํจ์๋ฅผ ์ฌ์ฉํ ๋
- ์)
- ๋ช ๋ น ํจ์์์ ์ค๋ฅ ์ฝ๋๋ฅผ ๋ฐํํ๋ ๋ฐฉ์์ ๋ช ๋ น/์กฐํ ๋ถ๋ฆฌ ๊ท์น์ ๋ฏธ๋ฌํ๊ฒ ์๋ฐํ๋ค. ์์นซํ๋ฉด if๋ฌธ์์ ๋ช ๋ น์ ํํ์์ผ๋ก ์ฌ์ฉํ๊ธฐ ์ฌ์ด ํ์ด๋ค.
- ์) if (deletePage(page) == E_OK)`
- ์ ์ฝ๋๋ ๋์ฌ/ํ์ฉ์ฌ ํผ๋์ ์ผ์ผํค์ง ์๋ ๋์ ์ฌ๋ฌ ๋จ๊ณ๋ก ์ค์ฒฉ๋๋ ์ฝ๋๋ฅผ ์ผ๊ธฐํ๋ค. ์ค๋ฅ์ฝ๋๋ฅผ ๋ฐํํ๋ฉด ํธ์ถ์๋ ์ค๋ฅ ์ฝ๋๋ฅผ ๊ณง๋ฐ๋ก ์ฒ๋ฆฌํด์ผ ํ๋ค๋ ๋ฌธ์ ์ ๋ถ๋ชํ๋ค.
- ๋ฐ๋ผ์ ์๋์ ๊ฐ์ด ์ค๋ฅ ์ฝ๋ ๋์ ์์ธ๋ฅผ ์ฌ์ฉํ๋ฉด ์ค๋ฅ ์ฒ๋ฆฌ ์ฝ๋๊ฐ ์๋ ์ฝ๋์์ ๋ถ๋ฆฌ๋๋ฏ๋ก ์ฝ๋๊ฐ ๊น๋ํด์ง๋ค.
try { deletePage(page); registry.deleteReference(page.name); configKeys.deleteKey(page.name.makeKey()); } catch (Exception e) { logger.log(e.getMessage()); }
- try/catch ๋ธ๋ก์ ์ฝ๋ ๊ตฌ์กฐ์ ํผ๋์ ์ผ์ผํค๋ฉฐ, ์ ์ ๋์๊ณผ ์ค๋ฅ ์ฒ๋ฆฌ ๋์์ ๋ค์๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก try/catch ๋ธ๋ก์ ๋ณ๋ ํจ์๋ก ๋ฝ์๋ด๋ ํธ์ด ์ข๋ค.
public void delete(Page page) {
try {
deletePageAndAllReferences(page);
} catch (Exception e) {
logError(e);
}
}
private void deletePageAndAllReferences(Page page) throws Exception {
deletePage(page);
registry.deleteReference(page.name);
configKeys.deleteKey(page.name.makeKey());
}
private void logError(Exception e) {
logger.log(e.getMessage());
}
- ํจ์๋ 'ํ ๊ฐ์ง' ์์ ๋ง ํด์ผ ํ๋ค. ์ค๋ฅ ์ฒ๋ฆฌ๋ 'ํ ๊ฐ์ง' ์์ ์ ์ํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์ค๋ฅ๋ฅผ ์ฒ๋ฆฌํ๋ ํจ์๋ ์ค๋ฅ๋ง ์ฒ๋ฆฌํด์ผ ๋ง๋ ํ๋ค. (์ ์์ ์์ ๋ณด์๋ฏ์ด)
- ํจ์์ ํค์๋ try๊ฐ ์๋ค๋ฉด ํจ์๋ try ๋ฌธ์ผ๋ก ์์ํด catch/finally ๋ฌธ์ผ๋ก ๋๋์ผ ํ๋ค.
- ์ค๋ฅ ์ฝ๋๋ฅผ ๋ฐํํ๋ค๋ ์ด์ผ๊ธฐ๋, ํด๋์ค๋ ์ด๊ฑฐํ ๋ณ์๋ , ์ด๋์ ๊ฐ ์ค๋ฅ ์ฝ๋๋ฅผ ์ ์ํ๋ค๋ ๋ป์ด๋ค.
public enum Error {
OK,
INVALID,
NO_SUCH,
LOCKED,
OUT_OF_RESOURCES,
WAITING_FOR_EVENT;
}
๋ฐ๋ผ์, ์ค๋ฅ ์ฝ๋๊ฐ ๋ฐ๋๋ฉด ์ฐธ์กฐํ๊ณ ์๋ ๋ค๋ฅธ ํด๋์ค ์ ๋ถ๋ฅผ ๋ค์ ์ปดํ์ผํ๊ณ ๋ค์ ๋ฐฐ์นํด์ผ ํ๋ค. ๊ทธ๋์ ์ ์ค๋ฅ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ ๋์ ๊ธฐ์กด ์ค๋ฅ ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํ๋ค.
- ์ค๋ฅ ์ฝ๋ ๋์ ์์ธ๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์์ธ๋ Exception ํด๋์ค์์ ํ์๋๋ค. ๋ฐ๋ผ์ ์ฌ์ปดํ์ผ/์ฌ๋ฐฐ์น ์์ด๋ ์ ์์ธ ํด๋์ค๋ฅผ ์ถ๊ฐํ ์ ์๋ค.
- ์ด์ฉ๋ฉด ์ค๋ณต์ ์ํํธ์จ์ด์์ ๋ชจ๋ ์ ์ ๊ทผ์์ด๋ค. ๋ง์ ์์น๊ณผ ๊ธฐ๋ฒ์ด ์ค๋ณต์ ์์ ๊ฑฐ๋ ์ ์ดํ ๋ชฉ์ ์ผ๋ก ๋์๋ค.
- ์๋ฅผ ๋ค์ด, ์ค๋ณต์ ์ ๊ฑฐํ ๋ชฉ์ ์ผ๋ก ๊ด๊ณํ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ท ํ์๋ ์๊ณ , ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ์ ์ฝ๋๋ฅผ ๋ถ๋ชจ ํด๋์ค๋ก ๋ชฐ์ ์ค๋ณต์ ์์ค๋ค. ๊ตฌ์กฐ์ ํ๋ก๊ทธ๋๋ฐ, AOP(Aspect Oriented Programming), COP(Component Oriented Programming) ๋ชจ๋ ์ด๋ค ๋ฉด์์ ์ค๋ณต ์ ๊ฑฐ ์ ๋ต์ด๋ค.
- ๊ตฌ์กฐ์ ํ๋ก๊ทธ๋๋ฐ: ๋ชจ๋ ํจ์์ ํจ์ ๋ด ๋ชจ๋ ๋ธ๋ก์ ์ ๊ตฌ์ ์ถ๊ตฌ๊ฐ ํ๋๋ง ์กด์ฌํด์ผ ํ๋ค. ์ฆ, ํจ์์ return ๋ฌธ์ด ํ๋์ฌ์ผ ํ๋ค. ๋ฃจํ ์์์ break์ด๋ continue๋ฅผ ์ฌ์ฉํด์ ์๋๋ฉฐ goto๋ ์ ๋๋ก, ์ ๋๋ก ์๋๋ค.
- ํจ์๊ฐ ์์ ๋๋ ๊ฐํน return, break, continue๋ฅผ ์ฌ๋ฌ ์ฐจ๋ก ์ฌ์ฉํด๋ ๊ด์ฐฎ๋ค. ์คํ๋ ค ๋๋ก๋ ๋จ์ผ ์ /์ถ๊ตฌ ๊ท์น๋ณด๋ค ์๋๋ฅผ ํํํ๊ธฐ ์ฌ์์ง๋ค.
- ํจ์๋ ์ฒ์์๋ ๊ธธ๊ณ ๋ณต์กํ๊ณ , ๋ค์ฌ์ฐ๊ธฐ ๋จ๊ณ๋ ๋ง๊ณ ์ค๋ณต๋ ๋ฃจํ๋ ๋ง๊ณ ์ธ์ ๋ชฉ๋ก๋ ์์ฃผ ๊ธธ ์ ์๋ค. ์ด๋ฆ์ ์ฆํฅ์ ์ด๊ณ ์ฝ๋๋ ์ค๋ณต๋๋ค. ๊ทธ๋ฌ๋ ์ด ์ํฌ๋ฅธ ์ฝ๋๋ฅผ ๋น ์ง์์ด ํ ์คํธํ๋ ๋จ์ ํ ์คํธ ์ผ์ด์ค๋ฅผ ๋ง๋ ๋ค.
- ๊ทธ๋ฌ๋ฉด ์ฝ๋๋ฅผ ๋ค๋ฌ๊ณ , ํจ์๋ฅผ ๋ง๋ค๊ณ , ์ด๋ฆ์ ๋ฐ๊พธ๊ณ , ์ค๋ณต์ ์ ๊ฑฐํด๋ ๋จ์ ํ ์คํธ๋ฅผ ํต๊ณผํ๊ธฐ ๋๋ฌธ์ ๋ถ๋ด์ด ์๋ค.
- ์ต์ข ์ ์ผ๋ก ์ด ์ฅ์์ ์ค๋ช ํ ๊ท์น์ ๋ฐ๋ฅด๋ ํจ์๊ฐ ์ป์ด์ง๋ค. ์ฒ์๋ถํฐ ๋ฑ ๋ง๋๋ ์ฌ๋์ ์์ผ๋ฆฌ๋ผ.
import fitnesse.responders.run.SuiteResponder;
import fitnesse.wiki.*;
public class SetupTeardownIncluder {
private PageData pageData;
private boolean isSuite;
private WikiPage testPage;
private StringBuffer newPageContent;
private PageCrawler pageCrawler;
public static String render(PageData pageData) throws Exception {
return render(pageData, false);
}
public static String render(PageData pageData, boolean isSuite) throws Exception {
return new SetupTeardownIncluder(pageData).render(isSuite);
}
private SetupTeardownIncluder(PageData pageData) {
this.pageData = pageData;
testPage = pageData.getWikiPage();
pageCrawler = testPage.getPageCrawler();
newPageContent = new StringBuffer();
}
private String render(boolean isSuite) throws Exception {
this.isSuite = isSuite;
if (isTestPage())
includeSetupAndTeardownPage();
return pageData.getHtml();
}
private boolean isTestPage() throws Exception {
return pageData.hasAttribute("Test");
}
private void includeSetupAndTeardownPage() throws Exception {
includeSetupPage();
includePageContent();
includeTeardownPages();
updatePageContent();
}
private void includeSetupPage() throws exception {
if (isSuite)
includeSuiteSetupPage();
includeSetupPage();
}
private void includeSuiteSetupPage() throws Exception {
include(SuiteResponder.SUITE_SETUP_NAME, "-setup");
}
private void includeSetupPage() throws Exception {
include("SetUp", "-setup");
}
private void includePageContent() throws Exception {
newPageContent.append(pageData.getContent());
}
private void includeTeardownPages() throws Exception {
includeTeardownPage();
if (isSuite)
includeSuiteTeardownPage();
}
private void includeTeardownPage() throws Exception {
include("TearDown", "-teardown");
}
private void includeSuiteTeardownPage() throws Exception {
include(SuiteREsponder.SUITE_TEARDOWN_NAME, "-teardown");
}
private void updatePageContent() throws Exception {
pageData.setContent(newPageContent.toString());
}
private void include(String pageName, String arg) throws Exception {
WikiPage inheritedPage = findInheritedPage(pageName);
if (inheritedPage != null) {
String pagePathName = gePathNameForPage(inheritedPage);
buildIncludeDirective(pagePathName, arg);
}
}
private WikiPage findInheritedPage(String pageName) throws Exception {
WikiPagePath pagePath = pageCrawler.getFullPath(page);
return PathParser.render(pagePath);
}
private void buildIncludeDirective(String pagePathName, String arg) {
newPageContent
.append("\n!include ")
.append(arg)
.append(" .")
.append(pagePathName)
.append("\n");
}
}
/**
* ์ฑ๋ ์์ - 2021.02.10 ํ์ฌ ์ฑ๋ ์์ฑ ๋ก์ง ๋ถ๋ฆฌ๋ก ์ธํด update ๋ง์ ์ฒ๋ฆฌํจ
*
* @param updateChannelParam
* @return
* @throws Exception
*/
public boolean upsertChannel(ContentsUpdateChannelParam updateChannelParam) throws Exception {
ContentsSearchTrackParam searchTrackParam = new ContentsSearchTrackParam();
searchTrackParam.setPaging(false);
searchTrackParam.setTrackIdList(updateChannelParam.getTrackIdList());
updateChannelParam.setChnlPlayTm(searchTrackParam.getTrackIdList().size() > 0 ? this.getPlayTm(channelMapper.selectTrackList(searchTrackParam)) : "0");
if (null == updateChannelParam.getChnlId()) {
// ์ฑ๋ ๋ฑ๋ก
LocalDateTime renewDate = LocalDateTime.now();
updateChannelParam.setRenewDtime(renewDate);
updateChannelParam.setRenewTrackCnt(0);
channelMapper.insertChannel(updateChannelParam);
this.insertChannelMultiLink(updateChannelParam);
if (ChnlType.AFLO == updateChannelParam.getChnlType()) {
channelMapper.insertAfloChnl(updateChannelParam);
}
if (ChnlType.AFLO != updateChannelParam.getChnlType() && !ObjectUtils.isEmpty(updateChannelParam.getOrgGenreId())) {
// ์ฑ๋ ์ฅ๋ฅด ๋งตํ ๋ฐ์ดํฐ ์ถ๊ฐ
channelMapper.deleteMapSvcGenreChannel(updateChannelParam);
// ์๋ฃ
channelMapper.insertMapSvcGenreChannel(updateChannelParam);
}
// ์ฑ๋ ํธ๋ ๋ฑ๋ก
insertChannelTrack(updateChannelParam);
} else {
updateChannelParam.setRenewTrackCnt(0);
//์ฑ๋ ์์
channelMapper.updateChannel(updateChannelParam);
this.updateChannelMultiLink(updateChannelParam);
if (ChnlType.AFLO != updateChannelParam.getChnlType() && !ObjectUtils.isEmpty(updateChannelParam.getOrgGenreId())) {
// ์ฑ๋ ์ฅ๋ฅด ๋งตํ ๋ฐ์ดํฐ ์ถ๊ฐ
channelMapper.deleteMapSvcGenreChannel(updateChannelParam);
channelMapper.insertMapSvcGenreChannel(updateChannelParam);
} else {
channelMapper.deleteMapSvcGenreChannel(updateChannelParam);
}
//์ฑ๋ ํธ๋ ์์
updateChannelTrack(updateChannelParam);
}
// ์ด๋ฏธ์ง ์ฒ๋ฆฌ
updateChannelImg(updateChannelParam);
// ์ ํจํ ํธ๋ ๊ฐฏ์๋ก ์
๋ฐ์ดํธ
channelMapper.updateChannelTrackCnt(updateChannelParam.getChnlId());
//์ฑ๋ ํ์ดํ๊ณก ์
๋ฐ์ดํธ
Long titleTrackId = updateChannelParam.getTitleTrackId();
if (updateChannelParam.getTrackIdList().size() > 0) {
if (titleTrackId == null) {
//์ฒซ๋ฒ์งธ trackId ๋ก
titleTrackId = updateChannelParam.getTrackIdList().get(0);
}
channelMapper.updateInitChannelTitleYn(updateChannelParam.getChnlId());
channelMapper.updateChannelTitleYn(updateChannelParam.getChnlId(), titleTrackId);
}
// ์ด๋ ฅ ์์ฑ
insertChannelHistory(updateChannelParam);
// ๋ ๋์ค ์บ์ ์ญ์
String channelRedisKey = String.format(godmusicChanneRedislKeyFormat, updateChannelParam.getChnlId());
redisService.delWithPrefix(channelRedisKey); // ์ฒด๋ ์บ์ ์ญ์
for (String key : godmusicRecommendRedislKey) { // ์ถ์ฒ ์บ์ ์ญ์
redisService.delWithPrefix(key);
}
return true;
}
/**
* ์ฑ๋ ์์ ์๋น์ค
*
* @param updateChannelParam
* @return
* @throws Exception
*/
public boolean updateChannel(ContentsUpdateChannelParam updateChannelParam) throws Exception {
beforeUpdate(updateChannelParam);
channelMapper.updateChannel(updateChannelParam);
afterUpdate(updateChannelParam);
return true;
}
public void beforeUpdate(ContentsUpdateChannelParam updateChannelParam) {
ContentsSearchTrackParam searchTrackParam = new ContentsSearchTrackParam();
searchTrackParam.setPaging(false);
searchTrackParam.setTrackIdList(updateChannelParam.getTrackIdList());
updateChannelParam.setChnlPlayTm(searchTrackParam.getTrackIdList().size() > 0 ? this.getPlayTm(channelMapper.selectTrackList(searchTrackParam)) : "0");
if (Objects.isNull(updateChannelParam.getChnlId())) throw new FloAdminException(CommonErrorDomain.BAD_REQUEST);
updateChannelParam.setRenewTrackCnt(0);
}
public void afterUpdate(ContentsUpdateChannelParam updateChannelParam) throws ParseException {
updateChannelMultiLink(updateChannelParam);
updateMapSvcGenreChannel(updateChannelParam);
updateChannelTrack(updateChannelParam);
updateChannelImg(updateChannelParam);
updateValidChannelTrackCnt(updateChannelParam);
updateChannelTitle(updateChannelParam);
insertChannelHistory(updateChannelParam);
deleteRedisCache(updateChannelParam);
}
/**
* ์ฑ๋ ์ฅ๋ฅด ๋งคํ ๋ฐ์ดํฐ ์ถ๊ฐ
* AFLO ํ์
์ผ ๊ฒฝ์ฐ ์ฅ๋ฅด ๊ฐ ์ญ์
*
* @param updateChannelParam
*/
private void updateMapSvcGenreChannel(ContentsUpdateChannelParam updateChannelParam) {
if (ChnlType.AFLO != updateChannelParam.getChnlType() && !ObjectUtils.isEmpty(updateChannelParam.getOrgGenreId())) {
// ์ฑ๋ ์ฅ๋ฅด ๋งตํ ๋ฐ์ดํฐ ์ถ๊ฐ
channelMapper.deleteMapSvcGenreChannel(updateChannelParam);
channelMapper.insertMapSvcGenreChannel(updateChannelParam);
} else {
channelMapper.deleteMapSvcGenreChannel(updateChannelParam);
}
}
/**
* ์ ํจํ ์ฑ๋ ํธ๋ ๊ฐฏ์๋ก ์
๋ฐ์ดํธ
* @param updateChannelParam
*/
private void updateValidChannelTrackCnt(ContentsUpdateChannelParam updateChannelParam) {
channelMapper.updateChannelTrackCnt(updateChannelParam.getChnlId());
}
/**
* ์
๋ฐ์ดํธ ํ ๋ ๋์ค ์บ์ ์ญ์
* @param updateChannelParam
*/
private void deleteRedisCache(ContentsUpdateChannelParam updateChannelParam){
// ๋ ๋์ค ์บ์ ์ญ์
String channelRedisKey = String.format(godmusicChanneRedislKeyFormat, updateChannelParam.getChnlId());
redisService.delWithPrefix(channelRedisKey); // ์ฒด๋ ์บ์ ์ญ์
for (String key : godmusicRecommendRedislKey) { // ์ถ์ฒ ์บ์ ์ญ์
redisService.delWithPrefix(key);
}
}
/**
* ์ฑ๋ ํ์ดํ๊ณก ์
๋ฐ์ดํธ
* titleTrackId๊ฐ ์์ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ํธ๋ ์์ด๋๋ก ์ค์
*
* @param updateChannelParam
*/
private void updateChannelTitle(ContentsUpdateChannelParam updateChannelParam){
Long titleTrackId = updateChannelParam.getTitleTrackId();
if (updateChannelParam.getTrackIdList().size() > 0) {
if (titleTrackId == null) {
titleTrackId = updateChannelParam.getTrackIdList().get(0);
}
channelMapper.updateInitChannelTitleYn(updateChannelParam.getChnlId());
channelMapper.updateChannelTitleYn(updateChannelParam.getChnlId(), titleTrackId);
}
}
/**
* ์ฑ๋ ์ด๋ฏธ์ง ์
๋ฐ์ดํธ
* @param updateChannelParam
*/
private void updateChannelImg(ContentsUpdateChannelParam updateChannelParam) {
if (ChnlType.AFLO.getCode().equals(updateChannelParam.getChnlType().getCode())) {
Long chnlId = updateChannelParam.getChnlId();
if (!CollectionUtils.isEmpty(updateChannelParam.getChnlImages())) {
channelMapper.deleteChnlImage(updateChannelParam.getChnlId());
for (ContentsChnlImage chnlImage : updateChannelParam.getChnlImages()) {
chnlImage.setChnlId(updateChannelParam.getChnlId());
chnlImage.setCreateUserNo(updateChannelParam.getCreateUserNo());
channelMapper.insertChnlImage(chnlImage);
}
} else {
channelMapper.deleteChnlImage(updateChannelParam.getChnlId());
}
channelMapper.updateAfloChnl(chnlId, updateChannelParam.getAfloArtistId());
} else {
if (null != updateChannelParam.getImgUrl() && !("").equals(updateChannelParam.getImgUrl())) {
channelMapper.deleteChnlImage(updateChannelParam.getChnlId());
channelMapper.insertChnlImage(ContentsChnlImage.builder()
.chnlId(updateChannelParam.getChnlId()).imgUrl(updateChannelParam.getImgUrl()).chnlImgType(ChnlImgType.PANNEL)
.createUserNo(updateChannelParam.getCreateUserNo()).build());
} else {
channelMapper.deleteChnlImage(updateChannelParam.getChnlId());
}
}
}
/**
* ์ฑ๋ ํ์คํ ๋ฆฌ ์ด๋ ฅ ์์ฑ
* @param updateChannelParam
*/
private void insertChannelHistory(ContentsUpdateChannelParam updateChannelParam) {
ContentsChannelHistory channelHistory = new ContentsChannelHistory();
channelHistory.setChnlChgType("TRACK");
channelHistory.setChnlId(updateChannelParam.getChnlId());
channelHistory.setCreateUserNo(updateChannelParam.getUpdateUserNo());
channelHistory.setCreateDtime(updateChannelParam.getCreateDtime());
channelMapper.insertChannelHistory(channelHistory);
channelMapper.insertChannelTrackHistory(channelHistory);
}
- Clean Code