-
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.
#28896 Including listParents as attribute on the response of the chil… (
#29116) Last PR for #28896 ### Proposed Changes * Create a new class to represent the Category plus the Hierarchy list https://github.com/dotCMS/core/pull/29116/files#diff-89fd51608ec8ccbe6e79cf1e53ff4bf88fc7e79a82458f8d7aceda8555ce6cd7R18 * return this new class on the findAll CategoryFactory method https://github.com/dotCMS/core/pull/29116/files#diff-88379e3d0d9b5a5c54cb2207518bb686c3a9243cf6419ff11377616a7cd88dd2R293 * Convert the Database result to HierarchedCategory instead of category https://github.com/dotCMS/core/pull/29116/files#diff-bf828c747c99cefe73af7cec527db7f7e64bd4a66ba54a55eb1170f6a2996333R625
- Loading branch information
1 parent
dcfa034
commit a33cb02
Showing
10 changed files
with
287 additions
and
78 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
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
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
44 changes: 44 additions & 0 deletions
44
dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/HierarchedCategory.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,44 @@ | ||
package com.dotmarketing.portlets.categories.model; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a {@link Category} with its hierarchy calculated. | ||
* This means traversing from the current category all the way up to the first-level category that you encounter. | ||
* | ||
* For example: | ||
* | ||
* | Name | Parent | hierarchy | | ||
* |-------------|----------------|------------------------ | | ||
* | Top Category| null | [] | | ||
* | Child | Top Category | [Top Category] | | ||
* | Grand Child | Child | [Top Category, Child] | | ||
* | ||
*/ | ||
public class HierarchedCategory extends Category{ | ||
|
||
private List<ShortCategory> parentList; | ||
|
||
public void setParentList(final List<ShortCategory> parentList) { | ||
this.parentList = parentList; | ||
} | ||
|
||
public List<ShortCategory> getParentList() { | ||
return parentList; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (!super.equals(o)) return false; | ||
HierarchedCategory that = (HierarchedCategory) o; | ||
return Objects.equals(parentList, that.parentList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), parentList); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
dotCMS/src/main/java/com/dotmarketing/portlets/categories/model/ShortCategory.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,60 @@ | ||
package com.dotmarketing.portlets.categories.model; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Represents a {@link Category}, but only contains the most important data: | ||
* | ||
* - Category's name | ||
* - Category's key | ||
* - Category's inode | ||
*/ | ||
public class ShortCategory implements Serializable { | ||
|
||
private String categoryName; | ||
private String inode; | ||
private String key; | ||
|
||
private ShortCategory(final Builder builder) { | ||
this.categoryName = builder.categoryName; | ||
this.inode = builder.inode; | ||
this.key = builder.key; | ||
} | ||
|
||
public String getCategoryName() { | ||
return categoryName; | ||
} | ||
|
||
public String getInode() { | ||
return inode; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public static class Builder { | ||
private String categoryName; | ||
private String inode; | ||
private String key; | ||
|
||
public Builder setCategoryName(String categoryName) { | ||
this.categoryName = categoryName; | ||
return this; | ||
} | ||
|
||
public Builder setInode(String inode) { | ||
this.inode = inode; | ||
return this; | ||
} | ||
|
||
public Builder setKey(String key) { | ||
this.key = key; | ||
return this; | ||
} | ||
|
||
public ShortCategory build() { | ||
return new ShortCategory(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.