/*
* #%L
* BroadleafCommerce CMS Module
* %%
* Copyright (C) 2009 - 2013 Broadleaf Commerce
* %%
* 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.
* #L%
*/
package org.broadleafcommerce.cms.field.domain;
import org.broadleafcommerce.common.copy.CreateResponse;
import org.broadleafcommerce.common.copy.MultiTenantCopyContext;
import org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyArchive;
import org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransform;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransformMember;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransformTypes;
import org.broadleafcommerce.common.extensibility.jpa.copy.ProfileEntity;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
/**
* Created by bpolster.
*/
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "BLC_FLD_GROUP")
@Cache(usage= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="blCMSElements")
@DirectCopyTransform({
@DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.SANDBOX, skipOverlaps = true),
@DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.MULTITENANT_SITE)
})
public class FieldGroupImpl implements FieldGroup, ProfileEntity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "FieldGroupId")
@GenericGenerator(
name="FieldGroupId",
strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
parameters = {
@Parameter(name="segment_value", value="FieldGroupImpl"),
@Parameter(name="entity_name", value="org.broadleafcommerce.cms.field.domain.FieldGroupImpl")
}
)
@Column(name = "FLD_GROUP_ID")
protected Long id;
@Column (name = "NAME")
protected String name;
@Column (name = "INIT_COLLAPSED_FLAG")
protected Boolean initCollapsedFlag = false;
@OneToMany(mappedBy = "fieldGroup", targetEntity = FieldDefinitionImpl.class, cascade = { CascadeType.ALL }, orphanRemoval = true)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blCMSElements")
@OrderBy("fieldOrder")
@BatchSize(size = 20)
@ClonePolicyCollectionOverride
@ClonePolicyArchive
protected List<FieldDefinition> fieldDefinitions = new ArrayList<FieldDefinition>();
@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 Boolean getInitCollapsedFlag() {
return initCollapsedFlag;
}
@Override
public void setInitCollapsedFlag(Boolean initCollapsedFlag) {
this.initCollapsedFlag = initCollapsedFlag;
}
@Override
public List<FieldDefinition> getFieldDefinitions() {
return fieldDefinitions;
}
@Override
public void setFieldDefinitions(List<FieldDefinition> fieldDefinitions) {
this.fieldDefinitions = fieldDefinitions;
}
@Override
public <G extends FieldGroup> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context)
throws CloneNotSupportedException {
CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
if (createResponse.isAlreadyPopulated()) {
return createResponse;
}
FieldGroup cloned = createResponse.getClone();
cloned.setInitCollapsedFlag(initCollapsedFlag);
cloned.setName(name);
for (FieldDefinition fieldDefinition : fieldDefinitions) {
FieldDefinition clonedDef = fieldDefinition.createOrRetrieveCopyInstance(context).getClone();
cloned.getFieldDefinitions().add(clonedDef);
}
return createResponse;
}
@Override
public Boolean isMasterFieldGroup() {
return name != null && name.toLowerCase().contains("master");
}
}