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.DeletePublisher; 26 import org.apache.juddi.api_v3.GetAllPublisherDetail; 27 import org.apache.juddi.api_v3.GetPublisherDetail; 28 import org.apache.juddi.api_v3.SavePublisher; 29 import org.apache.juddi.model.Publisher; 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.UserMismatchException; 35 import org.apache.juddi.v3.error.ValueNotAllowedException; 36 import org.uddi.v3_service.DispositionReportFaultMessage; 37 38 39 /** 40 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> 41 */ 42 public class ValidatePublisher extends ValidateUDDIApi { 43 44 public ValidatePublisher(UddiEntityPublisher publisher) { 45 super(publisher); 46 } 47 48 49 50 /*------------------------------------------------------------------- 51 Publisher functions are specific to jUDDI. 52 --------------------------------------------------------------------*/ 53 54 public void validateDeletePublisher(EntityManager em, DeletePublisher body) throws DispositionReportFaultMessage { 55 56 // No null input 57 if (body == null) 58 throw new FatalErrorException(new ErrorMessage("errors.NullInput")); 59 60 // No null or empty list 61 List<String> entityKeyList = body.getPublisherId(); 62 if (entityKeyList == null || entityKeyList.size() == 0) 63 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys")); 64 65 if (!((Publisher)publisher).isAdmin()) 66 throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd")); 67 68 HashSet<String> dupCheck = new HashSet<String>(); 69 for (String entityKey : entityKeyList) { 70 boolean inserted = dupCheck.add(entityKey); 71 if (!inserted) 72 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey)); 73 74 Object obj = em.find(org.apache.juddi.model.Publisher.class, entityKey); 75 if (obj == null) 76 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.PublisherNotFound", entityKey)); 77 78 } 79 } 80 81 public void validateSavePublisher(EntityManager em, SavePublisher body) throws DispositionReportFaultMessage { 82 83 // No null input 84 if (body == null) 85 throw new FatalErrorException(new ErrorMessage("errors.NullInput")); 86 87 // No null or empty list 88 List<org.apache.juddi.api_v3.Publisher> entityList = body.getPublisher(); 89 if (entityList == null || entityList.size() == 0) 90 throw new ValueNotAllowedException(new ErrorMessage("errors.savepublisher.NoInput")); 91 92 if (!((Publisher)publisher).isAdmin()) 93 throw new UserMismatchException(new ErrorMessage("errors.savepublisher.AdminReqd")); 94 95 for (org.apache.juddi.api_v3.Publisher entity : entityList) { 96 validatePublisher(em, entity); 97 } 98 } 99 100 public void validatePublisher(EntityManager em, org.apache.juddi.api_v3.Publisher publisher) throws DispositionReportFaultMessage { 101 102 // No null input 103 if (publisher == null) 104 throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NullInput")); 105 106 String authorizedName = publisher.getAuthorizedName(); 107 if (authorizedName == null || authorizedName.length() == 0) 108 throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoAuthorizedName")); 109 110 String publisherName = publisher.getPublisherName(); 111 if (publisherName == null || publisherName.length() == 0) 112 throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoPublisherName")); 113 114 } 115 116 public void validateGetPublisherDetail(GetPublisherDetail body) throws DispositionReportFaultMessage { 117 118 // No null input 119 if (body == null) 120 throw new FatalErrorException(new ErrorMessage("errors.NullInput")); 121 122 // No null or empty list 123 List<String> publisherIdList = body.getPublisherId(); 124 if (publisherIdList == null || publisherIdList.size() == 0) 125 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys")); 126 127 HashSet<String> dupCheck = new HashSet<String>(); 128 for (String publisherId : publisherIdList) { 129 boolean inserted = dupCheck.add(publisherId); 130 if (!inserted) 131 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", publisherId)); 132 } 133 } 134 135 public void validateGetAllPublisherDetail(GetAllPublisherDetail body) throws DispositionReportFaultMessage { 136 137 // No null input 138 if (body == null) 139 throw new FatalErrorException(new ErrorMessage("errors.NullInput")); 140 141 } 142 143 144 }