Skip to content
Snippets Groups Projects
Commit 39567461 authored by Martin Weise's avatar Martin Weise
Browse files

Re-executing still fails

Former-commit-id: 0d9fe9a5
parent 4b5e8cc4
No related branches found
No related tags found
2 merge requests!81New stable release,!47Resolve "Show error messages from response"
...@@ -14,6 +14,8 @@ import java.util.List; ...@@ -14,6 +14,8 @@ import java.util.List;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@EqualsAndHashCode
@ToString
public class ExecuteStatementDto { public class ExecuteStatementDto {
@NotBlank(message = "statement is required") @NotBlank(message = "statement is required")
......
package at.tuwien.api.database.query; package at.tuwien.api.database.query;
import at.tuwien.api.user.UserDto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*; import lombok.*;
...@@ -30,6 +33,15 @@ public class QueryDto { ...@@ -30,6 +33,15 @@ public class QueryDto {
@ApiModelProperty(name = "database id", example = "1") @ApiModelProperty(name = "database id", example = "1")
private Long dbid; private Long dbid;
@JsonIgnore
@NotNull(message = "created by is required")
@ApiModelProperty(name = "creator id", example = "1")
private Long createdBy;
@NotNull(message = "creator is required")
@ApiModelProperty(name = "creator")
private UserDto creator;
@ApiModelProperty(name = "execution time", example = "2022-01-01 08:00:00.000") @ApiModelProperty(name = "execution time", example = "2022-01-01 08:00:00.000")
private Instant execution; private Instant execution;
......
package at.tuwien.endpoint; package at.tuwien.endpoint;
import at.tuwien.api.database.query.QueryDto; import at.tuwien.api.database.query.QueryDto;
import at.tuwien.entities.user.User;
import at.tuwien.mapper.UserMapper;
import at.tuwien.querystore.Query; import at.tuwien.querystore.Query;
import at.tuwien.exception.*; import at.tuwien.exception.*;
import at.tuwien.mapper.QueryMapper; import at.tuwien.mapper.QueryMapper;
import at.tuwien.service.StoreService; import at.tuwien.service.StoreService;
import at.tuwien.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
...@@ -20,12 +23,16 @@ import java.util.List; ...@@ -20,12 +23,16 @@ import java.util.List;
@RequestMapping("/api/container/{id}/database/{databaseId}/query") @RequestMapping("/api/container/{id}/database/{databaseId}/query")
public class StoreEndpoint { public class StoreEndpoint {
private final UserMapper userMapper;
private final QueryMapper queryMapper; private final QueryMapper queryMapper;
private final UserService userService;
private final StoreService storeService; private final StoreService storeService;
@Autowired @Autowired
public StoreEndpoint(QueryMapper queryMapper, StoreService storeService) { public StoreEndpoint(UserMapper userMapper, QueryMapper queryMapper, UserService userService, StoreService storeService) {
this.userMapper = userMapper;
this.queryMapper = queryMapper; this.queryMapper = queryMapper;
this.userService = userService;
this.storeService = storeService; this.storeService = storeService;
} }
...@@ -40,8 +47,17 @@ public class StoreEndpoint { ...@@ -40,8 +47,17 @@ public class StoreEndpoint {
public ResponseEntity<List<QueryDto>> findAll(@NotNull @PathVariable("id") Long id, public ResponseEntity<List<QueryDto>> findAll(@NotNull @PathVariable("id") Long id,
@NotNull @PathVariable("databaseId") Long databaseId) throws QueryStoreException, @NotNull @PathVariable("databaseId") Long databaseId) throws QueryStoreException,
DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException { DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException {
final List<Query> queries = storeService.findAll(id, databaseId); final List<Query> storedQueries = storeService.findAll(id, databaseId);
return ResponseEntity.ok(queryMapper.queryListToQueryDtoList(queries)); final List<QueryDto> queries = queryMapper.queryListToQueryDtoList(storedQueries);
queries.forEach(query -> {
try {
final User user = userService.findById(query.getCreatedBy());
query.setCreator(userMapper.userToUserDto(user));
} catch (UserNotFoundException e) {
/* already logged */
}
});
return ResponseEntity.ok(queries);
} }
@GetMapping("/{queryId}") @GetMapping("/{queryId}")
...@@ -56,8 +72,11 @@ public class StoreEndpoint { ...@@ -56,8 +72,11 @@ public class StoreEndpoint {
@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("databaseId") Long databaseId,
@NotNull @PathVariable Long queryId) @NotNull @PathVariable Long queryId)
throws DatabaseNotFoundException, ImageNotSupportedException, throws DatabaseNotFoundException, ImageNotSupportedException,
QueryStoreException, QueryNotFoundException, ContainerNotFoundException { QueryStoreException, QueryNotFoundException, ContainerNotFoundException, UserNotFoundException {
final Query query = storeService.findOne(id, databaseId, queryId); final Query storeQuery = storeService.findOne(id, databaseId, queryId);
return ResponseEntity.ok(queryMapper.queryToQueryDto(query)); final QueryDto query = queryMapper.queryToQueryDto(storeQuery);
final User user = userService.findById(query.getCreatedBy());
query.setCreator(userMapper.userToUserDto(user));
return ResponseEntity.ok(query);
} }
} }
...@@ -56,7 +56,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { ...@@ -56,7 +56,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test @Test
public void find_succeeds() throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException, public void find_succeeds() throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException,
ImageNotSupportedException, ContainerNotFoundException { ImageNotSupportedException, ContainerNotFoundException, UserNotFoundException {
/* mock */ /* mock */
when(storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID)) when(storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID))
......
...@@ -3,6 +3,7 @@ package at.tuwien.mapper; ...@@ -3,6 +3,7 @@ package at.tuwien.mapper;
import at.tuwien.api.user.GrantedAuthorityDto; import at.tuwien.api.user.GrantedAuthorityDto;
import at.tuwien.api.user.UserDetailsDto; import at.tuwien.api.user.UserDetailsDto;
import at.tuwien.api.user.UserDto; import at.tuwien.api.user.UserDto;
import at.tuwien.entities.user.User;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
...@@ -10,6 +11,8 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; ...@@ -10,6 +11,8 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
@Mapper(componentModel = "spring") @Mapper(componentModel = "spring")
public interface UserMapper { public interface UserMapper {
UserDto userToUserDto(User data);
UserDetailsDto userDtoToUserDetailsDto(UserDto data); UserDetailsDto userDtoToUserDetailsDto(UserDto data);
default GrantedAuthority grantedAuthorityDtoToGrantedAuthority(GrantedAuthorityDto data) { default GrantedAuthority grantedAuthorityDtoToGrantedAuthority(GrantedAuthorityDto data) {
......
...@@ -14,4 +14,5 @@ public interface UserService { ...@@ -14,4 +14,5 @@ public interface UserService {
*/ */
User findByUsername(String username) throws UserNotFoundException; User findByUsername(String username) throws UserNotFoundException;
User findById(Long id) throws UserNotFoundException;
} }
...@@ -30,4 +30,14 @@ public class UserServiceImpl implements UserService { ...@@ -30,4 +30,14 @@ public class UserServiceImpl implements UserService {
} }
return user.get(); return user.get();
} }
@Override
public User findById(Long id) throws UserNotFoundException {
final Optional<User> user = userRepository.findById(id);
if (user.isEmpty()) {
log.error("Failed to find user by id {}", id);
throw new UserNotFoundException("Failed to find user");
}
return user.get();
}
} }
...@@ -204,7 +204,7 @@ export default { ...@@ -204,7 +204,7 @@ export default {
const url = '/server-middleware/query/build' const url = '/server-middleware/query/build'
const data = { const data = {
table: this.table.internal_name, table: this.table.internal_name,
select: this.select.map(s => s.name), select: this.select.map(s => s.internal_name),
clauses: this.clauses clauses: this.clauses
} }
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment