Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

Code Java

Bloc de code
languagejava

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.multipart.MultipartException;

import fr.univville.siham.dossieragent.DossierAgentDateWebService;
import fr.univville.siham.dossieragent.Individu;
import fr.univville.siham.dossieragent.Matricule;
import fr.univville.siham.dossieragent.ParamAgentDateWS;
import fr.univville.siham.dossieragent.ReferentielService;
import fr.univville.siham.dossieragent.WebserviceException_Exception;
import fr.univville.siham.listeagents.IListeAgentsWebService;
import fr.univville.siham.listeagents.ListeAgentsWS;
import fr.univville.siham.listeagents.ParamListeAgents;
import fr.univville.siham.listeagents.ResultatsListeAgents;
import fr.univville.siham.listeagents.WebServiceException_Exception;
import fr.univville.siham.parametrage.DossierParametrageWebService;
import fr.univville.siham.parametrage.ListeNomenclatures;
import fr.univville.siham.parametrage.ListeUO;
import fr.univville.siham.parametrage.NomenclatureService;
import fr.univville.siham.parametrage.ParamNomenclature;
import fr.univville.siham.parametrage.ParamStructure;
import fr.univville.siham.parametrage.Repertoire;
import fr.univville.siham.parametrage.Structures;


public class SihamService implements InitializingBean {
	
	private static final int NB_AGENTS_PER_REQUEST = 20;
	
    protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	private IListeAgentsWebService listeAgentsWebService;
	
	private DossierAgentDateWebService dossierAgentDateWebService;
	
	private DossierParametrageWebService parametrageWebService;
	
	private String url;
	
	private String username;
	
