001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.core.right.profile; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020import org.apache.avalon.framework.service.Serviceable; 021 022import org.ametys.core.right.Profile; 023import org.ametys.core.right.RightManager; 024import org.ametys.core.right.RightProfilesDAO; 025import org.ametys.runtime.plugin.Init; 026import org.ametys.runtime.plugin.component.AbstractLogEnabled; 027 028/** 029 * Creates the READER profile at initialization. 030 */ 031public class CreateReaderProfileInit extends AbstractLogEnabled implements Init, Serviceable 032{ 033 private RightProfilesDAO _profilesDAO; 034 035 @Override 036 public void service(ServiceManager manager) throws ServiceException 037 { 038 _profilesDAO = (RightProfilesDAO) manager.lookup(RightProfilesDAO.ROLE); 039 } 040 041 @Override 042 public void init() throws Exception 043 { 044 // Create the reader profile 045 if (_profilesDAO.getProfile(RightManager.READER_PROFILE_ID) != null) 046 { 047 // already exist 048 getLogger().info("READER profile already exists, it will not be created"); 049 return; 050 } 051 052 getLogger().info("Creating READER profile"); 053 String profileName = RightManager.READER_PROFILE_ID; // We give the same name as its id 054 055 Profile profile = new Profile(RightManager.READER_PROFILE_ID, profileName); 056 _profilesDAO.addProfile(profile, true); 057 } 058}