TSK-1654: fixed current code smells

This commit is contained in:
Mustapha Zorgati 2021-06-09 23:51:50 +02:00
parent a8376e1f72
commit dd5bccc62c
14 changed files with 64 additions and 120 deletions

View File

@ -198,18 +198,16 @@ public class HistoryCleanupJob extends AbstractTaskanaJob {
private int deleteHistoryEventsTransactionally(List<String> taskIdsToDeleteHistoryEventsFor) {
int deletedEventsCount = 0;
if (txProvider != null) {
int count =
(Integer)
txProvider.executeInTransaction(
() -> {
try {
return deleteEvents(taskIdsToDeleteHistoryEventsFor);
} catch (Exception e) {
LOGGER.warn("Could not delete history events.", e);
return 0;
}
});
return count;
return (int)
txProvider.executeInTransaction(
() -> {
try {
return deleteEvents(taskIdsToDeleteHistoryEventsFor);
} catch (Exception e) {
LOGGER.warn("Could not delete history events.", e);
return 0;
}
});
} else {
try {
deletedEventsCount = deleteEvents(taskIdsToDeleteHistoryEventsFor);

View File

@ -84,10 +84,7 @@ public class TaskHistoryEventController {
TaskHistoryEventPagedRepresentationModel pagedResources =
assembler.toPagedModel(historyEvents, pagingParameter.getPageMetadata());
ResponseEntity<TaskHistoryEventPagedRepresentationModel> response =
ResponseEntity.ok(pagedResources);
return response;
return ResponseEntity.ok(pagedResources);
}
/**

View File

@ -323,14 +323,8 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override
public List<ClassificationSummary> list() {
List<ClassificationSummary> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
result = taskanaEngine.getSqlSession().selectList(LINK_TO_SUMMARYMAPPER, this);
return result;
} finally {
taskanaEngine.returnConnection();
}
return taskanaEngine.openAndReturnConnection(
() -> taskanaEngine.getSqlSession().selectList(LINK_TO_SUMMARYMAPPER, this));
}
@Override

View File

@ -6,7 +6,7 @@ import java.util.List;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.RowBounds;
import pro.taskana.common.api.exceptions.TaskanaRuntimeException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.ObjectReferenceQuery;
import pro.taskana.task.api.ObjectReferenceQueryColumnName;
@ -67,19 +67,13 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
@Override
public List<ObjectReference> list() {
List<ObjectReference> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
result = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngine.returnConnection();
}
return taskanaEngine.openAndReturnConnection(
() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
}
@Override
public List<ObjectReference> list(int offset, int limit) {
List<ObjectReference> result = new ArrayList<>();
List<ObjectReference> result;
try {
taskanaEngine.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
@ -87,8 +81,8 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
return result;
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex =
new TaskanaRuntimeException(
SystemException ex =
new SystemException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
@ -102,7 +96,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
@Override
public List<String> listValues(
ObjectReferenceQueryColumnName columnName, SortDirection sortDirection) {
List<String> result = new ArrayList<>();
List<String> result;
try {
taskanaEngine.openConnection();
this.columnName = columnName;

View File

@ -917,21 +917,17 @@ public class TaskQueryImpl implements TaskQuery {
@Override
public List<TaskSummary> list() {
List<TaskSummary> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
checkForIllegalParamCombinations();
checkOpenAndReadPermissionForSpecifiedWorkbaskets();
setupJoinAndOrderParameters();
setupAccessIds();
List<TaskSummaryImpl> tasks =
taskanaEngine.getSqlSession().selectList(getLinkToMapperScript(), this);
return taskanaEngine.openAndReturnConnection(
() -> {
checkForIllegalParamCombinations();
checkOpenAndReadPermissionForSpecifiedWorkbaskets();
setupJoinAndOrderParameters();
setupAccessIds();
List<TaskSummaryImpl> tasks =
taskanaEngine.getSqlSession().selectList(getLinkToMapperScript(), this);
result = taskService.augmentTaskSummariesByContainedSummariesWithPartitioning(tasks);
return result;
} finally {
taskanaEngine.returnConnection();
}
return taskService.augmentTaskSummariesByContainedSummariesWithPartitioning(tasks);
});
}
@Override

View File

@ -133,18 +133,16 @@ public class TaskCleanupJob extends AbstractTaskanaJob {
int deletedTaskCount = 0;
if (txProvider != null) {
int count =
(Integer)
txProvider.executeInTransaction(
() -> {
try {
return deleteTasks(tasksToBeDeleted);
} catch (Exception e) {
LOGGER.warn("Could not delete tasks.", e);
return 0;
}
});
return count;
return (int)
txProvider.executeInTransaction(
() -> {
try {
return deleteTasks(tasksToBeDeleted);
} catch (Exception e) {
LOGGER.warn("Could not delete tasks.", e);
return 0;
}
});
} else {
try {
deletedTaskCount = deleteTasks(tasksToBeDeleted);

View File

@ -76,16 +76,8 @@ abstract class AbstractWorkbasketAccessItemQueryImpl<
@Override
public List<T> list() {
List<T> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
List<T> foundAccessItms =
taskanaEngine.getSqlSession().selectList(getLinkToMapper(), _this());
result.addAll(foundAccessItms);
return result;
} finally {
taskanaEngine.returnConnection();
}
return taskanaEngine.openAndReturnConnection(
() -> taskanaEngine.getSqlSession().selectList(getLinkToMapper(), _this()));
}
@Override

View File

@ -99,10 +99,8 @@ public class WorkbasketAccessItemQueryImpl implements WorkbasketAccessItemQuery
@Override
public List<WorkbasketAccessItem> list() {
List<WorkbasketAccessItem> result =
taskanaEngine.openAndReturnConnection(
() -> new ArrayList<>(taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this)));
return result;
return taskanaEngine.openAndReturnConnection(
() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
}
@Override

View File

@ -359,15 +359,9 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
@Override
public List<WorkbasketSummary> list() {
List<WorkbasketSummary> workbaskets = new ArrayList<>();
try {
taskanaEngine.openConnection();
handleCallerRolesAndAccessIds();
workbaskets = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
return workbaskets;
} finally {
taskanaEngine.returnConnection();
}
handleCallerRolesAndAccessIds();
return taskanaEngine.openAndReturnConnection(
() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
}
@Override

View File

@ -78,7 +78,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasket(String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
Workbasket result = null;
Workbasket result;
try {
taskanaEngine.openConnection();
result = workbasketMapper.findById(workbasketId);
@ -100,7 +100,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasket(String workbasketKey, String domain)
throws WorkbasketNotFoundException, NotAuthorizedException {
Workbasket result = null;
Workbasket result;
try {
taskanaEngine.openConnection();
result = workbasketMapper.findByKeyAndDomain(workbasketKey, domain);
@ -382,7 +382,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public void checkAuthorization(String workbasketId, WorkbasketPermission... requestedPermissions)
throws NotAuthorizedException, WorkbasketNotFoundException {
boolean isAuthorized = true;
try {
taskanaEngine.openConnection();
@ -413,7 +412,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (WorkbasketPermission perm : requestedPermissions) {
if (!grantedPermissions.contains(perm)) {
isAuthorized = false;
throw new NotAuthorizedException(
"Not authorized. Permission '"
+ perm.name()
@ -432,7 +430,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public void checkAuthorization(
String workbasketKey, String domain, WorkbasketPermission... requestedPermissions)
throws NotAuthorizedException, WorkbasketNotFoundException {
boolean isAuthorized = true;
try {
taskanaEngine.openConnection();
@ -465,7 +462,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (WorkbasketPermission perm : requestedPermissions) {
if (!grantedPermissions.contains(perm)) {
isAuthorized = false;
throw new NotAuthorizedException(
"Not authorized. Permission '"
+ perm.name()
@ -998,7 +994,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
throw new ConcurrencyException(
"The current Workbasket has been modified while editing. "
+ "The values can not be updated. Workbasket "
+ workbasketImplToUpdate.toString());
+ workbasketImplToUpdate);
}
}

View File

@ -89,11 +89,9 @@ public class ClassificationController {
sortParameter.applyToQuery(query);
List<ClassificationSummary> classificationSummaries = pagingParameter.applyToQuery(query);
ResponseEntity<ClassificationSummaryPagedRepresentationModel> response =
ResponseEntity.ok(
summaryModelAssembler.toPagedModel(
classificationSummaries, pagingParameter.getPageMetadata()));
return response;
return ResponseEntity.ok(
summaryModelAssembler.toPagedModel(
classificationSummaries, pagingParameter.getPageMetadata()));
}
/**
@ -109,9 +107,7 @@ public class ClassificationController {
public ResponseEntity<ClassificationRepresentationModel> getClassification(
@PathVariable String classificationId) throws ClassificationNotFoundException {
Classification classification = classificationService.getClassification(classificationId);
ResponseEntity<ClassificationRepresentationModel> response =
ResponseEntity.ok(modelAssembler.toModel(classification));
return response;
return ResponseEntity.ok(modelAssembler.toModel(classification));
}
/**
@ -136,10 +132,7 @@ public class ClassificationController {
Classification classification = modelAssembler.toEntityModel(repModel);
classification = classificationService.createClassification(classification);
ResponseEntity<ClassificationRepresentationModel> response =
ResponseEntity.status(HttpStatus.CREATED).body(modelAssembler.toModel(classification));
return response;
return ResponseEntity.status(HttpStatus.CREATED).body(modelAssembler.toModel(classification));
}
/**
@ -171,10 +164,8 @@ public class ClassificationController {
}
Classification classification = modelAssembler.toEntityModel(resource);
classification = classificationService.updateClassification(classification);
ResponseEntity<ClassificationRepresentationModel> result =
ResponseEntity.ok(modelAssembler.toModel(classification));
return result;
return ResponseEntity.ok(modelAssembler.toModel(classification));
}
/**
@ -194,8 +185,7 @@ public class ClassificationController {
@PathVariable String classificationId)
throws ClassificationNotFoundException, ClassificationInUseException, NotAuthorizedException {
classificationService.deleteClassification(classificationId);
ResponseEntity<ClassificationRepresentationModel> response = ResponseEntity.noContent().build();
return response;
return ResponseEntity.noContent().build();
}
enum ClassificationQuerySortBy implements QuerySortBy<ClassificationQuery> {

View File

@ -83,10 +83,7 @@ public class ClassificationDefinitionController {
Collectors.collectingAndThen(
Collectors.toList(), assembler::toTaskanaCollectionModel));
ResponseEntity<ClassificationDefinitionCollectionRepresentationModel> response =
ResponseEntity.ok(collectionModel);
return response;
return ResponseEntity.ok(collectionModel);
}
/**
@ -119,8 +116,7 @@ public class ClassificationDefinitionController {
mapChildrenToParentKeys(collection.getContent(), systemIds);
insertOrUpdateClassificationsWithoutParent(collection.getContent(), systemIds);
updateParentChildrenRelations(childrenInFile);
ResponseEntity<Void> response = ResponseEntity.noContent().build();
return response;
return ResponseEntity.noContent().build();
}
private Map<String, String> getSystemIds() {
@ -150,7 +146,7 @@ public class ClassificationDefinitionController {
}
if (!duplicates.isEmpty()) {
throw new DuplicateKeyException(
"The 'key|domain'-identifier is not unique for the value(s): " + duplicates.toString());
"The 'key|domain'-identifier is not unique for the value(s): " + duplicates);
}
}

View File

@ -50,7 +50,6 @@ public class TaskanaEngineController {
@GetMapping(path = RestEndpoints.URL_CLASSIFICATION_CATEGORIES)
public ResponseEntity<List<String>> getClassificationCategories(
@RequestParam(required = false) String type) {
ResponseEntity<List<String>> response;
if (type != null) {
return ResponseEntity.ok(taskanaEngineConfiguration.getClassificationCategoriesByType(type));
}

View File

@ -62,8 +62,10 @@ public class AttachmentRepresentationModelAssembler
attachment.setClassificationSummary(
classificationSummaryAssembler.toEntityModel(
attachmentRepresentationModel.getClassificationSummary()));
attachment.setObjectReference(
objectReferenceAssembler.toEntity(attachmentRepresentationModel.getObjectReference()));
if (attachmentRepresentationModel.getObjectReference() != null) {
attachment.setObjectReference(
objectReferenceAssembler.toEntity(attachmentRepresentationModel.getObjectReference()));
}
attachment.setChannel(attachmentRepresentationModel.getChannel());
attachment.setCustomAttributeMap(attachmentRepresentationModel.getCustomAttributes());
return attachment;