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