001/* 002 * Copyright 2020 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.core.migration.notification; 017 018import java.util.List; 019import java.util.Map; 020 021import org.apache.avalon.framework.activity.Initializable; 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025 026import org.ametys.core.ObservationConstants; 027import org.ametys.core.observation.Event; 028import org.ametys.core.observation.ObservationManager; 029import org.ametys.core.observation.Observer; 030import org.ametys.runtime.plugins.admin.notificator.AbstractConfigurableAdministratorNotificator; 031import org.ametys.runtime.plugins.admin.notificator.Notification; 032 033/** 034 * Notify when migration is not completed correctly 035 */ 036public class MigrationAdministratorNotificator extends AbstractConfigurableAdministratorNotificator implements Observer, Initializable, Serviceable 037{ 038 039 private ObservationManager _observationManager; 040 private boolean _migrationDone; 041 042 public List<Notification> getNotifications() 043 { 044 if (_migrationDone) 045 { 046 return List.of(); 047 } 048 else 049 { 050 return List.of(new Notification(_type, _title, _message, _iconGlyph, _action)); 051 } 052 } 053 054 public boolean supports(Event event) 055 { 056 return event.getId().equals(ObservationConstants.EVENT_MIGRATION_ENDED); 057 } 058 059 public int getPriority(Event event) 060 { 061 return 0; 062 } 063 064 public void observe(Event event, Map<String, Object> transientVars) throws Exception 065 { 066 _migrationDone = true; 067 } 068 069 public void initialize() throws Exception 070 { 071 _observationManager.registerObserver(this); 072 } 073 074 public void service(ServiceManager manager) throws ServiceException 075 { 076 _observationManager = (ObservationManager) manager.lookup(ObservationManager.ROLE); 077 } 078 079}