Skip to content

Commit 560ba7e

Browse files
committed
initial commit
0 parents  commit 560ba7e

9 files changed

+508
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
*.pyc
3+
*.xml
4+
*.iml

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EntityCodeCreation.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from EntityUseFullFunctions import *
2+
from EntityData import *
3+
from EntityFileCreation import createFile
4+
from EntityPaths import *
5+
6+
7+
def create_all_entities(text, path):
8+
rows = [i for i in text.split("\n") if i]
9+
for row in rows:
10+
val = [i.strip() for i in row.split('→')]
11+
cols = [i.strip() for i in val[1].split(',')]
12+
col_array = []
13+
a = val[0]
14+
for col in cols:
15+
col_array.append(column_code(col))
16+
name_file = file_name(a)
17+
file_data = file_total_code(a, col_array)
18+
createFile(name_file, file_data, path)
19+
20+
21+
def create_all_repositories(text, path):
22+
rows = [i for i in text.split("\n") if i]
23+
for row in rows:
24+
val = [i.strip() for i in row.split('→')]
25+
a = val[0]
26+
name_file = file_name(a)
27+
file_data = file_total_repo_code(a)
28+
createFile(name_file + "Repository", file_data, path)
29+
30+
31+
def service_code(text,path):
32+
file_data = ""
33+
rows = [i for i in text.split("\n") if i]
34+
for row in rows:
35+
val = [i.strip() for i in row.split('→')]
36+
37+
a = val[0]
38+
ans = [''] * 12
39+
ans[0] = file_name(a)
40+
ans[1] = ans[0]
41+
ans[2] = column_name(a)
42+
ans[3] = ans[2]
43+
ans[4] = ans[0].upper()
44+
ans[5] = ans[2]
45+
ans[6] = ans[5]
46+
ans[7] = ans[6]
47+
ans[8] = ans[4]
48+
ans[9] = ans[6]
49+
ans[10] = ans[0]
50+
ans[11] = ans[0]
51+
52+
file_data += service_bolier_code.format(*ans)
53+
54+
name_file = 'serCode'
55+
createFile(name_file, file_data, path)
56+
57+
58+
def autowired_code(text,path):
59+
file_data = ""
60+
rows = [i for i in text.split("\n") if i]
61+
for row in rows:
62+
val = [i.strip() for i in row.split('→')]
63+
64+
a = val[0] + '_repository'
65+
ans = [''] * 2
66+
ans[0] = file_name(a)
67+
ans[1] = column_name(a)
68+
69+
file_data += autboiler_code.format(*ans)
70+
71+
name_file = 'AutoCode'
72+
createFile(name_file, file_data, path)
73+
74+
75+
def load_code_lines(text,path):
76+
file_data = ""
77+
rows = [i for i in text.split("\n") if i]
78+
for row in rows:
79+
val = [i.strip() for i in row.split('→')]
80+
81+
a = val[0]
82+
ans = [''] * 1
83+
ans[0] = file_name(a)
84+
85+
file_data += load_boiler_code.format(*ans)
86+
87+
name_file = 'loadCode'
88+
createFile(name_file, file_data, path)
89+
90+
91+
# service_code(extra_text,actual_service_path)
92+
# autowired_code(extra_text,actual_service_path)
93+
# load_code_lines(extra_text,actual_service_path)
94+
create_all_entities(extra_text, actual_entity_path)
95+
# create_all_repositories(extra_text,actual_repository_path)

