@simplix-boot/cli 0.0.0-stage → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/LICENSE_KO +28 -0
- package/README.ko.md +82 -0
- package/README.md +81 -2
- package/bin/simplix-boot.js +6 -0
- package/package.json +45 -4
- package/src/cli.js +103 -0
- package/src/commands/config.js +129 -0
- package/src/commands/generate.js +291 -0
- package/src/commands/generated.js +125 -0
- package/src/commands/init.js +41 -0
- package/src/commands/promote.js +172 -0
- package/src/commands/templates.js +100 -0
- package/src/commands/version.js +134 -0
- package/src/lib/analysis/fields.js +217 -0
- package/src/lib/analysis/imports.js +76 -0
- package/src/lib/analysis/structure.js +193 -0
- package/src/lib/analysis/types.js +94 -0
- package/src/lib/args.js +69 -0
- package/src/lib/comment-extractor.js +141 -0
- package/src/lib/config/fields.js +321 -0
- package/src/lib/config/parents.js +108 -0
- package/src/lib/config/paths.js +156 -0
- package/src/lib/config/yml.js +61 -0
- package/src/lib/console.js +83 -0
- package/src/lib/controller-name.js +33 -0
- package/src/lib/entity-analyzer.js +49 -0
- package/src/lib/entity-type-resolver.js +80 -0
- package/src/lib/entity-type.js +35 -0
- package/src/lib/errors.js +17 -0
- package/src/lib/export-config.js +74 -0
- package/src/lib/file-utils.js +77 -0
- package/src/lib/generate/file-plan.js +155 -0
- package/src/lib/generate/search-fields.js +111 -0
- package/src/lib/generate/settings.js +111 -0
- package/src/lib/generate/support-classes.js +47 -0
- package/src/lib/generate/template-vars.js +183 -0
- package/src/lib/git-utils.js +18 -0
- package/src/lib/name-field.js +42 -0
- package/src/lib/project.js +121 -0
- package/src/lib/promote-files.js +132 -0
- package/src/lib/rendered-output.js +13 -0
- package/src/lib/search-operators.js +87 -0
- package/src/lib/templates.js +50 -0
- package/src/lib/tracked-render.js +200 -0
- package/src/lib/version-check.js +195 -0
- package/src/lib/version-utils.js +97 -0
- package/templates/controller/rest/EntityRestController.java.template +517 -0
- package/templates/controller/web/EntityWebController.java.template +211 -0
- package/templates/dto/EntityDTOs.java.template +981 -0
- package/templates/repository/EntityRepository.java.template +78 -0
- package/templates/service/EntityService.java.template +790 -0
- package/templates/service/EntityTreeService.java.template +352 -0
- package/templates/test/EntityServiceTest.java.template +937 -0
- package/templates/test/EntityTreeServiceTest.java.template +842 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const packageJsonPath = join(dirname(fileURLToPath(import.meta.url)), '../../package.json');
|
|
6
|
+
|
|
7
|
+
let cachedPackageJson;
|
|
8
|
+
|
|
9
|
+
function readOwnPackageJson() {
|
|
10
|
+
if (cachedPackageJson) {
|
|
11
|
+
return cachedPackageJson;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
cachedPackageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Failed to read package.json:', error.message);
|
|
18
|
+
cachedPackageJson = {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return cachedPackageJson;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getGeneratorVersion() {
|
|
25
|
+
return readOwnPackageJson().version || '0.0.0';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getGeneratorPackageName() {
|
|
29
|
+
return readOwnPackageJson().name || '@simplix-boot/cli';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The npm dist-tag this build's release line is published under. Each release line publishes
|
|
34
|
+
* under its own tag, so the newest version of one line is never offered to a project on another.
|
|
35
|
+
*/
|
|
36
|
+
export function getReleaseTag() {
|
|
37
|
+
return readOwnPackageJson().publishConfig?.tag || 'latest';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Development builds carry a -SNAPSHOT suffix; released builds never do.
|
|
42
|
+
*/
|
|
43
|
+
export function isSnapshotVersion(version) {
|
|
44
|
+
return typeof version === 'string' && version.endsWith('-SNAPSHOT');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parse the release core of a version into [major, minor, patch].
|
|
49
|
+
* Any pre-release suffix (-SNAPSHOT, -rc.1) is dropped: a project pinned to
|
|
50
|
+
* 1.2.0 is satisfied by 1.2.0-SNAPSHOT, so local development against an
|
|
51
|
+
* unreleased build is never blocked by its own suffix.
|
|
52
|
+
*
|
|
53
|
+
* Returns null when the string is not an X.Y.Z version.
|
|
54
|
+
*/
|
|
55
|
+
export function parseReleaseCore(version) {
|
|
56
|
+
if (typeof version !== 'string') {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version.trim());
|
|
61
|
+
if (!match) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The X.Y.Z a version belongs to, with any pre-release suffix removed.
|
|
70
|
+
* A project records this rather than the running build, so a development
|
|
71
|
+
* generator pins the release line it belongs to and not `1.0.0-SNAPSHOT`.
|
|
72
|
+
*/
|
|
73
|
+
export function toReleaseVersion(version) {
|
|
74
|
+
const core = parseReleaseCore(version);
|
|
75
|
+
return core ? core.join('.') : version;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Compare two versions by release core only.
|
|
80
|
+
* Returns -1, 0 or 1, or null when either side cannot be parsed.
|
|
81
|
+
*/
|
|
82
|
+
export function compareReleaseVersions(a, b) {
|
|
83
|
+
const left = parseReleaseCore(a);
|
|
84
|
+
const right = parseReleaseCore(b);
|
|
85
|
+
|
|
86
|
+
if (!left || !right) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < 3; i++) {
|
|
91
|
+
if (left[i] !== right[i]) {
|
|
92
|
+
return left[i] < right[i] ? -1 : 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
package <%= packagePaths['controllerRest'] %>;
|
|
2
|
+
|
|
3
|
+
import dev.simplecore.simplix.web.controller.SimpliXBaseController;
|
|
4
|
+
import dev.simplecore.simplix.web.controller.SimpliXStandardApi;
|
|
5
|
+
<%
|
|
6
|
+
// The classes of the application this controller calls; the project configuration names them
|
|
7
|
+
// under supportClasses.
|
|
8
|
+
const messages = ymlConfig.notFoundMessageKey ? supportClasses.require('messages', 'notFoundMessageKey') : null;
|
|
9
|
+
const searchFigures = (ymlConfig.statusCounts || []).length > 0 || (ymlConfig.aggregates || []).length > 0
|
|
10
|
+
? supportClasses.require('searchFigures', 'statusCounts or aggregates')
|
|
11
|
+
: null;
|
|
12
|
+
// The order the list opens in. Refused here, before anything is written, when it names the id or a
|
|
13
|
+
// field the search DTO cannot order by; SimpliX Meta refuses the same at runtime.
|
|
14
|
+
const defaultSort = ymlConfig.defaultSort;
|
|
15
|
+
if (defaultSort) {
|
|
16
|
+
const sortField = defaultSort.field;
|
|
17
|
+
const sortDirection = defaultSort.direction || 'desc';
|
|
18
|
+
if (!sortField) throw new Error(`${entityName}.yml defaultSort has no field`);
|
|
19
|
+
if (sortField === ymlConfig.idField) throw new Error(`${entityName}.yml defaultSort names the id field ${sortField}`);
|
|
20
|
+
if (!(ymlConfig.fields && ymlConfig.fields[sortField] && ymlConfig.fields[sortField].sortable === true)) {
|
|
21
|
+
throw new Error(`${entityName}.yml defaultSort names ${sortField}, which is not a sortable field`);
|
|
22
|
+
}
|
|
23
|
+
if (sortDirection !== 'asc' && sortDirection !== 'desc') {
|
|
24
|
+
throw new Error(`${entityName}.yml defaultSort direction must be asc or desc, not ${sortDirection}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
-%>
|
|
28
|
+
<% if (defaultSort) { -%>
|
|
29
|
+
import dev.simplecore.simplix.web.controller.SimpliXDefaultSort;
|
|
30
|
+
<% } -%>
|
|
31
|
+
<% if ((ymlConfig.statusCounts || []).length > 0 || (ymlConfig.aggregates || []).length > 0 || ymlConfig.timeAxisField) { -%>
|
|
32
|
+
import dev.simplecore.simplix.web.controller.SimpliXListFigures;
|
|
33
|
+
<% } -%>
|
|
34
|
+
import dev.simplecore.simplix.core.model.SimpliXApiResponse;
|
|
35
|
+
<% if (ymlConfig.notFoundMessageKey) { -%>
|
|
36
|
+
import <%= messages.fqn %>;
|
|
37
|
+
<% } -%>
|
|
38
|
+
import <%= packagePaths['dto'] %>.<%= classPrefix %>DTOs.*;
|
|
39
|
+
import <%= entityPackage %>.<%= entityName %>;
|
|
40
|
+
<% if (hasEmbeddedId) { %>
|
|
41
|
+
import <%= entityPackage %>.<%= entityName %>.<%= embeddedIdType %>;
|
|
42
|
+
import java.util.stream.Collectors;
|
|
43
|
+
<% } %>
|
|
44
|
+
import <%= packagePaths['service'] %>.<%= classPrefix %>Service;
|
|
45
|
+
<% if (hasTreeEntity) { %>
|
|
46
|
+
import <%= packagePaths['service'] %>.<%= classPrefix %>TreeService;
|
|
47
|
+
import dev.simplecore.simplix.core.exception.SimpliXGeneralException;
|
|
48
|
+
<% } %>
|
|
49
|
+
import dev.simplecore.searchable.core.condition.SearchCondition;
|
|
50
|
+
import dev.simplecore.searchable.openapi.annotation.SearchableParams;
|
|
51
|
+
import io.swagger.v3.oas.annotations.Operation;
|
|
52
|
+
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
53
|
+
import org.springframework.data.domain.Page;
|
|
54
|
+
<% if (exportConfig.enabled) { -%>
|
|
55
|
+
import dev.simplecore.simplix.excel.export.ExportFormat;
|
|
56
|
+
import jakarta.servlet.http.HttpServletResponse;
|
|
57
|
+
import java.io.IOException;
|
|
58
|
+
<% } -%>
|
|
59
|
+
import org.springframework.security.access.prepost.PreAuthorize;
|
|
60
|
+
import org.springframework.validation.annotation.Validated;
|
|
61
|
+
import org.springframework.web.bind.annotation.*;
|
|
62
|
+
|
|
63
|
+
import java.util.List;
|
|
64
|
+
import java.util.Map;
|
|
65
|
+
import java.util.Set;
|
|
66
|
+
<% const statusCountFields = ymlConfig.statusCounts || []; const aggregateItems = ymlConfig.aggregates || []; %>
|
|
67
|
+
<% if (statusCountFields.length > 0 || aggregateItems.length > 0) { %>
|
|
68
|
+
import <%= searchFigures.fqn %>.AggregateValueDTO;
|
|
69
|
+
import <%= searchFigures.fqn %>.ValueCountDTO;
|
|
70
|
+
<% } %>
|
|
71
|
+
<% if (ymlConfig.timeAxisField) { %>
|
|
72
|
+
import dev.simplecore.searchable.core.service.bucket.TimeWindowParams;
|
|
73
|
+
import io.swagger.v3.oas.annotations.Parameter;
|
|
74
|
+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
75
|
+
import org.springframework.format.annotation.DateTimeFormat;
|
|
76
|
+
|
|
77
|
+
import java.time.Instant;
|
|
78
|
+
<% } %>
|
|
79
|
+
<%
|
|
80
|
+
function generatePathVariableParams() {
|
|
81
|
+
if (hasEmbeddedId) {
|
|
82
|
+
return embeddedIdFields.map(function(field, index) {
|
|
83
|
+
return `@PathVariable String ${field.name}${index < embeddedIdFields.length - 1 ? ',' : ''}`;
|
|
84
|
+
}).join(' ');
|
|
85
|
+
} else {
|
|
86
|
+
return `@PathVariable ${idType} ${ymlConfig.idField}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
%>
|
|
90
|
+
/**
|
|
91
|
+
* REST Controller for <%= entityComment.split(':')[0] %>.
|
|
92
|
+
* <p>
|
|
93
|
+
* Provides CRUD operations and search functionality for <%= entityName %> entities.
|
|
94
|
+
*
|
|
95
|
+
* @see <%= classPrefix %>Service
|
|
96
|
+
* @see <%= entityName %>
|
|
97
|
+
*/
|
|
98
|
+
@RestController
|
|
99
|
+
@RequestMapping("/<%= templatePath %>")
|
|
100
|
+
@Tag(name = "<%= packagePaths['controllerRest'].substring(basePackage.length + 1).replace(/\.controller$/, '') %>.<%= classPrefix %>", description = "<%= entityComment.split(':')[0] %>")
|
|
101
|
+
<% if (defaultSort) { -%>
|
|
102
|
+
@SimpliXDefaultSort(field = "<%= defaultSort.field %>", direction = "<%= defaultSort.direction || 'desc' %>")
|
|
103
|
+
<% } -%>
|
|
104
|
+
<% if ((ymlConfig.statusCounts || []).length > 0 || (ymlConfig.aggregates || []).length > 0 || ymlConfig.timeAxisField) { -%>
|
|
105
|
+
@SimpliXListFigures(statusCounts = {<%- (ymlConfig.statusCounts || []).map(f => `"${f}"`).join(', ') %>}, aggregates = {<%- (ymlConfig.aggregates || []).map(a => `@SimpliXListFigures.Figure(field = "${a.field}", op = "${a.op}")`).join(', ') %>}<% if (ymlConfig.timeAxisField) { %>, timeAxis = "<%= ymlConfig.timeAxisField %>"<% } %>)
|
|
106
|
+
<% } -%>
|
|
107
|
+
public class <%= controllerName %> extends SimpliXBaseController<<%= entityName %>, <%= idType %>> {
|
|
108
|
+
|
|
109
|
+
private final <%= classPrefix %>Service service;
|
|
110
|
+
<% if (hasTreeEntity) { %>
|
|
111
|
+
private final <%= classPrefix %>TreeService treeService;
|
|
112
|
+
<% } %>
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Constructs a new <%= controllerName %>.
|
|
116
|
+
*
|
|
117
|
+
* @param service the service for handling <%= entityName %> operations
|
|
118
|
+
<% if (hasTreeEntity) { %>
|
|
119
|
+
* @param treeService the tree service for handling tree-specific <%= entityName %> operations
|
|
120
|
+
<% } %> */
|
|
121
|
+
<% if (hasTreeEntity) { %>
|
|
122
|
+
public <%= controllerName %>(<%= classPrefix %>Service service, <%= classPrefix %>TreeService treeService) {
|
|
123
|
+
super(service);
|
|
124
|
+
this.service = service;
|
|
125
|
+
this.treeService = treeService;
|
|
126
|
+
}
|
|
127
|
+
<% } else { %>
|
|
128
|
+
public <%= controllerName %>(<%= classPrefix %>Service service) {
|
|
129
|
+
super(service);
|
|
130
|
+
this.service = service;
|
|
131
|
+
}
|
|
132
|
+
<% } %>
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new <%= entityName %> entity.
|
|
136
|
+
*
|
|
137
|
+
* @param createDto the DTO containing data for the new <%= entityName %>
|
|
138
|
+
* @return response containing the created <%= classPrefix %>DetailDTO
|
|
139
|
+
*/
|
|
140
|
+
@PostMapping("/create")
|
|
141
|
+
@Operation(summary = "Create <%= entityName %>", description = "Creates a new <%= entityName %>")
|
|
142
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'create')")
|
|
143
|
+
public SimpliXApiResponse<<%= classPrefix %>DetailDTO> create(@RequestBody @Validated <%= classPrefix %>CreateDTO createDto) {
|
|
144
|
+
<% if (hasTreeEntity) { %>
|
|
145
|
+
return SimpliXApiResponse.success(treeService.createNode(createDto));
|
|
146
|
+
<% } else { %>
|
|
147
|
+
return SimpliXApiResponse.success(service.create(createDto));
|
|
148
|
+
<% } %>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Updates an existing <%= entityName %> entity.
|
|
153
|
+
*<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
|
|
154
|
+
* @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
|
|
155
|
+
* @param <%= ymlConfig.idField %> the ID of the <%= entityName %> to update<% } %>
|
|
156
|
+
* @param updateDto the DTO containing updated data
|
|
157
|
+
* @return response containing the updated <%= classPrefix %>DetailDTO, or failure if not found
|
|
158
|
+
*/
|
|
159
|
+
@PutMapping("/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
|
|
160
|
+
@Operation(summary = "Update <%= entityName %>", description = "Updates existing <%= entityName %>")
|
|
161
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')<%= ymlConfig.ownerPermission ? " or @" + classPrefixLowerFirst + "Service.hasOwnerPermission('edit', #" + ymlConfig.idField + ", #updateDto)" : '' %>")
|
|
162
|
+
public SimpliXApiResponse<<%= classPrefix %>DetailDTO> update(<%= generatePathVariableParams() %>, @RequestBody @Validated <%= classPrefix %>UpdateDTO updateDto) {
|
|
163
|
+
<% if (hasEmbeddedId) { %>
|
|
164
|
+
<%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);
|
|
165
|
+
updateDto.set<%= capitalizeFirstLetter(ymlConfig.idField || 'id') %>(<%= ymlConfig.idField %>);
|
|
166
|
+
<% } %>
|
|
167
|
+
|
|
168
|
+
<% if (hasTreeEntity) { %>
|
|
169
|
+
return treeService.findById(<%= ymlConfig.idField %>)
|
|
170
|
+
.map(entity -> SimpliXApiResponse.success(treeService.updateNode(entity, updateDto)))
|
|
171
|
+
.orElse(SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>));
|
|
172
|
+
<% } else { %>
|
|
173
|
+
return service.findById(<%= ymlConfig.idField %>)
|
|
174
|
+
.map(entity -> SimpliXApiResponse.success(service.update(entity, updateDto)))
|
|
175
|
+
.orElse(SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>));
|
|
176
|
+
<% } %>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Updates multiple <%= entityName %> entities in a single operation.
|
|
181
|
+
*
|
|
182
|
+
* @param updateDtos set of DTOs containing update data
|
|
183
|
+
* @return response containing the list of updated <%= classPrefix %>DetailDTOs
|
|
184
|
+
*/
|
|
185
|
+
@PatchMapping
|
|
186
|
+
@Operation(summary = "Update Multiple <%= entityName %>", description = "Updates multiple existing <%= entityName %>")
|
|
187
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
|
|
188
|
+
public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> multiUpdate(@RequestBody Set<<%= classPrefix %>UpdateDTO> updateDtos) {
|
|
189
|
+
<% if (hasTreeEntity) { %>
|
|
190
|
+
// TreeService doesn't support multiUpdate - use service instead
|
|
191
|
+
List<<%= classPrefix %>DetailDTO> updatedItems = service.multiUpdate(updateDtos);
|
|
192
|
+
<% } else { %>
|
|
193
|
+
List<<%= classPrefix %>DetailDTO> updatedItems = service.multiUpdate(updateDtos);
|
|
194
|
+
<% } %>
|
|
195
|
+
|
|
196
|
+
return SimpliXApiResponse.success(updatedItems);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a <%= entityName %> by its ID.
|
|
201
|
+
*<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
|
|
202
|
+
* @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
|
|
203
|
+
* @param <%= ymlConfig.idField %> the ID of the <%= entityName %> to delete<% } %>
|
|
204
|
+
* @return response with success or failure message
|
|
205
|
+
*/
|
|
206
|
+
@DeleteMapping("/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
|
|
207
|
+
@Operation(summary = "Delete <%= entityName %>", description = "Deletes <%= entityName %> by ID")
|
|
208
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'delete')")
|
|
209
|
+
public SimpliXApiResponse<Void> delete(<%= generatePathVariableParams() %>) {
|
|
210
|
+
<% if (hasEmbeddedId) { %><%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);<% } %>
|
|
211
|
+
<% if (hasTreeEntity) { %>
|
|
212
|
+
if (!service.existsById(<%= ymlConfig.idField %>)) {
|
|
213
|
+
return SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>);
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
treeService.deleteNode(<%= ymlConfig.idField %>);
|
|
217
|
+
return SimpliXApiResponse.success(null, "<%= entityName %> deleted successfully");
|
|
218
|
+
} catch (SimpliXGeneralException e) {
|
|
219
|
+
return SimpliXApiResponse.failure(null, e.getMessage());
|
|
220
|
+
}
|
|
221
|
+
<% } else { %>
|
|
222
|
+
if (!service.existsById(<%= ymlConfig.idField %>)) {
|
|
223
|
+
return SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>);
|
|
224
|
+
}
|
|
225
|
+
service.delete(<%= ymlConfig.idField %>);
|
|
226
|
+
|
|
227
|
+
return SimpliXApiResponse.success(null, "<%= entityName %> deleted successfully");
|
|
228
|
+
<% } %>
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Retrieves a <%= entityName %> by its ID.
|
|
233
|
+
*<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
|
|
234
|
+
* @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
|
|
235
|
+
* @param <%= ymlConfig.idField %> the ID of the <%= entityName %> to retrieve<% } %>
|
|
236
|
+
* @return response containing the <%= classPrefix %>DetailDTO, or failure if not found
|
|
237
|
+
*/
|
|
238
|
+
@GetMapping("/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
|
|
239
|
+
@Operation(summary = "Get <%= entityName %>", description = "Retrieves <%= entityName %> by ID")
|
|
240
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'view')<%= ymlConfig.ownerPermission ? " or @" + classPrefixLowerFirst + "Service.hasOwnerPermission('view', #" + ymlConfig.idField + ", null)" : '' %>")
|
|
241
|
+
public SimpliXApiResponse<<%= classPrefix %>DetailDTO> get(<%= generatePathVariableParams() %>) {
|
|
242
|
+
<% if (hasEmbeddedId) { %>
|
|
243
|
+
<%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);
|
|
244
|
+
<% } %>
|
|
245
|
+
|
|
246
|
+
return service.findById(<%= ymlConfig.idField %>, <%= classPrefix %>DetailDTO.class)
|
|
247
|
+
.map(result -> SimpliXApiResponse.success(result))
|
|
248
|
+
.orElse(SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Retrieves a <%= entityName %> for update purposes.
|
|
253
|
+
*<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
|
|
254
|
+
* @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
|
|
255
|
+
* @param <%= ymlConfig.idField %> the ID of the <%= entityName %> to retrieve<% } %>
|
|
256
|
+
* @return response containing the <%= classPrefix %>UpdateDTO, or failure if not found
|
|
257
|
+
*/
|
|
258
|
+
@GetMapping("/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}/edit")
|
|
259
|
+
@Operation(summary = "Get <%= entityName %> for Update", description = "Retrieves <%= entityName %> by ID for update purposes")
|
|
260
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'view')<%= ymlConfig.ownerPermission ? " or @" + classPrefixLowerFirst + "Service.hasOwnerPermission('edit', #" + ymlConfig.idField + ", null)" : '' %>")
|
|
261
|
+
public SimpliXApiResponse<<%= classPrefix %>UpdateFormDTO> updateForm(<%= generatePathVariableParams() %>) {
|
|
262
|
+
<% if (hasEmbeddedId) { %>
|
|
263
|
+
<%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);
|
|
264
|
+
<% } %>
|
|
265
|
+
|
|
266
|
+
return service.findById(<%= ymlConfig.idField %>, <%= classPrefix %>UpdateFormDTO.class)
|
|
267
|
+
.map(result -> SimpliXApiResponse.success(result))
|
|
268
|
+
.orElse(SimpliXApiResponse.failure(null, <%- ymlConfig.notFoundMessageKey ? messages.name + '.get("' + ymlConfig.notFoundMessageKey + '")' : '"' + entityName + ' not found"' %>));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Batch updates multiple <%= entityName %> entities.
|
|
273
|
+
*
|
|
274
|
+
* @param batchUpdateDto the DTO containing batch update data
|
|
275
|
+
* @return response with success or failure message
|
|
276
|
+
*/
|
|
277
|
+
@PatchMapping("/batch")
|
|
278
|
+
@Operation(summary = "Batch Update <%= entityName %>s", description = "Updates multiple <%= entityName %>s")
|
|
279
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
|
|
280
|
+
public SimpliXApiResponse<Void> batchUpdate(@RequestBody @Validated <%= classPrefix %>BatchUpdateDTO batchUpdateDto) {
|
|
281
|
+
service.batchUpdate(batchUpdateDto);
|
|
282
|
+
return SimpliXApiResponse.success(null, "<%= entityName %>s updated successfully");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Deletes multiple <%= entityName %> entities by their IDs.
|
|
287
|
+
*<% if (hasEmbeddedId) { %>
|
|
288
|
+
* @param compositeIds list of composite key strings<% } else { %>
|
|
289
|
+
* @param <%= ymlConfig.idField %>s list of IDs to delete<% } %>
|
|
290
|
+
* @return response with success or failure message
|
|
291
|
+
*/
|
|
292
|
+
@DeleteMapping("/batch")
|
|
293
|
+
@Operation(summary = "Delete multiple <%= entityName %>s", description = "Deletes multiple <%= entityName %> by their IDs")
|
|
294
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'delete')")
|
|
295
|
+
public SimpliXApiResponse<Void> batchDelete(<% if (hasEmbeddedId) { %>@RequestParam List<String> compositeIds) {
|
|
296
|
+
List<<%= idType %>> <%= ymlConfig.idField %>s = compositeIds.stream()
|
|
297
|
+
.map(compositeId -> (new <%= embeddedIdType %>()).fromCompositeId(compositeId))
|
|
298
|
+
.collect(Collectors.toList());<% } else { %>@RequestParam List<<%= idType %>> <%= ymlConfig.idField %>s) {<% } %>
|
|
299
|
+
<% if (hasTreeEntity) { %>
|
|
300
|
+
try {
|
|
301
|
+
treeService.batchDeleteNodes(<%= ymlConfig.idField %>s);
|
|
302
|
+
return SimpliXApiResponse.success(null, "<%= entityName %>s deleted successfully");
|
|
303
|
+
} catch (SimpliXGeneralException e) {
|
|
304
|
+
return SimpliXApiResponse.failure(null, e.getMessage());
|
|
305
|
+
}
|
|
306
|
+
<% } else { %>
|
|
307
|
+
service.batchDelete(<%= ymlConfig.idField %>s);
|
|
308
|
+
|
|
309
|
+
return SimpliXApiResponse.success(null, "<%= entityName %>s deleted successfully");
|
|
310
|
+
<% } %>
|
|
311
|
+
}
|
|
312
|
+
<% if (hasOrderField) { %>
|
|
313
|
+
|
|
314
|
+
//----------------------------------
|
|
315
|
+
// Order Update
|
|
316
|
+
//----------------------------------
|
|
317
|
+
<% if (hasTreeEntity) { %>
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Updates the order of sibling nodes under a specific parent.
|
|
321
|
+
*
|
|
322
|
+
* @param parentId the parent node ID (empty string or null for root level)
|
|
323
|
+
* @param orderUpdateDtos list of DTOs containing the IDs and new order values
|
|
324
|
+
* @return response containing the list of updated <%= classPrefix %>ListDTOs
|
|
325
|
+
*/
|
|
326
|
+
@PatchMapping("/order")
|
|
327
|
+
@Operation(summary = "Update <%= entityName %> Orders", description = "Updates the order of sibling <%= entityName %> entities under a parent")
|
|
328
|
+
@SimpliXStandardApi
|
|
329
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
|
|
330
|
+
public SimpliXApiResponse<List<<%= classPrefix %>ListDTO>> updateTreeOrder(
|
|
331
|
+
@RequestParam(required = false) <%= idType %> parentId,
|
|
332
|
+
@RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
|
|
333
|
+
try {
|
|
334
|
+
List<<%= classPrefix %>ListDTO> updatedEntities = treeService.updateOrders(parentId, orderUpdateDtos);
|
|
335
|
+
return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
|
|
336
|
+
} catch (SimpliXGeneralException e) {
|
|
337
|
+
return SimpliXApiResponse.failure(null, e.getMessage());
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
<% } else { %>
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Updates the order of multiple <%= entityName %> entities.
|
|
344
|
+
*
|
|
345
|
+
* @param orderUpdateDtos list of DTOs containing the IDs and new order values
|
|
346
|
+
* @return response containing the list of updated <%= classPrefix %>DetailDTOs
|
|
347
|
+
*/
|
|
348
|
+
@PatchMapping("/order")
|
|
349
|
+
@Operation(summary = "Update <%= entityName %> Orders", description = "Updates the order of multiple <%= entityName %> entities")
|
|
350
|
+
@SimpliXStandardApi
|
|
351
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
|
|
352
|
+
public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> updateOrder(
|
|
353
|
+
@RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
|
|
354
|
+
List<<%= classPrefix %>DetailDTO> updatedEntities = service.updateOrders(orderUpdateDtos);
|
|
355
|
+
return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
|
|
356
|
+
}
|
|
357
|
+
<% } %>
|
|
358
|
+
<% } %>
|
|
359
|
+
<% if (hasTreeEntity) { %>
|
|
360
|
+
|
|
361
|
+
//----------------------------------
|
|
362
|
+
// Tree Operations
|
|
363
|
+
//----------------------------------
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Retrieves the tree structure starting from root nodes.
|
|
367
|
+
*
|
|
368
|
+
* @param fullTree if true, returns full tree with all descendants; if false, returns only root nodes
|
|
369
|
+
* @return response containing the list of <%= classPrefix %>ListDTO representing the tree structure
|
|
370
|
+
*/
|
|
371
|
+
@GetMapping("/tree")
|
|
372
|
+
@Operation(summary = "Get <%= entityName %> Tree", description = "Retrieves the tree structure of <%= entityName %> entities")
|
|
373
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
374
|
+
public SimpliXApiResponse<List<<%= classPrefix %>ListDTO>> getTree(
|
|
375
|
+
@RequestParam(value = "fullTree", defaultValue = "false") boolean fullTree) {
|
|
376
|
+
List<<%= classPrefix %>ListDTO> tree = treeService.findTree(fullTree);
|
|
377
|
+
return SimpliXApiResponse.success(tree);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Retrieves the subtree starting from a specific node.
|
|
382
|
+
*
|
|
383
|
+
* @param <%= ymlConfig.idField %> the root node ID to start from
|
|
384
|
+
* @param fullTree if true, returns full subtree with all descendants; if false, returns only immediate children
|
|
385
|
+
* @return response containing the list of <%= classPrefix %>ListDTO representing the subtree
|
|
386
|
+
*/
|
|
387
|
+
@GetMapping("/tree/{<%= ymlConfig.idField %>}")
|
|
388
|
+
@Operation(summary = "Get <%= entityName %> Subtree", description = "Retrieves the subtree of <%= entityName %> entities starting from a specific node")
|
|
389
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
390
|
+
public SimpliXApiResponse<List<<%= classPrefix %>ListDTO>> getSubtree(
|
|
391
|
+
@PathVariable <%= idType %> <%= ymlConfig.idField %>,
|
|
392
|
+
@RequestParam(value = "fullTree", defaultValue = "false") boolean fullTree) {
|
|
393
|
+
List<<%= classPrefix %>ListDTO> subtree = treeService.findTree(<%= ymlConfig.idField %>, fullTree);
|
|
394
|
+
return SimpliXApiResponse.success(subtree);
|
|
395
|
+
}
|
|
396
|
+
<% } %>
|
|
397
|
+
|
|
398
|
+
//----------------------------------
|
|
399
|
+
// Searchable JPA
|
|
400
|
+
//----------------------------------
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Searches <%= entityName %> entities using GET method.
|
|
404
|
+
*
|
|
405
|
+
* @param params map of search parameters
|
|
406
|
+
* @return response containing a page of <%= classPrefix %>ListDTO
|
|
407
|
+
*/
|
|
408
|
+
@GetMapping("/search")
|
|
409
|
+
@Operation(summary = "Search <%= entityName %> list (GET)", description = "Searches <%= entityName %> with various conditions using GET method")
|
|
410
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
411
|
+
public SimpliXApiResponse<Page<<%= classPrefix %>ListDTO>> simpleSearch(@RequestParam(required = false) @SearchableParams(<%= classPrefix %>SearchDTO.class) Map<String, String> params) {
|
|
412
|
+
return SimpliXApiResponse.success(service.search(params));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
<% if (exportConfig.enabled) { %>
|
|
416
|
+
/**
|
|
417
|
+
* Downloads every entry the list's search parameters match as CSV or Excel.
|
|
418
|
+
*
|
|
419
|
+
* <p>Writes the file to the response rather than returning an envelope: the body is the file,
|
|
420
|
+
* streamed page by page through simplix-excel. Errors still reach the global handler as
|
|
421
|
+
* exceptions.
|
|
422
|
+
*
|
|
423
|
+
* @param params map of search parameters, the same the list takes
|
|
424
|
+
* @param format the file kind, CSV when absent
|
|
425
|
+
* @param response where the file is written
|
|
426
|
+
* @throws IOException when the response cannot be written
|
|
427
|
+
*/
|
|
428
|
+
@GetMapping("/export")
|
|
429
|
+
@Operation(summary = "Export <%= entityName %> list",
|
|
430
|
+
description = "Downloads every <%= entityName %> the search conditions match as a CSV or XLSX file")
|
|
431
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'export')")
|
|
432
|
+
public void export(
|
|
433
|
+
@RequestParam(required = false) @SearchableParams(<%= classPrefix %>SearchDTO.class) Map<String, String> params,
|
|
434
|
+
@RequestParam(defaultValue = "CSV") ExportFormat format,
|
|
435
|
+
HttpServletResponse response) throws IOException {
|
|
436
|
+
service.export(params, format, response);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
<% } %>
|
|
440
|
+
<% if (ymlConfig.timeAxisField) { %>
|
|
441
|
+
/**
|
|
442
|
+
* Counts <%= entityName %> per slice of a time window, for the strip above the list.
|
|
443
|
+
*
|
|
444
|
+
* <p>Takes the same search parameters the list does, so the strip thins when the list is
|
|
445
|
+
* narrowed rather than showing a shape the rows below it do not have.
|
|
446
|
+
*
|
|
447
|
+
* @param from the first instant in the window, inclusive
|
|
448
|
+
* @param to the instant the window ends at, exclusive
|
|
449
|
+
* @param buckets how many slices to divide the window into
|
|
450
|
+
* @param params map of search parameters
|
|
451
|
+
* @return response containing one count per bucket, oldest first
|
|
452
|
+
*/
|
|
453
|
+
@GetMapping("/counts")
|
|
454
|
+
@Operation(summary = "Count <%= entityName %> per time bucket", description = "Counts <%= entityName %> per slice of a time window under the same search conditions")
|
|
455
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
456
|
+
public SimpliXApiResponse<List<Long>> counts(
|
|
457
|
+
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant from,
|
|
458
|
+
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant to,
|
|
459
|
+
@RequestParam int buckets,
|
|
460
|
+
@RequestParam(required = false) @SearchableParams(<%= classPrefix %>SearchDTO.class) Map<String, String> params) {
|
|
461
|
+
return SimpliXApiResponse.success(
|
|
462
|
+
service.countBuckets(TimeWindowParams.strip(params), from, to, buckets));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
<% } %>
|
|
466
|
+
<% if (statusCountFields.length > 0) { %>
|
|
467
|
+
/**
|
|
468
|
+
* Counts <%= entityName %> per value of one field, for the cards above the list.
|
|
469
|
+
*
|
|
470
|
+
* <p>Takes the same search parameters the list does, so a card's count is the number of rows
|
|
471
|
+
* the list shows once that value is picked.
|
|
472
|
+
*
|
|
473
|
+
* @param field the field to count by: <%= statusCountFields.join(', ') %>
|
|
474
|
+
* @param params map of search parameters
|
|
475
|
+
* @return response containing one count per value, every enum constant in declaration order
|
|
476
|
+
*/
|
|
477
|
+
@GetMapping("/status-counts")
|
|
478
|
+
@Operation(summary = "Count <%= entityName %> per value", description = "Counts <%= entityName %> per value of one field under the same search conditions as the list")
|
|
479
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
480
|
+
public SimpliXApiResponse<List<ValueCountDTO>> statusCounts(
|
|
481
|
+
@RequestParam String field,
|
|
482
|
+
@RequestParam(required = false) @SearchableParams(<%= classPrefix %>SearchDTO.class) Map<String, String> params) {
|
|
483
|
+
return SimpliXApiResponse.success(service.statusCounts(field, params));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
<% } %>
|
|
487
|
+
<% if (aggregateItems.length > 0) { %>
|
|
488
|
+
/**
|
|
489
|
+
* Computes <%= entityName %> figures, for the cards above the list.
|
|
490
|
+
*
|
|
491
|
+
* <p>Takes the same search parameters the list does, so a figure covers the rows the list shows.
|
|
492
|
+
*
|
|
493
|
+
* @param params map of search parameters
|
|
494
|
+
* @return response containing <%= aggregateItems.map(a => `${a.op} of ${a.field}`).join(', ') %>, in that order
|
|
495
|
+
*/
|
|
496
|
+
@GetMapping("/aggregates")
|
|
497
|
+
@Operation(summary = "Compute <%= entityName %> figures", description = "Computes sums and counts over <%= entityName %> under the same search conditions as the list")
|
|
498
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
499
|
+
public SimpliXApiResponse<List<AggregateValueDTO>> aggregates(
|
|
500
|
+
@RequestParam(required = false) @SearchableParams(<%= classPrefix %>SearchDTO.class) Map<String, String> params) {
|
|
501
|
+
return SimpliXApiResponse.success(service.aggregates(params));
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
<% } %>
|
|
505
|
+
/**
|
|
506
|
+
* Searches <%= entityName %> entities using POST method.
|
|
507
|
+
*
|
|
508
|
+
* @param searchCondition the search conditions for filtering
|
|
509
|
+
* @return response containing a page of <%= classPrefix %>ListDTO
|
|
510
|
+
*/
|
|
511
|
+
@PostMapping("/search")
|
|
512
|
+
@Operation(summary = "Search <%= entityName %> list (POST)", description = "Searches <%= entityName %> with various conditions using POST method")
|
|
513
|
+
@PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'list')")
|
|
514
|
+
public SimpliXApiResponse<Page<<%= classPrefix %>ListDTO>> search(@RequestBody @Validated SearchCondition<<%= classPrefix %>SearchDTO> searchCondition) {
|
|
515
|
+
return SimpliXApiResponse.success(service.search(searchCondition));
|
|
516
|
+
}
|
|
517
|
+
}
|