/* * Copyright (C) 2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * * StatoolInfos is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * StatoolInfos is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ package fr.devinsy.statoolinfos.htmlize; import java.util.ArrayList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; import fr.devinsy.xidyn.utils.XidynUtils; /** * The Class ServiceMetricMenuView. */ public class ServiceMetricMenuView { private static Logger logger = LoggerFactory.getLogger(ServiceMetricMenuView.class); public enum PeriodMenu { FULL, LAST, Y2020, Y2021; /** * Gets the name. * * @return the name */ public String getName() { String result; if (this.name().startsWith("Y")) { result = this.name().substring(1); } else { result = this.name().toLowerCase(); } // return result; } /** * Gets the years. * * @return the years */ public static PeriodMenu[] getYears() { PeriodMenu[] result; ArrayList list = new ArrayList(); for (PeriodMenu item : values()) { if (item.name().startsWith("Y")) { list.add(item); } } result = list.toArray(new PeriodMenu[0]); // return result; } } public enum TypeMenu { SUMMARY, WEB, GENERIC, SPECIFIC; /** * Gets the name. * * @return the name */ public String getName() { String result; result = this.name().toLowerCase(); // return result; } } public enum ViewMenu { YEARS, MONTHS, WEEKS, DAYS; /** * Gets the name. * * @return the name */ public String getName() { String result; result = this.name().toLowerCase(); // return result; } } /** * Htmlize. * * @param service * the service * @return the string * @throws StatoolInfosException * the statool infos exception */ public static String htmlize(final Service service, final TypeMenu type, final ViewMenu view, final PeriodMenu period) throws StatoolInfosException { String result; try { TagDataManager data = new TagDataManager(); // String filename = String.format("%s-metrics-summary-%s-%s.xhtml", service.getLocalFileBaseName(), view.getName(), period.getName()); data.setAttribute("summaryTypeButton", "href", filename); filename = String.format("%s-metrics-generic-%s-%s.xhtml", service.getLocalFileBaseName(), view.getName(), period.getName()); data.setAttribute("genericTypeButton", "href", filename); filename = String.format("%s-metrics-specific-%s-%s.xhtml", service.getLocalFileBaseName(), view.getName(), period.getName()); data.setAttribute("specificTypeButton", "href", filename); filename = String.format("%s-metrics-web-%s-%s.xhtml", service.getLocalFileBaseName(), view.getName(), period.getName()); data.setAttribute("webTypeButton", "href", filename); // filename = String.format("%s-metrics-%s-years-%s.xhtml", service.getLocalFileBaseName(), type.getName(), PeriodMenu.FULL.getName()); data.setAttribute("yearsViewButton", "href", filename); filename = String.format("%s-metrics-%s-months-%s.xhtml", service.getLocalFileBaseName(), type.getName(), period.getName()); data.setAttribute("monthsViewButton", "href", filename); filename = String.format("%s-metrics-%s-weeks-%s.xhtml", service.getLocalFileBaseName(), type.getName(), period.getName()); data.setAttribute("weeksViewButton", "href", filename); data.setAttribute("daysViewButton", "href", "#"); // filename = String.format("%s-metrics-%s-%s-full.xhtml", service.getLocalFileBaseName(), type.getName(), view.getName()); data.setAttribute("fullPeriodButton", "href", filename); if (view != ViewMenu.YEARS) { filename = String.format("%s-metrics-%s-%s-last.xhtml", service.getLocalFileBaseName(), type.getName(), view.getName()); data.setAttribute("lastPeriodButton", "href", filename); filename = String.format("%s-metrics-%s-%s-2020.xhtml", service.getLocalFileBaseName(), type.getName(), view.getName()); data.setAttribute("2020PeriodButton", "href", filename); filename = String.format("%s-metrics-%s-%s-2021.xhtml", service.getLocalFileBaseName(), type.getName(), view.getName()); data.setAttribute("2021PeriodButton", "href", filename); } // if ((type == null) || (type == TypeMenu.SUMMARY)) { data.appendAttribute("summaryTypeButton", "class", "button selected"); } else if (type == TypeMenu.GENERIC) { data.appendAttribute("genericTypeButton", "class", "button selected"); } else if (type == TypeMenu.WEB) { data.appendAttribute("webTypeButton", "class", "button selected"); } else if (type == TypeMenu.SPECIFIC) { data.appendAttribute("specificTypeButton", "class", "button selected"); } // if ((view == null) || (view == ViewMenu.YEARS)) { data.appendAttribute("yearsViewButton", "class", "button selected"); } else if (view == ViewMenu.MONTHS) { data.appendAttribute("monthsViewButton", "class", "button selected"); } else if (view == ViewMenu.WEEKS) { data.appendAttribute("weeksViewButton", "class", "button selected"); } else if (view == ViewMenu.DAYS) { data.appendAttribute("daysViewButton", "class", "button selected"); } // if ((period == null) || (period == PeriodMenu.FULL)) { data.appendAttribute("fullPeriodButton", "class", "button selected"); } else if (period == PeriodMenu.LAST) { data.appendAttribute("lastPeriodButton", "class", "button selected"); } else if (period == PeriodMenu.Y2020) { data.appendAttribute("2020PeriodButton", "class", "button selected"); } else if (period == PeriodMenu.Y2021) { data.appendAttribute("2021PeriodButton", "class", "button selected"); } // String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/metricMenuView.xhtml", data).toString(); result = XidynUtils.extractBodyContent(content); } catch (XidynException exception) { throw new StatoolInfosException("Error building metric menu view: " + exception.getMessage(), exception); } // return result; } }