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-94f89814c4df
pull/2/head
jensp 2016-12-02 18:01:53 +00:00
parent bdf9058901
commit 0367ef4f70
5 changed files with 183 additions and 5 deletions

View File

@ -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 <strong>additional</strong>
*
* An implementation should add all default components which have to be present
* in page. The {@link PageModel} should only specify
* <strong>additional</strong>
* components.
*
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <P> The type of page the page builder creates.
*/
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.
*

View File

@ -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();
}

View File

@ -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}.
*

View File

@ -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;

View File

@ -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;