1 /*
2 * Copyright 2001-2008 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 package org.apache.juddi.validation;
19
20 import java.util.List;
21
22 import javax.persistence.EntityManager;
23
24 import org.apache.juddi.api_v3.Clerk;
25 import org.apache.juddi.api_v3.Node;
26 import org.apache.juddi.model.UddiEntityPublisher;
27 import org.apache.juddi.v3.error.ErrorMessage;
28 import org.apache.juddi.v3.error.FatalErrorException;
29 import org.apache.juddi.v3.error.InvalidKeyPassedException;
30 import org.apache.juddi.v3.error.ValueNotAllowedException;
31 import org.uddi.v3_service.DispositionReportFaultMessage;
32
33
34 /**
35 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
36 */
37 public class ValidateClerk extends ValidateUDDIApi {
38
39 public ValidateClerk(UddiEntityPublisher publisher) {
40 super(publisher);
41 }
42
43
44
45 /*-------------------------------------------------------------------
46 ClientSubscriptionInf functions are specific to jUDDI.
47 --------------------------------------------------------------------*/
48
49
50 public void validateSaveClerk(EntityManager em, org.apache.juddi.api_v3.SaveClerk body) throws DispositionReportFaultMessage {
51
52 if (body == null)
53 throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
54
55 // No null or empty list
56 List<Clerk> clerks = body.getClerk();
57 if (clerks == null)
58 throw new ValueNotAllowedException(new ErrorMessage("errors.saveClerk.NoInput"));
59
60 for (Clerk clerk : body.getClerk()) {
61 validateClerk(em, clerk);
62 }
63
64 }
65
66 public void validateClerk(EntityManager em, org.apache.juddi.api_v3.Clerk clerk) throws DispositionReportFaultMessage {
67
68 // No null input
69 if (clerk == null)
70 throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NullInput"));
71
72 String name = clerk.getName();
73 if (name == null || name.length() == 0)
74 throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NoName"));
75
76 String publisherName = clerk.getPublisher();
77 if (publisherName == null || publisherName.length() == 0)
78 throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NoPublisherName"));
79
80 Node node = clerk.getNode();
81 if (node == null)
82 throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NullNodeInput"));
83
84 String nodeName = node.getName();
85 if (nodeName == null || nodeName.length() == 0)
86 throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoName"));
87
88 //make sure node exists
89 //edit, doesn't matter if it doesn't exist, it'll be created on save of the clerk
90 /*Object obj = em.find(org.apache.juddi.model.Node.class, nodeName);
91 if (obj == null)
92 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NodeNotFound", nodeName));
93 */
94 }
95
96
97
98
99 }