juddi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfa...@apache.org
Subject svn commit: r765401 - in /webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi: api/impl/UDDISubscriptionImpl.java mapping/MappingModelToApi.java query/FindSubscriptionByPublisherQuery.java query/SubscriptionQuery.java
Date Wed, 15 Apr 2009 22:31:34 GMT
Author: jfaath
Date: Wed Apr 15 22:31:34 2009
New Revision: 765401

URL: http://svn.apache.org/viewvc?rev=765401&view=rev
Log:
JUDDI-208: implementing get_subscriptions method of subscription api

Added:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java
  (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java
  (with props)
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/MappingModelToApi.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=765401&r1=765400&r2=765401&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
Wed Apr 15 22:31:34 2009
@@ -17,6 +17,7 @@
 
 package org.apache.juddi.api.impl;
 
+import java.util.ArrayList;
 import java.util.GregorianCalendar;
 import java.util.List;
 
@@ -41,8 +42,10 @@
 import org.apache.juddi.error.ErrorMessage;
 import org.apache.juddi.error.FatalErrorException;
 import org.apache.juddi.mapping.MappingApiToModel;
+import org.apache.juddi.mapping.MappingModelToApi;
 import org.apache.juddi.model.SubscriptionMatch;
 import org.apache.juddi.model.UddiEntityPublisher;
+import org.apache.juddi.query.FindSubscriptionByPublisherQuery;
 import org.apache.juddi.query.PersistenceManager;
 import org.apache.juddi.util.JAXBMarshaller;
 import org.apache.juddi.validation.ValidateSubscription;
@@ -55,7 +58,7 @@
 public class UDDISubscriptionImpl extends AuthenticatedService implements UDDISubscriptionPortType
{
 
 	private static Logger logger = Logger.getLogger(UDDISubscriptionImpl.class);
-	
+
 	public static final int DEFAULT_SUBSCRIPTIONEXPIRATION_DAYS = 30;
 
 
@@ -96,21 +99,33 @@
 	}
 
 
+	@SuppressWarnings("unchecked")
 	public List<Subscription> getSubscriptions(String authInfo)
 			throws DispositionReportFaultMessage {
 		EntityManager em = PersistenceManager.getEntityManager();
         EntityTransaction tx = em.getTransaction();
         tx.begin();
-        
-        @SuppressWarnings("unused")
-		List<?> keysFound = null;
 
-        // TODO JUDDI-153 : find the subscriptions
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, authInfo);
+		
+		List<Subscription> result = new ArrayList<Subscription>(0);
+		
+		List<org.apache.juddi.model.Subscription> modelSubscriptionList = (List<org.apache.juddi.model.Subscription>)FindSubscriptionByPublisherQuery.select(em,
publisher.getAuthorizedName());
+		if (modelSubscriptionList != null && modelSubscriptionList.size() > 0) {
+			for (org.apache.juddi.model.Subscription modelSubscription : modelSubscriptionList) {
+				
+				Subscription apiSubscription = new Subscription();
+				
+				MappingModelToApi.mapSubscription(modelSubscription, apiSubscription);
+				
+				result.add(apiSubscription);
+			}
+		}
         
         tx.commit();
         em.close();
 		
-		return null;
+		return result;
 	}
 
 

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java?rev=765401&r1=765400&r2=765401&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
(original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
Wed Apr 15 22:31:34 2009
@@ -17,23 +17,28 @@
 
 package org.apache.juddi.mapping;
 
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
 import javax.xml.datatype.XMLGregorianCalendar;
 
 import org.apache.juddi.error.ErrorMessage;
 import org.apache.juddi.error.FatalErrorException;
 import org.apache.juddi.model.OverviewDoc;
 import org.apache.juddi.model.UddiEntity;
+import org.apache.juddi.util.JAXBMarshaller;
+import org.apache.log4j.Logger;
 import org.uddi.api_v3.CompletionStatus;
 import org.uddi.api_v3.ObjectFactory;
 import org.uddi.api_v3.OperationalInfo;
+import org.uddi.sub_v3.SubscriptionFilter;
 import org.uddi.v3_service.DispositionReportFaultMessage;
 
 /**
@@ -41,6 +46,8 @@
  * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
  */
 public class MappingModelToApi {
+	private static Logger logger = Logger.getLogger(MappingModelToApi.class);
+
 	
 	public static void mapPublisher(org.apache.juddi.model.Publisher modelPublisher, 
 									org.apache.juddi.api.datatype.Publisher apiPublisher) 
@@ -724,29 +731,57 @@
 		apiOperationalInfo.setAuthorizedName(modelUddiEntity.getAuthorizedName());
 	}
 
+
+	public static void mapSubscription(org.apache.juddi.model.Subscription modelSubscription,

+									   org.uddi.sub_v3.Subscription apiSubscription) 
+				   throws DispositionReportFaultMessage {
+		
+		apiSubscription.setSubscriptionKey(modelSubscription.getSubscriptionKey());
+		apiSubscription.setBrief(modelSubscription.isBrief());
+		apiSubscription.setExpiresAfter(convertDateToXMLGregorianCalendar(modelSubscription.getExpiresAfter()));
+		apiSubscription.setBindingKey(modelSubscription.getBindingKey());
+		apiSubscription.setMaxEntities(modelSubscription.getMaxEntities());
+		apiSubscription.setNotificationInterval(converStringToDuration(modelSubscription.getNotificationInterval()));
+
+		try {
+			SubscriptionFilter existingFilter = (SubscriptionFilter)JAXBMarshaller.unmarshallFromString(modelSubscription.getSubscriptionFilter(),
"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"));
+		} 
+	}
+	
 	public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(Date date) throws DispositionReportFaultMessage
{
 		XMLGregorianCalendar result = null;
 		try { 
-			Calendar calendar = Calendar.getInstance();
-			calendar.setTime(date);
+			GregorianCalendar gc = new GregorianCalendar();
+			gc.setTimeInMillis(date.getTime());
 			
 			DatatypeFactory df = DatatypeFactory.newInstance();
-			result = df.newXMLGregorianCalendar(calendar.get(Calendar.YEAR), 
-												calendar.get(Calendar.MONTH), 
-												calendar.get(Calendar.DAY_OF_MONTH), 
-												calendar.get(Calendar.HOUR), 
-												calendar.get(Calendar.MINUTE), 
-												calendar.get(Calendar.SECOND), 
-												calendar.get(Calendar.MILLISECOND), 
-												0);
+			result = df.newXMLGregorianCalendar(gc);
 		}
 		catch(DatatypeConfigurationException ce) { 
 			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
 		}
 		
 		return result;
-		
 	}
