Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions openaev-api/src/main/java/io/openaev/rest/team/TeamApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ public Team upsertTeam(@Valid @RequestBody TeamCreateInput input) {
@Transactional
public void deleteTeam(@PathVariable @Schema(description = "ID of the team") String teamId)
throws ResourceInUseException {
if (!teamRepository.existsByIdAndTenantId(teamId, TenantContext.getCurrentTenant())) {
throw new ElementNotFoundException();
}
Team team =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: you should add a test for this case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: can you test on bulk delete team if we have the issue?

teamRepository
.findByIdAndTenantId(teamId, TenantContext.getCurrentTenant())
.orElseThrow(ElementNotFoundException::new);
try {
teamRepository.deleteById(teamId);
team.getInjects().forEach(inject -> inject.getTeams().remove(team));
teamRepository.delete(team);
Comment on lines +247 to +253
} catch (InvalidDataAccessApiUsageException | TransientObjectException ex) {
throw new ResourceInUseException(
"Cannot delete this team because it is still in use. Please remove its dependencies first.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ private List<ImportMessage> addFields(
.map(column -> InjectImportUtils.getValueAsString(row, column))
.collect(Collectors.joining(","))
.split(","))
.map(String::trim)
Comment thread
johanah29 marked this conversation as resolved.
.filter(value -> !value.isBlank())
.toList();
Comment on lines +891 to 893
}
if (columnValues.isEmpty() || columnValues.stream().allMatch(String::isEmpty)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import io.openaev.database.repository.ScenarioRepository;
import io.openaev.rest.exception.ElementNotFoundException;
import io.openaev.utils.InjectImportUtils;
import io.openaev.utils.fixtures.XlsFixture;
import io.openaev.utils.mockMapper.MockMapperUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
Expand Down Expand Up @@ -235,6 +235,33 @@ void testExtractWithoutConvertingCellAsHTML() {
assertEquals("Test\nTest", result);
}

@DisplayName("Test parse teams cell with spaces and trailing comma")
@Test
void testParseTeamsCellWithSpacesAndTrailingComma() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: this test don't test your changes. Please do a real import.

// -- PREPARE --
XlsFixture lsFixture = new XlsFixture();
workbook = lsFixture.createXlsFileWithTeams("Team A,\n Team A , Team_B,");
Sheet sheet = workbook.getSheetAt(0);
row = sheet.getRow(0);
RuleAttribute ruleAttribute = MockMapperUtils.createRuleAttribute();
ruleAttribute.setColumns("A");

// -- EXECUTE --
List<String> columnValues =
Arrays.stream(
Arrays.stream(ruleAttribute.getColumns().split("\\+"))
.map(column -> InjectImportUtils.getValueAsString(row, column))
.collect(Collectors.joining(","))
.split(","))
.map(String::trim)
.filter(value -> !value.isBlank())
.distinct()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: that's a huge issue. Having a disctinct here instead of having it on the prod code. Please put the distinct method in openaev-api/src/main/java/io/openaev/service/InjectImportService.java

.toList();

// -- ASSERT --
assertEquals(List.of("Team A", "Team_B"), columnValues);
}

@DisplayName("Test get inject date without pattern but with an ISO_DATE_TIME format")
@Test
void testGetInjectDateWithoutPattern() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public static String createDefaultXlsFile() throws IOException {
xlsFile.toFile().deleteOnExit();
return importId;
}

public Workbook createXlsFileWithTeams(String teamsCellValue) {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet(DEFAULT_SHEET_NAME);
Row dataRow = sheet.createRow(0);
dataRow.createCell(0).setCellValue(teamsCellValue);
return wb;
}
}
Loading