001/* 002 * Copyright 2026 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.workspaces; 017 018import java.util.LinkedHashMap; 019import java.util.List; 020import java.util.Map; 021import java.util.stream.Collectors; 022 023import org.apache.avalon.framework.component.Component; 024import org.apache.avalon.framework.logger.AbstractLogEnabled; 025import org.apache.avalon.framework.service.ServiceException; 026import org.apache.avalon.framework.service.ServiceManager; 027import org.apache.avalon.framework.service.Serviceable; 028 029import org.ametys.plugins.workspaces.project.modules.WorkspaceModule; 030import org.ametys.plugins.workspaces.project.modules.WorkspaceModuleExtensionPoint; 031import org.ametys.runtime.i18n.I18nizableText; 032import org.ametys.runtime.model.Enumerator; 033 034/** 035 * Enumerator of the workspace modules 036 */ 037public class WorkspacesModuleEnumerator extends AbstractLogEnabled implements Enumerator<String>, Serviceable, Component 038{ 039 /** Module managers EP */ 040 protected WorkspaceModuleExtensionPoint _moduleManagerEP; 041 042 @Override 043 public void service(ServiceManager serviceManager) throws ServiceException 044 { 045 _moduleManagerEP = (WorkspaceModuleExtensionPoint) serviceManager.lookup(WorkspaceModuleExtensionPoint.ROLE); 046 } 047 048 public I18nizableText getEntry(String code) throws Exception 049 { 050 WorkspaceModule module = _moduleManagerEP.getModule(code); 051 return module != null ? module.getModuleTitle() : null; 052 } 053 054 public Map<String, I18nizableText> getEntries() throws Exception 055 { 056 List<WorkspaceModule> modules = _moduleManagerEP.getModules(); 057 return modules.stream().collect(Collectors.toMap( 058 WorkspaceModule::getId, 059 WorkspaceModule::getModuleTitle, 060 (a, b) -> b, 061 LinkedHashMap::new 062 )); 063 } 064 065}