+	
+	public static Duration converStringToDuration(String duration) throws DispositionReportFaultMessage
{
+		Duration result = null;
+		try { 
+			
+			DatatypeFactory df = DatatypeFactory.newInstance();
+			result = df.newDuration(duration);
+		}
+		catch(DatatypeConfigurationException ce) { 
+			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
+		}
 
+		return result;
+	}
 	
+
 }

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java?rev=765401&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java
(added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java
Wed Apr 15 22:31:34 2009
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.juddi.query;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.juddi.query.util.DynamicQuery;
+
+/**
+ * Finds and returns a list of subscriptions by the authorized name.
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindSubscriptionByPublisherQuery extends SubscriptionQuery {
+	
+	
+	public static List<?> select(EntityManager em, String authorizedName) {
+		DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+		dynamicQry.WHERE().pad();
+		dynamicQry.appendGroupedAnd(new DynamicQuery.Parameter(ENTITY_ALIAS + "." + FindEntityByPublisherQuery.AUTHORIZED_NAME_FIELD,
authorizedName, DynamicQuery.PREDICATE_EQUALS));		
+		return getQueryResult(em, dynamicQry, null, null);
+	}
+
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindSubscriptionByPublisherQuery.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java?rev=765401&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java
(added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java
Wed Apr 15 22:31:34 2009
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.juddi.query;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class SubscriptionQuery extends EntityQuery {
+
+	public static final String ENTITY_NAME = "Subscription";
+	public static final String ENTITY_ALIAS = "ss";
+	
+	protected static String selectSQL;
+
+	static {
+		StringBuffer sql = new StringBuffer(200);
+		sql.append("select distinct "+ ENTITY_ALIAS + " from " + ENTITY_NAME + " " + ENTITY_ALIAS
+ " ");
+		selectSQL = sql.toString();
+	}
+
+	public static String getSelectSQL() {
+		return selectSQL;
+	}
+	
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/SubscriptionQuery.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
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