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

Re-executing still fails

parent 033d8619
No related branches found
No related tags found
3 merge requests!81New stable release,!47Resolve "Show error messages from response",!42Fixed the query service tests
......@@ -14,6 +14,8 @@ import java.util.List;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@ToString
public class ExecuteStatementDto {
@NotBlank(message = "statement is required")
......
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
......@@ -30,6 +33,15 @@ public class QueryDto {
@ApiModelProperty(name = "database id", example = "1")
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")
private Instant execution;
......
package at.tuwien.endpoint;
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.exception.*;
import at.tuwien.mapper.QueryMapper;
import at.tuwien.service.StoreService;
import at.tuwien.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
......@@ -20,12 +23,16 @@ import java.util.List;
@RequestMapping("/api/container/{id}/database/{databaseId}/query")
public class StoreEndpoint {
private final UserMapper userMapper;
private final QueryMapper queryMapper;
private final UserService userService;
private final StoreService storeService;
@Autowired
public StoreEndpoint(QueryMapper queryMapper, StoreService storeService) {
public StoreEndpoint(UserMapper userMapper, QueryMapper queryMapper, UserService userService, StoreService storeService) {
this.userMapper = userMapper;
this.queryMapper = queryMapper;
this.userService = userService;
this.storeService = storeService;
}
......@@ -40,8 +47,17 @@ public class StoreEndpoint {
public ResponseEntity<List<QueryDto>> findAll(@NotNull @PathVariable("id") Long id,
@NotNull @PathVariable("databaseId") Long databaseId) throws QueryStoreException,
DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException {
final List<Query> queries = storeService.findAll(id, databaseId);
return ResponseEntity.ok(queryMapper.queryListToQueryDtoList(queries));
final List<Query> storedQueries = storeService.findAll(id, databaseId);
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}")
......@@ -56,8 +72,11 @@ public class StoreEndpoint {
@NotNull @PathVariable("databaseId") Long databaseId,
@NotNull @PathVariable Long queryId)
throws DatabaseNotFoundException, ImageNotSupportedException,
QueryStoreException, QueryNotFoundException, ContainerNotFoundException {
final Query query = storeService.findOne(id, databaseId, queryId);
return ResponseEntity.ok(queryMapper.queryToQueryDto(query));
QueryStoreException, QueryNotFoundException, ContainerNotFoundException, UserNotFoundException {
final Query storeQuery = storeService.findOne(id, databaseId, queryId);
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 {
@Test
public void find_succeeds() throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException,
ImageNotSupportedException, ContainerNotFoundException {
ImageNotSupportedException, ContainerNotFoundException, UserNotFoundException {
/* mock */
when(storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID))
......
......@@ -3,6 +3,7 @@ package at.tuwien.mapper;
import at.tuwien.api.user.GrantedAuthorityDto;
import at.tuwien.api.user.UserDetailsDto;
import at.tuwien.api.user.UserDto;
import at.tuwien.entities.user.User;
import org.mapstruct.Mapper;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
......@@ -10,6 +11,8 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
@Mapper(componentModel = "spring")
public interface UserMapper {
UserDto userToUserDto(User data);
UserDetailsDto userDtoToUserDetailsDto(UserDto data);
default GrantedAuthority grantedAuthorityDtoToGrantedAuthority(GrantedAuthorityDto data) {
......
......@@ -14,4 +14,5 @@ public interface UserService {
*/
User findByUsername(String username) throws UserNotFoundException;
User findById(Long id) throws UserNotFoundException;
}
......@@ -30,4 +30,14 @@ public class UserServiceImpl implements UserService {
}
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 {
const url = '/server-middleware/query/build'
const data = {
table: this.table.internal_name,
select: this.select.map(s => s.name),
select: this.select.map(s => s.internal_name),
clauses: this.clauses
}
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment