Skip to content

Commit

Permalink
Merge pull request #217 from michielspiritus7/develop
Browse files Browse the repository at this point in the history
added filterByPropertyIsMultiple
  • Loading branch information
nhirrle committed Oct 26, 2023
2 parents 487135a + ed84704 commit 891f68c
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 16 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ Filters the resources by property values.
* filterByHasProperty: matches all nodes that have the given property. The value of the property is not relevant.
* filterByNotHasProperty: matches all nodes that do not have the given property. The value of the property is not relevant.
* filterByProperty: matches all nodes that have the given attribute value. Filter does not match if attribute is not present. By using a value of "null" you can search if an attribute is not present.
* filterByPropertyIsMultiple: matches all nodes where a given property is a multi-value property (such as an array or list) and contains a specific value or values. The filter does not match if the attribute does not exist, or if it exists but is not a multi-value property or does not contain the specified value or values.
* filterByNotProperty: matches all nodes that do not have the given attribute value. Filter matches if attribute is not present.
* filterByProperties: use this to filter by a list of property values (e.g. sling:resourceType). All properties in the map are required to to match. Filter does not match if attribute does not exist.
* filterByNotProperties: use this to filter by a list of property values (e.g. sling:resourceType) is not matching. If any property in the map does not match the filter matches. Filter matches if attribute does not exist.
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public interface ContentUpgrade {
*/
ContentUpgrade filterByNotProperty(String name, Object value);

/**
* Filters by matching a single property using a regular expression for the value. This is
* intended for single value properties.
*
* @param name property name
* @param value attribute value
* @return upgrade object
*/
ContentUpgrade filterByPropertyIsMultiple(String name, Object value);

/**
* Filters by matching a single property using a regular expression for the value. This is
* intended for single value properties.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2018 - 2019 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.api.groovy.console.bindings.filters;

import javax.annotation.Nonnull;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;

import de.valtech.aecu.api.groovy.console.bindings.GStringConverter;


/**
* Filters resources by a given property. The filter only matches if the attribute exists and has
* the exact given value and the property is an array or a list.
*
* @author Michiel Spiritus
*/
public class FilterByPropertyIsMultiple implements FilterBy {

private String name;
private Object value;

/**
* Constructor
*
* @param name attribute name
* @param value attribute value
*/
public FilterByPropertyIsMultiple(@Nonnull String name, Object value) {
this.name = name;
this.value = GStringConverter.convert(value);
}

@Override
public boolean filter(@Nonnull Resource resource, StringBuilder output) {
ValueMap properties = resource.getValueMap();
Object attrValue = properties.get(name);

// Check if the property is an array or a list
if (attrValue instanceof Object[] || attrValue instanceof java.util.List) {
return ((value == null) && (attrValue == null)) || ((value != null) && value.equals(attrValue));
}

return false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("3.2.0")
@Version("3.3.0")
package de.valtech.aecu.api.groovy.console.bindings.filters;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("4.10.0")
@Version("4.11.0")
package de.valtech.aecu.api.groovy.console.bindings;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2023 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.core.groovy.console.bindings.filters;

import org.apache.sling.api.resource.ValueMap;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPropertyIsMultiple;

import java.util.Arrays;
import java.util.List;

/**
* Tests FilterByPropertyIsMultiple
*
* @author Roland Gruber
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class FilterByPropertyIsMultipleTest {

private static final String NAME = "name";
private static final List<String> MULTIPLE_VALUE = Arrays.asList("value1", "value2");

@Mock
private Resource resource;

@Mock
ValueMap values;

@Mock
ValueMap valueMap;

@BeforeEach
public void setup() {
when(resource.getValueMap()).thenReturn(values);
}

@Test
void filterAttributeArray() {
Object[] attrArray = new Object[]{"value1", "value2", "value3"};
when(resource.getValueMap()).thenReturn(valueMap);
when(valueMap.get("name")).thenReturn(attrArray);

FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple("name", attrArray);

assertTrue(filter.filter(resource, new StringBuilder()));
}



@Test
public void filterAttributeList() {
FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple(NAME, MULTIPLE_VALUE);
when(values.get(NAME)).thenReturn(MULTIPLE_VALUE);

assertTrue(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeNonMultiple() {
FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple(NAME, "value");
when(values.get(NAME)).thenReturn("value");

assertFalse(filter.filter(resource, new StringBuilder()));
}

}
2 changes: 1 addition & 1 deletion cloud.startup.hook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.cloud.startup.hook</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion complete-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.complete.cloud</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.complete</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPathRegex;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperty;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPropertyIsMultiple;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPropertyRegex;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeRootPaths;
import de.valtech.aecu.api.groovy.console.bindings.filters.NOTFilter;
Expand Down Expand Up @@ -219,6 +220,12 @@ public ContentUpgrade filterByNotProperty(String name, Object value) {
return this;
}

@Override
public ContentUpgrade filterByPropertyIsMultiple(@Nonnull String name, Object value) {
addFilter(new FilterByPropertyIsMultiple(name, value));
return this;
}

@Override
public ContentUpgrade filterByPropertyRegex(String name, String regex) {
addFilter(new FilterByPropertyRegex(name, regex));
Expand Down
2 changes: 1 addition & 1 deletion examples-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.examples-cloud</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oak.index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.oak.index</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<packaging>pom</packaging>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
<name>AECU</name>
<description>AEM Easy Content Upgrade</description>
<url>https://github.com/valtech/aem-easy-content-upgrade</url>
Expand Down Expand Up @@ -735,4 +735,4 @@
</pluginRepository>
</pluginRepositories>

</project>
</project>
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sonar.projectKey=aecu
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=AEM Easy Content Upgrade
sonar.projectVersion=6.4.1-SNAPSHOT
sonar.projectVersion=6.5.0-SNAPSHOT

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.structure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.ui.apps.structure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.ui.apps</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.4.1-SNAPSHOT</version>
<version>6.5.0-SNAPSHOT</version>
</parent>

<artifactId>aecu.ui.content</artifactId>
Expand Down

0 comments on commit 891f68c

Please sign in to comment.