/**
* Copyright (C) 2008-2010, Squale Project - http://www.squale.org
*
* This file is part of Squale.
*
* Squale is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* Squale 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 Lesser General Public License
* along with Squale. If not, see <http://www.gnu.org/licenses/>.
*/
package org.squale.squaleweb.applicationlayer.action.tag;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.squale.jraf.commons.exception.JrafEnterpriseException;
import org.squale.jraf.helper.AccessDelegateHelper;
import org.squale.jraf.spi.accessdelegate.IApplicationComponent;
import org.squale.squalecommon.daolayer.tag.TagDAOImpl;
import org.squale.squalecommon.datatransfertobject.component.ComponentDTO;
import org.squale.squalecommon.datatransfertobject.tag.TagDTO;
import org.squale.squaleweb.applicationlayer.action.accessRights.DefaultAction;
import org.squale.squaleweb.applicationlayer.formbean.component.ApplicationForm;
import org.squale.squaleweb.applicationlayer.formbean.component.ApplicationListForm;
import org.squale.squaleweb.applicationlayer.formbean.component.SplitAuditsListForm;
import org.squale.squaleweb.transformer.ApplicationListTransformer;
import org.squale.squaleweb.transformer.ApplicationTransformer;
import org.squale.squaleweb.transformer.FactorsResultListTransformer;
import org.squale.welcom.struts.bean.WActionForm;
import org.squale.welcom.struts.transformer.WTransformerException;
import org.squale.welcom.struts.transformer.WTransformerFactory;
/**
* Affichage de la liste des applications Cette action permet d'extraire la liste des applications disponibles pour
* l'utilisateur courant et de les restituer sous une forme synth�tique
*/
public class AllTaggedApplicationsAction
extends DefaultAction
{
/**
* Affichage de la liste des applications non publiques
*
* @param pMapping le mapping.
* @param pForm le formulaire � lire.
* @param pRequest la requ�te HTTP.
* @param pResponse la r�ponse de la servlet.
* @return l'action � r�aliser.
*/
public ActionForward listSameTagAplications( ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest,
HttpServletResponse pResponse )
{
ActionForward forward;
try
{
// R�cup�ration du tag en session voulu
String tagId = (String) pRequest.getParameter( "tag" );
Object[] paramIn = { Long.parseLong( tagId ) };
IApplicationComponent ac = AccessDelegateHelper.getInstance( "TagAdmin" );
// R�cup�ration des tags pour chacun des applications concern�es
TagDTO tag = ( (TagDTO) ac.execute( "getTag", paramIn ) );
pRequest.setAttribute( "tagName", tag.getName() );
// R�cup�ration de la liste des applications
paramIn[0] = new TagDTO[] { tag };
IApplicationComponent ac2 = AccessDelegateHelper.getInstance( "Component" );
List<ComponentDTO> applicationsDTO = ( (List) ac2.execute( "getTaggedApplications", paramIn ) );
List<ApplicationForm> applicationsForm = new ArrayList<ApplicationForm>();
List<ApplicationForm> applicationsFormTest = new ArrayList<ApplicationForm>();
for ( ComponentDTO applicationDTO : applicationsDTO )
{
applicationsForm.add( (ApplicationForm) WTransformerFactory.objToForm( ApplicationTransformer.class,
applicationDTO ) );
}
// forward = execute( pMapping, pForm, getSameTagUserApplicationList( pRequest, tag ) );
// applicationsFormTest = getSameTagUserApplicationList( pRequest, tag );
forward = execute( pMapping, pForm, applicationsForm );
}
catch ( Exception e )
{
ActionErrors errors = new ActionErrors();
// Traitement factoris� des erreurs
handleException( e, errors, pRequest );
saveMessages( pRequest, errors );
forward = pMapping.findForward( "failure" );
}
// On est pass� par un menu donc on r�initialise le traceur
// resetTracker( pRequest );
return ( forward );
}
/**
* @param pMapping le mapping
* @param pForm le formulaire
* @param pAppli les applications
* @return le forward
* @throws WTransformerException si erreur
* @throws JrafEnterpriseException si erreur
*/
private ActionForward execute( ActionMapping pMapping, ActionForm pForm, List pAppli )
throws WTransformerException, JrafEnterpriseException
{
ActionForward forward;
ApplicationListForm applicationListForm = new ApplicationListForm();
ArrayList applicationsList = new ArrayList();
applicationsList.addAll( pAppli );
applicationListForm.setList( applicationsList );
List applications =
(List) ( WTransformerFactory.formToObj( ApplicationListTransformer.class, applicationListForm )[0] );
if ( applications.isEmpty() )
{
// S'il n'y a pas d'applications, on redirige vers une page d�di�e
forward = pMapping.findForward( "empty" );
}
else
{
List results = new LinkedList();
// R�cup�ration des r�sultats � partir de l'Application Component
IApplicationComponent ac = AccessDelegateHelper.getInstance( "Results" );
Object[] paramIn = { applications, null };
// R�cup�ration des r�sultats pour chacun des applications concern�es
List applicationResults = ( (List) ac.execute( "getApplicationResults", paramIn ) );
// Transformation des r�sultats avant leur affichage par la couche
// welcom
WTransformerFactory.objToForm( FactorsResultListTransformer.class, (WActionForm) pForm, new Object[] {
applications, applicationResults } );
forward = pMapping.findForward( "list" );
}
return forward;
}
}