-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thorsten Marx
committed
Dec 15, 2023
1 parent
8cfbe03
commit 709585c
Showing
37 changed files
with
835 additions
and
54 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
42 changes: 42 additions & 0 deletions
42
cms-api/src/main/java/com/github/thmarx/cms/api/content/TaxonomyResponse.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,42 @@ | ||
package com.github.thmarx.cms.api.content; | ||
|
||
import com.github.thmarx.cms.api.Constants; | ||
import com.github.thmarx.cms.api.db.ContentNode; | ||
import com.github.thmarx.cms.api.db.taxonomy.Taxonomy; | ||
|
||
/*- | ||
* #%L | ||
* cms-server | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public record TaxonomyResponse(String content, String contentType, Taxonomy taxonomy) { | ||
|
||
public TaxonomyResponse (String content, Taxonomy taxonomy) { | ||
this(content, Constants.DEFAULT_CONTENT_TYPE, taxonomy); | ||
} | ||
|
||
public TaxonomyResponse (Taxonomy taxonomy) { | ||
this("", Constants.DEFAULT_CONTENT_TYPE, taxonomy); | ||
} | ||
}; |
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
cms-api/src/main/java/com/github/thmarx/cms/api/db/taxonomy/Taxonomies.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.github.thmarx.cms.api.db.taxonomy; | ||
|
||
/*- | ||
* #%L | ||
* cms-api | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import com.github.thmarx.cms.api.db.ContentNode; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public interface Taxonomies { | ||
|
||
public Optional<Taxonomy> forSlug (String slug); | ||
|
||
public Map<String, Integer> valueCount (Taxonomy taxonomy); | ||
|
||
public Set<String> values (Taxonomy taxonomy); | ||
|
||
public List<ContentNode> withValue (Taxonomy taxonomy, Object value); | ||
} |
38 changes: 38 additions & 0 deletions
38
cms-api/src/main/java/com/github/thmarx/cms/api/db/taxonomy/Taxonomy.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,38 @@ | ||
package com.github.thmarx.cms.api.db.taxonomy; | ||
|
||
/*- | ||
* #%L | ||
* cms-api | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
@Data | ||
public class Taxonomy { | ||
public String title; | ||
public String slug; | ||
public String template = "taxonomy.html"; | ||
public String field; | ||
public boolean array = false; | ||
} |
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
115 changes: 115 additions & 0 deletions
115
cms-filesystem/src/main/java/com/github/thmarx/cms/filesystem/taxonomy/FileTaxonomies.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,115 @@ | ||
package com.github.thmarx.cms.filesystem.taxonomy; | ||
|
||
/*- | ||
* #%L | ||
* cms-filesystem | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
import com.github.thmarx.cms.api.SiteProperties; | ||
import com.github.thmarx.cms.api.db.ContentNode; | ||
import com.github.thmarx.cms.api.db.taxonomy.Taxonomies; | ||
import com.github.thmarx.cms.api.db.taxonomy.Taxonomy; | ||
import com.github.thmarx.cms.api.eventbus.EventListener; | ||
import com.github.thmarx.cms.api.eventbus.events.SitePropertiesChanged; | ||
import com.github.thmarx.cms.api.utils.MapUtil; | ||
import com.github.thmarx.cms.filesystem.FileSystem; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class FileTaxonomies implements Taxonomies, EventListener<SitePropertiesChanged> { | ||
|
||
private final SiteProperties siteProperties; | ||
private final FileSystem fileSystem; | ||
|
||
private ConcurrentMap<String, Taxonomy> taxonomies = new ConcurrentHashMap<>(); | ||
|
||
private String defaulTemplate = "taxonomy.html"; | ||
|
||
public void reloadTaxonomies() { | ||
var tasList = (List<Map>) siteProperties.getOrDefault("taxonomy", Map.of()).getOrDefault("taxonomies", List.of()); | ||
|
||
tasList.stream().map((taxo) -> { | ||
Taxonomy tax = new Taxonomy(); | ||
tax.setTitle((String) taxo.get("title")); | ||
tax.setSlug((String) taxo.get("slug")); | ||
tax.setField((String) taxo.get("field")); | ||
tax.setTemplate((String) taxo.getOrDefault("template", defaulTemplate)); | ||
tax.setArray((Boolean) taxo.getOrDefault("array", false)); | ||
return tax; | ||
}).forEach(tax -> taxonomies.put(tax.getSlug(), tax)); | ||
} | ||
|
||
@Override | ||
public Optional<Taxonomy> forSlug(final String slug) { | ||
return Optional.ofNullable(taxonomies.get(slug)); | ||
} | ||
|
||
@Override | ||
public Map<String, Integer> valueCount(Taxonomy taxonomy) { | ||
fileSystem.query((node, index) -> node).where(taxonomy.getField(), "!=", null); | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public Set<String> values(Taxonomy taxonomy) { | ||
var nodes = fileSystem.query((node, index) -> node).where(taxonomy.getField(), "!=", null).get(); | ||
|
||
Set<String> values = new HashSet<>(); | ||
nodes.forEach(node -> { | ||
var value = MapUtil.getValue(node.data(), taxonomy.getField()); | ||
if (value instanceof List) { | ||
values.addAll((List) value); | ||
} else { | ||
values.add((String) value); | ||
} | ||
}); | ||
|
||
return values; | ||
} | ||
|
||
@Override | ||
public List<ContentNode> withValue(final Taxonomy taxonomy, final Object value) { | ||
List<ContentNode> nodes = null; | ||
if (taxonomy.isArray()) { | ||
nodes = fileSystem.query((node, index) -> node).whereContains(taxonomy.getField(), value).get(); | ||
} else { | ||
nodes = fileSystem.query((node, index) -> node).where(taxonomy.getField(), value).get(); | ||
} | ||
|
||
return nodes; | ||
} | ||
|
||
@Override | ||
public void consum(SitePropertiesChanged event) { | ||
reloadTaxonomies(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
cms-filesystem/src/main/java/com/github/thmarx/cms/filesystem/taxonomy/package-info.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,30 @@ | ||
package com.github.thmarx.cms.filesystem.taxonomy; | ||
|
||
/*- | ||
* #%L | ||
* cms-filesystem | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
/** | ||
* | ||
* Template resolution: | ||
* 1. taxonomy.html | ||
* 2. taxonomy-taxid.html | ||
* | ||
*/ |
Oops, something went wrong.