001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.ListTypeConstants;
020    import com.liferay.portal.model.OrgLabor;
021    import com.liferay.portal.service.base.OrgLaborLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class OrgLaborLocalServiceImpl extends OrgLaborLocalServiceBaseImpl {
029    
030            public OrgLabor addOrgLabor(
031                            long organizationId, int typeId, int sunOpen, int sunClose,
032                            int monOpen, int monClose, int tueOpen, int tueClose, int wedOpen,
033                            int wedClose, int thuOpen, int thuClose, int friOpen, int friClose,
034                            int satOpen, int satClose)
035                    throws PortalException, SystemException {
036    
037                    validate(typeId);
038    
039                    long orgLaborId = counterLocalService.increment();
040    
041                    OrgLabor orgLabor = orgLaborPersistence.create(orgLaborId);
042    
043                    orgLabor.setOrganizationId(organizationId);
044                    orgLabor.setTypeId(typeId);
045                    orgLabor.setSunOpen(sunOpen);
046                    orgLabor.setSunClose(sunClose);
047                    orgLabor.setMonOpen(monOpen);
048                    orgLabor.setMonClose(monClose);
049                    orgLabor.setTueOpen(tueOpen);
050                    orgLabor.setTueClose(tueClose);
051                    orgLabor.setWedOpen(wedOpen);
052                    orgLabor.setWedClose(wedClose);
053                    orgLabor.setThuOpen(thuOpen);
054                    orgLabor.setThuClose(thuClose);
055                    orgLabor.setFriOpen(friOpen);
056                    orgLabor.setFriClose(friClose);
057                    orgLabor.setSatOpen(satOpen);
058                    orgLabor.setSatClose(satClose);
059    
060                    orgLaborPersistence.update(orgLabor, false);
061    
062                    return orgLabor;
063            }
064    
065            @Override
066            public void deleteOrgLabor(long orgLaborId)
067                    throws PortalException, SystemException {
068    
069                    OrgLabor orgLabor = orgLaborPersistence.findByPrimaryKey(orgLaborId);
070    
071                    deleteOrgLabor(orgLabor);
072            }
073    
074            @Override
075            public void deleteOrgLabor(OrgLabor orgLabor) throws SystemException {
076                    orgLaborPersistence.remove(orgLabor);
077            }
078    
079            @Override
080            public OrgLabor getOrgLabor(long orgLaborId)
081                    throws PortalException, SystemException {
082    
083                    return orgLaborPersistence.findByPrimaryKey(orgLaborId);
084            }
085    
086            public List<OrgLabor> getOrgLabors(long organizationId)
087                    throws SystemException {
088    
089                    return orgLaborPersistence.findByOrganizationId(organizationId);
090            }
091    
092            public OrgLabor updateOrgLabor(
093                            long orgLaborId, int typeId, int sunOpen, int sunClose, int monOpen,
094                            int monClose, int tueOpen, int tueClose, int wedOpen, int wedClose,
095                            int thuOpen, int thuClose, int friOpen, int friClose, int satOpen,
096                            int satClose)
097                    throws PortalException, SystemException {
098    
099                    validate(typeId);
100    
101                    OrgLabor orgLabor = orgLaborPersistence.findByPrimaryKey(orgLaborId);
102    
103                    orgLabor.setTypeId(typeId);
104                    orgLabor.setSunOpen(sunOpen);
105                    orgLabor.setSunClose(sunClose);
106                    orgLabor.setMonOpen(monOpen);
107                    orgLabor.setMonClose(monClose);
108                    orgLabor.setTueOpen(tueOpen);
109                    orgLabor.setTueClose(tueClose);
110                    orgLabor.setWedOpen(wedOpen);
111                    orgLabor.setWedClose(wedClose);
112                    orgLabor.setThuOpen(thuOpen);
113                    orgLabor.setThuClose(thuClose);
114                    orgLabor.setFriOpen(friOpen);
115                    orgLabor.setFriClose(friClose);
116                    orgLabor.setSatOpen(satOpen);
117                    orgLabor.setSatClose(satClose);
118    
119                    orgLaborPersistence.update(orgLabor, false);
120    
121                    return orgLabor;
122            }
123    
124            protected void validate(int typeId)
125                    throws PortalException, SystemException {
126    
127                    listTypeService.validate(
128                            typeId, ListTypeConstants.ORGANIZATION_SERVICE);
129            }
130    
131    }