This project has retired. For details please refer to its Attic page.
ValidateClientSubscriptionInfo xref
View Javadoc
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.HashSet;
21  import java.util.List;
22  
23  import javax.persistence.EntityManager;
24  
25  import org.apache.juddi.api_v3.ClientSubscriptionInfo;
26  import org.apache.juddi.api_v3.DeleteClientSubscriptionInfo;
27  import org.apache.juddi.api_v3.GetAllClientSubscriptionInfoDetail;
28  import org.apache.juddi.api_v3.GetClientSubscriptionInfoDetail;
29  import org.apache.juddi.api_v3.SaveClientSubscriptionInfo;
30  import org.apache.juddi.model.UddiEntityPublisher;
31  import org.apache.juddi.v3.error.ErrorMessage;
32  import org.apache.juddi.v3.error.FatalErrorException;
33  import org.apache.juddi.v3.error.InvalidKeyPassedException;
34  import org.apache.juddi.v3.error.ValueNotAllowedException;
35  import org.uddi.v3_service.DispositionReportFaultMessage;
36  
37  
38  /**
39   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
40   */
41  public class ValidateClientSubscriptionInfo extends ValidateUDDIApi {
42  
43  	public ValidateClientSubscriptionInfo(UddiEntityPublisher publisher) {
44  		super(publisher);
45  	}
46  
47  	
48  	
49  	/*-------------------------------------------------------------------
50  	 ClientSubscriptionInf functions are specific to jUDDI.
51  	 --------------------------------------------------------------------*/
52  	
53  	public void validateDeleteClientSubscriptionInfo(EntityManager em, DeleteClientSubscriptionInfo body) throws DispositionReportFaultMessage {
54  
55  		// No null input
56  		if (body == null)
57  			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
58  		
59  		// No null or empty list
60  		List<String> entityKeyList = body.getSubscriptionKey();
61  		if (entityKeyList == null || entityKeyList.size() == 0)
62  			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
63  		
64  		HashSet<String> dupCheck = new HashSet<String>();
65  		for (String entityKey : entityKeyList) {
66  			boolean inserted = dupCheck.add(entityKey);
67  			if (!inserted)
68  				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
69  			
70  			Object obj = em.find(org.apache.juddi.model.ClientSubscriptionInfo.class, entityKey);
71  			if (obj == null)
72  				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.SubscriptionKeyNotFound", entityKey));
73  			
74  		}
75  	}
76  
77  	public void validateSaveClientSubscriptionInfo(EntityManager em, SaveClientSubscriptionInfo body) throws DispositionReportFaultMessage {
78  
79  		// No null input
80  		if (body == null)
81  			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
82  		
83  		// No null or empty list
84  		List<ClientSubscriptionInfo> clientSubscriptionInfos = body.getClientSubscriptionInfo();
85  		if (clientSubscriptionInfos == null)
86  			throw new ValueNotAllowedException(new ErrorMessage("errors.saveclientsubscriptioninfo.NoInput"));
87  		
88  		for (ClientSubscriptionInfo clientSubscriptionInfo : body.getClientSubscriptionInfo()) {
89  			if (clientSubscriptionInfo.getSubscriptionKey()==null || clientSubscriptionInfo.getSubscriptionKey().equals("")) {
90  				throw new ValueNotAllowedException(new ErrorMessage("errors.saveclientsubscriptionKey.NoInput"));
91  			}
92  			validateClerk(em, clientSubscriptionInfo.getFromClerk());
93  		}
94  	}
95  
96  	public void validateClerk(EntityManager em, org.apache.juddi.api_v3.Clerk clerk) throws DispositionReportFaultMessage {
97  
98  		// No null input
99  		if (clerk == null)
100 			throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NullInput"));
101 		
102 		String name = clerk.getName();
103 		if (name == null || name.length() == 0)
104 			throw new ValueNotAllowedException(new ErrorMessage("errors.clerk.NoName"));
105 		
106 		//make sure clerk exists
107 		Object obj = em.find(org.apache.juddi.model.Clerk.class, name);
108 		if (obj == null)
109 			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ClerkNotFound", name));
110 	}
111 	
112 	public void validateGetClientSubscriptionInfoDetail(GetClientSubscriptionInfoDetail body) throws DispositionReportFaultMessage {
113 
114 		// No null input
115 		if (body == null)
116 			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
117 		
118 		// No null or empty list
119 		List<String> clientSubscriptionKeyList = body.getClientSubscriptionKey();
120 		if (clientSubscriptionKeyList == null || clientSubscriptionKeyList.size() == 0)
121 			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
122 
123 		HashSet<String> dupCheck = new HashSet<String>();
124 		for (String clientSubscriptionKey : clientSubscriptionKeyList) {
125 			boolean inserted = dupCheck.add(clientSubscriptionKey);
126 			if (!inserted)
127 				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", clientSubscriptionKey));
128 		}
129 	}
130 	
131 	public void validateGetAllClientSubscriptionDetail(GetAllClientSubscriptionInfoDetail body) throws DispositionReportFaultMessage {
132 
133 		// No null input
134 		if (body == null)
135 			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
136 		
137 	}
138 	
139 	
140 }