1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie;
37 import java.util.HashSet;
38 import java.util.Iterator;
41 import com.liferay.portal.kernel.language.LanguageUtil;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.model.Role;
44 import com.liferay.portal.model.User;
46 public class ENTDisplayUtil {
48 public static String formatSCONETName(User user, String name) {
49 return formatSCONETName(name, true);
52 public static String formatSCONETName(User user, String name, boolean showEtabLabel) {
53 return formatSCONETName(name, showEtabLabel);
56 public static String formatSCONETName(long companyId, String name) {
57 return formatSCONETName(name, true);
60 public static String formatSCONETName(long companyId, String name, boolean showEtabLabel) {
61 return formatSCONETName(name, showEtabLabel);
64 public static String formatSCONETName(String name, boolean showEtabLabel) {
65 // on ne traite que les entrees commencant par CLG-
66 if (!name.startsWith("CLG-") &&
67 !name.startsWith("LGT-") &&
68 !name.startsWith("LG-") &&
69 !name.startsWith("Lyc") &&
70 !name.startsWith("CLG PR-") &&
71 !name.startsWith("LGT PR-") &&
72 !name.startsWith("LP PR-") &&
73 !name.startsWith("LP-") &&
74 !name.startsWith("LPO-") &&
75 !name.startsWith("I.A.-") &&
76 !name.startsWith("EREA-") &&
77 !name.startsWith("Erea-") &&
78 !name.startsWith("SEGPA-") &&
79 !name.startsWith("GRETA-") &&
80 !name.startsWith("SEP-") &&
81 !name.startsWith("LP LYC METIER-") &&
82 !name.startsWith("LPO LYC METIER-") &&
83 !name.startsWith("Lpo") &&
84 !name.startsWith("Lp") &&
85 !name.startsWith("Lgt") &&
86 !name.startsWith("Site") &&
87 !name.startsWith("RECTORAT-")) {
91 if (name.contains("LFR_ORGANIZATION")) {
92 name = name.replace("LFR_ORGANIZATION", "");
96 String[] first = StringUtil.split(name, " - ");
97 if (first.length > 1) {
100 // on a une classe et on veut le nom du college
101 res = getEtabLabel(first[0]);
104 for (int i=1; i<first.length; i++) {
105 res += " - " + first[i];
108 if (res.startsWith(" - ")){
109 res = res.substring(3);
115 if (first.length == 0) {
116 // cas peu probable !!!!
120 String res = first[0];
121 return getEtabLabel(res);
125 private static String getEtabLabel(String etabLabel) {
126 if (etabLabel.startsWith("CLG-")){
127 etabLabel = etabLabel.replace("CLG-", "clg ");
129 if (etabLabel.startsWith("SEP-")){
130 etabLabel = etabLabel.replace("SEP-", "sep ");
132 if (etabLabel.startsWith("LGT-")){
133 etabLabel = etabLabel.replace("LGT-", "lgt ");
135 if (etabLabel.startsWith("LG-")){
136 etabLabel = etabLabel.replace("LG-", "lg ");
138 if (etabLabel.startsWith("CLG PR-")){
139 etabLabel = etabLabel.replace("CLG PR-", "clg pr ");
141 if (etabLabel.startsWith("LGT PR-")){
142 etabLabel = etabLabel.replace("LGT PR-", "lgt pr ");
144 if (etabLabel.startsWith("LP PR-")){
145 etabLabel = etabLabel.replace("LP PR-", "lp pr ");
147 if (etabLabel.startsWith("LP-")){
148 etabLabel = etabLabel.replace("LP-", "lp ");
150 if (etabLabel.startsWith("LPO-")){
151 etabLabel = etabLabel.replace("LPO-", "lpo ");
153 if (etabLabel.startsWith("I.A.-")){
154 etabLabel = etabLabel.replace("I.A.-", "I.A. ");
156 if (etabLabel.startsWith("SEGPA-")){
157 etabLabel = etabLabel.replace("SEGPA-", "SEGPA ");
159 if (etabLabel.startsWith("GRETA-")){
160 etabLabel = etabLabel.replace("GRETA-", "GRETA ");
162 if (etabLabel.startsWith("LP LYC METIER-")){
163 etabLabel = etabLabel.replace("LP LYC METIER-", "lp lyc metier ");
165 if (etabLabel.startsWith("LPO LYC METIER-")){
166 etabLabel = etabLabel.replace("LPO LYC METIER-", "lpo lyc metier ");
168 if (etabLabel.startsWith("RECTORAT-")){
169 etabLabel = etabLabel.replace("RECTORAT-", "Rectorat ");
171 etabLabel = etabLabel.replace("-ac-GRENOBLE", "");
172 etabLabel = etabLabel.replace("-ac-ROUEN", "");
173 etabLabel = capitalize(etabLabel);
178 * Capitalize a string
179 * Manages string that contains a double space
183 public static String capitalize(String s){
184 StringBuilder bob = new StringBuilder();
185 for (String string : s.split(" ")) {
186 if (!string.equals("")) {
187 bob.append(string.substring(0, 1).toUpperCase());
188 bob.append(string.substring(1).toLowerCase());
192 s = bob.toString().trim();
198 * Permet l'affichage des roles de la personne dans les differnetes interface de l'ENT
201 public static String displayUserRoles(User currentUser, User user) {
203 final Role[] lesRoles = ENTRoleUtilFactory.getInstance(currentUser.getCompanyId()).getENTRoles(user);
205 Set<String> roleLabels = new HashSet<String>();
207 for (int i=0; i<lesRoles.length; i++) {
208 roleLabels.add(LanguageUtil.get(currentUser.getLocale(), lesRoles[i].getName()));
211 Iterator<String> it = roleLabels.iterator();
213 for (int i=0; it.hasNext(); i++) {
214 roleStr += it.next();