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.alarm.service.impl; import java.util.Date; import java.util.List; import com.crm.alarm.service.base.AlarmEntryLocalServiceBaseImpl; import com.crm.alarm.model.AlarmEntry; import com.crm.util.ValidateUtil; 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; /** * The implementation of the alarm 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.alarm.service.AlarmEntryLocalService} 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.alarm.service.base.AlarmEntryLocalServiceBaseImpl * @see com.crm.alarm.service.AlarmEntryLocalServiceUtil */ public class AlarmEntryLocalServiceImpl extends AlarmEntryLocalServiceBaseImpl { public AlarmEntry fetchAlarm(long alarmId) throws PortalException, SystemException { return alarmEntryPersistence.fetchByPrimaryKey(alarmId); } public AlarmEntry getAlarm(long alarmId) throws PortalException, SystemException { return alarmEntryPersistence.findByPrimaryKey(alarmId); } public AlarmEntry fetchAlarm(String code) throws PortalException, SystemException { return alarmEntryPersistence.fetchByCode(code); } public AlarmEntry getAlarm(String code) throws PortalException, SystemException { return alarmEntryPersistence.findByCode(code); } public List<AlarmEntry> getAll() throws PortalException, SystemException { return alarmEntryPersistence.findAll(); } protected AlarmEntry updateAlarm(long userId, AlarmEntry alarm) throws PortalException, SystemException { // Finder User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); alarm.setUserId(user.getUserId()); alarm.setUserName(user.getScreenName()); if (alarm.isNew()) { alarm.setCreateDate(now); } alarm.setModifiedDate(now); return alarmEntryPersistence.update(alarm, false); } public AlarmEntry addAlarm(long userId, String code, String title, boolean autoTicket, long categoryId, int waitDuration, String processClass, String processMethod, String properties, String description, String solution, int status) throws PortalException, SystemException { validate(code, title, categoryId, solution, autoTicket, processClass, processMethod, properties); AlarmEntry alarm = alarmEntryPersistence.create(0); alarm.setAlias(code.toUpperCase()); alarm.setTitle(title); alarm.setDescription(description); alarm.setSolution(solution); alarm.setAutoTicket(autoTicket); alarm.setCategoryId(categoryId); alarm.setWaitDuration(waitDuration); alarm.setProcessClass(processClass); alarm.setProcessMethod(processMethod); alarm.setProperties(properties); alarm.setStatus(status); return updateAlarm(userId, alarm); } public AlarmEntry updateAlarm(long userId, long alarmId, String code, String title, boolean autoTicket, long categoryId, int waitDuration, String processClass, String processMethod, String properties, String description, String solution, int status) throws PortalException, SystemException { validate(code, title, categoryId, solution, autoTicket, processClass, processMethod, properties); AlarmEntry alarm = getAlarm(alarmId); alarm.setAlias(code.toUpperCase()); alarm.setTitle(title); alarm.setDescription(description); alarm.setSolution(solution); alarm.setCategoryId(categoryId); alarm.setAutoTicket(autoTicket); alarm.setWaitDuration(waitDuration); alarm.setProcessClass(processClass); alarm.setProcessMethod(processMethod); alarm.setProperties(properties); alarm.setStatus(WorkflowConstants.STATUS_APPROVED); return updateAlarm(userId, alarm); } public AlarmEntry deleteAlarm(long userId, long alarmId) throws PortalException, SystemException { return alarmEntryPersistence.remove(alarmId); } protected void validate(String code, String title, long categoryId, String solution, boolean autoTicket, String processClass, String processMethod, String properties) throws PortalException, SystemException { ValidateUtil.check("ANY", code, title); } }