com.bemis.portal.report.service.impl.ReportPreferencesLocalServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.bemis.portal.report.service.impl.ReportPreferencesLocalServiceImpl.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.bemis.portal.report.service.impl;

import aQute.bnd.annotation.ProviderType;

import com.bemis.portal.report.definition.ReportParameter;
import com.bemis.portal.report.model.ReportPreferences;
import com.bemis.portal.report.runtime.ReportParametersValuesSerializer;
import com.bemis.portal.report.service.base.ReportPreferencesLocalServiceBaseImpl;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.spring.extender.service.ServiceReference;

import java.io.Serializable;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

/**
 * @author Michael C. Han
 * @see ReportPreferencesLocalServiceBaseImpl
 * @see com.bemis.portal.report.service.ReportPreferencesLocalServiceUtil
 */
@ProviderType
public class ReportPreferencesLocalServiceImpl extends ReportPreferencesLocalServiceBaseImpl {

    @Override
    public ReportPreferences addReportPreferences(long reportDefinitionId, Set<String> selectedFields,
            Set<String> sortFields, Map<ReportParameter, Serializable> reportParametersValues,
            ServiceContext serviceContext) throws PortalException {

        final User user = userLocalService.getUser(serviceContext.getGuestOrUserId());

        Date now = new Date();

        final long reportPreferencesId = counterLocalService.increment();

        ReportPreferences reportPreferences = reportPreferencesPersistence.create(reportPreferencesId);

        reportPreferences.setCompanyId(user.getCompanyId());
        reportPreferences.setUserId(user.getUserId());
        reportPreferences.setUserName(user.getFullName());
        reportPreferences.setCreateDate(serviceContext.getCreateDate(now));
        reportPreferences.setModifiedDate(serviceContext.getModifiedDate(now));

        reportPreferences.setReportDefinitionId(reportDefinitionId);
        reportPreferences.setSelectedFields(StringUtils.join(selectedFields, StringPool.COMMA));
        reportPreferences.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

        String reportParametersString = reportParametersValuesSerializer.serialize(reportParametersValues);

        reportPreferences.setParametersValues(reportParametersString);

        reportPreferences.setExpandoBridgeAttributes(serviceContext);

        reportPreferencesPersistence.update(reportPreferences);

        return reportPreferences;
    }

    @Override
    public ReportPreferences fetchReportPreferences(long reportDefinitionId, long userId) {

        return reportPreferencesPersistence.fetchByRDI_U(reportDefinitionId, userId);
    }

    @Override
    public List<ReportPreferences> getReportPreferences(long userId, int start, int end) {

        return reportPreferencesPersistence.findByUserId(userId, start, end);
    }

    @Override
    public List<ReportPreferences> getReportPreferencesByReportDefintionId(long reportDefinitionId, int start,
            int end) {

        return reportPreferencesPersistence.findByReportDefinitionId(reportDefinitionId, start, end);
    }

    @Override
    public ReportPreferences updateReportPreferences(long reportPreferencesId, Set<String> selectedFields,
            Set<String> sortFields, Map<ReportParameter, Serializable> reportParametersValues,
            ServiceContext serviceContext) throws PortalException {

        Date now = new Date();

        ReportPreferences reportPreferences = reportPreferencesPersistence.findByPrimaryKey(reportPreferencesId);

        reportPreferences.setModifiedDate(serviceContext.getModifiedDate(now));

        reportPreferences.setSelectedFields(StringUtils.join(selectedFields, StringPool.COMMA));
        reportPreferences.setSortFields(StringUtils.join(sortFields, StringPool.COMMA));

        String reportParametersString = reportParametersValuesSerializer.serialize(reportParametersValues);

        reportPreferences.setParametersValues(reportParametersString);

        reportPreferences.setExpandoBridgeAttributes(serviceContext);

        reportPreferencesPersistence.update(reportPreferences);

        return reportPreferences;
    }

    @ServiceReference(type = ReportParametersValuesSerializer.class)
    protected ReportParametersValuesSerializer reportParametersValuesSerializer;

}