package pt.estgp.estgweb.web.controllers.manageidentifiers;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import pt.estgp.estgweb.web.controllers.AddRolesController;
import pt.estgp.estgweb.web.form.AddRolesForm;
import pt.estgp.estgweb.web.form.managedidentifier.ManagedIdentifierForm;
import pt.estgp.estgweb.web.utils.RequestUtils;
import pt.estgp.estgweb.domain.views.ManagedIdentifierCollectionView;
import pt.estgp.estgweb.domain.views.ManagedIdentifierView;
import pt.estgp.estgweb.Globals;
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author Jorge Machado
* @date 26/Fev/2008
* @time 18:01:54
* @see pt.estgp.estgweb.web
*/
public class ManagedIdentifierController
extends AddRolesController
{
private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger =
1.5.0/docs/api/java/util/logging/Logger.html">Logger.
getLogger(ManagedIdentifierController.
class);
public ActionForward loadCollections
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{};
List
<ManagedIdentifierCollectionView
> collections =
(List
<ManagedIdentifierCollectionView
>) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferLoadCollections", args, names
);
managedIdentifierForm.
setCollections(collections
);
return mapping.
findForward("load.collections");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
private ActionForward loadCollection
(ManagedIdentifierForm managedIdentifierForm, ActionMapping mapping, HttpServletRequest request, HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferLoadCollection", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
return null;
}
public ActionForward addUser
(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"userId",
"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getUserView().
getId(),managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferAssignCollectionUser", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
return mapping.
findForward("edit.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward removeUser
(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"userId",
"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getAuxId(),managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferDeleteCollectionUser", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
return mapping.
findForward("edit.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
/**
* NEW OBJECTS
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Throwable
* @throws ServletException
*/
public ActionForward newIdentifier
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
ActionForward forward = loadCollection
(managedIdentifierForm,mapping,request,response
);
if(forward
!=
null)
return forward
;
return mapping.
findForward("new.identifier");
}
public ActionForward newCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
return mapping.
findForward("new.collection");
}
/**
* START EDIT
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Throwable
* @throws ServletException
*/
public ActionForward startEditIdentifier
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getIdentifierView().
getId()};
ManagedIdentifierView identifierView =
(ManagedIdentifierView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferStartEditIdentifier", args, names
);
managedIdentifierForm.
setIdentifierView(identifierView
);
return mapping.
findForward("edit.identifier");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward startEditCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferStartEditCollection", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
return mapping.
findForward("edit.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward startSearchIdentifier
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferLoadCollection", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
return mapping.
findForward("search.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward searchIdentifier
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getIdentifierView().
getSequenceNumber(), managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierView identifierView =
(ManagedIdentifierView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferFindIdentifier", args, names
);
if(identifierView
!=
null)
{
managedIdentifierForm.
setIdentifierView(identifierView
);
return mapping.
findForward("found.identifier");
}
else
{
addError
(request,
"managed.identifier.not.found");
args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView().
getId()};
ManagedIdentifierCollectionView collectionView =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferLoadCollection", args, names
);
managedIdentifierForm.
setCollectionView(collectionView
);
return mapping.
findForward("search.collection");
}
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward deleteCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView().
getId()};
List
<ManagedIdentifierCollectionView
> collections =
(List
<ManagedIdentifierCollectionView
>) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferDeleteCollection", args, names
);
managedIdentifierForm.
setCollections(collections
);
return mapping.
findForward("load.collections");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
/**
* Submissions
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Throwable
* @throws ServletException
*/
public ActionForward submitCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView()};
1.5.0/docs/api/java/lang/String.html">String service
;
if(managedIdentifierForm.
getIdentifierView().
getId() > 0)
service =
"managedIdentiferEditCollection";
else
service =
"managedIdentiferCreateCollection";
List
<ManagedIdentifierCollectionView
> collections =
(List
<ManagedIdentifierCollectionView
>) sm.
execute(RequestUtils.
getRequester(request, response
), service, args, names
);
managedIdentifierForm.
setCollections(collections
);
return mapping.
findForward("load.collections");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward submitIdentifier
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"object",
"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getIdentifierView(),managedIdentifierForm.
getCollectionView().
getId()};
1.5.0/docs/api/java/lang/String.html">String service
;
boolean newIdentifier =
false;
if(managedIdentifierForm.
getIdentifierView().
getId() > 0)
service =
"managedIdentiferEditIdentifier";
else
{
newIdentifier =
true;
service =
"managedIdentiferCreateIdentifier";
}
ManagedIdentifierView identifierView =
(ManagedIdentifierView
) sm.
execute(RequestUtils.
getRequester(request, response
), service, args, names
);
managedIdentifierForm.
setIdentifierView(identifierView
);
if(newIdentifier
)
addMessage
(request,
"managedidentifier.new.success",
"" + identifierView.
getSequenceNumber());
else
addMessage
(request,
"managedidentifier.edit.success",
"" + identifierView.
getSequenceNumber());
loadCollection
(managedIdentifierForm,mapping,request,response
);
return mapping.
findForward("load.identifier");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
/**
* Assigns
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Throwable
* @throws ServletException
*/
public ActionForward assignUserCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
if(managedIdentifierForm.
getCollectionView().
getId() <= 0
)
{
}
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable",
"user"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getCollectionView(),managedIdentifierForm.
getUserView().
getId()};
ManagedIdentifierCollectionView collection =
(ManagedIdentifierCollectionView
) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferAssignCollectionUser", args, names
);
managedIdentifierForm.
setCollectionView(collection
);
return mapping.
findForward("edit.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
public ActionForward removeUserCollection
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
{
try
{
ManagedIdentifierForm managedIdentifierForm =
(ManagedIdentifierForm
) form
;
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{managedIdentifierForm.
getIdentifierView()};
List
<ManagedIdentifierCollectionView
> collections =
(List
<ManagedIdentifierCollectionView
>) sm.
execute(RequestUtils.
getRequester(request, response
),
"managedIdentiferEditIdentifier", args, names
);
managedIdentifierForm.
setCollections(collections
);
return mapping.
findForward("edit.collection");
}
catch (FilterChainFailedException e
)
{
return mapping.
findForward("error401");
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e, e
);
throw e
;
}
}
}