Skip to content

Commit ff5c4e9

Browse files
committed
clean code
Signed-off-by: achour94 <[email protected]>
1 parent 1d1a758 commit ff5c4e9

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/java/org/gridsuite/spreadsheetconfig/server/service/SpreadsheetConfigService.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public UUID createSpreadsheetConfig(SpreadsheetConfigInfos dto) {
3838

3939
@Transactional
4040
public UUID duplicateSpreadsheetConfig(UUID id) {
41-
SpreadsheetConfigEntity entity = spreadsheetConfigRepository.findById(id)
42-
.orElseThrow(() -> new EntityNotFoundException("SpreadsheetConfig not found with id: " + id));
41+
SpreadsheetConfigEntity entity = findEntityById(id);
4342

4443
SpreadsheetConfigEntity duplicate = SpreadsheetConfigEntity.builder()
4544
.sheetType(entity.getSheetType())
@@ -59,9 +58,7 @@ public UUID duplicateSpreadsheetConfig(UUID id) {
5958

6059
@Transactional(readOnly = true)
6160
public SpreadsheetConfigInfos getSpreadsheetConfig(UUID id) {
62-
return spreadsheetConfigRepository.findById(id)
63-
.map(SpreadsheetConfigMapper::toDto)
64-
.orElseThrow(() -> new EntityNotFoundException("SpreadsheetConfig not found with id: " + id));
61+
return SpreadsheetConfigMapper.toDto(findEntityById(id));
6562
}
6663

6764
@Transactional(readOnly = true)
@@ -83,8 +80,7 @@ public List<MetadataInfos> getSpreadsheetConfigsMetadata(List<UUID> ids) {
8380

8481
@Transactional
8582
public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {
86-
SpreadsheetConfigEntity entity = spreadsheetConfigRepository.findById(id)
87-
.orElseThrow(() -> new EntityNotFoundException("SpreadsheetConfig not found with id: " + id));
83+
SpreadsheetConfigEntity entity = findEntityById(id);
8884

8985
entity.setSheetType(dto.sheetType());
9086
entity.getCustomColumns().clear();
@@ -98,9 +94,18 @@ public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {
9894
@Transactional
9995
public void deleteSpreadsheetConfig(UUID id) {
10096
if (!spreadsheetConfigRepository.existsById(id)) {
101-
throw new EntityNotFoundException("SpreadsheetConfig not found with id: " + id);
97+
throw entityNotFoundException(id);
10298
}
10399
spreadsheetConfigRepository.deleteById(id);
104100
}
105101

102+
private SpreadsheetConfigEntity findEntityById(UUID id) {
103+
return spreadsheetConfigRepository.findById(id)
104+
.orElseThrow(() -> entityNotFoundException(id));
105+
}
106+
107+
private EntityNotFoundException entityNotFoundException(UUID id) {
108+
return new EntityNotFoundException("SpreadsheetConfig not found with id: " + id);
109+
}
110+
106111
}

0 commit comments

Comments
 (0)