package nc.noumea.mairie.organigramme.utils; /* * #%L * Logiciel de Gestion des Organigrammes de la Ville de Nouméa * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2015 - 2016 Mairie de Nouméa * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ import java.util.HashMap; import nc.noumea.mairie.organigramme.dto.EntiteDto; import nc.noumea.mairie.organigramme.dto.FichePosteDto; import nc.noumea.mairie.organigramme.dto.FichePosteTreeNodeDto; public class EntityUtils { /** * Retourne l entite par rapport a l ID en parametre * #28374 * @param idServiceAds Integer * @param entiteDto EntiteDto * @return EntiteDto */ public static EntiteDto getEntiteByIdServiceAds(Integer idServiceAds, EntiteDto entiteDto) { EntiteDto result = null; if(entiteDto.getIdEntite().equals(idServiceAds)) { result = entiteDto; } for(EntiteDto enfant : entiteDto.getEnfants()) { if(enfant.getIdEntite().equals(idServiceAds)) { result = enfant; break; } if(null == result) { result = getEntiteByIdServiceAds(idServiceAds, enfant); } } return result; } /** * La fiche de poste du chef d'entité de chaque entite doit avoir la meme couleur que l'entité. * #28374 * @param node * @return EntiteDto Retourne l entite si la fiche de poste est chef de ce service */ public static EntiteDto getBackgroundColorOfFichePoste(FichePosteTreeNodeDto node, EntiteDto entiteDto, HashMap<Integer, FichePosteTreeNodeDto> mapFichesPosteSuperieureByService) { // on recupere la fiche de poste du chef du service en question FichePosteDto fichePosteChef = mapFichesPosteSuperieureByService.get(node.getIdServiceADS()); // si la fiche de poste en parametre est la fiche de poste chef // on retourne la couleur if(null != fichePosteChef && fichePosteChef.getIdFichePoste().equals(node.getIdFichePoste()) && null != node.getIdServiceADS()) { return getEntiteByIdServiceAds(node.getIdServiceADS(), entiteDto); } // sinon la couleur par defaut return null; } /** * On recupere ici les fiches de poste "CHEF" de chaque entite (service). * Etant donne qu'on descend dans l arbre des fiches de poste, * la 1ere fiche de poste rencontree d un service est la superieure des autres. * #28374 * @param nodeRoot FichePosteTreeNodeDto arbre des fiches de poste * @return HashMap Id Entite associe a la fiche de poste superieure (chef) */ public static HashMap<Integer, FichePosteTreeNodeDto> getFichesPosteChefDeService(FichePosteTreeNodeDto nodeRoot) { HashMap<Integer, FichePosteTreeNodeDto> result = new HashMap<Integer, FichePosteTreeNodeDto>(); if(!result.containsKey(nodeRoot.getIdServiceADS())) { result.put(nodeRoot.getIdServiceADS(), nodeRoot); } getFichesPosteChefDeServiceRecursive(nodeRoot, result); return result; } private static void getFichesPosteChefDeServiceRecursive(FichePosteTreeNodeDto nodeRoot, HashMap<Integer, FichePosteTreeNodeDto> result) { for(FichePosteTreeNodeDto enfant : nodeRoot.getFichePostesEnfant()) { if(!result.containsKey(enfant.getIdServiceADS())) { result.put(enfant.getIdServiceADS(), enfant); } getFichesPosteChefDeServiceRecursive(enfant, result); } } }