1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.function;
17
18 import java.util.Vector;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.juddi.datastore.DataStore;
23 import org.apache.juddi.datastore.DataStoreFactory;
24 import org.apache.juddi.datatype.RegistryObject;
25 import org.apache.juddi.datatype.publisher.Publisher;
26 import org.apache.juddi.datatype.request.AuthInfo;
27 import org.apache.juddi.datatype.request.DeletePublisher;
28 import org.apache.juddi.datatype.response.DispositionReport;
29 import org.apache.juddi.datatype.response.Result;
30 import org.apache.juddi.error.RegistryException;
31 import org.apache.juddi.registry.RegistryEngine;
32 import org.apache.juddi.util.Config;
33
34 /***
35 * @author Steve Viens (sviens@apache.org)
36 */
37 public class DeletePublisherFunction extends AbstractFunction
38 {
39
40 private static Log log = LogFactory.getLog(DeletePublisherFunction.class);
41
42 /***
43 *
44 */
45 public DeletePublisherFunction(RegistryEngine registry)
46 {
47 super(registry);
48 }
49
50 /***
51 * Here are the rules:
52 *
53 * 1. A publisher must have administrative privs to
54 * delete anything.
55 * 2. A publisher cannot delete itself.
56 */
57 public RegistryObject execute(RegistryObject regObject)
58 throws RegistryException
59 {
60
61 DeletePublisher request = (DeletePublisher)regObject;
62 String generic = request.getGeneric();
63 AuthInfo authInfo = request.getAuthInfo();
64 Vector publisherIDVector = request.getPublisherIDVector();
65
66
67 DataStore dataStore = DataStoreFactory.getDataStore();
68
69 try
70 {
71 dataStore.beginTrans();
72
73
74 Publisher publisher = getPublisher(authInfo,dataStore);
75 String publisherID = publisher.getPublisherID();
76
77
78 if (!dataStore.isAdministrator(publisherID))
79 throw new RegistryException("Invalid Operation, You must have " +
80 "administrative priveledges to delete a publisher account.");
81
82
83 for (int i=0; i<publisherIDVector.size(); i++)
84 {
85
86 String pubID = (String)publisherIDVector.elementAt(i);
87
88 if (pubID.equalsIgnoreCase(publisherID))
89 throw new RegistryException("Invalid Operation, A publisher " +
90 "cannot delete it's own publisher account.");
91
92
93 dataStore.deletePublisher(pubID);
94 }
95
96
97 for (int i=0; i<publisherIDVector.size(); i++)
98 {
99 String tModelKey = (String)publisherIDVector.elementAt(i);
100 dataStore.deleteTModel(tModelKey);
101
102 log.info("Publisher '"+publisherID+"' deleted TModel with key: "+tModelKey);
103 }
104
105 dataStore.commit();
106 }
107 catch(RegistryException regex)
108 {
109 try { dataStore.rollback(); } catch(Exception e) { }
110 log.error(regex);
111 throw (RegistryException)regex;
112 }
113 catch(Exception ex)
114 {
115 try { dataStore.rollback(); } catch(Exception e) { }
116 log.error(ex);
117 throw new RegistryException(ex);
118 }
119 finally
120 {
121 if (dataStore != null)
122 dataStore.release();
123 }
124
125
126
127
128 Result result = new Result(Result.E_SUCCESS);
129 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS));
130 DispositionReport dispRpt = new DispositionReport();
131 dispRpt.setGeneric(generic);
132 dispRpt.setOperator(Config.getOperator());
133 dispRpt.addResult(result);
134
135 return dispRpt;
136 }
137
138
139 /****************************************************************************/
140 /****************************** TEST DRIVER *********************************/
141 /****************************************************************************/
142
143
144 public static void main(String[] args)
145 {
146
147 RegistryEngine reg = new RegistryEngine();
148 reg.init();
149
150 try
151 {
152 }
153 catch (Exception ex)
154 {
155
156 ex.printStackTrace();
157 }
158 finally
159 {
160
161 reg.dispose();
162 }
163 }
164 }