This project has retired. For details please refer to its
Attic page.
UDDIPublicationImplExt xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.api.impl;
17
18 import java.util.Date;
19 import java.util.List;
20
21 import javax.persistence.EntityManager;
22 import javax.persistence.EntityTransaction;
23 import javax.xml.ws.WebServiceContext;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.juddi.config.PersistenceManager;
28 import org.apache.juddi.mapping.MappingApiToModel;
29 import org.apache.juddi.model.UddiEntityPublisher;
30 import org.apache.juddi.validation.ValidatePublish;
31 import org.uddi.api_v3.BusinessDetail;
32 import org.uddi.api_v3.SaveBusiness;
33 import org.uddi.v3_service.DispositionReportFaultMessage;
34
35
36
37
38
39
40
41 public class UDDIPublicationImplExt extends UDDIPublicationImpl {
42
43
44
45
46
47
48 protected UDDIPublicationImplExt(WebServiceContext ctx) {
49 super();
50 this.ctx = ctx;
51 }
52 Log log = LogFactory.getLog(UDDIPublicationImplExt.class);
53
54 private String nodeId="";
55 public BusinessDetail saveBusinessFudge(SaveBusiness body, String nodeID)
56 throws DispositionReportFaultMessage {
57
58 if (!body.getBusinessEntity().isEmpty()) {
59 log.debug("Inbound save business Fudger request for key " + body.getBusinessEntity().get(0).getBusinessKey());
60 }
61 EntityManager em = PersistenceManager.getEntityManager();
62 EntityTransaction tx = em.getTransaction();
63 try {
64 tx.begin();
65
66 UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
67 ValidatePublish validator = new ValidatePublish(publisher);
68 validator.validateSaveBusiness(em, body, null, publisher);
69
70 BusinessDetail result = new BusinessDetail();
71
72 List<org.uddi.api_v3.BusinessEntity> apiBusinessEntityList = body.getBusinessEntity();
73 for (org.uddi.api_v3.BusinessEntity apiBusinessEntity : apiBusinessEntityList) {
74
75 org.apache.juddi.model.BusinessEntity modelBusinessEntity = new org.apache.juddi.model.BusinessEntity();
76
77
78 MappingApiToModel.mapBusinessEntity(apiBusinessEntity, modelBusinessEntity);
79 nodeId = nodeID;
80
81 setOperationalInfo(em, modelBusinessEntity, publisher);
82
83 em.persist(modelBusinessEntity);
84
85 result.getBusinessEntity().add(apiBusinessEntity);
86 }
87
88
89 validator.validateSaveBusinessMax(em);
90
91 tx.commit();
92
93 return result;
94 } catch (DispositionReportFaultMessage drfm) {
95
96 throw drfm;
97 } finally {
98 if (tx.isActive()) {
99 tx.rollback();
100 }
101 em.close();
102 }
103 }
104
105 private void setOperationalInfo(EntityManager em, org.apache.juddi.model.BusinessEntity uddiEntity, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
106
107 uddiEntity.setAuthorizedName(publisher.getAuthorizedName());
108
109 Date now = new Date();
110 uddiEntity.setModified(now);
111 uddiEntity.setModifiedIncludingChildren(now);
112
113
114 uddiEntity.setNodeId(nodeId);
115
116 org.apache.juddi.model.BusinessEntity existingUddiEntity = em.find(uddiEntity.getClass(), uddiEntity.getEntityKey());
117 if (existingUddiEntity != null)
118 uddiEntity.setCreated(existingUddiEntity.getCreated());
119 else
120 uddiEntity.setCreated(now);
121
122 List<org.apache.juddi.model.BusinessService> serviceList = uddiEntity.getBusinessServices();
123 for (org.apache.juddi.model.BusinessService service : serviceList)
124 setOperationalInfo(em, service, publisher, true);
125
126
127 if (existingUddiEntity != null)
128 em.remove(existingUddiEntity);
129
130 }
131
132 private void setOperationalInfo(EntityManager em, org.apache.juddi.model.BusinessService uddiEntity, UddiEntityPublisher publisher, boolean isChild) throws DispositionReportFaultMessage {
133
134 uddiEntity.setAuthorizedName(publisher.getAuthorizedName());
135
136 Date now = new Date();
137 uddiEntity.setModified(now);
138 uddiEntity.setModifiedIncludingChildren(now);
139
140 if(!isChild) {
141 org.apache.juddi.model.BusinessEntity parent = em.find(org.apache.juddi.model.BusinessEntity.class, uddiEntity.getBusinessEntity().getEntityKey());
142 parent.setModifiedIncludingChildren(now);
143 em.persist(parent);
144 }
145
146 uddiEntity.setNodeId(nodeId);
147
148 org.apache.juddi.model.BusinessService existingUddiEntity = em.find(uddiEntity.getClass(), uddiEntity.getEntityKey());
149 if (existingUddiEntity != null) {
150 uddiEntity.setCreated(existingUddiEntity.getCreated());
151 }
152 else
153 uddiEntity.setCreated(now);
154
155 List<org.apache.juddi.model.BindingTemplate> bindingList = uddiEntity.getBindingTemplates();
156 for (org.apache.juddi.model.BindingTemplate binding : bindingList)
157 setOperationalInfo(em, binding, publisher, true);
158
159
160 if (existingUddiEntity != null)
161 em.remove(existingUddiEntity);
162
163 }
164
165 private void setOperationalInfo(EntityManager em, org.apache.juddi.model.BindingTemplate uddiEntity, UddiEntityPublisher publisher, boolean isChild) throws DispositionReportFaultMessage {
166
167 uddiEntity.setAuthorizedName(publisher.getAuthorizedName());
168
169 Date now = new Date();
170 uddiEntity.setModified(now);
171 uddiEntity.setModifiedIncludingChildren(now);
172
173 if(!isChild) {
174 org.apache.juddi.model.BusinessService parent = em.find(org.apache.juddi.model.BusinessService.class, uddiEntity.getBusinessService().getEntityKey());
175 parent.setModifiedIncludingChildren(now);
176 em.persist(parent);
177
178
179 org.apache.juddi.model.BusinessEntity businessParent = em.find(org.apache.juddi.model.BusinessEntity.class, parent.getBusinessEntity().getEntityKey());
180 businessParent.setModifiedIncludingChildren(now);
181 em.persist(businessParent);
182 }
183
184 uddiEntity.setNodeId(nodeId);
185
186 org.apache.juddi.model.BindingTemplate existingUddiEntity = em.find(uddiEntity.getClass(), uddiEntity.getEntityKey());
187 if (existingUddiEntity != null)
188 uddiEntity.setCreated(existingUddiEntity.getCreated());
189 else
190 uddiEntity.setCreated(now);
191
192 if (existingUddiEntity != null)
193 em.remove(existingUddiEntity);
194
195 }
196
197 private void setOperationalInfo(EntityManager em, org.apache.juddi.model.Tmodel uddiEntity, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
198
199 uddiEntity.setAuthorizedName(publisher.getAuthorizedName());
200
201 Date now = new Date();
202 uddiEntity.setModified(now);
203 uddiEntity.setModifiedIncludingChildren(now);
204
205 uddiEntity.setNodeId(nodeId);
206
207 org.apache.juddi.model.Tmodel existingUddiEntity = em.find(uddiEntity.getClass(), uddiEntity.getEntityKey());
208 if (existingUddiEntity != null)
209 uddiEntity.setCreated(existingUddiEntity.getCreated());
210 else
211 uddiEntity.setCreated(now);
212
213 if (existingUddiEntity != null)
214 em.remove(existingUddiEntity);
215
216 }
217
218 }