Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.orsup;

import org.litesoft.commonfoundation.base.*;
import org.litesoft.commonfoundation.exceptions.*;
import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.configuration.*;
import org.litesoft.server.file.*;

import java.io.*;
import java.util.*;

public class DataLoader {
    public static final DataLoader INSTANCE = new DataLoader();

    public static final String DEFAULT_LOAD_DATA_RELATIVE_DIR_PARENT_PATH = "LoadData";
    public static final String DEFAULT_LOAD_DATA_SUB_DIR_REGULAR = "Default";
    public static final String DEFAULT_LOAD_DATA_SUB_DIR_DEMO = "Demo";

    public static final String PROPERTY_LOAD_DATA_PATH = "LoadDataPath";
    public static final String PROPERTY_LOAD_DATA_DIR_PARENT_PATH = "LoadDataDirParentPath";
    public static final String PROPERTY_LOAD_DATA_SUB_DIR = "LoadDataSubDir";

    private String getSubDirPath( String pSubDir ) {
        String parent = ServerConfiguration.getPath( PROPERTY_LOAD_DATA_DIR_PARENT_PATH, DEFAULT_LOAD_DATA_RELATIVE_DIR_PARENT_PATH );
        return parent + "/" + pSubDir;
    }

    public void loadData() {
        String zLoadDataPath = ServerConfiguration.getPath( PROPERTY_LOAD_DATA_PATH, null );
        if ( zLoadDataPath == null ) {
            zLoadDataPath = getSubDirPath( Configuration.getString( PROPERTY_LOAD_DATA_SUB_DIR, DEFAULT_LOAD_DATA_SUB_DIR_REGULAR ) );
        }
        loadDataFrom( zLoadDataPath );
    }

    public void loadDataFrom( String zLoadDataPath ) {
        try {
            File zLoadDir = new File( zLoadDataPath );
            String[] zFilesToLoad = getFileNames( zLoadDir );
            DB_Import.importCSV( zLoadDir, zFilesToLoad );
        }
        catch ( IOException e ) {
            throw new RuntimeException( e );
        }
    }

    public void loadDemoData() {
        synchronized ( getClass() ) {
            if ( mCSVtoMemo == null ) {
                mCSVtoMemo = loadDemoDataMemo();
            }
        }
        loadMemoDemoData( mCSVtoMemo );
    }

    private Object mCSVtoMemo = null;

    private Object loadDemoDataMemo() {
        try {
            File zLoadDir = new File( getSubDirPath( DEFAULT_LOAD_DATA_SUB_DIR_DEMO ) );
            String[] zFilesToLoad = getFileNames( zLoadDir );
            return DB_Import.importCSVtoMemo( FileUtils.filesToReaders( zLoadDir, zFilesToLoad ) );
        }
        catch ( IOException e ) {
            throw new RuntimeException( e );
        }
    }

    private void loadMemoDemoData( Object pCSVtoMemo ) {
        try {
            File zLoadDir = new File( getSubDirPath( DEFAULT_LOAD_DATA_SUB_DIR_DEMO ) );
            DB_Import.importCSVfromMemo( zLoadDir, pCSVtoMemo );
        }
        catch ( IOException e ) {
            throw new RuntimeException( e );
        }
    }

    private String[] getFileNames( File pLoadDir ) {
        FilenameFilter zCSV_FilesFilter = FileUtils.createFileNameFilter( Strings.parseChar( "*.csv", '*' ) );
        String[] zFilesToLoad = pLoadDir.list( zCSV_FilesFilter );
        if ( Currently.isNullOrEmpty( zFilesToLoad ) ) {
            throw new DisplayableRuntimeException( "No Load Data Files at: " + pLoadDir.getAbsolutePath() );
        }
        Arrays.sort( zFilesToLoad );
        return zFilesToLoad;
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/orsup/DataLoader.java

Diff revisions: vs.
Revision Author Commited Message
958 Diff Diff GeorgeS picture GeorgeS Mon 14 Jul, 2014 15:29:35 +0000

Embrace OSS code bases.
Drop NAS-Video.

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
475 Diff Diff GeorgeS picture GeorgeS Sat 03 Sep, 2011 13:54:51 +0000
474 GeorgeS picture GeorgeS Fri 02 Sep, 2011 14:29:50 +0000

Switch to Properties and eliminate some of the Per App shit