-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #83] Implement service layer for fetching ManagedEntity and Faul…
…tTreeSummary properties. - add ComplexManagedEntityRepositoryService encapsulating common functionality for complex artifacts such as fault trees and systems. - fix bug not being able to update fault tree name
- Loading branch information
Showing
6 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/cz/cvut/kbss/analysis/service/ComplexManagedEntityRepositoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cz.cvut.kbss.analysis.service; | ||
|
||
|
||
import cz.cvut.kbss.analysis.dao.ManagedEntityDao; | ||
import cz.cvut.kbss.analysis.dao.UserDao; | ||
import cz.cvut.kbss.analysis.model.ManagedEntity; | ||
import cz.cvut.kbss.analysis.model.UserReference; | ||
import cz.cvut.kbss.analysis.service.security.SecurityUtils; | ||
import lombok.NonNull; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.validation.Validator; | ||
|
||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* A common repository service for entities stored in their own context, e.g. System, FaultTree, along with their parts, | ||
* e.g. for System its components and their behaviors, for FaultTrees its FaultEvents. | ||
* @param <T> | ||
*/ | ||
public abstract class ComplexManagedEntityRepositoryService<T extends ManagedEntity> extends BaseRepositoryService<T> { | ||
protected final UserDao userDao; | ||
|
||
public ComplexManagedEntityRepositoryService(Validator validator, UserDao userDao) { | ||
super(validator); | ||
this.userDao = userDao; | ||
} | ||
|
||
@Override | ||
protected void preUpdate(@NonNull T instance) { | ||
super.preUpdate(instance); | ||
UserReference user = SecurityUtils.currentUserReference(); | ||
instance.setLastEditor(user); | ||
instance.setModified(new Date()); | ||
} | ||
|
||
@Override | ||
protected void prePersist(@NonNull T instance) { | ||
super.prePersist(instance); | ||
UserReference user = SecurityUtils.currentUserReference(); | ||
instance.setCreator(user); | ||
instance.setCreated(new Date()); | ||
} | ||
|
||
|
||
@Transactional(readOnly = true) | ||
public List<T> findAllSummaries(){ | ||
return ((ManagedEntityDao<T>)getPrimaryDao()).findAllSummaries().stream().map(this::postLoad).toList(); | ||
} | ||
|
||
|
||
@Override | ||
protected T postLoad(@NonNull T instance) { | ||
super.postLoad(instance); | ||
for(UserReference user :Arrays.asList(instance.getLastEditor(), instance.getCreator())){ | ||
if(user == null) continue; | ||
setUserName(user); | ||
} | ||
return instance; | ||
} | ||
|
||
protected void setUserName(UserReference user){ | ||
String username = userDao.findUsername(user.getUri()); | ||
user.setUsername(username); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters