-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issue-30521-Create-content-analytics-query-e…
…ndpoint-that-doesnt-require-map
- Loading branch information
Showing
12 changed files
with
938 additions
and
92 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
21 changes: 21 additions & 0 deletions
21
dotCMS/src/main/java/com/dotcms/rest/api/v3/contenttype/FieldResponseView.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,21 @@ | ||
package com.dotcms.rest.api.v3.contenttype; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.rest.ResponseEntityView; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This class represents a Response View for objects of type {@link Field}. It's very useful for | ||
* returning a list of fields, or a filtered sub-set if necessary. | ||
* | ||
* @author Jose Castro | ||
* @since Nov 29th, 2024 | ||
*/ | ||
public class FieldResponseView extends ResponseEntityView<List<Field>> { | ||
|
||
public FieldResponseView(final List<Field> entity) { | ||
super(entity); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
dotCMS/src/main/java/com/dotcms/rest/api/v3/contenttype/FilteringCriteria.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,66 @@ | ||
package com.dotcms.rest.api.v3.contenttype; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.util.filtering.Specification; | ||
import com.dotcms.util.filtering.contenttype.field.CombinedSpecification; | ||
import com.dotcms.util.filtering.contenttype.field.RequiredSpecification; | ||
import com.dotcms.util.filtering.contenttype.field.ShowInListSpecification; | ||
import com.dotcms.util.filtering.contenttype.field.SystemIndexedSpecification; | ||
import com.dotcms.util.filtering.contenttype.field.UniqueSpecification; | ||
import com.dotcms.util.filtering.contenttype.field.UserSearchableSpecification; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Enum that represents the different criteria that can be used to filter fields in a Content Type. | ||
* This allows you to get a specific list of {@link Field}s from a Content Type that meet your | ||
* specified criteria via @{link Specification} classes. In here, you can define as many | ||
* Specifications as you need. | ||
* <p>The initial specifications represent the default attributes that you can enable for a given | ||
* field, such as:</p> | ||
* <ul> | ||
* <li>Required.</li> | ||
* <li>User Searchable.</li> | ||
* <li>System Indexed.</li> | ||
* <li>Show in List.</li> | ||
* <li>Unique.</li> | ||
* </ul> | ||
* | ||
* @author Jose Castro | ||
* @since Nov 30th, 2024 | ||
*/ | ||
public enum FilteringCriteria { | ||
|
||
REQUIRED(new RequiredSpecification()), | ||
USER_SEARCHABLE(new UserSearchableSpecification()), | ||
SYSTEM_INDEXED(new SystemIndexedSpecification()), | ||
SHOW_IN_LIST(new ShowInListSpecification()), | ||
UNIQUE(new UniqueSpecification()); | ||
|
||
final Specification<Field> specification; | ||
|
||
FilteringCriteria(final Specification<Field> specification) { | ||
this.specification = specification; | ||
} | ||
|
||
public Specification<Field> specification() { | ||
return this.specification; | ||
} | ||
|
||
/** | ||
* Takes the list of criteria that will be used to query for specific fields in a Content Type | ||
* and generates the appropriate Specification object to be used in the filtering. | ||
* | ||
* @param criteria A Set of FilteringCriteria objects that will be used to filter the fields. | ||
* | ||
* @return The {@link Specification} object that will be used to filter the fields. | ||
*/ | ||
public static Specification<Field> specificationsFrom(final Set<FilteringCriteria> criteria) { | ||
Specification<Field> mainSpec = new CombinedSpecification(); | ||
for (final FilteringCriteria criterion : criteria) { | ||
mainSpec = mainSpec.and(criterion.specification()); | ||
} | ||
return mainSpec; | ||
} | ||
|
||
} |
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
61 changes: 61 additions & 0 deletions
61
dotCMS/src/main/java/com/dotcms/util/filtering/Specification.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,61 @@ | ||
package com.dotcms.util.filtering; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* This class represents the base Specification interface for filtering objects that meet given | ||
* satisfaction criteria using the <b>Specification Pattern</b>, which is a behavioral pattern | ||
* often used to encapsulate filtering logic. | ||
* <p>By implementing this interface, you can create your own custom Specification class to filter | ||
* objects based on given criteria.</p> | ||
* | ||
* @param <T> The type of the object to be filtered. | ||
* | ||
* @author Jose Castro | ||
* @since Nov 29th, 2024 | ||
*/ | ||
public interface Specification<T> extends Serializable { | ||
|
||
/** | ||
* Determines whether the provided object meets the satisfaction criteria for your Specification | ||
* or not. | ||
* | ||
* @param item The object to be evaluated. | ||
* | ||
* @return If the object meets your criteria, returns {@code true}. | ||
*/ | ||
boolean isSatisfiedBy(final T item); | ||
|
||
/** | ||
* Allows you to chain multiple Specifications together using the logical AND operator. | ||
* | ||
* @param other The other Specification to be chained. | ||
* | ||
* @return If all chained Specifications are satisfied, returns {@code true}. | ||
*/ | ||
default Specification<T> and(final Specification<T> other) { | ||
return item -> Specification.this.isSatisfiedBy(item) && other.isSatisfiedBy(item); | ||
} | ||
|
||
/** | ||
* Allows you to chain multiple Specifications together using the logical OR operator. | ||
* | ||
* @param other The other Specification to be chained. | ||
* | ||
* @return If any of the chained Specifications are satisfied, returns {@code true}. | ||
*/ | ||
default Specification<T> or(final Specification<T> other) { | ||
return item -> this.isSatisfiedBy(item) || other.isSatisfiedBy(item); | ||
} | ||
|
||
/** | ||
* Allows you to chain multiple Specifications together using the logical NOT operator. This is | ||
* particularly useful for excluding objects from your result set. | ||
* | ||
* @return If the Specification is not satisfied, returns {@code true}. | ||
*/ | ||
default Specification<T> not() { | ||
return item -> !this.isSatisfiedBy(item); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
dotCMS/src/main/java/com/dotcms/util/filtering/contenttype/field/CombinedSpecification.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,22 @@ | ||
package com.dotcms.util.filtering.contenttype.field; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.util.filtering.Specification; | ||
|
||
/** | ||
* This simple Specification serves as a base/placeholder for developers to combine multiple | ||
* {@link Specification} objects. This is very useful when the given list of Specifications is | ||
* dynamic. | ||
* | ||
* @author Jose Castro | ||
* @since Nov 29th, 2024 | ||
*/ | ||
public class CombinedSpecification implements Specification<Field> { | ||
|
||
@Override | ||
public boolean isSatisfiedBy(final Field field) { | ||
// This base Specification returns 'true' by default | ||
return true; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
dotCMS/src/main/java/com/dotcms/util/filtering/contenttype/field/RequiredSpecification.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,19 @@ | ||
package com.dotcms.util.filtering.contenttype.field; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.util.filtering.Specification; | ||
|
||
/** | ||
* This Specification is responsible for verifying if a Field is flagged as {@code Required}. | ||
* | ||
* @author Jose Castro | ||
* @since Nov 29th, 2024 | ||
*/ | ||
public class RequiredSpecification implements Specification<Field> { | ||
|
||
@Override | ||
public boolean isSatisfiedBy(final Field field) { | ||
return field.required(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...MS/src/main/java/com/dotcms/util/filtering/contenttype/field/ShowInListSpecification.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,19 @@ | ||
package com.dotcms.util.filtering.contenttype.field; | ||
|
||
import com.dotcms.contenttype.model.field.Field; | ||
import com.dotcms.util.filtering.Specification; | ||
|
||
/** | ||
* This Specification is responsible for verifying if a Field is flagged as {@code Show in List}. | ||
* | ||
* @author Jose Castro | ||
* @since Nov 29th, 2024 | ||
*/ | ||
public class ShowInListSpecification implements Specification<Field> { | ||
|
||
@Override | ||
public boolean isSatisfiedBy(final Field field) { | ||
return field.listed(); | ||
} | ||
|
||
} |
Oops, something went wrong.