EntityData.py

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
text = """
2+
permit_product_level → permit_product_level_name, mfg_id, eff_date, end_date, permit_product_level_id
3+
4+
permit_purchase_unit → permit_purchase_unit_name, mfg_id, eff_date, end_date
5+
6+
"""
7+
8+
extra_text = """
9+
sku_type → sku_type_id, sku_type, sku_type_desc, bundle_flag, manual_flag, comp_maint_flag, nexus_safe_flag, include_in_mart_flag, show_cost_form_flag, autogen_new_sku_flag, update_dts, update_uid, inventory_flag, leadtime_flag
10+
product_flag_type → product_flag_type_id, product_flag_type
11+
"""
12+
13+
boiler_code = """
14+
package com.comp.project.cache.entity;
15+
16+
import java.sql.Timestamp;
17+
18+
import javax.persistence.Column;
19+
import javax.persistence.Entity;
20+
import javax.persistence.GeneratedValue;
21+
import javax.persistence.GenerationType;
22+
import javax.persistence.Id;
23+
import javax.persistence.Table;
24+
25+
@Entity
26+
@Table(name = "{0}")
27+
public class {1} """
28+
29+
column_boiler_code = """
30+
@Column(name="{}")
31+
private {} {};
32+
"""
33+
34+
id_boiler_code = """
35+
@Id
36+
@GeneratedValue(strategy = GenerationType.IDENTITY)
37+
@Column(name="{}")
38+
private Integer {};
39+
"""
40+
41+
repo_boiler_code = """package com.comp.project.cache.dao;
42+
43+
import org.springframework.data.jpa.repository.JpaRepository;
44+
import org.springframework.stereotype.Repository;
45+
46+
import com.comp.project.cache.entity.{};
47+
48+
49+
@Repository
50+
public interface {}Repository extends JpaRepository<{}, Integer> """
51+
52+
service_bolier_code = """
53+
public void load{0}Repository() {{
54+
try {{
55+
List<{1}> {2}s = {3}Repository.findAll();
56+
redisTemplate.delete("{4}");
57+
Gson gson = new Gson();
58+
{5}s.parallelStream().forEach({6}->{{
59+
String json = gson.toJson({7});
60+
redisTemplate.opsForHash().put("{8}",
61+
String.valueOf({9}.get{10}Id()), json);
62+
}});
63+
}}
64+
catch (Exception e) {{
65+
logger.error("Error in load{11}Repository {{}}",e.getMessage());
66+
}}
67+
}}
68+
"""
69+
70+
autboiler_code = """
71+
@Autowired
72+
{0} {1};
73+
74+
"""
75+
76+
load_boiler_code = """load{0}Repository();
77+
"""
78+
79+
junit_boiler_code = """
80+
package com.comp.team.project.catalog.handler.entity;
81+
82+
import static org.junit.jupiter.api.Assertions.assertNull;
83+
84+
import org.junit.jupiter.api.Test;
85+
86+
class {0}Test {{
87+
88+
private {0} {1};
89+
90+
91+
@Test
92+
void test() {{
93+
{1} = new {0}();
94+
95+
{2}
96+
}}
97+
98+
}}
99+
100+
"""
101+
102+
setter_boiler_code = """{0}.{1}(null);"""
103+
104+
getter_boiler_code = """assertNull({0}.{1});"""
105+
106+
107+
test_mock_boiler_code = """
108+
@Mock
109+
List<{0}> {1};
110+
"""
111+
112+
test_when_boiler_code = """when({0}).thenReturn({1});
113+
"""
114+
115+
test_new_object = """
116+
{0} = new ArrayList<{1}>() {{{{
117+
add(new {1}());
118+
}}}};
119+
"""
120+
121+
redis_boiler_delete = """when(redisTemplate.delete("{0}")).thenReturn(null);
122+
"""
123+
124+
test_function_boiler_code = """
125+
@Test
126+
@SuppressWarnings("serial")
127+
void {0}Test() {{
128+
{1}
129+
130+
{2}
131+
{3}
132+
teamCacheService.{0}();
133+
{4}thenReturn(null);
134+
teamCacheService.{0}();
135+
assertNull(null);
136+
}}
137+
"""
138+
139+
constructor_boiler_code = """doNothing().when(new teamCacheService()).{0};
140+
"""
141+
142+
meth_code = """
143+
144+
"""
145+
146+
147+
sql_boiler_code = """exec sp_help {0}
148+
"""

EntityFileCreation.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os.path
2+
3+
4+
5+
6+
def createFile(name_of_file, file_data,path):
7+
save_path = path
8+
9+
complete_name = os.path.join(save_path, name_of_file + ".java")
10+
11+
file1 = open(complete_name, "w")
12+
file1.write(file_data)
13+
file1.close()

EntityPaths.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
entity_path = ''
3+
repository_path = ''
4+
service_path = ''
5+
test_path = ''
6+
service_test_path = ''
7+
8+
9+
actual_entity_path = ''
10+
11+
actual_repository_path = ''
12+
13+
actual_service_path = ''
14+
15+
actual_test_path = ''
16+
17+
actual_service_test_path = ''

EntitySqlCode.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from EntityData import text,sql_boiler_code
2+
3+
data = [i.split('→')[0].strip() for i in text.split('\n') if i]
4+
5+
ans = ""
6+
for i in data:
7+
ans += sql_boiler_code.format(i)
8+
9+
print(ans)

EntityTestCodeCreation.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from EntityData import *
2+
from EntityFileCreation import createFile
3+
from EntityPaths import *
4+
from EntityUseFullFunctions import *
5+
import os
6+
7+
8+
def test_files():
9+
# only_list = ['BusinessUnit.java']
10+
for filename in os.listdir(actual_entity_path):
11+
# if filename not in only_list:
12+
# continue
13+
# print(filename)
14+
with open(os.path.join(actual_entity_path, filename), 'r') as f:
15+
data = f.read()
16+
name_file = class_name(data)
17+
var_name = class_var_name(name_file)
18+
file_data = segregate_setters_getters(data,var_name)
19+
20+
createFile(name_file+'Test',junit_boiler_code.format(name_file,var_name,file_data), actual_test_path)
21+
# pass
22+
23+
24+
def test_service_code():
25+
for filename in os.listdir(actual_service_path):
26+
with open(os.path.join(actual_service_path, filename), 'r') as f:
27+
data = f.read()
28+
file_data = test_service_code_lines(data)
29+
30+
part = when_code_lines(data)
31+
file_data = part[0] + part[1] + part[2] + part[3]
32+
createFile('xyz', file_data, actual_service_test_path)
33+
# break
34+
35+
36+
def contructor_code(data):
37+
file_data = ''
38+
data = data.split('\n')
39+
for line in data:
40+
if line:
41+
file_data += constructor_boiler_code.format(line.strip()[:-1])
42+
createFile('xyz', file_data, service_test_path)
43+
44+
45+
# test_service_code()
46+
test_files()

0 commit comments

Comments
 (0)