forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4352] Add support to range column filters in table
Bug: eclipse-sirius#4352 Signed-off-by: Florian ROUËNÉ <[email protected]>
- Loading branch information
1 parent
9d0106d
commit 17c005e
Showing
20 changed files
with
328 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rius-components-core/src/test/java/org/eclipse/sirius/components/core/URLParserTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 CEA LIST. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.core; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests of the URLParser. | ||
* | ||
* @author frouene | ||
*/ | ||
public class URLParserTests { | ||
|
||
@Test | ||
public void testGetParameterEntriesWithNestedLists() { | ||
URLParser parser = new URLParser(); | ||
String value = "[467ec1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"\"],4752c1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"2\"]]"; | ||
List<String> expected = List.of( | ||
"467ec1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"\"]", | ||
"4752c1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"2\"]" | ||
); | ||
List<String> result = parser.getParameterEntries(value); | ||
assertThat(expected).isEqualTo(result); | ||
} | ||
|
||
@Test | ||
public void testGetParameterEntriesWithEmptyList() { | ||
URLParser parser = new URLParser(); | ||
String value = "[]"; | ||
List<String> expected = List.of(); | ||
List<String> result = parser.getParameterEntries(value); | ||
assertThat(expected).isEqualTo(result); | ||
} | ||
|
||
@Test | ||
public void testGetParameterEntriesWithSingleElement() { | ||
URLParser parser = new URLParser(); | ||
String value = "[467ec1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"\"]]"; | ||
List<String> expected = List.of("467ec1c3-8ba7-32dc-9d72-71a2ccad161b:[\"1\",\"\"]"); | ||
List<String> result = parser.getParameterEntries(value); | ||
assertThat(expected).isEqualTo(result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...java/org/eclipse/sirius/web/papaya/representations/table/PapayaColumnFilterPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.papaya.representations.table; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.sirius.components.papaya.Type; | ||
import org.eclipse.sirius.components.tables.ColumnFilter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Used to indicate if a column should be filtered or not. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public class PapayaColumnFilterPredicate implements Predicate<ColumnFilter> { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final Type type; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(PapayaColumnFilterPredicate.class); | ||
|
||
public PapayaColumnFilterPredicate(ObjectMapper objectMapper, Type type) { | ||
this.objectMapper = Objects.requireNonNull(objectMapper); | ||
this.type = Objects.requireNonNull(type); | ||
} | ||
|
||
@Override | ||
public boolean test(ColumnFilter columnFilter) { | ||
boolean isValidColumFilterCandidate = true; | ||
if (columnFilter.id().equals("papaya.NamedElement#name")) { | ||
isValidColumFilterCandidate = this.isValidNameColumnFilterCandidate(columnFilter); | ||
} else if (columnFilter.id().equals("papaya.Type#nbAnnotation")) { | ||
isValidColumFilterCandidate = this.isValidAnnotationCountFilterCandidate(columnFilter); | ||
} | ||
return isValidColumFilterCandidate; | ||
} | ||
|
||
private boolean isValidNameColumnFilterCandidate(ColumnFilter columnFilter) { | ||
var isValid = true; | ||
try { | ||
String filterValue = this.objectMapper.readValue(columnFilter.value(), new TypeReference<>() { }); | ||
isValid = this.type.getName() != null && this.type.getName().contains(filterValue); | ||
} catch (JsonProcessingException exception) { | ||
this.logger.warn(exception.getMessage(), exception); | ||
} | ||
return isValid; | ||
} | ||
|
||
private boolean isValidAnnotationCountFilterCandidate(ColumnFilter columnFilter) { | ||
var isValid = true; | ||
try { | ||
List<String> filterValues = objectMapper.readValue(columnFilter.value(), new TypeReference<>() { }); | ||
int nbAnnotation = this.type.getAnnotations().size(); | ||
if (filterValues.size() == 2) { | ||
if (filterValues.get(0) != null && !filterValues.get(0).isBlank()) { | ||
try { | ||
int minValue = Integer.parseInt(filterValues.get(0)); | ||
isValid = minValue <= nbAnnotation; | ||
} catch (NumberFormatException exception) { | ||
this.logger.warn(exception.getMessage(), exception); | ||
} | ||
} | ||
if (filterValues.get(1) != null && !filterValues.get(1).isBlank()) { | ||
try { | ||
int maxValue = Integer.parseInt(filterValues.get(1)); | ||
isValid = isValid && maxValue >= nbAnnotation; | ||
} catch (NumberFormatException exception) { | ||
this.logger.warn(exception.getMessage(), exception); | ||
isValid = true; | ||
} | ||
} | ||
} | ||
} catch (JsonProcessingException exception) { | ||
this.logger.warn(exception.getMessage(), exception); | ||
} | ||
return isValid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.