Skip to content

Commit 4adf76a

Browse files
committed
Library system
1 parent 71a4237 commit 4adf76a

File tree

17 files changed

+3799
-1310
lines changed

17 files changed

+3799
-1310
lines changed
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# Bài tập: Enterprise Application Framework
2+
3+
## Mục tiêu:
4+
5+
Xây dựng framework cho enterprise applications với focus vào scalability và maintainability
6+
7+
## Yêu cầu chi tiết:
8+
9+
### 1. Abstract Class: BaseEntity
10+
11+
- Fields: `id` (UUID), `createdAt`, `updatedAt`, `version` (for optimistic locking)
12+
- Method: `updateTimestamp()`
13+
- Method: `incrementVersion()`
14+
- Abstract method: `validate()`
15+
- Implement equals(), hashCode() based trên id
16+
17+
### 2. Interface: Repository<T extends BaseEntity>
18+
19+
- Method: `save(T entity)`
20+
- Method: `findById(UUID id)`
21+
- Method: `findAll()`
22+
- Method: `delete(UUID id)`
23+
- Method: `existsById(UUID id)`
24+
- Method: `findByCriteria(SearchCriteria criteria)`
25+
26+
### 3. Interface: Service<T extends BaseEntity>
27+
28+
- Method: `create(T entity)`
29+
- Method: `update(UUID id, T entity)`
30+
- Method: `delete(UUID id)`
31+
- Method: `findById(UUID id)`
32+
- Method: `findAll(PageRequest pageRequest)`
33+
34+
### 4. Interface: Cacheable
35+
36+
- Method: `getCacheKey()`
37+
- Method: `getCacheTTL()` - Time To Live in seconds
38+
- Method: `shouldCache()`
39+
- Method: `evictCache()`
40+
41+
### 5. Interface: Auditable
42+
43+
- Method: `getAuditInfo()`
44+
- Method: `recordOperation(AuditOperation operation, String userId)`
45+
- Method: `getAuditHistory()`
46+
47+
### 6. Core Entity Classes:
48+
49+
#### User extends BaseEntity implements Auditable
50+
51+
- Fields: `username`, `email`, `passwordHash`, `roles`, `isActive`
52+
- Fields: `lastLoginAt`, `failedLoginAttempts`, `accountLockedUntil`
53+
- Method: `authenticate(String password)`
54+
- Method: `assignRole(Role role)`
55+
- Method: `hasPermission(Permission permission)`
56+
- Method: `lockAccount(Duration lockDuration)`
57+
58+
#### Role extends BaseEntity
59+
60+
- Fields: `name`, `description`, `permissions`
61+
- Method: `addPermission(Permission permission)`
62+
- Method: `removePermission(Permission permission)`
63+
- Method: `hasPermission(Permission permission)`
64+
65+
#### Permission extends BaseEntity
66+
67+
- Fields: `name`, `resource`, `action` (CREATE, READ, UPDATE, DELETE)
68+
- Method: `matches(String resource, String action)`
69+
70+
### 7. Service Layer Implementation:
71+
72+
#### UserService extends BaseService<User> implements Cacheable
73+
74+
- Method: `authenticateUser(String username, String password)`
75+
- Method: `registerUser(UserRegistrationRequest request)`
76+
- Method: `changePassword(UUID userId, String oldPassword, String newPassword)`
77+
- Method: `resetPassword(String email)`
78+
- Method: `searchUsers(UserSearchCriteria criteria)`
79+
- Implement caching cho frequently accessed users
80+
81+
#### RoleService extends BaseService<Role>
82+
83+
- Method: `createRoleWithPermissions(String roleName, List<Permission> permissions)`
84+
- Method: `assignRoleToUser(UUID userId, UUID roleId)`
85+
- Method: `getRolesByUser(UUID userId)`
86+
- Method: `updateRolePermissions(UUID roleId, List<Permission> permissions)`
87+
88+
### 8. Abstract Class: BaseService<T extends BaseEntity>
89+
90+
- Fields: `repository`, `cacheManager`, `auditService`, `validator`
91+
- Implement common CRUD operations
92+
- Method: `validateBeforeSave(T entity)`
93+
- Method: `performAudit(T entity, AuditOperation operation)`
94+
- Template method pattern cho save operations
95+
96+
### 9. Design Patterns Implementation:
97+
98+
#### Strategy Pattern: ValidationStrategy
99+
100+
```java
101+
public interface ValidationStrategy<T> {
102+
ValidationResult validate(T entity);
103+
}
104+
105+
public class UserValidationStrategy implements ValidationStrategy<User>
106+
public class EmailValidationStrategy implements ValidationStrategy<String>
107+
public class PasswordValidationStrategy implements ValidationStrategy<String>
108+
```
109+
110+
#### Decorator Pattern: ServiceDecorator
111+
112+
```java
113+
public abstract class ServiceDecorator<T> implements Service<T>
114+
public class CachingServiceDecorator<T> extends ServiceDecorator<T>
115+
public class AuditingServiceDecorator<T> extends ServiceDecorator<T>
116+
public class ValidationServiceDecorator<T> extends ServiceDecorator<T>
117+
```
118+
119+
#### Builder Pattern: QueryBuilder
120+
121+
```java
122+
public class QueryBuilder {
123+
public QueryBuilder select(String... fields)
124+
public QueryBuilder from(String table)
125+
public QueryBuilder where(String condition)
126+
public QueryBuilder orderBy(String field, SortDirection direction)
127+
public QueryBuilder limit(int count)
128+
public Query build()
129+
}
130+
```
131+
132+
### 10. Exception Handling Framework:
133+
134+
#### Custom Exception Hierarchy:
135+
136+
```java
137+
public class BusinessException extends Exception
138+
public class ValidationException extends BusinessException
139+
public class EntityNotFoundException extends BusinessException
140+
public class DuplicateEntityException extends BusinessException
141+
public class InsufficientPermissionException extends BusinessException
142+
```
143+
144+
#### Global Exception Handler:
145+
146+
```java
147+
public class GlobalExceptionHandler {
148+
public ErrorResponse handleValidationException(ValidationException ex)
149+
public ErrorResponse handleEntityNotFoundException(EntityNotFoundException ex)
150+
public ErrorResponse handleGenericException(Exception ex)
151+
}
152+
```
153+
154+
### 11. Configuration Management:
155+
156+
#### Interface: ConfigurationProvider
157+
158+
- Method: `getProperty(String key, Class<T> type)`
159+
- Method: `getProperty(String key, T defaultValue)`
160+
- Method: `getAllProperties()`
161+
- Method: `reloadConfiguration()`
162+
163+
#### Classes:
164+
165+
- `DatabaseConfigurationProvider` - load từ database
166+
- `FileConfigurationProvider` - load từ properties files
167+
- `EnvironmentConfigurationProvider` - load từ environment variables
168+
169+
### 12. Event-Driven Architecture:
170+
171+
#### Interface: Event
172+
173+
- Method: `getEventType()`
174+
- Method: `getTimestamp()`
175+
- Method: `getPayload()`
176+
177+
#### Interface: EventListener<T extends Event>
178+
179+
- Method: `handle(T event)`
180+
- Method: `canHandle(Event event)`
181+
182+
#### Class: EventBus (Singleton)
183+
184+
- Method: `publish(Event event)`
185+
- Method: `subscribe(EventListener<?> listener)`
186+
- Method: `unsubscribe(EventListener<?> listener)`
187+
- Async event processing với thread pool
188+
189+
### 13. Security Framework:
190+
191+
#### Interface: SecurityContext
192+
193+
- Method: `getCurrentUser()`
194+
- Method: `hasRole(String roleName)`
195+
- Method: `hasPermission(String resource, String action)`
196+
- Method: `authenticate(Credentials credentials)`
197+
198+
#### Class: JWTTokenManager
199+
200+
- Method: `generateToken(User user)`
201+
- Method: `validateToken(String token)`
202+
- Method: `extractClaims(String token)`
203+
- Method: `refreshToken(String refreshToken)`
204+
205+
### 14. Monitoring và Metrics:
206+
207+
#### Interface: MetricsCollector
208+
209+
- Method: `incrementCounter(String name, Map<String, String> tags)`
210+
- Method: `recordTimer(String name, Duration duration)`
211+
- Method: `recordGauge(String name, double value)`
212+
213+
#### Class: PerformanceMonitor
214+
215+
- Method: `startTimer(String operationName)`
216+
- Method: `endTimer(String operationName)`
217+
- Method: `recordMethodExecution(String methodName, long executionTime)`
218+
- AOP integration cho automatic monitoring
219+
220+
### 15. Advanced Features:
221+
222+
#### Multi-tenancy Support:
223+
224+
- Interface: TenantAware với getCurrentTenant()
225+
- TenantContext để manage tenant information
226+
- Data isolation strategies
227+
228+
#### Internationalization:
229+
230+
- MessageSource interface cho localized messages
231+
- ResourceBundleMessageSource implementation
232+
- Locale-aware error messages
233+
234+
#### Data Transfer Objects:
235+
236+
- Abstract class BaseDTO với mapping utilities
237+
- UserDTO, RoleDTO với proper validation annotations
238+
- Automatic mapping between entities và DTOs
239+
240+
### 16. Testing Framework:
241+
242+
- AbstractRepositoryTest với test database setup
243+
- AbstractServiceTest với mocking framework integration
244+
- Integration tests với TestContainers
245+
- Performance tests với JMH
246+
247+
### 17. Documentation Requirements:
248+
249+
- API documentation với detailed examples
250+
- Architecture diagrams
251+
- Configuration guide
252+
- Deployment instructions
253+
- Performance tuning guide
254+
255+
## Technical Requirements:
256+
257+
- Thread-safe implementations
258+
- Database transaction management
259+
- Connection pooling
260+
- Proper logging với structured formats
261+
- Health checks và metrics endpoints
262+
- Graceful shutdown handling
263+
264+
## Đánh giá:
265+
266+
- Architecture design (25%)
267+
- Security implementation (20%)
268+
- Performance optimization (20%)
269+
- Code quality và best practices (20%)
270+
- Documentationtesting (15%)

0 commit comments

Comments
 (0)