CCM NG: Migration scripts for new entites from page model, some cleanup
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4459 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
bdf9058901
commit
0367ef4f70
|
|
@ -22,12 +22,13 @@ 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 <strong>additional</strong>
|
||||
* in page. The {@link PageModel} should only specify
|
||||
* <strong>additional</strong>
|
||||
* components.
|
||||
*
|
||||
*
|
||||
|
|
@ -36,8 +37,20 @@ import javax.enterprise.context.RequestScoped;
|
|||
*/
|
||||
public interface PageBuilder<P> {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, PageModelComponentModel> components
|
||||
= new HashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
final ServiceLoader<CcmModule> 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<PageModelComponentModel> findAvailableComponents() {
|
||||
final List<PageModelComponentModel> list = new ArrayList<>(components
|
||||
.values());
|
||||
list.sort((component1, component2) -> {
|
||||
return component1.modelClass().getName().compareTo(
|
||||
component2.modelClass().getName());
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public Optional<PageModelComponentModel> 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}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue