Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Aug 29, 2018
2 parents f73da4f + 80de218 commit 8a2840d
Show file tree
Hide file tree
Showing 18 changed files with 366 additions and 27 deletions.
6 changes: 6 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2018-08-29 1.4.0
- Groovy Console extension:
- added filterByProperty()
- added filterByHasProperty()
- Fixed issue with access rights

2018-08-24 1.3.0
- Execute scripts in alphabetical order
- Stop execution after first failed script
Expand Down
14 changes: 13 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,19 @@ println aecu.contentUpgradeBuilder()
These methods can be used to filter the nodes that were collected above. Multiple filters can be applied for one run.

### Filter by Properties
Use this to filter by a list of property values (e.g. sling:resourceType).

Filters the resources by property values.

* filterByHasProperty: matches all nodes that 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.
* 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.
* filterByMultiValuePropContains: checks if all condition values are contained in the defined attribute. Filter does not match if attribute does not exist.

```java
filterByHasProperty(String name)
filterByProperty(String name, Object value)
filterByProperties(Map<String, String> properties)
filterByMultiValuePropContains(String name, Object[] conditionValues)
```

Example:
Expand All @@ -175,7 +184,10 @@ conditionMap["sling:resourceType"] = "weretail/components/structure/page"

println aecu.contentUpgradeBuilder()
.forChildResourcesOf("/content/we-retail/ca/en")
.filterByHasProperty("myProperty")
.filterByProperty("sling:resourceType", "wcm/foundation/components/responsivegrid")
.filterByProperties(conditionMap)
.filterByMultiValuePropContains("myAttribute", ["value"] as String[])
.doSetProperty("name", "value")
.run()
```
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>1.3.0</version>
<version>1.4.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
package de.valtech.aecu.api.groovy.console.bindings;

import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy;
import java.util.Map;

import org.apache.sling.api.resource.PersistenceException;

import java.util.Map;
import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy;

/**
* This class provides the builder methods to perform a content upgrade.
Expand Down Expand Up @@ -64,6 +64,23 @@ public interface ContentUpgrade {
*/
ContentUpgrade forResourcesInSubtree(String path);

/**
* Filters by existence of a single property.
*
* @param name property name
* @return upgrade object
*/
ContentUpgrade filterByHasProperty(String name);

/**
* Filters by a single property.
*
* @param name property name
* @param value property value
* @return upgrade object
*/
ContentUpgrade filterByProperty(String name, Object value);

/**
* Filters by properties. Can be used also for Multi-value properties.
*
Expand All @@ -75,11 +92,11 @@ public interface ContentUpgrade {
/**
* Filters by multi-value with the given name containing the given conditionValues
*
* @param name name of the multi-value property
* @param name name of the multi-value property
* @param conditionValues values to search for
* @return upgrade object
*/
ContentUpgrade filterByMultiValuePropContains(String name, Object[] conditionValues);
ContentUpgrade filterByMultiValuePropContains(String name, Object[] conditionValues);

/**
* Filters by node name exact match.
Expand Down Expand Up @@ -233,4 +250,5 @@ public interface ContentUpgrade {
* @throws PersistenceException error during execution
*/
StringBuffer run(boolean dryRun) throws PersistenceException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2018 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;

/**
* Filters resources by the existence a given property. The filter only matches if the attribute
* exists. The value of the property is not relevant.
*
* @author Roland Gruber
*/
public class FilterByHasProperty implements FilterBy {

private String name;

/**
* Constructor
*
* @param name attribute name
*/
public FilterByHasProperty(@Nonnull String name) {
this.name = name;
}

@Override
public boolean filter(@Nonnull Resource resource) {
ValueMap properties = resource.getValueMap();
Object attrValue = properties.get(name);
return (attrValue != null);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2018 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;

/**
* Filters resources by a given property. The filter only matches if the attribute exists and has
* the exact given value.
*
* @author Roland Gruber
*/
public class FilterByProperty implements FilterBy {

private String name;
private Object value;

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

@Override
public boolean filter(@Nonnull Resource resource) {
ValueMap properties = resource.getValueMap();
Object attrValue = properties.get(name);
return (value == null) && (attrValue == null) || ((value != null) && value.equals(attrValue));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2018 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 static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

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

/**
* Tests FilterByHasProperty
*
* @author Roland Gruber
*/
@RunWith(MockitoJUnitRunner.class)
public class FilterByHasPropertyTest {

private static final String NAME = "name";
private static final String VALUE = "value";

@Mock
private Resource resource;

@Mock
ValueMap values;

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

@Test
public void filterAttributeNullValue() {
FilterByHasProperty filter = new FilterByHasProperty(NAME);
when(values.get(NAME)).thenReturn(null);

assertFalse(filter.filter(resource));
}

@Test
public void filterAttributeNonNullValue() {
FilterByHasProperty filter = new FilterByHasProperty(NAME);
when(values.get(NAME)).thenReturn(VALUE);

assertTrue(filter.filter(resource));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2018 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 static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

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

/**
* Tests FilterByProperty
*
* @author Roland Gruber
*/
@RunWith(MockitoJUnitRunner.class)
public class FilterByPropertyTest {

private static final String NAME = "name";
private static final String VALUE = "value";

@Mock
private Resource resource;

@Mock
ValueMap values;

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

@Test
public void filterAttributeNullValueNull() {
FilterByProperty filter = new FilterByProperty(NAME, null);
when(values.get(NAME)).thenReturn(null);

assertTrue(filter.filter(resource));
}

@Test
public void filterAttributeNullValueNonNull() {
FilterByProperty filter = new FilterByProperty(NAME, VALUE);
when(values.get(NAME)).thenReturn(null);

assertFalse(filter.filter(resource));
}

@Test
public void filterAttributeNonNullValueNull() {
FilterByProperty filter = new FilterByProperty(NAME, null);
when(values.get(NAME)).thenReturn(VALUE);

assertFalse(filter.filter(resource));
}

@Test
public void filterAttributeNonNullValueNonNull() {
FilterByProperty filter = new FilterByProperty(NAME, VALUE);
when(values.get(NAME)).thenReturn(VALUE);

assertTrue(filter.filter(resource));
}

}
2 changes: 1 addition & 1 deletion bundle/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>1.3.0</version>
<version>1.4.0</version>
</parent>

<artifactId>aecu.bundle</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>1.3.0</version>
<version>1.4.0</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Loading

0 comments on commit 8a2840d

Please sign in to comment.