juddi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfa...@apache.org
Subject svn commit: r763853 - in /webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi: api/impl/UDDISubscriptionImpl.java mapping/MappingApiToModel.java validation/ValidateSubscription.java
Date Fri, 10 Apr 2009 01:18:52 GMT
Author: jfaath
Date: Fri Apr 10 01:18:52 2009
New Revision: 763853

URL: http://svn.apache.org/viewvc?rev=763853&view=rev
Log:
JUDDI-206, JUDDI-209: adding functionality for saving/deleting subscriptions

Modified:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISubscriptionImpl.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingApiToModel.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateSubscription.java

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISubscriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISubscriptionImpl.java?rev=763853&r1=763852&r2=763853&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISubscriptionImpl.java
(original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISubscriptionImpl.java
Fri Apr 10 01:18:52 2009
@@ -17,24 +17,36 @@
 
 package org.apache.juddi.api.impl;
 
+import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.jws.WebService;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
+import javax.xml.bind.JAXBException;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
 import javax.xml.ws.Holder;
 
 import org.uddi.sub_v3.DeleteSubscription;
 import org.uddi.sub_v3.GetSubscriptionResults;
-import org.uddi.sub_v3.SaveSubscription;
 import org.uddi.sub_v3.Subscription;
+import org.uddi.sub_v3.SubscriptionFilter;
 import org.uddi.sub_v3.SubscriptionResultsList;
 import org.uddi.v3_service.DispositionReportFaultMessage;
 import org.uddi.v3_service.UDDISubscriptionPortType;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.Property;
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.error.FatalErrorException;
 import org.apache.juddi.mapping.MappingApiToModel;
+import org.apache.juddi.model.SubscriptionMatch;
 import org.apache.juddi.model.UddiEntityPublisher;
 import org.apache.juddi.query.PersistenceManager;
+import org.apache.juddi.util.JAXBMarshaller;
 import org.apache.juddi.validation.ValidateSubscription;
+import org.apache.log4j.Logger;
 
 
 @WebService(serviceName="UDDISubscriptionService", 
@@ -42,6 +54,10 @@
 			targetNamespace = "urn:uddi-org:sub_v3_portType")
 public class UDDISubscriptionImpl extends AuthenticatedService implements UDDISubscriptionPortType
{
 
+	private static Logger logger = Logger.getLogger(UDDISubscriptionImpl.class);
+	
+	public static final int DEFAULT_SUBSCRIPTIONEXPIRATION_DAYS = 30;
+
 
 	public void deleteSubscription(DeleteSubscription body)
 			throws DispositionReportFaultMessage {
@@ -49,6 +65,9 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+		new ValidateSubscription(publisher).validateDeleteSubscription(em, body);
+		
         List<String> subscriptionKeyList = body.getSubscriptionKey();
         for (String subscriptionKey : subscriptionKeyList) {
                 Object obj = em.find(org.apache.juddi.model.Subscription.class, subscriptionKey);
@@ -109,10 +128,146 @@
 		List<org.uddi.sub_v3.Subscription> apiSubscriptionList = subscription.value;
 		for (org.uddi.sub_v3.Subscription apiSubscription : apiSubscriptionList) {
 			
+			org.apache.juddi.model.Subscription modelSubscription = new org.apache.juddi.model.Subscription();
+			
+			Object existingEntity = em.find(org.apache.juddi.model.Subscription.class, apiSubscription.getSubscriptionKey());
+			if (existingEntity != null) {
+				doRenewal((org.apache.juddi.model.Subscription)existingEntity, apiSubscription);
+				em.remove(existingEntity);
+			}
+
+			doSubscriptionExpirationDate(apiSubscription);
+			
+			MappingApiToModel.mapSubscription(apiSubscription, modelSubscription);
+
+			// Add the matching keys to the match collection
+			List<?> keys = getSubscriptionMatches(apiSubscription.getSubscriptionFilter(), em);
+			if (keys != null && keys.size() > 0) {
+				for (Object key : keys) {
+					SubscriptionMatch subMatch = new SubscriptionMatch(modelSubscription, (String)key);
+					modelSubscription.getSubscriptionMatches().add(subMatch);
+				}
+			}
+			
+			em.persist(modelSubscription);
 		}
 
 		tx.commit();
 		em.close();
 	}
+
+	/**
+	 * Will perform the necessary logic for when a subscription is renewed (evidenced by a subscription
with the same key in existence).  
+	 * In general, the appropriate data is copied from the stored subscription to the renewal
subscription request.
+	 * 
+	 * @param existingSubscription - existing stored subscription
+	 * @param apiSubscription - renewal subscription request
+	 * @throws DispositionReportFaultMessage 
+	 */
+	private void doRenewal(org.apache.juddi.model.Subscription existingSubscription, org.uddi.sub_v3.Subscription
apiSubscription) throws DispositionReportFaultMessage {
+		if (apiSubscription.getSubscriptionFilter() == null) {
+			String rawFilter = existingSubscription.getSubscriptionFilter();
+			try {
+				SubscriptionFilter existingFilter = (SubscriptionFilter)JAXBMarshaller.unmarshallFromString(rawFilter,
"org.uddi.sub_v3");
+				apiSubscription.setSubscriptionFilter(existingFilter);
+			} 
+			catch (JAXBException e) {
+				logger.error("JAXB Exception while marshalling subscription filter", e);
+				throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
+			} 
+		}
+		
+	}
+	
+	/**
+	 * Will add the expiration date to the provided subscription request.  Date is earlier of
user provided date and the system default
+	 * 
+	 * @param apiSubscription
+	 * @throws DispositionReportFaultMessage
+	 */
+	private void doSubscriptionExpirationDate(org.uddi.sub_v3.Subscription apiSubscription)
throws DispositionReportFaultMessage {
+
+		int subscriptionExpirationDays = DEFAULT_SUBSCRIPTIONEXPIRATION_DAYS;
+		try { 
+			subscriptionExpirationDays = AppConfig.getConfiguration().getInt(Property.JUDDI_SUBSCRIPTION_EXPIRATION_DAYS);

+		}
+		catch(ConfigurationException ce) { 
+			throw new FatalErrorException(new ErrorMessage("errors.configuration.Retrieval"));
+		}
+
+		GregorianCalendar expirationDate = new GregorianCalendar();
+		expirationDate.add(GregorianCalendar.DAY_OF_MONTH, subscriptionExpirationDays);
+		
+		// The expiration date is the earlier of the provided date and that specified by the parameter.
+		if (apiSubscription.getExpiresAfter() != null) {
+			GregorianCalendar userExpiration = apiSubscription.getExpiresAfter().toGregorianCalendar();
+			if (userExpiration.getTimeInMillis() < expirationDate.getTimeInMillis())
+				expirationDate.setTimeInMillis(userExpiration.getTimeInMillis());
+		}
+
+		try { 
+			DatatypeFactory df = DatatypeFactory.newInstance();
+			apiSubscription.setExpiresAfter(df.newXMLGregorianCalendar(expirationDate));
+		}
+		catch(DatatypeConfigurationException ce) { 
+			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
+		}
+		
+	}
+
+	/**
+	 * Will take a snapshot of the keys that match the subscription filter return them.
+	 * 
+	 * @param subscriptionFilter
+	 * @param em
+	 * @return
+	 * @throws DispositionReportFaultMessage
+	 */
+	private List<?> getSubscriptionMatches(SubscriptionFilter subscriptionFilter, EntityManager
em) 
+			 throws DispositionReportFaultMessage {
+		
+		
+		List<?> keys = null;
+		if (subscriptionFilter.getFindBinding() != null) {
+			org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+			findQualifiers.mapApiFindQualifiers(subscriptionFilter.getFindBinding().getFindQualifiers());
+			keys = InquiryHelper.findBinding(subscriptionFilter.getFindBinding(), findQualifiers,
em);
+		}
+		if (subscriptionFilter.getFindBusiness() != null) {
+			org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+			findQualifiers.mapApiFindQualifiers(subscriptionFilter.getFindBusiness().getFindQualifiers());
+			keys = InquiryHelper.findBusiness(subscriptionFilter.getFindBusiness(), findQualifiers,
em);
+		}
+		if (subscriptionFilter.getFindService() != null) {
+			org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+			findQualifiers.mapApiFindQualifiers(subscriptionFilter.getFindService().getFindQualifiers());
+			keys = InquiryHelper.findService(subscriptionFilter.getFindService(), findQualifiers,
em);
+		}
+		if (subscriptionFilter.getFindTModel() != null) {
+			org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+			findQualifiers.mapApiFindQualifiers(subscriptionFilter.getFindTModel().getFindQualifiers());
+			keys = InquiryHelper.findTModel(subscriptionFilter.getFindTModel(), findQualifiers, em);
+		}
+		if (subscriptionFilter.getFindRelatedBusinesses() != null) {
+			// TODO: should we bother taking a snapshot of these?
+		}
+		if (subscriptionFilter.getGetBindingDetail() != null) {
+			keys = subscriptionFilter.getGetBindingDetail().getBindingKey();
+		}
+		if (subscriptionFilter.getGetBusinessDetail() != null) {
+			keys = subscriptionFilter.getGetBusinessDetail().getBusinessKey();
+		}
+		if (subscriptionFilter.getGetServiceDetail() != null) {
+			keys = subscriptionFilter.getGetServiceDetail().getServiceKey();
+		}
+		if (subscriptionFilter.getGetTModelDetail() != null) {
+			keys = subscriptionFilter.getGetTModelDetail().getTModelKey();
+		}
+		if (subscriptionFilter.getGetAssertionStatusReport() != null) {
+			// Nothing needs to be done
+		}
+		return keys;
+		
+	}
 	
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingApiToModel.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingApiToModel.java?rev=763853&r1=763852&r2=763853&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingApiToModel.java
(original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingApiToModel.java
Fri Apr 10 01:18:52 2009
@@ -17,10 +17,18 @@
 
 package org.apache.juddi.mapping;
 
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
 
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.error.FatalErrorException;
+import org.apache.juddi.util.JAXBMarshaller;
+import org.apache.log4j.Logger;
+import org.uddi.sub_v3.ObjectFactory;
 import org.uddi.v3_service.DispositionReportFaultMessage;
 
 
@@ -29,7 +37,9 @@
  * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
  */
 public class MappingApiToModel {
+	private static Logger logger = Logger.getLogger(MappingApiToModel.class);
 
+	
 	public static void mapPublisher(org.apache.juddi.api.datatype.Publisher apiPublisher, 
 									org.apache.juddi.model.Publisher modelPublisher) 
 				   throws DispositionReportFaultMessage {
@@ -533,23 +543,29 @@
 	}
 
 	public static void mapSubscription(org.uddi.sub_v3.Subscription apiSubscription,
-			org.apache.juddi.model.Subscription modelSubscription) throws DispositionReportFaultMessage
{
-		if ((apiSubscription.getSubscriptionKey() != null) && (!"".equals(apiSubscription.getSubscriptionKey())))
{
-			// if the apiSubscription has a key, this is a renewal or update - we don't want to change
all of the fields, 
-			// just the ones that have been provided to update the record
-			if (apiSubscription.getBindingKey() != null) {
-				modelSubscription.setBindingKey(apiSubscription.getBindingKey());
-			}
-			
-			if (apiSubscription.getNotificationInterval() != null) {
-				modelSubscription.setNotificationInterval(apiSubscription.getNotificationInterval().toString());
-			}
-			
-		} else {
-			// No key provided, assume that this is a new subscription and map all fields
-			modelSubscription.setBindingKey(apiSubscription.getBindingKey());
-			modelSubscription.setNotificationInterval(apiSubscription.getNotificationInterval().toString());
+									   org.apache.juddi.model.Subscription modelSubscription) 
+				   throws DispositionReportFaultMessage {
+
+		modelSubscription.setSubscriptionKey(apiSubscription.getSubscriptionKey());
+		modelSubscription.setBindingKey(apiSubscription.getBindingKey());
+		modelSubscription.setNotificationInterval(apiSubscription.getNotificationInterval().toString());
+		modelSubscription.setMaxEntities(apiSubscription.getMaxEntities());
+		if (apiSubscription.getExpiresAfter() != null) {
+			GregorianCalendar gc = apiSubscription.getExpiresAfter().toGregorianCalendar();
+			modelSubscription.setExpiresAfter(new Date(gc.getTimeInMillis()));
+		}
+		modelSubscription.setBrief(apiSubscription.isBrief());
+		
+		try {
+			String rawFilter = JAXBMarshaller.marshallToString(new ObjectFactory().createSubscriptionFilter(apiSubscription.getSubscriptionFilter()),
"org.uddi.sub_v3");
+			logger.debug("marshalled subscription filter:  " + rawFilter);
+			modelSubscription.setSubscriptionFilter(rawFilter);
+
+		} catch (JAXBException e) {
+			logger.error("JAXBException while marshalling subscription filter", e);
+			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
 		}
+		
 	}
 	
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateSubscription.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateSubscription.java?rev=763853&r1=763852&r2=763853&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateSubscription.java
(original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateSubscription.java
Fri Apr 10 01:18:52 2009
@@ -17,18 +17,20 @@
 
  package org.apache.juddi.validation;
 
+import java.util.HashSet;
 import java.util.List;
 
 import javax.persistence.EntityManager;
 
 import org.apache.juddi.error.ErrorMessage;
 import org.apache.juddi.error.FatalErrorException;
+import org.apache.juddi.error.InvalidKeyPassedException;
 import org.apache.juddi.error.KeyUnavailableException;
 import org.apache.juddi.error.ValueNotAllowedException;
 import org.apache.juddi.keygen.KeyGenerator;
 import org.apache.juddi.keygen.KeyGeneratorFactory;
 import org.apache.juddi.model.UddiEntityPublisher;
-import org.uddi.sub_v3.SaveSubscription;
+import org.uddi.sub_v3.DeleteSubscription;
 import org.uddi.sub_v3.SubscriptionFilter;
 import org.uddi.v3_service.DispositionReportFaultMessage;
 
@@ -106,54 +108,84 @@
 		if (!entityExists && subscriptionFilter == null)
 			throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.NoFilterOnNewSubscription"));
 			
-		int filterCount = 0;
-		ValidateInquiry validateInquiry = new ValidateInquiry(publisher);
-		if (subscriptionFilter.getFindBinding() != null) {
-			filterCount++;
-			validateInquiry.validateFindBinding(subscriptionFilter.getFindBinding());
-		}
-		if (subscriptionFilter.getFindBusiness() != null) {
-			filterCount++;
-			validateInquiry.validateFindBusiness(subscriptionFilter.getFindBusiness());
-		}
-		if (subscriptionFilter.getFindService() != null) {
-			filterCount++;
-			validateInquiry.validateFindService(subscriptionFilter.getFindService());
-		}
-		if (subscriptionFilter.getFindTModel() != null) {
-			filterCount++;
-			validateInquiry.validateFindTModel(subscriptionFilter.getFindTModel(), false);
-		}
-		if (subscriptionFilter.getFindRelatedBusinesses() != null) {
-			filterCount++;
-			validateInquiry.validateFindRelatedBusinesses(subscriptionFilter.getFindRelatedBusinesses(),
false);
-		}
-		if (subscriptionFilter.getGetBindingDetail() != null) {
-			filterCount++;
-			validateInquiry.validateGetBindingDetail(subscriptionFilter.getGetBindingDetail());
-		}
-		if (subscriptionFilter.getGetBusinessDetail() != null) {
-			filterCount++;
-			validateInquiry.validateGetBusinessDetail(subscriptionFilter.getGetBusinessDetail());
-		}
-		if (subscriptionFilter.getGetServiceDetail() != null) {
-			filterCount++;
-			validateInquiry.validateGetServiceDetail(subscriptionFilter.getGetServiceDetail());
-		}
-		if (subscriptionFilter.getGetTModelDetail() != null) {
-			filterCount++;
-			validateInquiry.validateGetTModelDetail(subscriptionFilter.getGetTModelDetail());
-		}
-		if (subscriptionFilter.getGetAssertionStatusReport() != null) {
-			filterCount++;
+		if (subscriptionFilter != null) {
+			int filterCount = 0;
+			ValidateInquiry validateInquiry = new ValidateInquiry(publisher);
+			if (subscriptionFilter.getFindBinding() != null) {
+				filterCount++;
+				validateInquiry.validateFindBinding(subscriptionFilter.getFindBinding());
+			}
+			if (subscriptionFilter.getFindBusiness() != null) {
+				filterCount++;
+				validateInquiry.validateFindBusiness(subscriptionFilter.getFindBusiness());
+			}
+			if (subscriptionFilter.getFindService() != null) {
+				filterCount++;
+				validateInquiry.validateFindService(subscriptionFilter.getFindService());
+			}
+			if (subscriptionFilter.getFindTModel() != null) {
+				filterCount++;
+				validateInquiry.validateFindTModel(subscriptionFilter.getFindTModel(), false);
+			}
+			if (subscriptionFilter.getFindRelatedBusinesses() != null) {
+				filterCount++;
+				validateInquiry.validateFindRelatedBusinesses(subscriptionFilter.getFindRelatedBusinesses(),
false);
+			}
+			if (subscriptionFilter.getGetBindingDetail() != null) {
+				filterCount++;
+				validateInquiry.validateGetBindingDetail(subscriptionFilter.getGetBindingDetail());
+			}
+			if (subscriptionFilter.getGetBusinessDetail() != null) {
+				filterCount++;
+				validateInquiry.validateGetBusinessDetail(subscriptionFilter.getGetBusinessDetail());
+			}
+			if (subscriptionFilter.getGetServiceDetail() != null) {
+				filterCount++;
+				validateInquiry.validateGetServiceDetail(subscriptionFilter.getGetServiceDetail());
+			}
+			if (subscriptionFilter.getGetTModelDetail() != null) {
+				filterCount++;
+				validateInquiry.validateGetTModelDetail(subscriptionFilter.getGetTModelDetail());
+			}
+			if (subscriptionFilter.getGetAssertionStatusReport() != null) {
+				filterCount++;
+			}
+
+			if (filterCount == 0)
+				throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.BlankFilter"));
+			
+			if (filterCount > 1)
+				throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.TooManyFilters",
String.valueOf(filterCount)));
+
 		}
 		
-		if (!entityExists && filterCount == 0)
-			throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.NoFilterOnNewSubscription"));
-		
-		if (filterCount > 1)
-			throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.TooManyFilters",
String.valueOf(filterCount)));
 		
 	}
 	
+	public void validateDeleteSubscription(EntityManager em, DeleteSubscription body) throws
DispositionReportFaultMessage {
+		// No null input
+		if (body == null)
+			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
+
+		// No null or empty list
+		List<String> entityKeyList = body.getSubscriptionKey();
+		if (entityKeyList == null || entityKeyList.size() == 0)
+			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
+		
+		HashSet<String> dupCheck = new HashSet<String>();
+		for (String entityKey : entityKeyList) {
+			boolean inserted = dupCheck.add(entityKey);
+			if (!inserted)
+				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey",
entityKey));
+			
+			Object obj = em.find(org.apache.juddi.model.Subscription.class, entityKey);
+			if (obj == null)
+				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.SubscriptionNotFound",
entityKey));
+			
+			// No ownership specified for subscriptions
+			//if (!publisher.isOwner((UddiEntity)obj))
+			//	throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner",
entityKey));
+			
+		}
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org


Mime
View raw message