001    /**
002     * Copyright (c) 2000-present 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 aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.exception.NoSuchListTypeException;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.model.ClassName;
022    import com.liferay.portal.model.ListType;
023    import com.liferay.portal.service.base.ListTypeLocalServiceBaseImpl;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    @ProviderType
031    public class ListTypeLocalServiceImpl extends ListTypeLocalServiceBaseImpl {
032    
033            @Override
034            public ListType addListType(String name, String type) {
035                    ListType listType = listTypePersistence.fetchByN_T(name, type);
036    
037                    if (listType != null) {
038                            return listType;
039                    }
040    
041                    long listTypeId = counterLocalService.increment(
042                            ListType.class.getName());
043    
044                    listType = listTypePersistence.create(listTypeId);
045    
046                    listType.setName(name);
047                    listType.setType(type);
048    
049                    listTypePersistence.update(listType);
050    
051                    return listType;
052            }
053    
054            @Override
055            public ListType getListType(long listTypeId) throws PortalException {
056                    return listTypePersistence.findByPrimaryKey(listTypeId);
057            }
058    
059            @Override
060            public List<ListType> getListTypes(String type) {
061                    return listTypePersistence.findByType(type);
062            }
063    
064            @Override
065            public void validate(long listTypeId, long classNameId, String type)
066                    throws PortalException {
067    
068                    ClassName className = classNameLocalService.getClassName(classNameId);
069    
070                    validate(listTypeId, className.getValue() + type);
071            }
072    
073            @Override
074            public void validate(long listTypeId, String type) throws PortalException {
075                    ListType listType = listTypePersistence.fetchByPrimaryKey(listTypeId);
076    
077                    if ((listType == null) || !listType.getType().equals(type)) {
078                            NoSuchListTypeException nslte = new NoSuchListTypeException();
079    
080                            nslte.setType(type);
081    
082                            throw nslte;
083                    }
084            }
085    
086    }