Skip to content

Commit

Permalink
#21823 Allow PP filters to be added/updated via the UI or a REST call
Browse files Browse the repository at this point in the history
Also, update  required CURL Tests, and adding Javadoc.
  • Loading branch information
jcastro-dotcms committed May 17, 2022
1 parent 60de8f7 commit 0c0c09e
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 99 deletions.
100 changes: 74 additions & 26 deletions dotCMS/src/curl-test/PushPublishFilterResource.postman_collection.json
@@ -1,21 +1,25 @@
{
"info": {
"_postman_id": "93f937d9-6c07-4d0e-b18a-b863707aaae2",
"_postman_id": "214ebbd5-cae7-4080-806c-e7cf3a9f7dc3",
"name": "PushPublishFilterResource",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GetFilters",
"name": "Get All Filters",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var jsonData = pm.response.json();",
"",
"pm.test(\"body check\", function () {",
" pm.expect(jsonData.entity[0].key).to.eql('ForcePush.yml');",
"pm.test(\"The 'ContentOnly.yml' Filter must be the first one in the list\", function () {",
" pm.expect(jsonData.entity[0].key).to.eql('ContentOnly.yml');",
" pm.expect(jsonData.entity[0].roles).to.eql('DOTCMS_BACK_END_USER');",
"});",
""
Expand Down Expand Up @@ -58,15 +62,19 @@
"response": []
},
{
"name": "GetFilter",
"name": "Get a Specific Filter",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var jsonData = pm.response.json();",
"",
"pm.test(\"body check\", function () {",
"pm.test(\"The 'ForcePush.yml' Filter mut be the only result\", function () {",
" pm.expect(jsonData.entity.key).to.eql('ForcePush.yml');",
" pm.expect(jsonData.entity.roles).to.eql('DOTCMS_BACK_END_USER');",
"});",
Expand Down Expand Up @@ -117,10 +125,13 @@
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"body check\", function () {",
" pm.expect(text).contains('ForcePush.yml');",
"pm.test(\"The 'NoWorkflow.yml' Filter must be present in the filter list via Form\", function () {",
" pm.expect(text).contains('NoWorkflow.yml');",
"});",
""
Expand Down Expand Up @@ -178,10 +189,13 @@
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"body check\", function () {",
" pm.expect(text).contains('ForcePush.yml');",
"pm.test(\"The 'TestPPFilter.yml' Filter must be present in the filter list via File\", function () {",
" pm.expect(text).contains('TestPPFilter.yml');",
"});",
""
Expand Down Expand Up @@ -216,12 +230,7 @@
"type": "file",
"src": "resources/TestPPFilter.yml"
}
],
"options": {
"raw": {
"language": "json"
}
}
]
},
"url": {
"raw": "{{serverURL}}/api/v1/pushpublish/filters",
Expand All @@ -245,10 +254,13 @@
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"body check\", function () {",
" pm.expect(text).contains('ForcePush.yml');",
"pm.test(\"The 'NoWorkflow.yml' must have been updated via Form\", function () {",
" pm.expect(text).contains('NoWorkflow.yml');",
"});",
""
Expand Down Expand Up @@ -306,10 +318,13 @@
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"body check\", function () {",
" pm.expect(text).contains('ForcePush.yml');",
"pm.test(\"The 'TestPPFilter.yml' Filter must have been pudated via File\", function () {",
" pm.expect(text).contains('TestPPFilter.yml');",
"});",
""
Expand Down Expand Up @@ -344,12 +359,7 @@
"type": "file",
"src": "resources/TestPPFilter.yml"
}
],
"options": {
"raw": {
"language": "json"
}
}
]
},
"url": {
"raw": "{{serverURL}}/api/v1/pushpublish/filters",
Expand All @@ -368,6 +378,25 @@
},
{
"name": "Delete No Workflow",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"The 'NoWorkflow.yml' must NOT be part of the list now\", function () {",
" pm.expect(text).not.contains('NoWorkflow.yml');",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
Expand All @@ -389,6 +418,25 @@
},
{
"name": "Delete Test PP Filter",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code must be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text();",
"",
"pm.test(\"The 'TestPPFilter.yml' must NOT be part of the list now\", function () {",
" pm.expect(text).not.contains('TestPPFilter.yml');",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
Expand Down
56 changes: 35 additions & 21 deletions dotCMS/src/main/java/com/dotcms/publishing/FilterDescriptor.java
@@ -1,40 +1,49 @@
package com.dotcms.publishing;
import static com.dotmarketing.util.UtilMethods.isNotSet;
import static com.dotmarketing.util.UtilMethods.isSet;

import com.dotmarketing.exception.DotDataValidationException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.annotations.VisibleForTesting;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.dotmarketing.util.UtilMethods.isNotSet;
import static com.dotmarketing.util.UtilMethods.isSet;

/**
* This bean to read data from the yml file that stores the Push Publishing Filters
* The Key will be set from the fileName.
* The file might look like this:
* title: (arbitrary title for the exclude filter)
* defaultFilter: true|false
* roles: [ list of roles that can access the filter]
* filters:
* excludeDependencyQuery: ( lucene query that dependent content is checked against to exclude)
* excludeQuery: (lucene query that added content is checked against to exclude)
* excludeDependencyClasses: [ list of classes that should never be pushed as dependencies]
* excludeClasses: [ list of classes that should never be pushed]
* forcePush: true|false . (basically, force push - should the push history be consulted when pushing? Defaults to false)
* dependencies: true|false, defaults to true
* relationships: true|false, defaults to true
* This class represents the YML file that stores data about a specific Push Publishing Filter. The filter key will be
* set based on the fileName. Such a file might look like this:
* <ul>
* <li>title: Arbitrary title for the "exclude" filter</li>
* <li>defaultFilter: true|false</li>
* <li>roles: List of roles that can access the filter</li>
* <li>filters:</li>
* <ul>
* <li>excludeDependencyQuery: Lucene query that dependent content is checked against to exclude</li>
* <li>excludeQuery: Lucene query that added content is checked against to exclude</li>
* <li>excludeDependencyClasses: List of classes that should never be pushed as dependencies</li>
* <li>excludeClasses: List of classes that should never be pushed</li>
* <li>forcePush: true|false . (basically, force push - should the push history be consulted when
* pushing? Defaults to false)</li>
* <li>dependencies: true|false, defaults to true</li>
* <li>relationships: true|false, defaults to true</li>
* </ul>
* </ul>
*
* @author Erick Gonzalez
* @since Mar 6th, 2020
*/

public class FilterDescriptor {
public class FilterDescriptor implements Comparable<FilterDescriptor> {

private String key;
private final String title;
private final boolean defaultFilter;
private final String roles;
private final Map<String,Object> filters;

public static final String DEPENDENCIES_KEY = "dependencies";
public static final String RELATIONSHIPS_KEY = "relationships";
public static final String EXCLUDE_CLASSES_KEY = "excludeClasses";
Expand Down Expand Up @@ -150,8 +159,6 @@ public void validate() throws DotDataValidationException {
}
}



if(!errors.isEmpty()){
throw new DotDataValidationException(errors.size() + " error(s): " + String.join(" , ", errors));
}
Expand All @@ -168,4 +175,11 @@ public String toString() {
", filters{" + this.filters + "}" +
'}';
}

@Override
public int compareTo(@NotNull final FilterDescriptor o) {
// Order PP Filters based on their title, in ascending order
return this.title.compareTo(o.getTitle());
}

}

0 comments on commit 0c0c09e

Please sign in to comment.