Java tutorial
/** * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. * * 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. */ package com.crm.merchant.service.impl; import java.util.Date; import java.util.List; import com.crm.util.ValidateUtil; import com.crm.merchant.model.MerchantEntry; import com.crm.merchant.service.base.MerchantEntryLocalServiceBaseImpl; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.model.User; /** * The implementation of the merchant entry local service. * * <p> * All custom service methods should be put in this class. Whenever methods are * added, rerun ServiceBuilder to copy their definitions into the * {@link com.crm.merchant.service.MerchantEntryLocalService} interface. * * <p> * This is a local service. Methods of this service will not have security * checks based on the propagated JAAS credentials because this service can only * be accessed from within the same VM. * </p> * * @author ThangPV * @see com.crm.merchant.service.base.MerchantEntryLocalServiceBaseImpl * @see com.crm.merchant.service.MerchantEntryLocalServiceUtil */ public class MerchantEntryLocalServiceImpl extends MerchantEntryLocalServiceBaseImpl { public MerchantEntry getMerchant(long merchantId) throws PortalException, SystemException { return merchantEntryPersistence.findByPrimaryKey(merchantId); } public MerchantEntry getMerchant(String code) throws PortalException, SystemException { return merchantEntryPersistence.findByCode(code); } public MerchantEntry fetchMerchant(long merchantId) throws PortalException, SystemException { return merchantEntryPersistence.fetchByPrimaryKey(merchantId); } public MerchantEntry fetchMerchant(String code) throws PortalException, SystemException { return merchantEntryPersistence.fetchByCode(code); } public int countByType(String merchantType) throws PortalException, SystemException { if (Validator.isNotNull(merchantType)) { return merchantEntryPersistence.countByType(merchantType); } else { return merchantEntryPersistence.countAll(); } } public List<MerchantEntry> getByType(String merchantType) throws PortalException, SystemException { if (Validator.isNotNull(merchantType)) { return merchantEntryPersistence.findByType(merchantType); } else { return merchantEntryPersistence.findAll(); } } public String getMerchantType(long merchantId) throws PortalException, SystemException { MerchantEntry merchant = fetchMerchant(merchantId); return (merchant == null) ? "" : merchant.getType(); } protected MerchantEntry updateMerchant(long userId, MerchantEntry merchant, int status, String description) throws PortalException, SystemException { Date now = new Date(); User user = userLocalService.getUser(userId); if (merchant.isNew()) { merchant.setCreateDate(now); } merchant.setUserId(userId); merchant.setUserName(user.getScreenName()); merchant.setModifiedDate(now); status = (status == WorkflowConstants.STATUS_ANY) ? merchant.getStatus() : status; merchant.setStatus(status); merchant.setDescription(description); return merchantEntryPersistence.update(merchant, false); } public MerchantEntry addMerchant(long userId, String merchantType, String code, String title, String serviceAddress, String host, int port, String connectByUserName, String connectByPassword, String properties, int status, String description) throws PortalException, SystemException { // Finder code = code.trim().toUpperCase(); validate(merchantType, code, title); MerchantEntry merchant = merchantEntryPersistence.create(0); merchant.setType(merchantType); merchant.setAlias(code); merchant.setTitle(title); merchant.setServiceAddress(serviceAddress); merchant.setConnectionHost(host); merchant.setConnectionPort(port); merchant.setConnectByUserName(connectByUserName); merchant.setConnectByPassword(connectByPassword); merchant.setProperties(properties); return updateMerchant(userId, merchant, status, description); } public MerchantEntry updateMerchant(long userId, long merchantId, String merchantType, String code, String title, String serviceAddress, String connectionHost, int connectionPort, String connectByUserName, String connectByPassword, String properties, int status, String description) throws PortalException, SystemException { MerchantEntry merchant = getMerchant(merchantId); validate(merchant.getType(), code, title); merchant.setType(merchantType); merchant.setAlias(code); merchant.setTitle(title); merchant.setServiceAddress(serviceAddress); merchant.setConnectionHost(connectionHost); merchant.setConnectionPort(connectionPort); merchant.setConnectByUserName(connectByUserName); merchant.setConnectByPassword(connectByPassword); merchant.setProperties(properties); return updateMerchant(userId, merchant, status, description); } public MerchantEntry deleteMerchant(long merchantId) throws PortalException, SystemException { return merchantEntryPersistence.remove(merchantId); } protected void validate(String merchantType, String code, String title) throws PortalException, SystemException { ValidateUtil.check(merchantType, code, title); } }