com.crm.provisioning.service.impl.CommandEntryLocalServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.crm.provisioning.service.impl.CommandEntryLocalServiceImpl.java

Source

/**
 * Copyright (c) 2000-2011 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.provisioning.service.impl;

import java.util.Date;
import java.util.List;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.model.User;

import com.crm.util.ValidateUtil;
import com.crm.provisioning.model.CommandEntry;
import com.crm.provisioning.service.base.CommandEntryLocalServiceBaseImpl;

/**
 * The implementation of the command 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.provisioning.service.CommandEntryLocalService} interface.
 * </p>
 * 
 * <p>
 * Never reference this interface directly. Always use
 * {@link com.crm.provisioning.service.CommandEntryLocalServiceUtil} to access
 * the command entry local service.
 * </p>
 * 
 * <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.provisioning.service.base.CommandEntryLocalServiceBaseImpl
 * @see com.crm.provisioning.service.CommandEntryLocalServiceUtil
 */
public class CommandEntryLocalServiceImpl extends CommandEntryLocalServiceBaseImpl {
    public CommandEntry addCommand(long userId, String code, String title, String provisioningType,
            boolean retryEnable, int maxRetry, boolean logEnable, int priority, int timeout, String properties,
            String description) throws PortalException, SystemException {
        // Finder
        User user = userPersistence.findByPrimaryKey(userId);
        code = code.trim().toUpperCase();

        Date now = new Date();

        validate(code, title, provisioningType, description);

        CommandEntry command = commandEntryPersistence.create(0);

        command.setUserId(user.getUserId());
        command.setUserName(user.getScreenName());
        command.setCreateDate(now);
        command.setModifiedDate(now);

        command.setAlias(code);
        command.setTitle(title);
        command.setProvisioningType(provisioningType);
        command.setDescription(description);

        command.setRetryEnable(retryEnable);
        command.setMaxRetry(maxRetry);
        command.setPriority(priority);
        command.setTimeout(timeout);
        command.setProperties(properties);

        command.setStatus(WorkflowConstants.STATUS_APPROVED);

        commandEntryPersistence.update(command, false);

        return command;
    }

    public CommandEntry updateCommand(long userId, long commandId, String code, String title,
            String provisioningType, boolean retryEnable, int maxRetry, boolean logEnable, int priority,
            int timeout, String properties, String description) throws PortalException, SystemException {
        // Finder
        User user = userPersistence.findByPrimaryKey(userId);
        code = code.trim().toUpperCase();

        Date now = new Date();

        validate(code, title, provisioningType, description);

        CommandEntry command = getCommand(commandId);

        command.setUserId(user.getUserId());
        command.setUserName(user.getScreenName());
        command.setModifiedDate(now);

        command.setAlias(code);
        command.setTitle(title);
        command.setProvisioningType(provisioningType);
        command.setDescription(description);

        command.setRetryEnable(retryEnable);
        command.setMaxRetry(maxRetry);
        command.setPriority(priority);
        command.setTimeout(timeout);
        command.setProperties(properties);

        command.setStatus(WorkflowConstants.STATUS_APPROVED);

        commandEntryPersistence.update(command, false);

        return command;
    }

    public CommandEntry deleteCommand(long commandId) throws PortalException, SystemException {
        try {
            commandActionLocalService.deleteByCommand(commandId);

            return commandEntryPersistence.remove(commandId);
        } catch (Exception e) {
            throw new PortalException(e.getMessage());
        }

    }

    protected void validate(String code, String title, String provisioningType, String description)
            throws PortalException, SystemException {
        ValidateUtil.check(provisioningType, code, title);
    }

    public CommandEntry getCommand(long commandId) throws PortalException, SystemException {
        return commandEntryPersistence.findByPrimaryKey(commandId);
    }

    public CommandEntry getCommand(String code) throws PortalException, SystemException {
        return commandEntryPersistence.findByCode(code);
    }

    public CommandEntry fetchCommand(long commandId) throws PortalException, SystemException {
        return commandEntryPersistence.fetchByPrimaryKey(commandId);
    }

    public CommandEntry fetchCommand(String code) throws PortalException, SystemException {
        return commandEntryPersistence.fetchByCode(code);
    }

    public List<CommandEntry> getCommandByType(String provisioningType) throws PortalException, SystemException {
        return commandEntryPersistence.findByType(provisioningType);
    }

    public List<CommandEntry> getAll() throws PortalException, SystemException {
        return commandEntryPersistence.findAll();
    }
}