Removed PageModel usage from Page entity.
parent
fa8b63c444
commit
2c7208818f
|
|
@ -340,25 +340,25 @@ public class PagesAdminPage extends CMSApplicationPage {
|
|||
|
||||
if (page.isPresent()) {
|
||||
|
||||
if (page.get().getIndexPageModel() == null) {
|
||||
indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
} else {
|
||||
indexPageModelSelect.setValue(state,
|
||||
Long.toString(page
|
||||
.get()
|
||||
.getIndexPageModel()
|
||||
.getPageModelId()));
|
||||
}
|
||||
|
||||
if (page.get().getItemPageModel() == null) {
|
||||
itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
} else {
|
||||
itemPageModelSelect.setValue(state,
|
||||
Long.toString(page
|
||||
.get()
|
||||
.getItemPageModel()
|
||||
.getPageModelId()));
|
||||
}
|
||||
// if (page.get().getIndexPageModel() == null) {
|
||||
// indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
// } else {
|
||||
// indexPageModelSelect.setValue(state,
|
||||
// Long.toString(page
|
||||
// .get()
|
||||
// .getIndexPageModel()
|
||||
// .getPageModelId()));
|
||||
// }
|
||||
//
|
||||
// if (page.get().getItemPageModel() == null) {
|
||||
// itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
// } else {
|
||||
// itemPageModelSelect.setValue(state,
|
||||
// Long.toString(page
|
||||
// .get()
|
||||
// .getItemPageModel()
|
||||
// .getPageModelId()));
|
||||
// }
|
||||
} else {
|
||||
indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
|
|
@ -405,23 +405,23 @@ public class PagesAdminPage extends CMSApplicationPage {
|
|||
final String selectedItemPageModelId = data
|
||||
.getString(ITEM_PAGE_MODEL_SELECT);
|
||||
|
||||
if (!INHERIT_PAGEMODEL.equals(selectedIndexPageModelId)) {
|
||||
final PageModel model = pageModelRepo
|
||||
.findById(Long.parseLong(selectedIndexPageModelId))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No PageModel with ID %s in the database.",
|
||||
selectedIndexPageModelId)));
|
||||
page.setIndexPageModel(model);
|
||||
}
|
||||
|
||||
if (!INHERIT_PAGEMODEL.equals(selectedItemPageModelId)) {
|
||||
final PageModel model = pageModelRepo
|
||||
.findById(Long.parseLong(selectedItemPageModelId))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No PageModel with ID %s in the database.",
|
||||
selectedItemPageModelId)));
|
||||
page.setItemPageModel(model);
|
||||
}
|
||||
// if (!INHERIT_PAGEMODEL.equals(selectedIndexPageModelId)) {
|
||||
// final PageModel model = pageModelRepo
|
||||
// .findById(Long.parseLong(selectedIndexPageModelId))
|
||||
// .orElseThrow(() -> new UnexpectedErrorException(String
|
||||
// .format("No PageModel with ID %s in the database.",
|
||||
// selectedIndexPageModelId)));
|
||||
// page.setIndexPageModel(model);
|
||||
// }
|
||||
//
|
||||
// if (!INHERIT_PAGEMODEL.equals(selectedItemPageModelId)) {
|
||||
// final PageModel model = pageModelRepo
|
||||
// .findById(Long.parseLong(selectedItemPageModelId))
|
||||
// .orElseThrow(() -> new UnexpectedErrorException(String
|
||||
// .format("No PageModel with ID %s in the database.",
|
||||
// selectedItemPageModelId)));
|
||||
// page.setItemPageModel(model);
|
||||
// }
|
||||
|
||||
pageRepo.save(page);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
package org.librecms.pages;
|
||||
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.pagemodel.PageModel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
|
@ -27,12 +26,12 @@ import java.util.HashMap;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
|
|
@ -42,8 +41,9 @@ import static org.librecms.CmsConstants.*;
|
|||
import static org.librecms.pages.PagesConstants.*;
|
||||
|
||||
/**
|
||||
* A CMS page is a container which contains several data how a page is displayed.
|
||||
*
|
||||
* A CMS page is a container which contains several data how a page is
|
||||
* displayed.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
|
|
@ -62,69 +62,80 @@ public class Page extends CcmObject implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 5108486858438122008L;
|
||||
|
||||
/**
|
||||
* The page model for the index item of the associated category.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "INDEX_PAGE_MODEL_ID")
|
||||
private PageModel indexPageModel;
|
||||
|
||||
/**
|
||||
* The page model for other items in the associated category.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "ITEM_PAGE_MODEL_ID")
|
||||
private PageModel itemPageModel;
|
||||
|
||||
/**
|
||||
* The configurations for this page.
|
||||
*/
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "PAGE_THEME_CONFIGURATIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "PAGE_ID")
|
||||
})
|
||||
@CollectionTable(
|
||||
name = "PAGE_THEME_CONFIGURATIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "PAGE_ID")
|
||||
}
|
||||
)
|
||||
@MapKeyColumn(name = "THEME")
|
||||
private Map<String, ThemeConfiguration> themeConfiguration;
|
||||
|
||||
public PageModel getIndexPageModel() {
|
||||
return indexPageModel;
|
||||
}
|
||||
/**
|
||||
* Additional properties for the view/the theme
|
||||
*/
|
||||
@ElementCollection
|
||||
@CollectionTable(
|
||||
name = "PAGE_PROPERTIES",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "PAGE_ID")
|
||||
}
|
||||
)
|
||||
@MapKeyColumn(name = "PROPERTY_NAME")
|
||||
private Map<String, String> properties;
|
||||
|
||||
public void setIndexPageModel(final PageModel indexPageModel) {
|
||||
this.indexPageModel = indexPageModel;
|
||||
}
|
||||
|
||||
public PageModel getItemPageModel() {
|
||||
return itemPageModel;
|
||||
}
|
||||
|
||||
public void setItemPageModel(final PageModel itemPageModel) {
|
||||
this.itemPageModel = itemPageModel;
|
||||
public Page() {
|
||||
themeConfiguration = new HashMap<>();
|
||||
properties = new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<String, ThemeConfiguration> getThemeConfiguration() {
|
||||
return Collections.unmodifiableMap(themeConfiguration);
|
||||
return Optional
|
||||
.ofNullable(themeConfiguration)
|
||||
.map(Collections::unmodifiableMap)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public void setThemeConfiguration(
|
||||
final Map<String, ThemeConfiguration> themeConfiguration) {
|
||||
final Map<String, ThemeConfiguration> themeConfiguration
|
||||
) {
|
||||
|
||||
this.themeConfiguration = new HashMap<>(themeConfiguration);
|
||||
this.themeConfiguration = Optional
|
||||
.ofNullable(themeConfiguration)
|
||||
.map(conf -> new HashMap<>(conf))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return Optional
|
||||
.ofNullable(properties)
|
||||
.map(Collections::unmodifiableMap)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public void setProperties(final Map<String, String> properties) {
|
||||
this.properties = Optional
|
||||
.ofNullable(properties)
|
||||
.map(props -> new HashMap<>(props))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + Objects.hashCode(indexPageModel);
|
||||
hash = 47 * hash + Objects.hashCode(itemPageModel);
|
||||
hash = 47 * hash + Objects.hashCode(themeConfiguration);
|
||||
hash = 47 * hash + Objects.hashCode(properties);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -138,13 +149,12 @@ public class Page extends CcmObject implements Serializable {
|
|||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(indexPageModel, other.getIndexPageModel())) {
|
||||
if (!Objects.equals(properties, other.getProperties())) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(itemPageModel, other.getItemPageModel())) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(themeConfiguration, other.getThemeConfiguration());
|
||||
return Objects.equals(
|
||||
themeConfiguration, other.getThemeConfiguration()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -154,13 +164,15 @@ public class Page extends CcmObject implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", indexPageModel = %s, "
|
||||
+ "itemPageModel = %s, "
|
||||
+ "themeConfiguration = %s%s",
|
||||
Objects.toString(indexPageModel),
|
||||
Objects.toString(itemPageModel),
|
||||
Objects.toString(themeConfiguration),
|
||||
data));
|
||||
return super.toString(
|
||||
String.format(
|
||||
", themeConfiguration = %s,"
|
||||
+ "properties = %s%s",
|
||||
Objects.toString(themeConfiguration),
|
||||
Objects.toString(properties),
|
||||
data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ public class PagesRouter {
|
|||
protected static final String PAGE_PATH = "pagePath";
|
||||
|
||||
protected static final String PAGE_PATH_CATEGORY_ID = "categoryId";
|
||||
|
||||
|
||||
protected static final String PAGE_PATH_CATEGORY_NAME = "categoryName";
|
||||
|
||||
protected static final String PAGE_PATH_CATEGORY_TITLE = "categoryTitle";
|
||||
|
||||
|
||||
protected static final String PAGE_PATH_CATEGORY_UUID = "uuid";
|
||||
|
||||
protected static final String SITE_INFO = "siteInfo";
|
||||
|
|
@ -722,23 +722,24 @@ public class PagesRouter {
|
|||
pagePath,
|
||||
language,
|
||||
parameters);
|
||||
|
||||
final PageModel pageModel;
|
||||
if (pageModelVersion == PageModelVersion.DRAFT) {
|
||||
pageModel = pageModelManager
|
||||
.getDraftVersion(page.getIndexPageModel());
|
||||
} else {
|
||||
pageModel = pageModelManager
|
||||
.getLiveVersion(page.getIndexPageModel())
|
||||
.orElseThrow(() -> new NotFoundException(String
|
||||
.format("The PageModel for the index page of the category"
|
||||
+ "\"%s\" is not available as live version.",
|
||||
pagePath)));
|
||||
}
|
||||
|
||||
parameters.put(PARAMETER_LANGUAGE, language);
|
||||
|
||||
return buildPage(pageModel, parameters);
|
||||
// final PageModel pageModel;
|
||||
// if (pageModelVersion == PageModelVersion.DRAFT) {
|
||||
// pageModel = pageModelManager
|
||||
// .getDraftVersion(page.getIndexPageModel());
|
||||
// } else {
|
||||
// pageModel = pageModelManager
|
||||
// .getLiveVersion(page.getIndexPageModel())
|
||||
// .orElseThrow(() -> new NotFoundException(String
|
||||
// .format("The PageModel for the index page of the category"
|
||||
// + "\"%s\" is not available as live version.",
|
||||
// pagePath)));
|
||||
// }
|
||||
//
|
||||
// parameters.put(PARAMETER_LANGUAGE, language);
|
||||
//
|
||||
// return buildPage(pageModel, parameters);
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private Map<String, Object> getCategoryItemPage(
|
||||
|
|
@ -752,23 +753,24 @@ public class PagesRouter {
|
|||
final Page page = PagesRouter.this.getPage(uriInfo, pagePath, language,
|
||||
parameters);
|
||||
|
||||
final PageModel pageModel;
|
||||
if (pageModelVersion == PageModelVersion.DRAFT) {
|
||||
pageModel = pageModelManager.getDraftVersion(page
|
||||
.getItemPageModel());
|
||||
} else {
|
||||
pageModel = pageModelManager
|
||||
.getLiveVersion(page.getItemPageModel())
|
||||
.orElseThrow(() -> new NotFoundException(String
|
||||
.format("The PageModel for the index page of the category"
|
||||
+ "\"%s\" is not available as live version.",
|
||||
pagePath)));
|
||||
}
|
||||
|
||||
parameters.put(PARAMETER_ITEMNAME, itemName);
|
||||
parameters.put(PARAMETER_LANGUAGE, language);
|
||||
|
||||
return buildPage(pageModel, parameters);
|
||||
// final PageModel pageModel;
|
||||
// if (pageModelVersion == PageModelVersion.DRAFT) {
|
||||
// pageModel = pageModelManager.getDraftVersion(page
|
||||
// .getItemPageModel());
|
||||
// } else {
|
||||
// pageModel = pageModelManager
|
||||
// .getLiveVersion(page.getItemPageModel())
|
||||
// .orElseThrow(() -> new NotFoundException(String
|
||||
// .format("The PageModel for the index page of the category"
|
||||
// + "\"%s\" is not available as live version.",
|
||||
// pagePath)));
|
||||
// }
|
||||
//
|
||||
// parameters.put(PARAMETER_ITEMNAME, itemName);
|
||||
// parameters.put(PARAMETER_LANGUAGE, language);
|
||||
//
|
||||
// return buildPage(pageModel, parameters);
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> buildPageCategoriesPath(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
alter table ccm_cms.pages drop column index_page_model;
|
||||
alter table ccm_cms.pages drop column item_page_model;
|
||||
alter table ccm_cms.pages drop constraint FKqweb08d151ot4ij9io72w3yhx;
|
||||
alter table ccm_cms.pages drop constraint FKg2p2ahbayc2coei72pk1lnenf;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
create table CCM_CMS.PAGE_PROPERTIES (
|
||||
PAGE_ID bigint not null,
|
||||
properties varchar(255),
|
||||
PROPERTY_NAME varchar(255) not null,
|
||||
primary key (PAGE_ID, PROPERTY_NAME)
|
||||
);
|
||||
|
||||
alter table CCM_CMS.PAGE_PROPERTIES
|
||||
add constraint FKgvy9owhgeeyicnesuqf3t059x
|
||||
foreign key (PAGE_ID)
|
||||
references CCM_CMS.PAGES;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
alter table ccm_cms.pages drop column index_page_model;
|
||||
alter table ccm_cms.pages drop column item_page_model;
|
||||
alter table ccm_cms.pages drop constraint FKqweb08d151ot4ij9io72w3yhx;
|
||||
alter table ccm_cms.pages drop constraint FKg2p2ahbayc2coei72pk1lnenf;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
create table CCM_CMS.PAGE_PROPERTIES (
|
||||
PAGE_ID int8 not null,
|
||||
properties varchar(255),
|
||||
PROPERTY_NAME varchar(255) not null,
|
||||
primary key (PAGE_ID, PROPERTY_NAME)
|
||||
);
|
||||
|
||||
alter table CCM_CMS.PAGE_PROPERTIES
|
||||
add constraint FKgvy9owhgeeyicnesuqf3t059x
|
||||
foreign key (PAGE_ID)
|
||||
references CCM_CMS.PAGES;
|
||||
Loading…
Reference in New Issue