org.lazulite.boot.autoconfigure.osaam.shiro.sys.group.service.GroupService.java Source code

Java tutorial

Introduction

Here is the source code for org.lazulite.boot.autoconfigure.osaam.shiro.sys.group.service.GroupService.java

Source

/*
 * Copyright 2016. junfu
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.lazulite.boot.autoconfigure.osaam.shiro.sys.group.service;

import org.lazulite.boot.autoconfigure.core.service.BaseService;
import org.lazulite.boot.autoconfigure.osaam.shiro.sys.group.repository.GroupRepository;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.lazulite.boot.autoconfigure.osaam.shiro.sys.group.entity.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;

@Service
public class GroupService extends BaseService<Group, Long> {

    @Autowired
    private GroupRelationService groupRelationService;

    private GroupRepository getGroupRepository() {
        return (GroupRepository) baseRepository;
    }

    public Set<Map<String, Object>> findIdAndNames(Pageable pageable, String groupName) {

        return Sets.newHashSet(Lists.transform(findAll(), new Function<Group, Map<String, Object>>() {
            @Override
            public Map<String, Object> apply(Group input) {
                Map<String, Object> data = Maps.newHashMap();
                data.put("label", input.getName());
                data.put("value", input.getId());
                return data;
            }
        }));
    }

    /**
     * ???
     *
     * @param userId
     * @param organizationIds
     * @return
     */
    public Set<Long> findShowGroupIds(Long userId, Set<Long> organizationIds) {
        Set<Long> groupIds = Sets.newHashSet();
        groupIds.addAll(getGroupRepository().findDefaultGroupIds());
        groupIds.addAll(groupRelationService.findGroupIds(userId, organizationIds));

        //TODO ? ???
        for (Group group : findAll()) {
            if (Boolean.FALSE.equals(group.getShow())) {
                groupIds.remove(group.getId());
            }
        }

        return groupIds;
    }
}