org.broadleafcommerce.common.site.domain.SiteImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of broadleaf-common Show documentation
Show all versions of broadleaf-common Show documentation
A collection of classes shared by broadleaf profile, cms, admin, and core.
/*
* Copyright 2008-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.broadleafcommerce.common.site.domain;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.broadleafcommerce.common.persistence.ArchiveStatus;
import org.broadleafcommerce.common.persistence.Status;
import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.AdminPresentationClass;
import org.broadleafcommerce.common.presentation.AdminPresentationCollection;
import org.broadleafcommerce.common.presentation.RequiredOverride;
import org.broadleafcommerce.common.presentation.client.AddMethodType;
import org.broadleafcommerce.common.presentation.client.SupportedFieldType;
import org.broadleafcommerce.common.presentation.client.VisibilityEnum;
import org.broadleafcommerce.common.sandbox.domain.SandBox;
import org.broadleafcommerce.common.sandbox.domain.SandBoxImpl;
import org.broadleafcommerce.common.site.service.type.SiteResolutionType;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.SQLDelete;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* Created by bpolster.
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "BLC_SITE")
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="blCMSElements")
@AdminPresentationClass(friendlyName = "baseSite")
@SQLDelete(sql="UPDATE BLC_SITE SET ARCHIVED = 'Y' WHERE SITE_ID = ?")
public class SiteImpl implements Site, Status {
private static final long serialVersionUID = 1L;
private static final Log LOG = LogFactory.getLog(SiteImpl.class);
@Id
@GeneratedValue(generator = "SiteId")
@GenericGenerator(
name="SiteId",
strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
parameters = {
@Parameter(name="segment_value", value="SiteImpl"),
@Parameter(name="entity_name", value="org.broadleafcommerce.common.site.domain.SiteImpl")
}
)
@Column(name = "SITE_ID")
protected Long id;
@Column (name = "NAME")
@AdminPresentation(friendlyName = "SiteImpl_Site_Name", order=1, gridOrder = 1, group = "SiteImpl_Site", prominent = true, requiredOverride = RequiredOverride.REQUIRED)
protected String name;
@Column (name = "SITE_IDENTIFIER_TYPE")
@AdminPresentation(friendlyName = "SiteImpl_Site_Identifier_Type", order=2, gridOrder = 2, group = "SiteImpl_Site", prominent = true, broadleafEnumeration = "org.broadleafcommerce.common.site.service.type.SiteResolutionType", fieldType = SupportedFieldType.BROADLEAF_ENUMERATION, requiredOverride = RequiredOverride.REQUIRED)
protected String siteIdentifierType;
@Column (name = "SITE_IDENTIFIER_VALUE")
@AdminPresentation(friendlyName = "SiteImpl_Site_Identifier_Value", order=3, gridOrder = 3, group = "SiteImpl_Site", prominent = true, requiredOverride = RequiredOverride.REQUIRED)
@Index(name = "BLC_SITE_ID_VAL_INDEX", columnNames = { "SITE_IDENTIFIER_VALUE" })
protected String siteIdentifierValue;
@ManyToOne(targetEntity = SandBoxImpl.class)
@JoinColumn(name = "PRODUCTION_SANDBOX_ID")
@AdminPresentation(friendlyName = "SiteImpl_Production_SandBox", visibility = VisibilityEnum.HIDDEN_ALL)
protected SandBox productionSandbox;
@ManyToMany(targetEntity = CatalogImpl.class, cascade = {CascadeType.PERSIST, CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH})
@JoinTable(name = "BLC_SITE_CATALOG", joinColumns = @JoinColumn(name = "SITE_ID"), inverseJoinColumns = @JoinColumn(name = "CATALOG_ID"))
@BatchSize(size = 50)
@AdminPresentationCollection(addType = AddMethodType.LOOKUP, friendlyName = "siteCatalogTitle", manyToField = "sites")
protected List catalogs = new ArrayList();
@Column(name = "DEACTIVATED")
@AdminPresentation(friendlyName = "SiteImpl_Deactivated", order=4, gridOrder = 4, group = "SiteImpl_Site")
protected Boolean deactivated = false;
@Embedded
protected ArchiveStatus archiveStatus = new ArchiveStatus();
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getSiteIdentifierType() {
return siteIdentifierType;
}
@Override
public void setSiteIdentifierType(String siteIdentifierType) {
this.siteIdentifierType = siteIdentifierType;
}
@Override
public String getSiteIdentifierValue() {
return siteIdentifierValue;
}
@Override
public void setSiteIdentifierValue(String siteIdentifierValue) {
this.siteIdentifierValue = siteIdentifierValue;
}
@Override
public SandBox getProductionSandbox() {
return productionSandbox;
}
@Override
public void setProductionSandbox(SandBox productionSandbox) {
this.productionSandbox = productionSandbox;
}
@Override
public SiteResolutionType getSiteResolutionType() {
return SiteResolutionType.getInstance(siteIdentifierType);
}
@Override
public void setSiteResolutionType(SiteResolutionType siteResolutionType) {
this.siteIdentifierType = siteResolutionType.getType();
}
@Override
public List getCatalogs() {
return catalogs;
}
@Override
public void setCatalogs(List catalogs) {
this.catalogs = catalogs;
}
@Override
public Character getArchived() {
if (archiveStatus == null) {
archiveStatus = new ArchiveStatus();
}
return archiveStatus.getArchived();
}
@Override
public void setArchived(Character archived) {
if (archiveStatus == null) {
archiveStatus = new ArchiveStatus();
}
archiveStatus.setArchived(archived);
}
@Override
public boolean isActive() {
if (LOG.isDebugEnabled()) {
if (isDeactivated()) {
LOG.debug("site, " + id + ", inactive due to deactivated property");
}
if ('Y'==getArchived()) {
LOG.debug("site, " + id + ", inactive due to archived status");
}
}
return !isDeactivated() && 'Y'!=getArchived();
}
@Override
public boolean isDeactivated() {
if (deactivated == null) {
return false;
} else {
return deactivated;
}
}
@Override
public void setDeactivated(boolean deactivated) {
this.deactivated = deactivated;
}
@Override
public boolean isTemplateSite() {
return false;
}
public void checkCloneable(Site site) throws CloneNotSupportedException, SecurityException, NoSuchMethodException {
Method cloneMethod = site.getClass().getMethod("clone", new Class[]{});
if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce") && !site.getClass().getName().startsWith("org.broadleafcommerce")) {
//subclass is not implementing the clone method
throw new CloneNotSupportedException("Custom extensions and implementations should implement clone.");
}
}
@Override
public Site clone() {
Site clone;
try {
clone = (Site) Class.forName(this.getClass().getName()).newInstance();
try {
checkCloneable(clone);
} catch (CloneNotSupportedException e) {
LOG.warn("Clone implementation missing in inheritance hierarchy outside of Broadleaf: " + clone.getClass().getName(), e);
}
clone.setId(id);
clone.setName(name);
clone.setDeactivated(isDeactivated());
((Status) clone).setArchived(getArchived());
for (Catalog catalog : getCatalogs()) {
Catalog cloneCatalog = new CatalogImpl();
cloneCatalog.setId(catalog.getId());
cloneCatalog.setName(catalog.getName());
clone.getCatalogs().add(cloneCatalog);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return clone;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy