stable workspace version
This commit is contained in:
@@ -7,9 +7,11 @@ import com.litoralregas.backend.charts.dto.ChartWorkspaceResponse;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class ChartWorkspaceService {
|
||||
@@ -45,12 +47,14 @@ public class ChartWorkspaceService {
|
||||
return toResponse(saved);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ChartWorkspaceResponse getWorkspace(
|
||||
ChartWorkspaceScope scope
|
||||
) {
|
||||
return toResponse(getOrCreateDefaultWorkspace(scope));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<ChartWorkspaceResponse> listWorkspaces(
|
||||
ChartWorkspaceScope scope
|
||||
) {
|
||||
@@ -132,6 +136,10 @@ public class ChartWorkspaceService {
|
||||
repository.delete(workspace);
|
||||
|
||||
if (Boolean.TRUE.equals(workspace.getDefaultWorkspace())) {
|
||||
if (TransactionSynchronizationManager.isActualTransactionActive()) {
|
||||
repository.flush();
|
||||
}
|
||||
|
||||
repository.findAllByScopeOrderBySortOrderAscIdAsc(workspace.getScope())
|
||||
.stream()
|
||||
.findFirst()
|
||||
@@ -216,24 +224,39 @@ public class ChartWorkspaceService {
|
||||
workspace.setDefaultWorkspace(false);
|
||||
}
|
||||
|
||||
if (request.layoutMode() != null) {
|
||||
workspace.setLayoutMode(
|
||||
normalizeLayoutMode(request.layoutMode())
|
||||
);
|
||||
}
|
||||
|
||||
if (request.chartsJson() != null) {
|
||||
workspace.setChartsJson(
|
||||
normalizeChartsJson(request.chartsJson())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void setDefaultWorkspace(
|
||||
ChartWorkspace workspace
|
||||
) {
|
||||
repository.findAllByScopeOrderBySortOrderAscIdAsc(workspace.getScope())
|
||||
.forEach(candidate -> {
|
||||
if (!candidate.getId().equals(workspace.getId())) {
|
||||
List<ChartWorkspace> workspaces =
|
||||
repository.findAllByScopeOrderBySortOrderAscIdAsc(workspace.getScope());
|
||||
|
||||
boolean changedCurrentDefault = false;
|
||||
|
||||
for (ChartWorkspace candidate : workspaces) {
|
||||
if (!Objects.equals(candidate.getId(), workspace.getId())) {
|
||||
changedCurrentDefault =
|
||||
changedCurrentDefault ||
|
||||
Boolean.TRUE.equals(candidate.getDefaultWorkspace());
|
||||
candidate.setDefaultWorkspace(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (changedCurrentDefault && TransactionSynchronizationManager.isActualTransactionActive()) {
|
||||
repository.flush();
|
||||
}
|
||||
|
||||
workspace.setDefaultWorkspace(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user