Next part of the sites/pages/themes complex
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5041 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
314a451e10
commit
903b2d5eb6
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.pagemodel.PageModel;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "PAGES", schema = DB_SCHEMA)
|
||||
@NamedQueries(
|
||||
@NamedQuery(
|
||||
name = "Page.findForCategory",
|
||||
query = "SELECT p FROM Page p WHERE p.category = :category"
|
||||
)
|
||||
)
|
||||
public class Page implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5108486858438122008L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "PAGE_ID")
|
||||
private long pageId;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "CATEGORY_ID")
|
||||
private Category category;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "INDEX_PAGE_MODEL_ID")
|
||||
private PageModel indexPageModel;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "ITEM_PAGE_MODEL_ID")
|
||||
private PageModel itemPageModel;
|
||||
|
||||
@Embedded
|
||||
@JoinTable(name = "PAGE_THEME_CONFIGURATIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "PAGE_ID")
|
||||
})
|
||||
private Map<String, ThemeConfiguration> themeConfiguration;
|
||||
|
||||
public long getPageId() {
|
||||
return pageId;
|
||||
}
|
||||
|
||||
protected void setPageId(final long pageId) {
|
||||
this.pageId = pageId;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(final Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public PageModel getIndexPageModel() {
|
||||
return indexPageModel;
|
||||
}
|
||||
|
||||
public void setIndexPageModel(final PageModel indexPageModel) {
|
||||
this.indexPageModel = indexPageModel;
|
||||
}
|
||||
|
||||
public PageModel getItemPageModel() {
|
||||
return itemPageModel;
|
||||
}
|
||||
|
||||
public void setItemPageModel(final PageModel itemPageModel) {
|
||||
this.itemPageModel = itemPageModel;
|
||||
}
|
||||
|
||||
public Map<String, ThemeConfiguration> getThemeConfiguration() {
|
||||
return Collections.unmodifiableMap(themeConfiguration);
|
||||
}
|
||||
|
||||
public void setThemeConfiguration(
|
||||
final Map<String, ThemeConfiguration> themeConfiguration) {
|
||||
|
||||
this.themeConfiguration = new HashMap<>(themeConfiguration);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class PageRepository extends AbstractEntityRepository<Long, Page>{
|
||||
|
||||
public Optional<Page> findPageForCategory(final Category category) {
|
||||
|
||||
final TypedQuery<Page> query = getEntityManager()
|
||||
.createNamedQuery("Page.findForCategory", Page.class);
|
||||
query.setParameter("category", category);
|
||||
|
||||
try {
|
||||
return Optional.of(query.getSingleResult());
|
||||
} catch(NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Override
|
||||
public void save(final Page page) {
|
||||
super.save(page);
|
||||
}
|
||||
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Override
|
||||
public void delete(final Page page) {
|
||||
super.delete(page);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<Page> getEntityClass() {
|
||||
return Page.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(final Page page) {
|
||||
return page.getPageId() == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.libreccm.pagemodel;
|
||||
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
|
@ -37,6 +36,9 @@ import javax.persistence.Embedded;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
|
|
@ -109,10 +111,31 @@ import javax.persistence.Table;
|
|||
+ "AND p.version = org.libreccm.pagemodel.PageModelVersion.LIVE"
|
||||
)
|
||||
})
|
||||
public class PageModel extends CcmObject implements Serializable {
|
||||
public class PageModel implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7252512839926020978L;
|
||||
|
||||
/**
|
||||
*
|
||||
* The ID of the entity in the database.
|
||||
*
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "PAGE_MODEL_ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long pageModelId;
|
||||
|
||||
/**
|
||||
*
|
||||
* The UUID of this {@code PageModel}. Please note that this UUID identifies
|
||||
* the dataset not the model. Therefore the draft and the live version have
|
||||
* different values for this field.
|
||||
*
|
||||
*/
|
||||
@Column(name = "UUID", length = 255, nullable = false)
|
||||
@NotNull
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* The UUID of the model. Same for draft and live version.
|
||||
*/
|
||||
|
|
@ -185,6 +208,22 @@ public class PageModel extends CcmObject implements Serializable {
|
|||
description = new LocalizedString();
|
||||
}
|
||||
|
||||
public long getPageModelId() {
|
||||
return pageModelId;
|
||||
}
|
||||
|
||||
protected void setPageModelId(final long pageModelId) {
|
||||
this.pageModelId = pageModelId;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
protected void setUuid(final String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getModelUuid() {
|
||||
return modelUuid;
|
||||
}
|
||||
|
|
@ -265,7 +304,9 @@ public class PageModel extends CcmObject implements Serializable {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
int hash = 7;
|
||||
hash = 71 * hash + (int) (pageModelId ^ (pageModelId >>> 32));
|
||||
hash = 71 * hash + Objects.hashCode(uuid);
|
||||
hash = 71 * hash + Objects.hashCode(name);
|
||||
hash = 71 * hash + Objects.hashCode(title);
|
||||
hash = 71 * hash + Objects.hashCode(description);
|
||||
|
|
@ -281,11 +322,6 @@ public class PageModel extends CcmObject implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof PageModel)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -293,6 +329,12 @@ public class PageModel extends CcmObject implements Serializable {
|
|||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
if (pageModelId != other.getPageModelId()) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(uuid, other.getUuid())) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(name, other.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -305,21 +347,35 @@ public class PageModel extends CcmObject implements Serializable {
|
|||
return Objects.equals(description, other.getDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof PageModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public final String toString() {
|
||||
|
||||
return toString("");
|
||||
|
||||
}
|
||||
|
||||
public String toString(final String data) {
|
||||
return super.toString(String.format(", name = \"%s\", "
|
||||
+ "title = %s, "
|
||||
+ "description = %s%s",
|
||||
super.toString(),
|
||||
name,
|
||||
Objects.toString(title),
|
||||
Objects.toString(description),
|
||||
data));
|
||||
|
||||
return String.format("%s{ "
|
||||
+ "pageModelId = %d, "
|
||||
+ "uuid = %s, "
|
||||
+ "name = \"%s\", "
|
||||
+ "title = %s, "
|
||||
+ "description = %s, "
|
||||
+ "type = \"%s\""
|
||||
+ " }",
|
||||
super.toString(),
|
||||
pageModelId,
|
||||
uuid,
|
||||
name,
|
||||
Objects.toString(title),
|
||||
Objects.toString(description),
|
||||
type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
|
|||
throw new IllegalArgumentException("PageModel can't be null.");
|
||||
}
|
||||
|
||||
return pageModel.getObjectId() == 0;
|
||||
return pageModel.getPageModelId() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue