1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
public class ModifierTermeAction extends DispatchAction {
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
@SuppressWarnings("unchecked")
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("modify", "change");
map.put("add", "ajouter");
map.put("delete", "effacer");
return map;
}
@SuppressWarnings("unchecked")
public ActionForward change(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ModifierTermeForm modifierTermeForm = (ModifierTermeForm) form;
TermeDAO ter = new TermeDAO();
List termelist = ter.findByDescripteur(modifierTermeForm.getDescripteur());
if (termelist.size() > 0) {
for(Iterator iter = termelist.iterator(); iter.hasNext();)
{
Terme result = (Terme) iter.next();
if((modifierTermeForm.getDescripteur()).equalsIgnoreCase(result.getDescripteur())){
modifierTermeForm.setIdTerme(result.getIdTerme());
modifierTermeForm.setIdLangue(result.getIdLangue());
modifierTermeForm.setIdThesaurus(result.getIdThesaurus());
modifierTermeForm.setDescripteur(result.getDescripteur());
modifierTermeForm.setNoteApplication(result.getNoteApplication());
modifierTermeForm.setNoteHistorique(result.getNoteHistorique());
modifierTermeForm.setType(result.getType());
modifierTermeForm.setIdMt(result.getIdMt());
modifierTermeForm.setTest(result.getTest());
System.out.println(
"result : "+(result.getDescripteur()));
}
}
}
if (isCancelled(request)){
return(mapping.findForward("main"));
}
return mapping.findForward("change");
}
@SuppressWarnings("unchecked")
public ActionForward ajouter(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ModifierTermeForm modifierTermeForm = (ModifierTermeForm) form;
Terme terme = new Terme();
TermeDAO ter = new TermeDAO();
ThesaurusDAO dao = new ThesaurusDAO();
terme.setIdTerme(modifierTermeForm.getIdTerme());
terme.setIdLangue(modifierTermeForm.getIdLangue());
terme.setIdThesaurus(modifierTermeForm.getIdThesaurus());
terme.setDescripteur(modifierTermeForm.getDescripteur());
terme.setNoteApplication(modifierTermeForm.getNoteApplication());
terme.setNoteHistorique(modifierTermeForm.getNoteHistorique());
terme.setType(modifierTermeForm.getType());
terme.setIdMt(modifierTermeForm.getIdMt());
terme.setTest(modifierTermeForm.getTest());
Transaction tx = ter.getSession().beginTransaction();
ter.save(terme);
tx.commit();
List theso = dao.findAll();
List termeList = ter.findAll();
request.setAttribute("afficherTheso", theso);
request.setAttribute("afficherTerme", termeList);
ter.getSession().close();
if (isCancelled(request)){
return(mapping.findForward("main"));
}
return mapping.findForward("ajouter");
}
@SuppressWarnings("unchecked")
public ActionForward effacer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ModifierTermeForm modifierTermeForm = (ModifierTermeForm) form;
TermeDAO ter = new TermeDAO();
ThesaurusDAO dao = new ThesaurusDAO();
List terme = ter.findByDescripteur(modifierTermeForm.getDescripteur());
Transaction tx = ter.getSession().beginTransaction();
if (terme.size() > 0) {
for(Iterator iter = terme.iterator(); iter.hasNext();)
{
Terme result = (Terme) iter.next();
if((modifierTermeForm.getDescripteur()).equalsIgnoreCase(result.getDescripteur())){
System.out.println(result.getDescripteur());
ter.delete(result);
tx.commit();
}
}
}
List theso = dao.findAll();
List termeList = ter.findAll();
request.setAttribute("afficherTheso", theso);
request.setAttribute("afficherTerme", termeList);
ter.getSession().close();
if (isCancelled(request)){
return(mapping.findForward("main"));
}
return mapping.findForward("effacer");
}
} |
Partager