package org.dbflute.intro.app.logic.document.decomment;

import javax.annotation.Resource;

import org.dbflute.intro.app.logic.intro.IntroPhysicalLogic;

/**
 * @author cabos
 */
public class DocumentDecommentPhysicalLogic {

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    @Resource
    private IntroPhysicalLogic introPhysicalLogic;

    // ===================================================================================
    //                                                                                Path
    //                                                                                ====
    public String buildDecommentDiffDirPath(String clientProject) {
        return null;
    }

    public String buildDecommentPickupDirPath(String clientProject) {
        return null;
    }
}

@@ -65,91 +65,411 @@
 java
-x.annotation.Resource;%0A%0Aimport org.dbflute.intro.app.logic.intro.IntroPhysicalLogic
+.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.io.UncheckedIOException;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Map;%0A%0Aimport javax.annotation.Resource;%0A%0Aimport org.dbflute.intro.app.logic.intro.IntroPhysicalLogic;%0Aimport org.dbflute.intro.app.model.document.decomment.DfDecoMapFile;%0Aimport org.lastaflute.core.time.TimeManager
 ;%0A%0A/
@@ -876,16 +876,67 @@
 alLogic;
+%0A    @Resource%0A    private TimeManager timeManager;
 %0A%0A    //
@@ -1105,148 +1105,2120 @@
     
-     Path
+Piece Map%0A    //                                                                           =========%0A    public void saveDecommentPieceMap(String clientProject, String tableName, Map%3CString, Object%3E decomentPieceMap) %7B%0A        File pieceMapFile = new File(buildDecommentPiecePath(clientProject, buildPieceFileName(tableName)));
 %0A    
-//
     
-                                                                            ====%0A    public String buildDecommentDiffDir
+createPieceMapFile(pieceMapFile);%0A        try (OutputStream outputStream = new FileOutputStream(pieceMapFile)) %7B%0A            DfDecoMapFile dfDecoMapFile = new DfDecoMapFile();%0A            dfDecoMapFile.writeMap(outputStream, decomentPieceMap);%0A        %7D catch (IOException e) %7B%0A            // TODO cabos throw more detail exception (2017/07/29)%0A            throw new UncheckedIOException(e);%0A        %7D%0A    %7D%0A%0A    private String buildPieceFileName(String tableName) %7B // e.g decomment-piece-MEMBER-20170316-123456-789-jflute.dfmap%0A        return %22 decomment-piece-%22 + tableName + %22-%22 + getCurrentDateStr() + %22-%22 + getAuthor() + %22.dfmap%22;%0A    %7D%0A%0A    private String getCurrentDateStr() %7B%0A        SimpleDateFormat formatter = new SimpleDateFormat(%22yyyyMMdd-HHmmss-SSS%22);%0A        return formatter.format(timeManager.currentDate());%0A    %7D%0A%0A    private String getAuthor() %7B%0A        return System.getProperty(%22user.home%22);%0A    %7D%0A%0A    private void createPieceMapFile(File pieceMapFile) %7B%0A        try %7B%0A            if (!pieceMapFile.createNewFile()) %7B%0A                // TODO cabos throw file exists exception (it is strange that same name file exists) (2017/07/29)%0A                throw new IllegalStateException(pieceMapFile.getName() + %22 is already exists.%22);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            // TODO cabos throw more detail exception (2017/07/29)%0A            throw new UncheckedIOException(%22fail to create piece map file%22, e);%0A        %7D%0A    %7D%0A%0A    // ===================================================================================%0A    //                                                                                Path%0A    //                                                                                ====%0A    private String buildDecommentPiece
 Path
@@ -3230,32 +3230,49 @@
 ng clientProject
+, String fileName
 ) %7B%0A        retu
@@ -3266,36 +3266,113 @@
 %0A        return 
-null
+introPhysicalLogic.buildClientPath(clientProject, %22schema%22, %22decomment%22, %22piece%22)
 ;%0A    %7D%0A%0A    pub
@@ -3369,21 +3369,22 @@
 %7D%0A%0A    p
-ublic
+rivate
  String 
@@ -3407,11 +3407,8 @@
 ckup
-Dir
 Path
@@ -3451,12 +3451,90 @@
 urn 
-null
+introPhysicalLogic.buildClientPath(clientProject, %22schema%22, %22decomment%22, %22pickup%22)
 ;%0A  

create piece map save logic