com.luna.sys.group.service.GroupService.java Source code

Java tutorial

Introduction

Here is the source code for com.luna.sys.group.service.GroupService.java

Source

/**
 * Copyright (c) 2005-2012 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.luna.sys.group.service;

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 com.luna.common.entity.search.SearchOperator;
import com.luna.common.entity.search.Searchable;
import com.luna.common.service.BaseService;
import com.luna.sys.group.entity.Group;
import com.luna.sys.group.repository.GroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 
 * <p>Date: 13-2-4 ?3:01
 * <p>Version: 1.0
 */
@Service
public class GroupService extends BaseService<Group, Long> {

    @Autowired
    private GroupRelationService groupRelationService;

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

    public Set<Map<String, Object>> findIdAndNames(Searchable searchable, String groupName) {

        searchable.addSearchFilter("name", SearchOperator.like, groupName);

        return Sets.newHashSet(
                Lists.transform(findAll(searchable).getContent(), 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;
    }
}