KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > categories > CategoriesObject


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.categories;
7
8 import java.sql.SQLException JavaDoc;
9 import java.util.Locale JavaDoc;
10
11 import com.raptus.owxv3.*;
12 import com.raptus.owxv3.api.*;
13
14
15 /**
16  *
17  * <table width="100%" border="0">
18  * <tr>
19  * <td width="24%"><b>Filename</b></td><td width="76%">CategoriesObject.java</td>
20  * </tr>
21  * <tr>
22  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Date</b></td><td width="76%">10th of December 2001</td>
26  * </tr>
27  * </table>
28  * <hr>
29  * <table width="100%" border="0">
30  * <tr>
31  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
32  * </tr>
33  * </table>
34  * <hr>
35  * <table width="100%" border="0">
36  * <tr>
37  * <td>
38  * This class is responsable of all business logic: save, delete and update of categories.
39  * </td>
40  * </tr>
41  * </table>
42  * <hr>
43  */

44 public class CategoriesObject extends Object JavaDoc
45 //extends BusinessObject no use for this time to extend BusinessObject
46
{
47     /**
48      *A GlobalResources object that will br used do the database modifications
49      */

50     protected GlobalResources gres = null;
51
52
53     /**
54      *
55      */

56
57     public CategoriesObject()
58     {
59         gres=new GlobalResources();
60     }
61
62     /**
63      *Method for saving a new or an already existing Category
64      * @param editbean the EACategoryEditBean created by struts that holds the neccesary data
65      * to save this category
66      * @return CategoryConstants.RESPONSE_INCOMPATIBLE_OWNER_ERROR if the owner of the parent is different
67      * or CategoryConstants.RESPONSE_NESTING_LEVEL_ERROR of the maximum allowed nesting level is reached
68      * or CategoryConstants.RESPONSE_SQLERROR in case of an sql error
69      * or CategoryConstants.RESPONSE_OK if the category was saved succesfully
70      */

71
72     public int saveCategory(EACategoryEditBean editbean) throws SQLException JavaDoc
73     {
74
75
76         GResCategory grescat=new GResCategory();
77
78         if(editbean.getParentCategory()!=0)
79         {
80             GResCategory parent=gres.loadCategory(editbean.getParentCategory());
81
82             //checing if the parent owner==owner
83
if(! parent.getOwner().equals(editbean.getOwner())) return CategoryConstants.RESPONSE_INCOMPATIBLE_OWNER_ERROR;
84
85             //checking if this nesting level is allowed
86
int maxnestlevel=0;
87             try
88             {
89                 VModuleManager vmm=VModuleManager.getInstance();
90                 VModule ownervm=vmm.getVModule(editbean.getOwner());
91                 //maxnestlevel=ownervm.getIntegerProperty(CategoryConstants.PROPERTY_NESTING_LEVEL);
92
XMLConfigManager xcm=XMLConfigManager.getInstance();
93                 maxnestlevel=xcm.getIntegerByTree("virtualhost/vmodules/vmodule?name="+ownervm.getIdentification()+"/component-properties/component-property?for=fc_categories/property?name=nesting_level","value");
94                
95             }catch(Exception JavaDoc e)
96             {
97                 LoggingManager.log("Unable to retrieve category nesting level for vmodule "+editbean.getOwner(),this);
98             }
99
100
101             if(maxnestlevel>0 && parent.getLevel()>=(maxnestlevel-1)) return CategoryConstants.RESPONSE_NESTING_LEVEL_ERROR;
102
103             grescat.setLevel(parent.getLevel()+1);
104         }
105
106         grescat.setOwner(editbean.getOwner());
107         grescat.setParent(editbean.getParentCategory());
108
109         grescat.setRowID(editbean.getRowId());
110         grescat.setCategoryID(editbean.getCatId());
111         grescat.setStatic(0);
112         //saving category
113
int result=gres.saveCategory(grescat);
114         if( result==0) return CategoryConstants.RESPONSE_SQLERROR;
115         if( result==-1) return CategoryConstants.RESPONSE_DUPLICATE_ID_ERROR;
116
117
118         //saving category name
119
Locale JavaDoc[] l=editbean.getLocales();
120         String JavaDoc[] catname=editbean.getName();
121         if(l!=null && catname!=null)
122         {
123             for(int i=0;i<l.length;i++)
124             {
125                 if(catname[i]==null) catname[i]="";
126
127                 gres.saveMessage(gres.getCategoryTableName(), grescat.getRowID(),CategoryConstants.RESCATFIELD_NAME, l[i], catname[i]);
128
129             }
130         }
131
132         return CategoryConstants.RESPONSE_OK;
133     }
134
135     /**
136      *Method for deleting a Category
137      * @param id the id of the category
138      * @return CategoryConstants.RESPONSE_NOTEMTPY_ERROR in case that category is not empty
139      * or CategoryConstants.RESPONSE_NODELETESTATIC_ERROR in case of the category is static
140      * or CategoryConstants.RESPONSE_SQLERROR in case of an SQL error
141      * or CategoryConstants.RESPONSE_OK if the category was succsefully deleted
142      */

143
144
145
146     public int deleteCategory(int id)
147     {
148         try
149         {
150             GResCategory cat=gres.loadCategory(id);
151             if(cat.getUsageCount()>0) return CategoryConstants.RESPONSE_NOTEMTPY_ERROR;
152
153             if(cat.getStatic()==1) return CategoryConstants.RESPONSE_NODELETESTATIC_ERROR;
154
155             gres.deleteCategory(cat);
156         }catch(SQLException JavaDoc e)
157         {
158             LoggingManager.log("SQL error:"+e,this);
159             return CategoryConstants.RESPONSE_SQLERROR;
160         }
161
162         return CategoryConstants.RESPONSE_OK;
163     }
164
165
166     /**
167      *Method for deleting a CategoryLink i.e. an item link to a category
168      * @param id the id of the category link
169      * @return CategoryConstants.RESPONSE_SQLERROR in case of an SQL error
170      * or CategoryConstants.RESPONSE_OK if the category link was succsefully deleted
171      */

172     public int deleteCatLink(int linkid)
173     {
174        try
175         {
176             gres.deleteCatLink(linkid);
177
178         }catch(SQLException JavaDoc e)
179         {
180             LoggingManager.log("SQL error:"+e,this);
181             return CategoryConstants.RESPONSE_SQLERROR;
182         }
183
184         return CategoryConstants.RESPONSE_OK;
185
186
187     }
188
189
190
191 }
192
Popular Tags