001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
031            public OrgLabor addOrgLabor(
032                            long organizationId, int typeId, int sunOpen, int sunClose,
033                            int monOpen, int monClose, int tueOpen, int tueClose, int wedOpen,
034                            int wedClose, int thuOpen, int thuClose, int friOpen, int friClose,
035                            int satOpen, int satClose)
036                    throws PortalException, SystemException {
037    
038                    validate(typeId);
039    
040                    long orgLaborId = counterLocalService.increment();
041    
042                    OrgLabor orgLabor = orgLaborPersistence.create(orgLaborId);
043    
044                    orgLabor.setOrganizationId(organizationId);
045                    orgLabor.setTypeId(typeId);
046                    orgLabor.setSunOpen(sunOpen);
047                    orgLabor.setSunClose(sunClose);
048                    orgLabor.setMonOpen(monOpen);
049                    orgLabor.setMonClose(monClose);
050                    orgLabor.setTueOpen(tueOpen);
051                    orgLabor.setTueClose(tueClose);
052                    orgLabor.setWedOpen(wedOpen);
053                    orgLabor.setWedClose(wedClose);
054                    orgLabor.setThuOpen(thuOpen);
055                    orgLabor.setThuClose(thuClose);
056                    orgLabor.setFriOpen(friOpen);
057                    orgLabor.setFriClose(friClose);
058                    orgLabor.setSatOpen(satOpen);
059                    orgLabor.setSatClose(satClose);
060    
061                    orgLaborPersistence.update(orgLabor, false);
062    
063                    return orgLabor;
064            }
065    
066            @Override
067            public List<OrgLabor> getOrgLabors(long organizationId)
068                    throws SystemException {
069    
070                    return orgLaborPersistence.findByOrganizationId(organizationId);
071            }
072    
073            @Override
074            public OrgLabor updateOrgLabor(
075                            long orgLaborId, int typeId, int sunOpen, int sunClose, int monOpen,
076                            int monClose, int tueOpen, int tueClose, int wedOpen, int wedClose,
077                            int thuOpen, int thuClose, int friOpen, int friClose, int satOpen,
078                            int satClose)
079                    throws PortalException, SystemException {
080    
081                    validate(typeId);
082    
083                    OrgLabor orgLabor = orgLaborPersistence.findByPrimaryKey(orgLaborId);
084    
085                    orgLabor.setTypeId(typeId);
086                    orgLabor.setSunOpen(sunOpen);
087                    orgLabor.setSunClose(sunClose);
088                    orgLabor.setMonOpen(monOpen);
089                    orgLabor.setMonClose(monClose);
090                    orgLabor.setTueOpen(tueOpen);
091                    orgLabor.setTueClose(tueClose);
092                    orgLabor.setWedOpen(wedOpen);
093                    orgLabor.setWedClose(wedClose);
094                    orgLabor.setThuOpen(thuOpen);
095                    orgLabor.setThuClose(thuClose);
096                    orgLabor.setFriOpen(friOpen);
097                    orgLabor.setFriClose(friClose);
098                    orgLabor.setSatOpen(satOpen);
099                    orgLabor.setSatClose(satClose);
100    
101                    orgLaborPersistence.update(orgLabor, false);
102    
103                    return orgLabor;
104            }
105    
106            protected void validate(int typeId)
107                    throws PortalException, SystemException {
108    
109                    listTypeService.validate(
110                            typeId, ListTypeConstants.ORGANIZATION_SERVICE);
111            }
112    
113    }