This project has retired. For details please refer to its
Attic page.
ValidateValueSetValidation xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.validation;
18
19 import java.util.List;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import javax.persistence.EntityManager;
23 import javax.persistence.EntityTransaction;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.juddi.api_v3.ValidValues;
27 import org.apache.juddi.config.PersistenceManager;
28 import org.apache.juddi.mapping.MappingModelToApi;
29 import org.apache.juddi.model.Tmodel;
30 import org.apache.juddi.model.UddiEntityPublisher;
31 import org.apache.juddi.v3.error.ErrorMessage;
32 import org.apache.juddi.v3.error.ValueNotAllowedException;
33 import org.uddi.api_v3.TModel;
34 import org.uddi.v3_service.DispositionReportFaultMessage;
35
36
37
38
39
40 public class ValidateValueSetValidation extends ValidateUDDIApi {
41
42 private static Log log = LogFactory.getLog(ValidateValueSetValidation.class);
43
44 public ValidateValueSetValidation(UddiEntityPublisher publisher) {
45 super(publisher);
46 }
47
48
49
50
51
52
53 public void validateSetAllValidValues(List<ValidValues> values) throws ValueNotAllowedException {
54 if (values == null || values.isEmpty()) {
55 throw new ValueNotAllowedException(new ErrorMessage("errors.NullInput"));
56 }
57
58 for (int i = 0; i < values.size(); i++) {
59 String key = values.get(i).getTModekKey();
60 if (key == null || key.trim().length() == 0) {
61 throw new ValueNotAllowedException(new ErrorMessage("errors.NullInput", "tModel key"));
62 }
63
64 Tmodel tm = GetTModel_MODEL_IfExists(values.get(i).getTModekKey());
65
66 if (tm == null) {
67 throw new ValueNotAllowedException(new ErrorMessage("errors.invalidkey.TModelNotFound", key));
68 }
69
70 if (!this.publisher.isOwner(tm)) {
71 throw new ValueNotAllowedException(new ErrorMessage("errors.usermismatch.InvalidOwner", key ));
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 public static TModel GetTModel_API_IfExists(String tmodelKey) throws ValueNotAllowedException {
97 EntityManager em = PersistenceManager.getEntityManager();
98
99 TModel apitmodel = null;
100 if (em == null) {
101
102 log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullEM"));
103 return null;
104 } else {
105
106
107 EntityTransaction tx = em.getTransaction();
108 try {
109 Tmodel modelTModel = null;
110 tx.begin();
111 modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);
112 if (modelTModel != null) {
113 apitmodel = new TModel();
114 try {
115 MappingModelToApi.mapTModel(modelTModel, apitmodel);
116 } catch (DispositionReportFaultMessage ex) {
117 log.warn(ex);
118 apitmodel=null;
119 }
120
121
122 }
123 tx.commit();
124 } finally {
125 if (tx.isActive()) {
126 tx.rollback();
127 }
128 em.close();
129 }
130
131 }
132 return apitmodel;
133 }
134
135
136 public static Tmodel GetTModel_MODEL_IfExists(String tmodelKey) throws ValueNotAllowedException {
137 EntityManager em = PersistenceManager.getEntityManager();
138
139 Tmodel model = null;
140 if (em == null) {
141
142 log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullEM"));
143 return null;
144 } else {
145
146
147 EntityTransaction tx = em.getTransaction();
148 try {
149
150 tx.begin();
151 model = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);
152 tx.commit();
153 } finally {
154 if (tx.isActive()) {
155 tx.rollback();
156 }
157 em.close();
158 }
159
160 }
161 return model;
162 }
163 }