	private String password;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public void afterPropertiesSet() throws Exceptionprivate Map<String, List<String>> getWsHeaders() {
		
		Authenticator.setDefault(new Authenticator() {
			 @Override
			 protected PasswordAuthentication getPasswordAuthentication() {
			   return new PasswordAuthentication(
				 username,
				 password.toCharArray());
			 }
		});
		
		Map<String, List<String>> headers = new HashMap<String, List<String>>();
		headers.put("Username", Collections.singletonList(username));
		headers.put("Password", Collections.singletonList(password));
		
		URL listeAgentsWsUrl = new URL(url Map<String, List<String>> headers = new HashMap<String, List<String>>();
		headers.put("Username", Collections.singletonList(username));
		headers.put("Password", Collections.singletonList(password));
		return headers;
	}
	
	private IListeAgentsWebService getIListeAgentsWebService() {
		if(listeAgentsWebService==null) {
			try {
				initAuthenticator();
				URL listeAgentsWsUrl = new URL(url + "/ListeAgentsWebService/ListeAgentsWebService?wsdl");
				ListeAgentsWS listeAgentsWS = new ListeAgentsWS(listeAgentsWsUrl);
				listeAgentsWebService = listeAgentsWS.getListeAgentsWebServiceImplPort();
				Map<String, Object> req_ctx = ((BindingProvider)listeAgentsWebService).getRequestContext();
				req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headersgetWsHeaders());
				log.info("Siham listeAgentsWebService OK");
		
		URL dossierAgentWsUrl =} catch(Exception ex) {
				throw new URL(url + "/DossierAgentDateWebService/DossierAgentDateWebService?wsdl");
		ReferentielService referentielService = new ReferentielService(dossierAgentWsUrl);
		dossierAgentDateWebService = referentielService.getDossierAgentDateWebServiceImpPort();
		Map<String, Object> req_ctx_ref = ((BindingProvider)dossierAgentDateWebService).getRequestContext();
		req_ctx_ref.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
		log.info("Siham dossierAgentDateWebService OK");
		
		URL parametrageWsUrlRuntimeException("Exception during initialization of siham ws ListeAgentsWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return listeAgentsWebService;
	}
	
	private DossierAgentDateWebService getDossierAgentDateWebService() {
		if(dossierAgentDateWebService==null) {
			try {
				initAuthenticator();
				URL dossierAgentWsUrl = new URL(url + "/DossierParametrageWebServiceDossierAgentDateWebService/DossierParametrageWebServiceDossierAgentDateWebService?wsdl");
		NomenclatureService		ReferentielService nomenclatureServicereferentielService = new NomenclatureServiceReferentielService(parametrageWsUrldossierAgentWsUrl);
				parametrageWebServicedossierAgentDateWebService = nomenclatureServicereferentielService.getDossierParametrageWebServiceImpPortgetDossierAgentDateWebServiceImpPort();
				Map<String, Object> req_ctx_parref = ((BindingProvider)parametrageWebServicedossierAgentDateWebService).getRequestContext();
				req_ctx_parref.put(MessageContext.HTTP_REQUEST_HEADERS, headersgetWsHeaders());
				log.info("Siham parametrageWebServicedossierAgentDateWebService OK");
		
		Authenticator.setDefault(null);
	}
	
	protected synchronized List<String> getAgentsMatricules(String nomUsuel) {
		List<String> matricules = new ArrayList<String>();
		ParamListeAgents paramRecupListeAgents = new ParamListeAgents();
		paramRecupListeAgents.setNomUsuel(nomUsuel);
		try {
			 List<ResultatsListeAgents> agents= listeAgentsWebService.recupListeAgents(paramRecupListeAgents);
			 for(ResultatsListeAgents agent : agents	} catch(Exception ex) {
				throw new RuntimeException("Exception during initialization of siham ws DossierAgentDateWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return dossierAgentDateWebService;
	}
	
	private DossierParametrageWebService getDossierParametrageWebService() {
				 matricules.add(agent.getMatricule());if(parametrageWebService==null) {
			try }{
				 log.debug(agents.size() + " matricules d'agents récupérés depuis SihaminitAuthenticator();
				URL parametrageWsUrl = new URL(url + "/DossierParametrageWebService/DossierParametrageWebService?wsdl");
		} catch (WebServiceException_Exception e) {		NomenclatureService nomenclatureService = new NomenclatureService(parametrageWsUrl);
			throw	parametrageWebService new= MultipartException("Erreur lors de la récupération agents depuis web-service siham", enomenclatureService.getDossierParametrageWebServiceImpPort();
				Map<String, Object> req_ctx_par = ((BindingProvider)parametrageWebService).getRequestContext();
				req_ctx_par.put(MessageContext.HTTP_REQUEST_HEADERS, getWsHeaders());
		}
		return matriculeslog.info("Siham parametrageWebService OK");
	}
	
	public} Individu getSihamIndividucatch(StringException matriculeex) {
		Map<String, Individu> sihamIndividus = getSihamIndividus(Arrays.asList(new String[] {matricule}));
		return sihamIndividus.get(matricule);
	}
	
	public synchronized Map<String, Individu> getSihamIndividus(List<String> matricules		throw new RuntimeException("Exception during initialization of siham ws DossierAgentDateWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return parametrageWebService;	
	}

	
	private void initAuthenticator() {
		Authenticator.setDefault(new Authenticator() {
		Map<String, Individu> sihamIndividus = new HashMap<String, Individu>();
		ParamAgentDateWS paramAgentDateWS = new ParamAgentDateWS();
		int i = 0;
		int n = 0;
		List<String> matriculesErreurs = new ArrayList<String>(	 @Override
			 protected PasswordAuthentication getPasswordAuthentication() {
			   return new PasswordAuthentication(
				 username,
				 password.toCharArray());
		for(String matricule: matricules	 }
		});
	}
	
	private void resetAuthenticator() {		
			i++Authenticator.setDefault(null);
	}
		n++;
	protected synchronized List<String> getAgentsMatricules(String nomUsuel) {
			MatriculeList<String> matriculeObjmatricules = new MatriculeArrayList<String>();
			matriculeObj.setMatricule(matriculeParamListeAgents paramRecupListeAgents = new ParamListeAgents();
			paramAgentDateWSparamRecupListeAgents.getListeMatriculessetNomUsuel(nomUsuel).add(matriculeObj);
			if(i==NB_AGENTS_PER_REQUEST || n==matricules.size()) try {
				try {
					List<Individu> List<ResultatsListeAgents> agents = dossierAgentDateWebServicegetIListeAgentsWebService().recupDonneesAgentsrecupListeAgents(paramAgentDateWSparamRecupListeAgents);
					 for(IndividuResultatsListeAgents agent : agents) {
						sihamIndividus.put matricules.add(agent.getDonneesPersonnelles().getMatricule(), agent);
					 }
				} catch (WebserviceException log.debug(agents.size() + " matricules d'agents récupérés depuis Siham");
		} catch (WebServiceException_Exception e) {
					log.infothrow new MultipartException("Erreur lors de la récupération agents depuis web-service siham", e);
		}
			for(Matricule agentMatricule : paramAgentDateWS.getListeMatricules()return matricules;
	}
	
	public Individu getSihamIndividu(String matricule) {
						ParamAgentDateWS agentParamAgentDateWS = new ParamAgentDateWS(Map<String, Individu> sihamIndividus = getSihamIndividus(Arrays.asList(new String[] {matricule}));
						agentParamAgentDateWS.getListeMatricules().add(agentMatriculereturn sihamIndividus.get(matricule);
	}
					try
	public synchronized Map<String, Individu> getSihamIndividus(List<String> matricules) {
							List<Individu> agents = dossierAgentDateWebService.recupDonneesAgents(agentParamAgentDateWSMap<String, Individu> sihamIndividus = new HashMap<String, Individu>();
							for(Individu agent: agents) {
								sihamIndividus.put(agent.getDonneesPersonnelles().getMatricule(), agent);
							}
						} catch (WebserviceException_Exception ee) {
							log.warn("Erreur lors de la récupération de cet agent depuis web-service siham : " + agentMatricule.getMatricule(), ee);
							sihamIndividus.put(agentMatricule.getMatricule(), new SihamIndividuAgentInError()ParamAgentDateWS paramAgentDateWS = new ParamAgentDateWS();
		int i = 0;
		int n = 0;
		List<String> matriculesErreurs = new ArrayList<String>();
		for(String matricule: matricules) {
			i++;
			n++;
			Matricule matriculeObj = new Matricule();
			matriculeObj.setMatricule(matricule);
			paramAgentDateWS.getListeMatricules().add(matriculeObj);
			if(i==NB_AGENTS_PER_REQUEST || n==matricules.size()) {
				try {
					List<Individu> agents = getDossierAgentDateWebService().recupDonneesAgents(paramAgentDateWS);
							matriculesErreurs.add(agentMatriculefor(Individu agent: agents) {
						sihamIndividus.put(agent.getDonneesPersonnelles().getMatricule(), agent);
						}
					}
				}
				paramAgentDateWS = new ParamAgentDateWS();
				i = 0;
			}
		}
		if(matriculesErreurs.size() > 0) {
} catch (WebserviceException_Exception e) {
					log.errorinfo("MatriculesErreur en erreur lors de la récupération de ces agents depuis web-service siham : ", + matriculesErreurse);
		}
			log.info(sihamIndividus.size() + " agents récupérés depuis Siham dont " + matriculesErreurs.size() + " en erreur.");
		return sihamIndividus;
	}
	
	public Map<String, Individu> getSihamIndividuFromNomUsuel(String nomUsuel) {
		List<String> matricules = getAgentsMatricules(nomUsuel);
		Map<String, Individu> sihamIndividus = getSihamIndividus(matricules);
		return sihamIndividus;
	}
	
	public synchronized List<Structures> getSihamStructures() {
		List<Structures> structures;
		try {
			ParamStructure paramStructure = new ParamStructure();
			paramStructure.setCodeAdministration("");
			paramStructure.setDateObservation("");
			paramStructure.getListeUO().add(new ListeUO());
			structures = parametrageWebService.recupStructures(paramStructure);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeExceptionfor(Matricule agentMatricule : paramAgentDateWS.getListeMatricules()) {
						ParamAgentDateWS agentParamAgentDateWS = new ParamAgentDateWS();
						agentParamAgentDateWS.getListeMatricules().add(agentMatricule);
						try {
							List<Individu> agents = getDossierAgentDateWebService().recupDonneesAgents(agentParamAgentDateWS);
							for(Individu agent: agents) {
								sihamIndividus.put(agent.getDonneesPersonnelles().getMatricule(), agent);
							}
						} catch (WebserviceException_Exception ee) {
							log.warn("Erreur lors de la récupération de descet structuresagent depuis web-service siham : " + agentMatricule.getMatricule(), eee);
		}
					logsihamIndividus.infoput(structuresagentMatricule.sizegetMatricule(), + " structures récupérées depuis Siham"new SihamIndividuAgentInError());
			return structures;
	}
	
	
	public synchronized List<Repertoire> getSihamNomenclaturesRepertoires() {
		List<Repertoire> repertoires;
		try {
			ParamNomenclature paramNomenclature	matriculesErreurs.add(agentMatricule.getMatricule());
						}
					}
				}
				paramAgentDateWS = new ParamNomenclatureParamAgentDateWS();
			paramNomenclature.setCodeAdministration("")	i = 0;
			paramNomenclature.setDateObservation("");
			paramNomenclature.getListeNomenclatures().add(new ListeNomenclatures());}
		}
		if(matriculesErreurs.size() > 0) {
			repertoires = parametrageWebService.recupNomenclaturesRH(paramNomenclature);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeException("Erreur log.error("Matricules en erreur lors de la récupération desde répertoiresces de nomenclaturesagents depuis web-service siham : ", + ematriculesErreurs);
		}
		log.info(repertoiressihamIndividus.size() + " répertoires de nomenclatures récupérées depuis Sihamagents récupérés depuis Siham dont " + matriculesErreurs.size() + " en erreur.");
		return repertoiressihamIndividus;
	}
}

Classe SihamIndividuAgentInError : 

Bloc de code
languagejava
import fr.univrouen.multipass.domain.siham.dossieragent.Individu;

public class SihamIndividuAgentInError extends Individu {

}

Descripteur Spring

En spring, on pourra initialiser le service ainsi : 

	
	public Map<String, Individu> getSihamIndividuFromNomUsuel(String nomUsuel) {
		List<String> matricules = getAgentsMatricules(nomUsuel);
		Map<String, Individu> sihamIndividus = getSihamIndividus(matricules);
		return sihamIndividus;
	}
	
	public synchronized List<Structures> getSihamStructures() {
		List<Structures> structures;
		try {
			ParamStructure paramStructure = new ParamStructure();
			paramStructure.setCodeAdministration("");
			paramStructure.setDateObservation("");
			paramStructure.getListeUO().add(new ListeUO());
			structures = getDossierParametrageWebService().recupStructures(paramStructure);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeException("Erreur lors de la récupération des structures depuis web-service siham", e);
		}
		log.info(structures.size() + " structures récupérées depuis Siham");
		return structures;
	}
	
	
	public synchronized List<Repertoire> getSihamNomenclaturesRepertoires() {
		List<Repertoire> repertoires;
		try {
			ParamNomenclature paramNomenclature = new ParamNomenclature();
			paramNomenclature.setCodeAdministration("");
			paramNomenclature.setDateObservation("");
			paramNomenclature.getListeNomenclatures().add(new ListeNomenclatures());
			repertoires = getDossierParametrageWebService().recupNomenclaturesRH(paramNomenclature);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeException("Erreur lors de la récupération des répertoires de nomenclatures depuis web-service siham", e);
		}
		log.info(repertoires.size() + " répertoires de nomenclatures récupérées depuis Siham");
		return repertoires;
	}


}

Classe SihamIndividuAgentInError : 

Bloc de code
languagejava
import fr.univrouen.multipass.domain.siham.dossieragent.Individu;

public class SihamIndividuAgentInError extends Individu {

}

Descripteur Spring

En spring, on pourra initialiser le service ainsi : 

Bloc de code
languagexml
<bean id="sihamService" class="fr.univville.siham.SihamService" lazy-init="true">
 	<property name="url" value="https://siham.univ-ville.fr/"/>
   	<property name="username" value="siham"/>
   	<property name="password" value="hello"/>
</bean>

Usage 

Bloc de code
languagejava
List<Structures> sihamStructures = sihamService.getSihamStructures();
// ...


List<Repertoire> sihamRepertoiresNomenclatures = sihamService.getSihamNomenclaturesRepertoires();
// ...

Map<String, Individu> sihamIndividus = sihamService.getSihamIndividuFromNomUsuel("%");
for(String matricule : sihamIndividus.keySet()) {
	Individu sihamIndividu = sihamIndividus.get(matricule);
	if(sihamIndividu instanceof SihamIndividuAgentInError) {
		// l'individu siham est en erreur - ne rien faire -> ne pas le supprimer notamment ;-) 
	} else {
		// ...
	}
}
Bloc de code
languagexml
<bean id="sihamService" class="fr.univville.siham.SihamService" lazy-init="true">
 	<property name="url" value="https://siham.univ-ville.fr/"/>
   	<property name="username" value="siham"/>
   	<property name="password" value="hello"/>
</bean>