diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageBuilder.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageBuilder.java
index 7aa5125c2..8e1470473 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageBuilder.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageBuilder.java
@@ -22,22 +22,35 @@ import javax.enterprise.context.RequestScoped;
/**
* Interface for page builders. A page builder is invoked to build a page a
- * specific type. An implementation should be a CDI bean which is annotated with
+ * specific type. An implementation must be a CDI bean which is annotated with
* the qualifier {@link PageModelType}. The recommended scope is
* {@link RequestScoped}.
- *
- * An implementation should add all default components which have to be present
- * in page. The {@link PageModel} should only specify additional
+ *
+ * An implementation should add all default components which have to be present
+ * in page. The {@link PageModel} should only specify
+ * additional
* components.
- *
+ *
*
* @author Jens Pelzetter
* @param
The type of page the page builder creates.
*/
public interface PageBuilder
{
+ /**
+ * Build a page for the view technology supported by this page builder
+ * without an additional components.
+ * {@link #buildPage(org.libreccm.pagemodel.PageModel)} should use this
+ * method for creating the default page.
+ *
+ * @return A page with the default components.
+ */
+ P buildPage();
+
/**
* Build a page of type {@code P} using the provided {@link PageModel}.
+ * Implementations should call the implementation of {@link #buildPage()}
+ * for creating the basic page with the default components.
*
* @param pageModel The {@link PageModel} from which the page is generated.
*
diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelComponentModel.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelComponentModel.java
index c8fb2f200..53914cf80 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelComponentModel.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelComponentModel.java
@@ -18,6 +18,8 @@
*/
package org.libreccm.pagemodel;
+import com.arsdigita.bebop.Form;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -39,4 +41,6 @@ public @interface PageModelComponentModel {
Class extends ComponentModel> modelClass();
+ Class extends Form> editor();
+
}
diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java
index 800c01abf..f6d178f39 100644
--- a/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java
+++ b/ccm-core/src/main/java/org/libreccm/pagemodel/PageModelManager.java
@@ -19,10 +19,20 @@
package org.libreccm.pagemodel;
import org.libreccm.core.CoreConstants;
+import org.libreccm.modules.CcmModule;
+import org.libreccm.modules.Module;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.RequiresPrivilege;
import org.libreccm.web.CcmApplication;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+
+import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
@@ -40,6 +50,28 @@ public class PageModelManager {
@Inject
private ComponentModelRepository componentModelRepo;
+ private final Map components
+ = new HashMap<>();
+
+ @PostConstruct
+ private void init() {
+ final ServiceLoader modules = ServiceLoader.load(
+ CcmModule.class);
+
+ for (CcmModule module : modules) {
+ final Module moduleData = module.getClass().getAnnotation(
+ Module.class);
+
+ final PageModelComponentModel[] models = moduleData
+ .pageModelComponentModels();
+
+ for (PageModelComponentModel model : models) {
+ components.put(model.modelClass().getName(),
+ model);
+ }
+ }
+ }
+
/**
* Creates a new {@link PageModel} for the provided application.
*
@@ -87,6 +119,27 @@ public class PageModelManager {
return pageModel;
}
+ public List findAvailableComponents() {
+ final List list = new ArrayList<>(components
+ .values());
+ list.sort((component1, component2) -> {
+ return component1.modelClass().getName().compareTo(
+ component2.modelClass().getName());
+ });
+
+ return list;
+ }
+
+ public Optional findComponentModel(
+ final String className) {
+
+ if (components.containsKey(className)) {
+ return Optional.of(components.get(className));
+ } else {
+ return Optional.empty();
+ }
+ }
+
/**
* Add a {@link ComponentModel} to a {@link PageModel}.
*
diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_10__add_page_model.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_10__add_page_model.sql
new file mode 100644
index 000000000..76228a3f1
--- /dev/null
+++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_10__add_page_model.sql
@@ -0,0 +1,54 @@
+ create table CCM_CORE.PAGE_MODEL_COMPONENT_MODELS (
+ COMPONENT_MODEL_ID bigint not null,
+ CLASS_ATTRIBUTE varchar(512),
+ ID_ATTRIBUTE varchar(255),
+ COMPONENT_KEY varchar(255),
+ STYLE_ATTRIBUTE varchar(1024),
+ UUID varchar(255) not null,
+ PAGE_MODEL_ID bigint,
+ primary key (COMPONENT_MODEL_ID)
+ );
+
+ create table CCM_CORE.PAGE_MODEL_DESCRIPTIONS (
+ PAGE_MODEL_ID bigint not null,
+ LOCALIZED_VALUE longvarchar,
+ LOCALE varchar(255) not null,
+ primary key (PAGE_MODEL_ID, LOCALE)
+ );
+
+ create table CCM_CORE.PAGE_MODEL_TITLES (
+ PAGE_MODEL_ID bigint not null,
+ LOCALIZED_VALUE longvarchar,
+ LOCALE varchar(255) not null,
+ primary key (PAGE_MODEL_ID, LOCALE)
+ );
+
+ create table CCM_CORE.PAGE_MODELS (
+ PAGE_MODEL_ID bigint not null,
+ NAME varchar(255),
+ TYPE varchar(255) not null,
+ UUID varchar(255) not null,
+ VERSION varchar(255) not null,
+ APPLICATION_ID bigint,
+ primary key (PAGE_MODEL_ID)
+ );
+
+ alter table CCM_CORE.PAGE_MODEL_COMPONENT_MODELS
+ add constraint FKo696ch035fe7rrueol1po13od
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODEL_DESCRIPTIONS
+ add constraint FKcc5d6eqxu1369k8ycyyt6vn3e
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODEL_TITLES
+ add constraint FKj14q9911yhd4js9p6rs21rwjf
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODELS
+ add constraint FKk2lihllrxj89mn3tqv43amafe
+ foreign key (APPLICATION_ID)
+ references CCM_CORE.APPLICATIONS;
diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_10__add_page_model.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_10__add_page_model.sql
new file mode 100644
index 000000000..89cc690fa
--- /dev/null
+++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_10__add_page_model.sql
@@ -0,0 +1,54 @@
+ create table CCM_CORE.PAGE_MODEL_COMPONENT_MODELS (
+ COMPONENT_MODEL_ID int8 not null,
+ CLASS_ATTRIBUTE varchar(512),
+ ID_ATTRIBUTE varchar(255),
+ COMPONENT_KEY varchar(255),
+ STYLE_ATTRIBUTE varchar(1024),
+ UUID varchar(255) not null,
+ PAGE_MODEL_ID int8,
+ primary key (COMPONENT_MODEL_ID)
+ );
+
+ create table CCM_CORE.PAGE_MODEL_DESCRIPTIONS (
+ PAGE_MODEL_ID int8 not null,
+ LOCALIZED_VALUE text,
+ LOCALE varchar(255) not null,
+ primary key (PAGE_MODEL_ID, LOCALE)
+ );
+
+ create table CCM_CORE.PAGE_MODEL_TITLES (
+ PAGE_MODEL_ID int8 not null,
+ LOCALIZED_VALUE text,
+ LOCALE varchar(255) not null,
+ primary key (PAGE_MODEL_ID, LOCALE)
+ );
+
+ create table CCM_CORE.PAGE_MODELS (
+ PAGE_MODEL_ID int8 not null,
+ NAME varchar(255),
+ TYPE varchar(255) not null,
+ UUID varchar(255) not null,
+ VERSION varchar(255) not null,
+ APPLICATION_ID int8,
+ primary key (PAGE_MODEL_ID)
+ );
+
+ alter table CCM_CORE.PAGE_MODEL_COMPONENT_MODELS
+ add constraint FKo696ch035fe7rrueol1po13od
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODEL_DESCRIPTIONS
+ add constraint FKcc5d6eqxu1369k8ycyyt6vn3e
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODEL_TITLES
+ add constraint FKj14q9911yhd4js9p6rs21rwjf
+ foreign key (PAGE_MODEL_ID)
+ references CCM_CORE.PAGE_MODELS;
+
+ alter table CCM_CORE.PAGE_MODELS
+ add constraint FKk2lihllrxj89mn3tqv43amafe
+ foreign key (APPLICATION_ID)
+ references CCM_CORE.APPLICATIONS;