Skip to content

Commit 4b94f98

Browse files
Merge pull request #49 from dynamiatools/26.2.x
improve javadocs
2 parents bbfbb6c + f9cec09 commit 4b94f98

File tree

46 files changed

+4519
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4519
-313
lines changed

platform/core/crud/src/main/java/tools/dynamia/crud/CrudControllerAPI.java

Lines changed: 207 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,94 +26,293 @@
2626
import java.util.Map;
2727

2828
/**
29-
* Basic interface for CrudController, normaly use it in UIs
30-
* @param <E>
29+
* Core API for managing CRUD operations on domain entities within user interface contexts.
30+
* This interface provides a comprehensive set of methods for creating, reading, updating, and deleting entities,
31+
* along with query capabilities, pagination support, and lifecycle hooks.
32+
*
33+
* <p>Implementations of this interface are typically used in UI controllers to handle entity operations
34+
* with minimal boilerplate code. It integrates seamlessly with the CrudService layer and provides
35+
* state management for current entity, selected entity, and query results.</p>
36+
*
37+
* <p>Example usage:</p>
38+
* <pre>{@code
39+
* CrudControllerAPI<Customer> controller = new CrudController<>(Customer.class, crudService);
40+
* controller.doCreate();
41+
* controller.getEntity().setName("John Doe");
42+
* controller.doSave();
43+
* }</pre>
44+
*
45+
* @param <E> the type of the domain entity managed by this controller
3146
*/
3247
public interface CrudControllerAPI<E> {
3348

49+
/**
50+
* Sets the CrudService used to perform database operations.
51+
*
52+
* @param crudService the service instance to handle persistence operations
53+
*/
3454
void setCrudService(CrudService crudService);
3555

56+
/**
57+
* Gets the current CrudService instance.
58+
*
59+
* @return the service responsible for CRUD operations
60+
*/
3661
CrudService getCrudService();
3762

63+
/**
64+
* Saves the current entity using the configured CrudService.
65+
* This method typically triggers validation and persistence operations.
66+
* Use {@link #doSave()} for the complete save workflow including UI feedback.
67+
*/
3868
void save();
3969

70+
/**
71+
* Deletes the current entity using the configured CrudService.
72+
* This method performs the deletion without confirmation or UI feedback.
73+
* Use {@link #doDelete()} for the complete deletion workflow.
74+
*/
4075
void delete();
4176

77+
/**
78+
* Executes a query using the current example entity and query parameters.
79+
* Results are stored in the query result dataset.
80+
* Use {@link #doQuery()} for the complete query workflow with UI updates.
81+
*/
4282
void query();
4383

4484
/**
45-
* Helper method to do a programatic delete
85+
* Performs a programmatic deletion of a specific entity.
86+
* This is a convenience method for deleting entities without setting them as the current entity.
4687
*
47-
*/
48-
void delete(E entity);
88+
* @param entity the entity to delete
89+
*/
90+
void delete(E entity);
4991

5092
/**
51-
* Helper method to do a programatic edit
93+
* Performs a programmatic edit operation on a specific entity.
94+
* Sets the given entity as the current entity and prepares it for editing.
5295
*
53-
*/
54-
void edit(E entity);
96+
* @param entity the entity to edit
97+
*/
98+
void edit(E entity);
5599

100+
/**
101+
* Creates a new instance of the managed entity class and sets it as the current entity.
102+
* The new entity is initialized with default values if configured.
103+
*/
56104
void newEntity();
57105

106+
/**
107+
* Creates a new example entity instance for query-by-example operations.
108+
* The example entity is used to specify search criteria.
109+
*/
58110
void newExample();
59111

112+
/**
113+
* Reloads the current entity from the database, discarding any unsaved changes.
114+
* This is useful to refresh the entity state after external modifications.
115+
*/
60116
void reloadEntity();
61117

118+
/**
119+
* Gets the current entity being managed by this controller.
120+
*
121+
* @return the current entity, or null if no entity is set
122+
*/
62123
E getEntity();
63124

125+
/**
126+
* Sets the current entity to be managed by this controller.
127+
*
128+
* @param entity the entity to set as current
129+
*/
64130
void setEntity(E entity);
65131

132+
/**
133+
* Gets the example entity used for query-by-example operations.
134+
*
135+
* @return the example entity, or null if no example is set
136+
*/
66137
E getExample();
67138

139+
/**
140+
* Gets the currently selected entity from the query results.
141+
* This is typically used in list/table views where users can select a row.
142+
*
143+
* @return the selected entity, or null if no entity is selected
144+
*/
68145
E getSelected();
69146

147+
/**
148+
* Checks if the current entity has been successfully saved.
149+
*
150+
* @return true if the entity was saved in the last operation, false otherwise
151+
*/
70152
boolean isSaved();
71153

154+
/**
155+
* Checks if the current entity has been successfully deleted.
156+
*
157+
* @return true if the entity was deleted in the last operation, false otherwise
158+
*/
72159
boolean isDeleted();
73160

161+
/**
162+
* Sets the currently selected entity from query results.
163+
*
164+
* @param selected the entity to mark as selected
165+
*/
74166
void setSelected(E selected);
75167

168+
/**
169+
* Gets the query parameters used for searching and filtering entities.
170+
*
171+
* @return the current query parameters
172+
*/
76173
QueryParameters getParams();
77174

175+
/**
176+
* Sets the query parameters for searching and filtering entities.
177+
*
178+
* @param params the query parameters to use
179+
*/
78180
void setParams(QueryParameters params);
79181

182+
/**
183+
* Gets a specific parameter value from the query parameters.
184+
*
185+
* @param param the parameter name
186+
* @return the parameter value, or null if not found
187+
*/
80188
Object getParameter(String param);
81189

190+
/**
191+
* Sets a specific parameter value in the query parameters.
192+
*
193+
* @param key the parameter name
194+
* @param value the parameter value
195+
*/
82196
void setParemeter(String key, Object value);
83197

198+
/**
199+
* Gets the dataset containing the results of the last query operation.
200+
*
201+
* @return the query result dataset
202+
*/
84203
DataSet getQueryResult();
85204

205+
/**
206+
* Sets the dataset containing query results.
207+
*
208+
* @param queryResult the dataset to set
209+
*/
86210
void setQueryResult(DataSet queryResult);
87211

212+
/**
213+
* Checks if the query results are empty.
214+
*
215+
* @return true if no results were found in the last query, false otherwise
216+
*/
88217
boolean isQueryResultEmpty();
89218

219+
/**
220+
* Gets the paginator for handling large query result sets.
221+
*
222+
* @return the data paginator instance
223+
*/
90224
DataPaginator getDataPaginator();
91225

226+
/**
227+
* Gets the sorter used to order query results.
228+
*
229+
* @return the bean sorter instance
230+
*/
92231
BeanSorter getSorter();
93232

233+
/**
234+
* Gets the class type of the entity managed by this controller.
235+
*
236+
* @return the entity class
237+
*/
94238
Class<E> getEntityClass();
95239

240+
/**
241+
* Sets the class type of the entity to be managed by this controller.
242+
*
243+
* @param entityClass the entity class to manage
244+
*/
96245
void setEntityClass(Class<E> entityClass);
97246

247+
/**
248+
* Executes a complete query workflow including UI updates and feedback.
249+
* This method triggers the query operation and updates the view accordingly.
250+
*/
98251
void doQuery();
99252

253+
/**
254+
* Executes a complete save workflow including validation, persistence, and UI feedback.
255+
* This is the main method to persist entity changes from the user interface.
256+
*/
100257
void doSave();
101258

259+
/**
260+
* Executes a save operation and immediately switches to edit mode for the saved entity.
261+
* Useful for workflows where users want to continue editing after saving.
262+
*/
102263
void doSaveAndEdit();
103264

265+
/**
266+
* Executes a complete edit workflow, preparing the selected entity for modification.
267+
* This method sets up the UI for editing the currently selected entity.
268+
*/
104269
void doEdit();
105270

271+
/**
272+
* Executes a complete delete workflow including confirmation prompts and UI feedback.
273+
* This is the main method to delete entities from the user interface.
274+
*/
106275
void doDelete();
107276

277+
/**
278+
* Executes a complete create workflow, initializing a new entity and preparing the UI.
279+
* This method sets up the form for creating a new entity instance.
280+
*/
108281
void doCreate();
109282

283+
/**
284+
* Gets the default values to be applied to new entities.
285+
* These values are automatically set when creating new entity instances.
286+
*
287+
* @return a map containing default field names and their values
288+
*/
110289
Map<String, Object> getDefaultEntityValues();
111290

291+
/**
292+
* Sets whether to show a confirmation dialog before saving entities.
293+
*
294+
* @param confirm true to require confirmation, false to save directly
295+
*/
112296
void setConfirmBeforeSave(boolean confirm);
113297

298+
/**
299+
* Checks if confirmation is required before saving entities.
300+
*
301+
* @return true if confirmation is enabled, false otherwise
302+
*/
114303
boolean isConfirmBeforeSave();
115304

305+
/**
306+
* Registers a callback to be executed after successful save operations.
307+
* This allows custom logic to be triggered post-save.
308+
*
309+
* @param onSave the callback to execute after saving
310+
*/
116311
void onSave(Callback onSave);
117312

313+
/**
314+
* Clears the controller state, resetting all entities and query results.
315+
* This method is useful for resetting the controller to its initial state.
316+
*/
118317
void clear();
119318
}

platform/core/crud/src/main/java/tools/dynamia/crud/SubcrudControllerAPI.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,81 @@
2020
import java.util.List;
2121

2222
/**
23-
* Basic interface for creation subcruds from {@link CrudControllerAPI}
24-
* @param <E>
23+
* Specialized CRUD controller API for managing child entities within a parent-child relationship context.
24+
* This interface extends {@link CrudControllerAPI} to provide additional functionality for handling
25+
* sub-entities (children) that belong to a parent entity, commonly used in master-detail UI patterns.
26+
*
27+
* <p>A subcrud controller manages collections of child entities and tracks pending changes
28+
* (creates, updates, deletes) that are typically committed together with the parent entity.
29+
* This allows for transactional consistency when saving complex object graphs.</p>
30+
*
31+
* <p>Example usage:</p>
32+
* <pre>{@code
33+
* // Managing order items within an order
34+
* SubcrudControllerAPI<OrderItem> itemsController = new SubcrudController<>(OrderItem.class);
35+
* itemsController.setParentEntity(order);
36+
* itemsController.doCreate();
37+
*
38+
* // Add new item
39+
* OrderItem newItem = itemsController.getEntity();
40+
* newItem.setProduct(product);
41+
* newItem.setQuantity(5);
42+
* itemsController.doSave();
43+
*
44+
* // All changes are tracked for batch processing
45+
* List<OrderItem> toCreate = itemsController.getToBeCreatedEntities();
46+
* List<OrderItem> toUpdate = itemsController.getToBeUpdatedEntities();
47+
* }</pre>
48+
*
49+
* @param <E> the type of the child entity managed by this subcrud controller
2550
*/
2651
public interface SubcrudControllerAPI<E> extends CrudControllerAPI<E> {
2752

53+
/**
54+
* Gets the parent entity that owns the child entities managed by this controller.
55+
* The parent entity represents the "master" in a master-detail relationship.
56+
*
57+
* @return the parent entity instance, or null if no parent is set
58+
*/
2859
Object getParentEntity();
2960

61+
/**
62+
* Gets the name or property identifier of the parent entity.
63+
* This is typically used for UI labels, field binding, or navigation purposes.
64+
*
65+
* @return the parent entity name or property identifier
66+
*/
3067
String getParentName();
3168

69+
/**
70+
* Gets the name or property identifier of the child entities collection.
71+
* This represents the collection property in the parent entity that holds the children.
72+
*
73+
* @return the children collection name or property identifier
74+
*/
3275
String getChildrenName();
3376

77+
/**
78+
* Gets the list of existing child entities that have been modified and need to be updated.
79+
* These entities will be persisted when the parent entity is saved.
80+
*
81+
* @return a list of entities pending update operations, or an empty list if none
82+
*/
3483
List<E> getToBeUpdatedEntities();
3584

85+
/**
86+
* Gets the list of new child entities that have been created and need to be persisted.
87+
* These entities will be inserted into the database when the parent entity is saved.
88+
*
89+
* @return a list of entities pending creation, or an empty list if none
90+
*/
3691
List<E> getToBeCreatedEntities();
3792

93+
/**
94+
* Gets the list of existing child entities that have been marked for deletion.
95+
* These entities will be removed from the database when the parent entity is saved.
96+
*
97+
* @return a list of entities pending deletion, or an empty list if none
98+
*/
3899
List<E> getToBeDeletedEntities();
39100
}

0 commit comments

Comments
 (0)