CCM NG: ContentItemRepository
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4215 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
6876f4f1be
commit
01d3f59f5f
|
|
@ -62,8 +62,13 @@ import static org.librecms.CmsConstants.*;
|
|||
query = "SELECT i FROM ContentItem i WHERE TYPE(I) = :type"),
|
||||
@NamedQuery(
|
||||
name = "ContentItem.findByFolder",
|
||||
query = "SELECT i FROM ContentItem i "
|
||||
+ "WHERE :folder MEMBER OF i.categories"
|
||||
// query = "SELECT i FROM ContentItem i "
|
||||
// + "WHERE (SELECT c FROM Categorization c "
|
||||
// + " WHERE c.category = :folder"
|
||||
// + " AND c.object = i) "
|
||||
// + "MEMBER OF i.categories"
|
||||
query = "SELECT c.categorizedObject FROM Categorization c "
|
||||
+ "WHERE c.category = :folder"
|
||||
)
|
||||
})
|
||||
public class ContentItem extends CcmObject implements Serializable {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.categorization.Category;
|
|||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.core.CcmObjectRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
|
@ -85,9 +86,15 @@ public class ContentItemRepository
|
|||
* {@link Optional} if there is no such item or if it is not of the
|
||||
* requested type.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> Optional<T> findById(final long itemId,
|
||||
final Class<T> type) {
|
||||
throw new UnsupportedOperationException();
|
||||
final CcmObject result = ccmObjectRepo.findById(itemId);
|
||||
if (result.getClass().isAssignableFrom(type)) {
|
||||
return Optional.of((T) result);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -139,11 +146,13 @@ public class ContentItemRepository
|
|||
*
|
||||
* @return A list of all content items of the requested type.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ContentItem> List<T> findByType(final Class<T> type) {
|
||||
final TypedQuery<T> query = getEntityManager().createNamedQuery(
|
||||
"ContentItem.findByType", type);
|
||||
final TypedQuery<ContentItem> query = getEntityManager()
|
||||
.createNamedQuery("ContentItem.findByType", ContentItem.class);
|
||||
query.setParameter("type", type);
|
||||
return query.getResultList();
|
||||
|
||||
return (List<T>) query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,7 +163,16 @@ public class ContentItemRepository
|
|||
* @return A list of all items in the provided folder.
|
||||
*/
|
||||
public List<ContentItem> findByFolder(final Category folder) {
|
||||
throw new UnsupportedOperationException();
|
||||
final TypedQuery<CcmObject> query = getEntityManager()
|
||||
.createNamedQuery("ContentItem.findByFolder", CcmObject.class);
|
||||
query.setParameter("folder", folder);
|
||||
|
||||
final List<ContentItem> result = new ArrayList<>();
|
||||
query.getResultList().stream()
|
||||
.filter(obj -> (obj instanceof ContentItem))
|
||||
.forEach(obj -> result.add((ContentItem) obj));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,39 @@ public class ContentItemRepositoryTest {
|
|||
|
||||
@Test
|
||||
@InSequence(100)
|
||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemRepositoryTest/data.xml")
|
||||
public void findByIdAndType() {
|
||||
final Optional<Article> article1 = itemRepo.findById(
|
||||
-10100L, Article.class);
|
||||
final Optional<Article> article2 = itemRepo.findById(
|
||||
-10200L, Article.class);
|
||||
final Optional<Article> article3 = itemRepo.findById(
|
||||
-10300L, Article.class);
|
||||
final Optional<News> news1 = itemRepo.findById(
|
||||
-10400L, News.class);
|
||||
|
||||
final Optional<Article> newsAsArticle = itemRepo.findById(
|
||||
-10400, Article.class);
|
||||
final Optional<News> articleAsNews = itemRepo.findById(
|
||||
-10200L, News.class);
|
||||
|
||||
assertThat(article1.isPresent(), is(true));
|
||||
assertThat(article1.get().getDisplayName(), is(equalTo("article1")));
|
||||
assertThat(article2.isPresent(), is(true));
|
||||
assertThat(article2.get().getDisplayName(), is(equalTo("article2")));
|
||||
assertThat(article3.isPresent(), is(true));
|
||||
assertThat(article3.get().getDisplayName(), is(equalTo("article3")));
|
||||
assertThat(news1.isPresent(), is(true));
|
||||
assertThat(news1.get().getDisplayName(), is(equalTo("news1")));
|
||||
|
||||
assertThat(newsAsArticle.isPresent(), is(false));
|
||||
assertThat(articleAsNews.isPresent(), is(false));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@InSequence(200)
|
||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemRepositoryTest/data.xml")
|
||||
public void findByUuidAndType() {
|
||||
|
|
@ -196,7 +229,7 @@ public class ContentItemRepositoryTest {
|
|||
"d9ea527d-c6e3-4bdd-962d-c0a1a80c6c72", News.class);
|
||||
|
||||
final Optional<Article> newsAsArticle = itemRepo.findByUuid(
|
||||
"f4b38abb-234b-4354-bc92-e36c068a1ebd", Article.class);
|
||||
"d9ea527d-c6e3-4bdd-962d-c0a1a80c6c72", Article.class);
|
||||
final Optional<News> articleAsNews = itemRepo.findByUuid(
|
||||
"acae860f-2ffa-450d-b486-054292f0dae6", News.class);
|
||||
|
||||
|
|
@ -214,7 +247,7 @@ public class ContentItemRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@InSequence(200)
|
||||
@InSequence(300)
|
||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemRepositoryTest/data.xml")
|
||||
public void findByType() {
|
||||
|
|
@ -228,7 +261,7 @@ public class ContentItemRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@InSequence(300)
|
||||
@InSequence(400)
|
||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemRepositoryTest/data.xml")
|
||||
public void findByFolder() {
|
||||
|
|
|
|||
|
|
@ -38,5 +38,5 @@
|
|||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
ccm-core/src/test/resources-wildfly8-remote-h2-mem/test-persistence.xml lines 1-40/40 (END)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,8 @@
|
|||
localized_value="Etiam euismod lacus laoreet sodales ultricies. Pellentesque non elit vitae purus sagittis." />
|
||||
|
||||
<ccm_cms.news object_id="-10400"
|
||||
news_date="2016-08-08" />
|
||||
news_date="2016-08-08"
|
||||
homepage="false" />
|
||||
|
||||
<ccm_cms.news_texts
|
||||
object_id="-10400"
|
||||
|
|
@ -146,16 +147,28 @@
|
|||
|
||||
<ccm_core.categorizations categorization_id="-30100"
|
||||
category_id="-2100"
|
||||
object_id="-10100" />
|
||||
object_id="-10100"
|
||||
category_order="1"
|
||||
object_order="1"
|
||||
category_index="false" />
|
||||
<ccm_core.categorizations categorization_id="-30200"
|
||||
category_id="-2100"
|
||||
object_id="-10200" />
|
||||
object_id="-10200"
|
||||
category_order="1"
|
||||
object_order="2"
|
||||
category_index="false" />
|
||||
<ccm_core.categorizations categorization_id="-30300"
|
||||
category_id="-2100"
|
||||
object_id="-10300" />
|
||||
object_id="-10300"
|
||||
category_order="1"
|
||||
object_order="3"
|
||||
category_index="false" />
|
||||
<ccm_core.categorizations categorization_id="-30400"
|
||||
category_id="-2100"
|
||||
object_id="-10400" />
|
||||
object_id="-10400"
|
||||
category_order="1"
|
||||
object_order="4"
|
||||
category_index="false" />
|
||||
|
||||
<ccm_core.ccm_roles role_id="-3100"
|
||||
name="info_alert_recipient" />
|
||||
|
|
|
|||
|
|
@ -1,3 +1,31 @@
|
|||
DELETE FROM ccm_cms.news_texts;
|
||||
|
||||
DELETE FROM ccm_cms.news;
|
||||
|
||||
DELETE FROM ccm_cms.article_texts;
|
||||
|
||||
DELETE FROM ccm_cms.articles;
|
||||
|
||||
DELETE FROM ccm_cms.content_item_names;
|
||||
|
||||
DELETE FROM ccm_cms.content_item_titles;
|
||||
|
||||
DELETE FROM ccm_cms.content_items;
|
||||
|
||||
DELETE FROM ccm_cms.lifecycle_definition_labels;
|
||||
|
||||
DELETE FROM ccm_cms.lifecycle_definition_descriptions;
|
||||
|
||||
DELETE FROM ccm_cms.lifecyle_definitions;
|
||||
|
||||
DELETE FROM ccm_core.workflow_templates;
|
||||
|
||||
DELETE FROM ccm_cms.content_type_labels;
|
||||
|
||||
DELETE FROM ccm_cms.content_type_descriptions;
|
||||
|
||||
DELETE FROM ccm_cms.content_types;
|
||||
|
||||
DELETE FROM ccm_cms.content_section_roles;
|
||||
|
||||
DELETE FROM ccm_cms.content_sections;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,35 @@
|
|||
DELETE FROM ccm_cms.news_texts;
|
||||
|
||||
DELETE FROM ccm_cms.news;
|
||||
|
||||
DELETE FROM ccm_cms.article_texts;
|
||||
|
||||
DELETE FROM ccm_cms.articles;
|
||||
|
||||
DELETE FROM ccm_cms.content_item_names;
|
||||
|
||||
DELETE FROM ccm_cms.content_item_titles;
|
||||
|
||||
DELETE FROM ccm_cms.content_items;
|
||||
|
||||
DELETE FROM ccm_cms.lifecycle_definition_labels;
|
||||
|
||||
DELETE FROM ccm_cms.lifecycle_definition_descriptions;
|
||||
|
||||
DELETE FROM ccm_cms.lifecyle_definitions;
|
||||
|
||||
DELETE FROM ccm_core.workflow_templates;
|
||||
|
||||
DELETE FROM ccm_cms.content_type_labels;
|
||||
|
||||
DELETE FROM ccm_cms.content_type_descriptions;
|
||||
|
||||
DELETE FROM ccm_cms.content_types;
|
||||
|
||||
DELETE FROM ccm_cms.content_section_roles;
|
||||
|
||||
DELETE FROM ccm_cms.content_sections;
|
||||
|
||||
DELETE FROM ccm_core.settings_string_list;
|
||||
|
||||
DELETE FROM ccm_core.settings_l10n_str_values;
|
||||
|
|
@ -12,10 +44,18 @@ DELETE FROM ccm_core.categorizations;
|
|||
|
||||
DELETE FROM ccm_core.category_domains;
|
||||
|
||||
DELETE FROM ccm_core.category_titles;
|
||||
|
||||
DELETE FROM ccm_core.categories;
|
||||
|
||||
DELETE FROM ccm_core.permissions;
|
||||
|
||||
DELETE FROM ccm_core.applications;
|
||||
|
||||
DELETE FROM ccm_core.resource_titles;
|
||||
|
||||
DELETE FROM ccm_core.resources;
|
||||
|
||||
DELETE FROM ccm_core.ccm_objects;
|
||||
|
||||
DELETE FROM ccm_core.role_memberships;
|
||||
|
|
@ -35,4 +75,4 @@ DELETE FROM ccm_core.parties;
|
|||
DELETE FROM ccm_core.ccm_roles;
|
||||
|
||||
ALTER SEQUENCE hibernate_sequence RESTART;
|
||||
ccm-core/src/test/resources/scripts/pgsql-cleanup.sql
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue