/**
*
*/
public PaymentGatewayViewBean buildViewBeanPaymentGateway(final RequestData requestData, final AbstractPaymentGateway paymentGateway) throws Exception {
final MarketArea marketArea = requestData.getMarketArea();
final PaymentGatewayViewBean paymentGatewayViewBean = new PaymentGatewayViewBean();
if (paymentGateway != null) {
paymentGatewayViewBean.setCode(paymentGateway.getCode());
paymentGatewayViewBean.setName(paymentGateway.getName());
paymentGatewayViewBean.setDescription(paymentGateway.getDescription());
if(Hibernate.isInitialized(paymentGateway.getMarketAreas())
&& paymentGateway.getMarketAreas() != null){
paymentGatewayViewBean.setActive(paymentGateway.getMarketAreas().contains(marketArea));
}
List<PaymentGatewayAttribute> globalAttributes = paymentGateway.getGlobalAttributes();
if(globalAttributes != null){
for (Iterator<PaymentGatewayAttribute> iterator = globalAttributes.iterator(); iterator.hasNext();) {
PaymentGatewayAttribute attribute = (PaymentGatewayAttribute) iterator.next();
paymentGatewayViewBean.getGlobalAttributes().put(attribute.getAttributeDefinition().getCode(), attribute.getValueAsString());
}
}
List<PaymentGatewayAttribute> marketAreaAttributes = paymentGateway.getMarketAreaAttributes(marketArea.getId());
if(marketAreaAttributes != null){
for (Iterator<PaymentGatewayAttribute> iterator = marketAreaAttributes.iterator(); iterator.hasNext();) {
PaymentGatewayAttribute attribute = (PaymentGatewayAttribute) iterator.next();
paymentGatewayViewBean.getMarketAreaAttributes().put(attribute.getAttributeDefinition().getCode(), attribute.getValueAsString());
}
}
Set<PaymentGatewayOption> options = paymentGateway.getOptions();
if(options != null){
for (Iterator<PaymentGatewayOption> iterator = options.iterator(); iterator.hasNext();) {
PaymentGatewayOption option = (PaymentGatewayOption) iterator.next();
paymentGatewayViewBean.getOptions().put(option.getCode(), option.getOptionValue());
}
}
DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
Date dateCreate = paymentGateway.getDateCreate();
if (dateCreate != null) {
paymentGatewayViewBean.setDateCreate(dateFormat.format(dateCreate));
} else {
paymentGatewayViewBean.setDateCreate(Constants.NOT_AVAILABLE);
}
Date dateUpdate = paymentGateway.getDateUpdate();
if (dateUpdate != null) {
paymentGatewayViewBean.setDateUpdate(dateFormat.format(dateUpdate));
} else {
paymentGatewayViewBean.setDateUpdate(Constants.NOT_AVAILABLE);
}
paymentGatewayViewBean.setDetailsUrl(backofficeUrlService.generateUrl(BoUrls.PAYMENT_GATEWAY_DETAILS, requestData, paymentGateway));
paymentGatewayViewBean.setEditUrl(backofficeUrlService.generateUrl(BoUrls.PAYMENT_GATEWAY_EDIT, requestData, paymentGateway));
}
return paymentGatewayViewBean;
}