Search in sources :

Example 6 with Area

use of jp.co.nexus.crm.db.Area in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method createAreaMap.

private static Map<Integer, Area> createAreaMap(ObjectContext context) throws IOException {
    File csvFile = new File(CSV_DIR, DBConstants.AREA + ".csv");
    if (!csvFile.exists()) {
        throw new FileNotFoundException("CSVファイルが存在しません。[" + csvFile.getName() + "]");
    }
    // CSVからサンプルデータを読み込み
    LOGGER.info("エリアテーブルのcsvファイルからサンプルデータをロード開始。");
    CSVFileReader reader = new CSVFileReader();
    List<Map<String, Object>> dataMaps = reader.readData(csvFile);
    LOGGER.debug("dataMaps=" + dataMaps);
    // テーブルオブジェクトにデータを設定し、テーブルにデータを登録
    LOGGER.info("サンプルデータをエリアテーブルのモデルに設定。");
    Map<Integer, Area> areaMap = new HashMap<Integer, Area>();
    for (Map<String, Object> dataMap : dataMaps) {
        // データ登録対象のテーブルオブジェクトを取得
        Area dataObj = context.newObject(Area.class);
        // テーブルオブジェクトにデータを設定
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            dataObj.writeProperty(entry.getKey(), entry.getValue());
        }
        int areaCode = dataObj.getAreaCd();
        areaMap.put(areaCode, dataObj);
    }
    return areaMap;
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) Area(jp.co.nexus.crm.db.Area) CayenneDataObject(org.apache.cayenne.CayenneDataObject) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Area

use of jp.co.nexus.crm.db.Area in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method createCustomerMap.

private static Map<Integer, NCCustomer> createCustomerMap(ObjectContext context, Map<Integer, Area> areaMap, Map<Integer, Employee> employeeMap) throws IOException {
    File csvFile = new File(CSV_DIR, DBConstants.NC_CUSTOMER + ".csv");
    if (!csvFile.exists()) {
        throw new FileNotFoundException("CSVファイルが存在しません。[" + csvFile.getName() + "]");
    }
    // CSVからサンプルデータを読み込み
    LOGGER.info("顧客管理テーブルのcsvファイルからサンプルデータをロード開始。");
    CSVFileReader reader = new CSVFileReader();
    List<Map<String, Object>> dataMaps = reader.readData(csvFile);
    LOGGER.info("dataMaps=" + dataMaps);
    // テーブルオブジェクトにデータを設定し、テーブルにデータを登録
    LOGGER.info("サンプルデータを顧客管理テーブルのモデルに設定。");
    int id = 1;
    Map<Integer, NCCustomer> customerMap = new HashMap<Integer, NCCustomer>();
    for (Map<String, Object> dataMap : dataMaps) {
        // データ登録対象のテーブルオブジェクトを取得
        NCCustomer dataObj = context.newObject(NCCustomer.class);
        // テーブルオブジェクトにデータを設定
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            if ("area".equals(entry.getKey())) {
                Integer areaCd = (Integer) entry.getValue();
                Area area = areaMap.get(areaCd);
                dataObj.setArea(area);
                area.getCustomers().add(dataObj);
            } else if ("employee".equals(entry.getKey())) {
                Integer empNo = (Integer) entry.getValue();
                Employee employee = employeeMap.get(empNo);
                dataObj.setEmployee(employee);
                employee.getCustomers().add(dataObj);
            } else {
                dataObj.writeProperty(entry.getKey(), entry.getValue());
            }
        }
        customerMap.put(Integer.valueOf(id), dataObj);
    }
    return customerMap;
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) NCCustomer(jp.co.nexus.crm.db.NCCustomer) CayenneDataObject(org.apache.cayenne.CayenneDataObject) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Area

use of jp.co.nexus.crm.db.Area in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method createEmployeeMap.

private static Map<Integer, Employee> createEmployeeMap(ObjectContext context, Map<Integer, Area> areaMap) throws IOException {
    File csvFile = new File(CSV_DIR, DBConstants.EMPLOYEE + ".csv");
    if (!csvFile.exists()) {
        throw new FileNotFoundException("CSVファイルが存在しません。[" + csvFile.getName() + "]");
    }
    // CSVからサンプルデータを読み込み
    LOGGER.info("職員テーブルのcsvファイルからサンプルデータをロード開始。");
    CSVFileReader reader = new CSVFileReader();
    List<Map<String, Object>> dataMaps = reader.readData(csvFile);
    LOGGER.info("dataMaps=" + dataMaps);
    // テーブルオブジェクトにデータを設定し、テーブルにデータを登録
    LOGGER.info("サンプルデータを職員テーブルのモデルに設定。");
    Map<Integer, Employee> employeeMap = new HashMap<Integer, Employee>();
    for (Map<String, Object> dataMap : dataMaps) {
        // データ登録対象のテーブルオブジェクトを取得
        Employee dataObj = context.newObject(Employee.class);
        ;
        // テーブルオブジェクトにデータを設定
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            if ("area".equals(entry.getKey())) {
                Integer areaCd = (Integer) entry.getValue();
                Area area = areaMap.get(areaCd);
                dataObj.setArea(area);
                area.getEmployees().add(dataObj);
            } else {
                dataObj.writeProperty(entry.getKey(), entry.getValue());
            }
        }
        int empNo = dataObj.getEmpNo();
        employeeMap.put(empNo, dataObj);
    }
    return employeeMap;
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) CayenneDataObject(org.apache.cayenne.CayenneDataObject) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Area (jp.co.nexus.crm.db.Area)8 Employee (jp.co.nexus.crm.db.Employee)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CayenneDataObject (org.apache.cayenne.CayenneDataObject)6 NCCalldoc (jp.co.nexus.crm.db.NCCalldoc)3 NCCustomer (jp.co.nexus.crm.db.NCCustomer)3 NCDivision (jp.co.nexus.crm.db.NCDivision)3 NCPerson (jp.co.nexus.crm.db.NCPerson)3 ObjectContext (org.apache.cayenne.ObjectContext)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 IOException (java.io.IOException)1 List (java.util.List)1 CustomerInfoBean (jp.co.nexus.crm.bean.CustomerInfoBean)1 CustomerListBean (jp.co.nexus.crm.bean.CustomerListBean)1 Expression (org.apache.cayenne.exp.Expression)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1