Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2015 the original author or authors
   *
   * 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.
  */
 
 package com.clusterra.iam.core.application.group;
 
 import  org.springframework.beans.factory.annotation.Autowired;
 import  org.springframework.context.ApplicationEventPublisher;
 import  org.springframework.stereotype.Service;
 import  org.springframework.transaction.annotation.Transactional;
 
 import java.util.Set;

Created with IntelliJ IDEA.

Author(s):
Denis Kuchugurov Date: 25.11.13
 
 @Service
 public class GroupServiceImpl implements GroupService {
 
     @Autowired
     private GroupRepository groupRepository;
 
     @Autowired
 
     @Autowired
     private ApplicationEventPublisher applicationEventPublisher;
 
     @Transactional
     public GroupDescriptor createGroup(TenantId tenantIdString groupNamethrows GroupAlreadyExistsExceptionTenantNotFoundException {
         Tenant tenant = .findOne(tenantId.getId());
         if (tenant == null) {
             throw new TenantNotFoundException(tenantId);
         }
 
         if (isGroupNameTaken(tenantIdgroupName)) {
             throw new GroupAlreadyExistsException(tenantIdgroupName);
         }
 
         return create(tenantIdgroupName);
     }
 
     private GroupDescriptor create(TenantId tenantIdString groupName) {
         Tenant tenant = .findOne(tenantId.getId());
         Group group = .save(new Group(tenantgroupName));
         GroupDescriptor groupDescriptor = new GroupDescriptor(group.getId(), group.getName());
 
         .publishEvent(new GroupCreatedEvent(thisgroupDescriptortenantId));
         return groupDescriptor;
     }
 
     @Transactional
     public GroupDescriptor findOrCreateGroup(TenantId tenantIdString groupName) {
         if (isGroupNameTaken(tenantIdgroupName)) {
             Group group = .findByTenantAndName(tenantId.getId(), groupName);
             return new GroupDescriptor(group.getId(), group.getName());
         }
         return create(tenantIdgroupName);
     }
 
     @Transactional
     public GroupDescriptor findGroupByName(TenantId tenantIdString groupNamethrows GroupNotFoundException {
         Group group = .findByTenantAndName(tenantId.getId(), groupName);
         if (group == null) {
             throw new GroupNotFoundException(tenantIdgroupName);
         }
         return new GroupDescriptor(group.getId(), group.getName());
     }
 
     @Transactional
     public boolean isGroupNameTaken(TenantId tenantIdString groupName) {
         return .findByTenantAndName(tenantId.getId(), groupName) != null;
     }
 
     @Transactional
     public void deleteByTenantId(TenantId tenantId) {
        Set<Groupgroups = .findByTenantId(tenantId.getId());
        for (Group group : groups) {
            .publishEvent(new GroupDeletingEvent(thisnew GroupDescriptor(group.getId(), group.getName())));
            .delete(group);
        }
    }
New to GrepCode? Check out our FAQ X