org.broadleafcommerce.core.payment.domain.secure.GiftCardPaymentImpl Maven / Gradle / Ivy
/*
* #%L
* BroadleafCommerce Framework
* %%
* 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.core.payment.domain.secure;
import org.broadleafcommerce.common.encryption.EncryptionModule;
import org.broadleafcommerce.core.payment.service.SecureOrderPaymentService;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Parameter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "BLC_GIFT_CARD_PAYMENT")
public class GiftCardPaymentImpl implements GiftCardPayment {
private static final long serialVersionUID = 1L;
/**
* Rather than constructing directly, use {@link SecureOrderPaymentService#create(org.broadleafcommerce.core.payment.service.type.PaymentType)}
* so that the appropriate {@link EncryptionModule} can be hooked up to this entity
*/
protected GiftCardPaymentImpl() {
// do not allow direct instantiation -- must at least be package private
// for bytecode instrumentation
// this complies with JPA specification requirements for entity
// construction
}
@Transient
protected EncryptionModule encryptionModule;
@Id
@GeneratedValue(generator = "GiftCardPaymentId")
@GenericGenerator(
name="GiftCardPaymentId",
strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
parameters = {
@Parameter(name="segment_value", value="GiftCardPaymentImpl"),
@Parameter(name="entity_name", value="org.broadleafcommerce.core.payment.domain.GiftCardPaymentInfoImpl")
}
)
@Column(name = "PAYMENT_ID")
protected Long id;
@Column(name = "REFERENCE_NUMBER", nullable = false)
@Index(name="GIFTCARD_INDEX", columnNames={"REFERENCE_NUMBER"})
protected String referenceNumber;
@Column(name = "PAN", nullable = false)
protected String pan;
@Column(name = "PIN")
protected String pin;
@Override
public Long getId() {
return id;
}
@Override
public String getPan() {
return encryptionModule.decrypt(pan);
}
@Override
public String getPin() {
return encryptionModule.decrypt(pin);
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public void setPan(String pan) {
this.pan = encryptionModule.encrypt(pan);
}
@Override
public void setPin(String pin) {
this.pin = encryptionModule.encrypt(pin);
}
@Override
public String getReferenceNumber() {
return referenceNumber;
}
@Override
public void setReferenceNumber(String referenceNumber) {
this.referenceNumber = referenceNumber;
}
@Override
public EncryptionModule getEncryptionModule() {
return encryptionModule;
}
@Override
public void setEncryptionModule(EncryptionModule encryptionModule) {
this.encryptionModule = encryptionModule;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((pan == null) ? 0 : pan.hashCode());
result = prime * result + ((pin == null) ? 0 : pin.hashCode());
result = prime * result + ((referenceNumber == null) ? 0 : referenceNumber.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!getClass().isAssignableFrom(obj.getClass()))
return false;
GiftCardPaymentImpl other = (GiftCardPaymentImpl) obj;
if (id != null && other.id != null) {
return id.equals(other.id);
}
if (pan == null) {
if (other.pan != null)
return false;
} else if (!pan.equals(other.pan))
return false;
if (pin == null) {
if (other.pin != null)
return false;
} else if (!pin.equals(other.pin))
return false;
if (referenceNumber == null) {
if (other.referenceNumber != null)
return false;
} else if (!referenceNumber.equals(other.referenceNumber))
return false;
return true;
}
}