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.portlet.softwarecatalog.util;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryCreateDateComparator;
019    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryModifiedDateComparator;
020    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryNameComparator;
021    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryTypeComparator;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class SCUtil {
027    
028            public static OrderByComparator getProductEntryOrderByComparator(
029                    String orderByCol, String orderByType) {
030    
031                    boolean orderByAsc = false;
032    
033                    if (orderByType.equals("asc")) {
034                            orderByAsc = true;
035                    }
036    
037                    OrderByComparator orderByComparator = null;
038    
039                    if (orderByCol.equals("create-date")) {
040                            orderByComparator = new ProductEntryCreateDateComparator(
041                                    orderByAsc);
042                    }
043                    else if (orderByCol.equals("modified-date")) {
044                            orderByComparator = new ProductEntryModifiedDateComparator(
045                                    orderByAsc);
046                    }
047                    else if (orderByCol.equals("name")) {
048                            orderByComparator = new ProductEntryNameComparator(orderByAsc);
049                    }
050                    else if (orderByCol.equals("type")) {
051                            orderByComparator = new ProductEntryTypeComparator(orderByAsc);
052                    }
053    
054                    return orderByComparator;
055            }
056    
057    }