From 6edfda46bfee26edf828418c8df0041bec02a968 Mon Sep 17 00:00:00 2001 From: Benjamin Phillippe Date: Mon, 22 Apr 2013 09:48:58 -0500 Subject: [PATCH] Issue #1931 Implemented REST binding for registry Change-Id: I604c02dc849e380f70e2d27fa1f2b30dadcf0776 Former-commit-id: 9a7971c872c852ab4c59cdf0f5bbd70fdf8ae661 [formerly 9065ebcb65cf9045ed84344fabcab171fad91454] [formerly 3d2e073dd7986159bcf6d27bb1a2d63e703dcd5b [formerly daef43d8947f690d15f9314f85b8cf31d30c06ab]] Former-commit-id: 3d2e073dd7986159bcf6d27bb1a2d63e703dcd5b Former-commit-id: cf7da4b0010ba65653cfdfd02761814d2ceb35a1 --- .../META-INF/MANIFEST.MF | 2 + edexOsgi/build.edex/esb/bin/setup.env | 5 +- .../build.edex/esb/conf/spring/edex-db.xml | 54 +++++ edexOsgi/build.edex/esb/conf/spring/edex.xml | 40 +--- .../res/spring/ebxml-edex-impl.xml | 96 -------- .../res/spring/ebxml-impl.xml | 51 ---- .../res/spring/ebxml-registry-init.xml | 16 ++ .../{ebxml-web.xml => ebxml-webserver.xml} | 14 +- .../res/spring/ebxml-webservices.xml | 102 ++++++++ .../res/spring/ebxml-xacml.xml | 18 ++ .../res/spring/ebxml.xml | 58 ++--- .../services/query/QueryManagerImpl.java | 10 +- .../query/types/AbstractEbxmlQuery.java | 7 +- .../query/types/canonical/GetObjectById.java | 16 +- .../rest/QueryProtocolRestService.java | 217 ++++++++++++++++++ .../rest/RegistryObjectsRestService.java | 137 +++++++++++ .../rest/RepositoryItemsRestService.java | 88 +++++++ .../ebxml/util/ServiceUrlFactory.java | 69 ------ .../registry/ebxml/web/AddRegistryParty.java | 168 +++++++------- .../ebxml/web/DeleteRegistryParty.java | 123 +++++----- .../ebxml/web/ModifyRegistryParty.java | 165 ++++++------- .../registry/ebxml/web/RegistryWebUtil.java | 21 +- .../web/RegistryOrganizationInterface.html | 10 +- .../web/RegistryOrganizationMenu.html | 8 +- .../web/RegistryUserInterface.html | 10 +- .../web/RegistryUserMenu.html | 8 +- .../web/WEB-INF/web.xml | 58 ++--- .../web/webServiceBeans.xml | 71 ++++++ .../LifecycleManagerSubmitObjectsTest.java | 3 +- 29 files changed, 1030 insertions(+), 615 deletions(-) create mode 100644 edexOsgi/build.edex/esb/conf/spring/edex-db.xml delete mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-edex-impl.xml create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-registry-init.xml rename edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/{ebxml-web.xml => ebxml-webserver.xml} (78%) create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webservices.xml create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/QueryProtocolRestService.java create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryObjectsRestService.java create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RepositoryItemsRestService.java delete mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/ServiceUrlFactory.java create mode 100644 edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/webServiceBeans.xml diff --git a/cots/org.apache.commons.cxf/META-INF/MANIFEST.MF b/cots/org.apache.commons.cxf/META-INF/MANIFEST.MF index b6ff1f1b99..be6018b3cf 100644 --- a/cots/org.apache.commons.cxf/META-INF/MANIFEST.MF +++ b/cots/org.apache.commons.cxf/META-INF/MANIFEST.MF @@ -24,6 +24,8 @@ Bundle-ClassPath: cxf-2.5.0.jar, Export-Package: javax.servlet, javax.servlet.http, javax.ws.rs, + javax.ws.rs.core, + javax.ws.rs.ext, org.apache.cxf.annotations, org.apache.cxf.binding.soap, org.apache.cxf.binding.soap.blueprint, diff --git a/edexOsgi/build.edex/esb/bin/setup.env b/edexOsgi/build.edex/esb/bin/setup.env index e765f2f1d7..2243d43854 100644 --- a/edexOsgi/build.edex/esb/bin/setup.env +++ b/edexOsgi/build.edex/esb/bin/setup.env @@ -28,7 +28,6 @@ export DATADELIVERY_PORT=9588 # Currently the registry is hosted on datadelivery, but this could be changed in the future export EBXML_REGISTRY_HOST=${DATADELIVERY_HOST} export EBXML_REGISTRY_PORT=${DATADELIVERY_PORT} -export EBXML_REGISTRY_SOAP_PORT=10144 export EBXML_REGISTRY_REPLICATION=1 # moved here from environment.xml @@ -39,8 +38,8 @@ export JMS_SERVER=tcp://localhost:5672 export RADAR_SERVER=tcp://localhost:8813 export DATADELIVERY_SERVER=http://${DATADELIVERY_HOST}:${DATADELIVERY_PORT}/services export EBXML_REGISTRY_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_REGISTRY_PORT}/services -export EBXML_REGISTRY_LCM_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_REGISTRY_SOAP_PORT}/lifecycleManager?WSDL -export EBXML_REGISTRY_QUERY_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_REGISTRY_SOAP_PORT}/queryManager?WSDL +export EBXML_REGISTRY_LCM_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_REGISTRY_PORT}/lifecycleManager?WSDL +export EBXML_REGISTRY_QUERY_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_REGISTRY_PORT}/queryManager?WSDL export NCF_BANDWIDTH_MANAGER_SERVICE=http://${DATADELIVERY_HOST}:9590/services # set the AWIPS II shared directory diff --git a/edexOsgi/build.edex/esb/conf/spring/edex-db.xml b/edexOsgi/build.edex/esb/conf/spring/edex-db.xml new file mode 100644 index 0000000000..1fa104e136 --- /dev/null +++ b/edexOsgi/build.edex/esb/conf/spring/edex-db.xml @@ -0,0 +1,54 @@ + + + + + + + + + com.raytheon.uf.common.dataplugin.text + com.raytheon.edex.plugin.shef + + + + + + file:///${edex.home}/conf/db/hibernateConfig/metadata/hibernate.cfg.xml + + + + + + + + + + + + + + file:///${edex.home}/conf/db/hibernateConfig/maps/hibernate.cfg.xml + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/build.edex/esb/conf/spring/edex.xml b/edexOsgi/build.edex/esb/conf/spring/edex.xml index 1506bca7e5..c3e470f8a1 100644 --- a/edexOsgi/build.edex/esb/conf/spring/edex.xml +++ b/edexOsgi/build.edex/esb/conf/spring/edex.xml @@ -12,8 +12,9 @@ http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> - - + + + @@ -279,41 +280,6 @@ - - - - - com.raytheon.uf.common.dataplugin.text - com.raytheon.edex.plugin.shef - - - - - - file:///${edex.home}/conf/db/hibernateConfig/metadata/hibernate.cfg.xml - - - - - - - - - - - - - file:///${edex.home}/conf/db/hibernateConfig/maps/hibernate.cfg.xml - - - - - - diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-edex-impl.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-edex-impl.xml deleted file mode 100644 index 6b14576b22..0000000000 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-edex-impl.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-impl.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-impl.xml index 78231ceb74..b24dd4dff9 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-impl.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-impl.xml @@ -4,57 +4,6 @@ http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-registry-init.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-registry-init.xml new file mode 100644 index 0000000000..d84fc69a37 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-registry-init.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-web.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml similarity index 78% rename from edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-web.xml rename to edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml index 831fa99c02..d1b1f11c06 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-web.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml @@ -37,7 +37,7 @@ - + @@ -52,16 +52,4 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webservices.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webservices.xml new file mode 100644 index 0000000000..13a22b82fc --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webservices.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-xacml.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-xacml.xml index a086e67859..2e6271f021 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-xacml.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-xacml.xml @@ -4,6 +4,24 @@ http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + + + + + + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml.xml index 02236cfec5..fced77072d 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml.xml @@ -1,50 +1,26 @@ - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/QueryManagerImpl.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/QueryManagerImpl.java index 4d1e7cde70..2cad222aa1 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/QueryManagerImpl.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/QueryManagerImpl.java @@ -202,15 +202,7 @@ public class QueryManagerImpl implements QueryManager { if (lang != null) { // TODO: Add support for specifying the lang attribute - response.getException() - .add(EbxmlExceptionUtil - .createRegistryException( - UnsupportedCapabilityExceptionType.class, - "", - "lang attribute not currently supported", - "This EBXML registry does not currently support the lang attribute on the QueryRequest object", - ErrorSeverity.WARNING, statusHandler)); - response.setStatus(RegistryResponseStatus.PARTIAL_SUCCESS); + statusHandler.warn("Lang attribute currently not supported."); } IRegistryQuery query = getQuery(queryType); diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/AbstractEbxmlQuery.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/AbstractEbxmlQuery.java index 64f20a5fb7..ce528dd7bb 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/AbstractEbxmlQuery.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/AbstractEbxmlQuery.java @@ -36,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional; import com.raytheon.uf.common.registry.constants.ErrorSeverity; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectTypeDao; +import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao; import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; import com.raytheon.uf.edex.registry.ebxml.services.query.QueryManagerImpl; import com.raytheon.uf.edex.registry.ebxml.services.query.QueryManagerImpl.RETURN_TYPE; @@ -79,7 +79,7 @@ public abstract class AbstractEbxmlQuery implements IRegistryQuery { protected RETURN_TYPE returnType; - protected RegistryObjectTypeDao registryObjectDao; + protected RegistryObjectDao registryObjectDao; public void executeQuery(QueryRequest queryRequest, QueryResponse queryResponse) throws EbxmlRegistryException { @@ -218,8 +218,7 @@ public abstract class AbstractEbxmlQuery implements IRegistryQuery { return filterResults(results, null); } - public void setRegistryObjectDao( - RegistryObjectTypeDao registryObjectDao) { + public void setRegistryObjectDao(RegistryObjectDao registryObjectDao) { this.registryObjectDao = registryObjectDao; } diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/GetObjectById.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/GetObjectById.java index 4d51f8ebd7..14fd867886 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/GetObjectById.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/GetObjectById.java @@ -26,6 +26,8 @@ import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryResponse; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ObjectRefListType; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ObjectRefType; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.QueryType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectListType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType; import com.raytheon.uf.common.registry.constants.CanonicalQueryTypes; import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; @@ -49,7 +51,7 @@ import com.raytheon.uf.edex.registry.ebxml.services.query.types.CanonicalEbxmlQu * Jan 18, 2012 bphillip Initial creation * 3/18/2013 1802 bphillip Modified to use transaction boundaries and spring dao injection * 4/9/2013 1802 bphillip Changed abstract method signature, modified return processing, and changed static variables - * + * 4/19/2013 1931 bphillip Fixed null pointer issue * * * @author bphillip @@ -88,7 +90,6 @@ public class GetObjectById extends CanonicalEbxmlQuery { return; } ids.addAll(matchingIds); - } else { ids.add(id); } @@ -102,8 +103,15 @@ public class GetObjectById extends CanonicalEbxmlQuery { } queryResponse.setObjectRefList(objectRefList); } else { - queryResponse.getRegistryObjectList().getRegistryObject() - .addAll(registryObjectDao.getById(ids)); + List results = new ArrayList(); + if (ids.size() == 1) { + results.add(registryObjectDao.getById(ids.get(0))); + } else { + results.addAll(registryObjectDao.getById(ids)); + } + RegistryObjectListType objList = new RegistryObjectListType(); + objList.getRegistryObject().addAll(results); + queryResponse.setRegistryObjectList(objList); } } diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/QueryProtocolRestService.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/QueryProtocolRestService.java new file mode 100644 index 0000000000..fdee897ef1 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/QueryProtocolRestService.java @@ -0,0 +1,217 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.registry.ebxml.services.rest; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.JAXBException; + +import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException; +import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.QueryManager; +import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryRequest; +import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryResponse; +import oasis.names.tc.ebxml.regrep.xsd.query.v4.ResponseOptionType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.QueryType; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.raytheon.uf.common.registry.constants.Languages; +import com.raytheon.uf.common.registry.constants.QueryReturnTypes; +import com.raytheon.uf.common.serialization.JAXBManager; +import com.raytheon.uf.edex.registry.ebxml.util.EbxmlObjectUtil; + +/** + * + * REST service implementation for the Query Protocol according to + * specifications in Section 12.2 of the ebRS specification + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#     Engineer    Description
+ * ------------ ----------  ----------- --------------------------
+ * 4/19/2013    1931        bphillip    Initial implementation
+ * 
+ * + * @author bphillip + * @version 1 + */ +@Path("/rest/search") +@Service +@Transactional +public class QueryProtocolRestService { + + /** The queryID canonical query parameter name */ + private static final String QUERY_ID = "queryId"; + + /** The depth canonical query parameter name */ + private static final String DEPTH = "depth"; + + /** The format canonical query parameter name */ + private static final String FORMAT = "format"; + + /** The federated canonical query parameter name */ + private static final String FEDERATED = "federated"; + + /** The federation canonical query parameter name */ + private static final String FEDERATION = "federation"; + + /** The matchOlderVersion canonical query parameter name */ + private static final String MATCH_OLDER_VERSIONS = "matchOlderVersions"; + + /** The startIndex canonical query parameter name */ + private static final String START_INDEX = "startIndex"; + + /** The lang canonical query parameter name */ + private static final String LANG = "lang"; + + /** The maxResults canonical query parameter name */ + private static final String MAX_RESULTS = "maxResults"; + + /** Convenience list of all the canonical query parameter names */ + private static final List CANONICAL_QUERY_PARAMETERS; + + static { + CANONICAL_QUERY_PARAMETERS = new ArrayList(); + CANONICAL_QUERY_PARAMETERS.add(QUERY_ID); + CANONICAL_QUERY_PARAMETERS.add(DEPTH); + CANONICAL_QUERY_PARAMETERS.add(FORMAT); + CANONICAL_QUERY_PARAMETERS.add(FEDERATED); + CANONICAL_QUERY_PARAMETERS.add(FEDERATION); + CANONICAL_QUERY_PARAMETERS.add(MATCH_OLDER_VERSIONS); + CANONICAL_QUERY_PARAMETERS.add(START_INDEX); + CANONICAL_QUERY_PARAMETERS.add(LANG); + CANONICAL_QUERY_PARAMETERS.add(MAX_RESULTS); + + } + + /** The local query manager */ + private QueryManager queryManager; + + /** Jaxb Manager for marshalling the response */ + private JAXBManager responseJaxb; + + /** + * Creates a new QueryProtocolRestService instance + * + * @throws JAXBException + * If errors occur while initializing the JAXBManager + */ + public QueryProtocolRestService() throws JAXBException { + responseJaxb = new JAXBManager(QueryResponse.class); + } + + /** + * Executes a query based on the submitted query parameters + * + * @param info + * The UriInfo containing the query parameters + * @return The marshalled QueryResponse + * @throws JAXBException + * If errors occur while marshalling the response + * @throws MsgRegistryException + * If errors occur in the registry while querying for the + * objects + */ + @GET + @Produces("text/xml") + public String executeQuery(@Context UriInfo info) throws JAXBException, + MsgRegistryException { + /* + * Extract out the canonical query parameters + */ + MultivaluedMap queryParameters = info + .getQueryParameters(); + String queryId = queryParameters.getFirst(QUERY_ID) == null ? "urn:oasis:names:tc:ebxml-regrep:query:GetObjectById" + : queryParameters.getFirst(QUERY_ID); + + BigInteger depth = queryParameters.getFirst(DEPTH) == null ? null + : new BigInteger(queryParameters.getFirst(DEPTH)); + + String format = queryParameters.getFirst(FORMAT); + + boolean federated = queryParameters.getFirst(FEDERATED) == null ? false + : Boolean.parseBoolean(queryParameters.getFirst(FEDERATED)); + + String federation = queryParameters.getFirst(FEDERATION); + + boolean matchOlderVersions = queryParameters + .getFirst(MATCH_OLDER_VERSIONS) == null ? true : Boolean + .parseBoolean(queryParameters.getFirst(MATCH_OLDER_VERSIONS)); + + BigInteger startIndex = queryParameters.getFirst(START_INDEX) == null ? new BigInteger( + "0") : new BigInteger(queryParameters.getFirst(START_INDEX)); + + String lang = queryParameters.getFirst(LANG) == null ? Languages.EN_US + : queryParameters.getFirst(LANG); + + BigInteger maxResults = queryParameters.getFirst(MAX_RESULTS) == null ? new BigInteger( + "0") : new BigInteger(queryParameters.getFirst(MAX_RESULTS)); + + /* + * Create the query request object + */ + QueryRequest restQueryRequest = new QueryRequest(); + ResponseOptionType responseOption = new ResponseOptionType(); + responseOption.setReturnType(QueryReturnTypes.REGISTRY_OBJECT); + responseOption.setReturnComposedObjects(true); + QueryType queryType = new QueryType(); + queryType.setQueryDefinition(queryId); + + restQueryRequest.setDepth(depth); + restQueryRequest.setFormat(format); + restQueryRequest.setFederated(federated); + restQueryRequest.setFederation(federation); + restQueryRequest.setMatchOlderVersions(matchOlderVersions); + restQueryRequest.setStartIndex(startIndex); + restQueryRequest.setLang(lang); + restQueryRequest.setMaxResults(maxResults); + restQueryRequest.setQuery(queryType); + restQueryRequest.setResponseOption(responseOption); + + /* + * Extract out any non-canonical query parameters and assign them as + * slots to be used as query specific arguments + */ + for (String key : queryParameters.keySet()) { + if (!CANONICAL_QUERY_PARAMETERS.contains(key)) { + EbxmlObjectUtil.addStringSlot(queryType, key, + queryParameters.getFirst(key), false); + } + } + return responseJaxb.marshalToXml(queryManager + .executeQuery(restQueryRequest)); + } + + public void setQueryManager(QueryManager queryManager) { + this.queryManager = queryManager; + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryObjectsRestService.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryObjectsRestService.java new file mode 100644 index 0000000000..0ab1425037 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryObjectsRestService.java @@ -0,0 +1,137 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.registry.ebxml.services.rest; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.xml.bind.JAXBException; + +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.AssociationType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.AuditableEventType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ClassificationNodeType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ClassificationSchemeType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ClassificationType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.CommentType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ExternalIdentifierType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ExternalLinkType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ExtrinsicObjectType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.FederationType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.NotificationType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.OrganizationType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.PartyType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.PersonType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.QueryDefinitionType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryPackageType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RoleType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ServiceBindingType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ServiceEndpointType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ServiceInterfaceType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ServiceType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.SubscriptionType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.TaxonomyElementType; +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.WorkflowActionType; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.raytheon.uf.common.serialization.JAXBManager; +import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao; + +/** + * + * REST service implementation for getting registry objects according to + * specifications in Section 12.1.1 of the ebRS specification + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#     Engineer    Description
+ * ------------ ----------  ----------- --------------------------
+ * 4/19/2013    1931        bphillip    Initial implementation
+ * 
+ * + * @author bphillip + * @version 1 + */ +@Path("/rest/registryObjects/{objectId}") +@Service +@Transactional +public class RegistryObjectsRestService { + + /** The data access object for getting registry objects */ + private RegistryObjectDao registryObjectDao; + + /** The jaxbManager used to marshal the response */ + private JAXBManager jaxbManager; + + /** + * Creates a new RegistryObjectRestService instance + * + * @throws JAXBException + * If errors occur while initializing the jaxb manager + */ + public RegistryObjectsRestService() throws JAXBException { + jaxbManager = new JAXBManager(RegistryObjectType.class, + AssociationType.class, AuditableEventType.class, + ClassificationType.class, ExternalIdentifierType.class, + ExternalLinkType.class, ExtrinsicObjectType.class, + CommentType.class, FederationType.class, + NotificationType.class, PartyType.class, + OrganizationType.class, PersonType.class, + QueryDefinitionType.class, RegistryPackageType.class, + RegistryType.class, RoleType.class, ServiceBindingType.class, + ServiceEndpointType.class, ServiceInterfaceType.class, + ServiceType.class, SubscriptionType.class, + TaxonomyElementType.class, ClassificationNodeType.class, + ClassificationSchemeType.class, WorkflowActionType.class); + } + + /** + * Gets a registry object based on the object ID specified in the path + * + * @param objectId + * The object Id of the object + * @return The marshalled object + * @throws JAXBException + * If errors occur marshalling the object + */ + @GET + @Produces("text/xml") + public String getRegistryObject(@PathParam("objectId") String objectId) + throws JAXBException { + Object obj = registryObjectDao.getById(objectId); + if (obj == null) { + throw new WebApplicationException(404); + } + return jaxbManager.marshalToXml(obj); + + } + + public void setRegistryObjectDao(RegistryObjectDao registryObjectDao) { + this.registryObjectDao = registryObjectDao; + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RepositoryItemsRestService.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RepositoryItemsRestService.java new file mode 100644 index 0000000000..8b747e03b0 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RepositoryItemsRestService.java @@ -0,0 +1,88 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.registry.ebxml.services.rest; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; + +import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ExtrinsicObjectType; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.raytheon.uf.edex.registry.ebxml.dao.ExtrinsicObjectDao; + +/** + * + * REST service implementation for getting repository items according to + * specifications in Section 12.1.2 of the ebRS specification + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#     Engineer    Description
+ * ------------ ----------  ----------- --------------------------
+ * 4/19/2013    1931        bphillip    Initial implementation
+ * 
+ * + * @author bphillip + * @version 1 + */ +@Path("/rest/repositoryItems/{repositoryItemId}") +@Service +@Transactional +public class RepositoryItemsRestService { + + /** + * The data access object for getting extrinsic objects containing + * repository items + */ + private ExtrinsicObjectDao extrinsicObjectDao; + + /** + * Gets the repository item for the object with the id specified in the url + * + * @param repositoryItemId + * The id of the object containing the repository item + * @return The repository item for the object specified + */ + @GET + @Produces("application/octet-stream") + public byte[] getRegistryObject( + @PathParam("repositoryItemId") String repositoryItemId) { + ExtrinsicObjectType obj = extrinsicObjectDao.getById(repositoryItemId); + if (obj == null) { + throw new WebApplicationException(404); + } + if (obj.getRepositoryItem() == null) { + throw new WebApplicationException(404); + } + return obj.getRepositoryItem(); + + } + + public void setExtrinsicObjectDao(ExtrinsicObjectDao extrinsicObjectDao) { + this.extrinsicObjectDao = extrinsicObjectDao; + } +} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/ServiceUrlFactory.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/ServiceUrlFactory.java deleted file mode 100644 index eeb547a5cd..0000000000 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/ServiceUrlFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.uf.edex.registry.ebxml.util; - -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; - -/** - * - * Bean used to dynamically assign the URL for a registry service via the spring - * configuration - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Feb 22, 2012 #184       bphillip     Initial creation
- * 
- * 
- * - * @author bphillip - * @version 1.0 - */ -public class ServiceUrlFactory { - - public ServiceUrlFactory() { - - } - - /** - * Gets a service address for the given service - * - * @param service - * The name of the service - * @param port - * The port on which the service will listen - * @return The URL String of the service endpoint - * @throws UnknownHostException - * If problems occur determining the host name - * @throws MalformedURLException - */ - public String getServiceAddress(String serviceName, int servicePort) - throws UnknownHostException, MalformedURLException { - URL url = new URL("http", InetAddress.getLocalHost().getHostAddress(), - servicePort, "/" + serviceName); - return url.toString(); - } -} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/AddRegistryParty.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/AddRegistryParty.java index 67f88ce337..c657c4c723 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/AddRegistryParty.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/AddRegistryParty.java @@ -21,26 +21,30 @@ package com.raytheon.uf.edex.registry.ebxml.web; import java.io.IOException; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; import oasis.names.tc.ebxml.regrep.xsd.lcm.v4.SubmitObjectsRequest; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.PartyType; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.raytheon.uf.common.registry.ebxml.RegistryUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.edex.registry.ebxml.dao.PartyDao; import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; import com.raytheon.uf.edex.registry.ebxml.services.lifecycle.LifecycleManagerImpl; /** * - * Servlet implementation used to add a user or organization to the registry + * Servlet implementation used to add a user or organization to the registry. + * FIXME: This class will be refactored in a later ticket * *
  * 
@@ -50,15 +54,17 @@ import com.raytheon.uf.edex.registry.ebxml.services.lifecycle.LifecycleManagerIm
  * ------------ ---------- ----------- --------------------------
  * 7/31/2012    #724       bphillip     Initial creation
  * 3/13/2013    1082       bphillip     Made transactional
+ * 4/19/2013    1931       bphillip     Refactored to use web application spring container and cxf services
  * 
  * 
* * @author bphillip * @version 1.0 */ +@Path("/AddRegistryParty") +@Service @Transactional -public class AddRegistryParty extends javax.servlet.http.HttpServlet implements - javax.servlet.Servlet { +public class AddRegistryParty { /** Serial */ private static final long serialVersionUID = 1422748054768442033L; @@ -73,93 +79,87 @@ public class AddRegistryParty extends javax.servlet.http.HttpServlet implements /** the page to display upon failure */ private static final String ERROR_RESPONSE_PAGE = "addPartyFailure"; - // FIXME: Add spring support to servlets + private PartyDao partyDao; - private PartyDao partyDao = (PartyDao) EDEXUtil.getESBComponent("partyDao"); + private LifecycleManagerImpl lcm; - private LifecycleManagerImpl lcm = (LifecycleManagerImpl) EDEXUtil - .getESBComponent("lcmServiceImpl"); + private RegistryWebUtil webUtil; - private RegistryWebUtil webUtil = (RegistryWebUtil) EDEXUtil - .getESBComponent("webUtil"); - - @Override - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws IOException { + @POST + @Produces("text/html") + public Response doPost(@Context HttpServletRequest request) + throws IOException { String partyId = request.getParameter(WebFields.ID.fieldName()); String objectType = request .getParameter(WebFields.OBJ_TYPE.fieldName()); PartyType existingParty = null; - try { - // The EDEX internal user cannot be modified - if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Cannot modify EDEX Internal User"); - } - - /* - * Check to see if the party already exists. If so, the user cannot - * be added - */ - existingParty = partyDao.getById(partyId); - - if (existingParty != null) { - statusHandler.error("Error adding " + objectType - + " to registry. " + objectType + " " + partyId - + " already exists"); - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, objectType - + " Already Exists"); - - } - - /* - * Create a new submit request containing the new party - */ - SubmitObjectsRequest submitRequest = null; - try { - submitRequest = webUtil.createParty(request); - } catch (EbxmlRegistryException e) { - statusHandler.error("Error creating " + objectType, e); - webUtil.sendErrorResponse( - request, - response, - ERROR_RESPONSE_PAGE, - partyId, - objectType, - "Error creating " + objectType + "\n" - + e.getLocalizedMessage()); - } - - // Submit the objects to the registry - try { - lcm.submitObjects(submitRequest); - webUtil.updatePC(request); - } catch (Exception e) { - statusHandler.error("Error submitting new " + objectType - + " to the registry", e); - webUtil.sendErrorResponse( - request, - response, - ERROR_RESPONSE_PAGE, - partyId, - objectType, - "Error submitting new " + objectType - + " to the registry\n" - + e.getLocalizedMessage()); - } - - // Send success response back to the caller - webUtil.sendSuccessResponse(request, response, - SUCCESS_RESPONSE_PAGE, partyId, objectType); - - } catch (ServletException e) { - statusHandler.error("Error generating response", e); - response.sendError(1, - "Error generating response: " + e.getLocalizedMessage()); + // The EDEX internal user cannot be modified + if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Cannot modify EDEX Internal User"); } + + /* + * Check to see if the party already exists. If so, the user cannot be + * added + */ + existingParty = partyDao.getById(partyId); + + if (existingParty != null) { + statusHandler.error("Error adding " + objectType + " to registry. " + + objectType + " " + partyId + " already exists"); + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, objectType + // + " Already Exists"); + + } + + /* + * Create a new submit request containing the new party + */ + SubmitObjectsRequest submitRequest = null; + try { + submitRequest = webUtil.createParty(request); + } catch (EbxmlRegistryException e) { + statusHandler.error("Error creating " + objectType, e); + return Response.serverError().build(); + // webUtil.sendErrorResponse( + // request, + // response, + // ERROR_RESPONSE_PAGE, + // partyId, + // objectType, + // "Error creating " + objectType + "\n" + // + e.getLocalizedMessage()); + } + + // Submit the objects to the registry + try { + lcm.submitObjects(submitRequest); + webUtil.updatePC(request); + } catch (Exception e) { + statusHandler.error("Error submitting new " + objectType + + " to the registry", e); + return Response.serverError().build(); + // webUtil.sendErrorResponse( + // request, + // response, + // ERROR_RESPONSE_PAGE, + // partyId, + // objectType, + // "Error submitting new " + objectType + // + " to the registry\n" + // + e.getLocalizedMessage()); + } + + // Send success response back to the caller + return Response.ok().build(); + // webUtil.sendSuccessResponse(request, response, SUCCESS_RESPONSE_PAGE, + // partyId, objectType); } public void setWebUtil(RegistryWebUtil webUtil) { diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/DeleteRegistryParty.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/DeleteRegistryParty.java index c2ced27a97..c110abcf5c 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/DeleteRegistryParty.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/DeleteRegistryParty.java @@ -21,24 +21,27 @@ package com.raytheon.uf.edex.registry.ebxml.web; import java.io.IOException; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.PartyType; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.raytheon.uf.common.registry.ebxml.RegistryUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.edex.registry.ebxml.dao.PartyDao; /** * * Servlet implementation used to delete a user or organization from the - * registry + * registry. FIXME: This class will be refactored in a later ticket * *
  * 
@@ -48,15 +51,17 @@ import com.raytheon.uf.edex.registry.ebxml.dao.PartyDao;
  * ------------ ---------- ----------- --------------------------
  * 7/31/2012    #724       bphillip     Initial creation
  * 3/13/2013    1082       bphillip     Made transactional
+ * 4/19/2013    1931       bphillip     Refactored to use web application spring container and cxf services
  * 
  * 
* * @author bphillip * @version 1.0 */ +@Path("/DeleteRegistryParty") +@Service @Transactional -public class DeleteRegistryParty extends javax.servlet.http.HttpServlet - implements javax.servlet.Servlet { +public class DeleteRegistryParty { /** The serial ID */ private static final long serialVersionUID = -9009661529309992652L; @@ -67,69 +72,65 @@ public class DeleteRegistryParty extends javax.servlet.http.HttpServlet /** The page to display upon failure */ private static final String ERROR_RESPONSE_PAGE = "deletePartyFailure"; - // FIXME: Add spring support to servlets + private PartyDao partyDao; - private PartyDao partyDao = (PartyDao) EDEXUtil.getESBComponent("partyDao"); - - private RegistryWebUtil webUtil = (RegistryWebUtil) EDEXUtil - .getESBComponent("webUtil"); + private RegistryWebUtil webUtil; /** The logger */ private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(DeleteRegistryParty.class); - @Override - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws IOException { - try { - String partyId = request.getParameter(WebFields.ID.fieldName()); - String objectType = request.getParameter(WebFields.OBJ_TYPE - .fieldName()); - PartyType existingParty = null; + @POST + @Produces("text/html") + public Response doPost(@Context HttpServletRequest request) + throws IOException { + String partyId = request.getParameter(WebFields.ID.fieldName()); + String objectType = request + .getParameter(WebFields.OBJ_TYPE.fieldName()); + PartyType existingParty = null; - // The EDEX internal user cannot be modified - if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Cannot remove EDEX Internal User"); - } - - /* - * Check if the party exists. If not, the party obviously cannot be - * deleted - */ - - existingParty = partyDao.getById(partyId); - - if (existingParty == null) { - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Unable to delete " + objectType + " " + partyId + ". " - + objectType + " does not exist"); - } - - /* - * Remove any associations to the party - */ - try { - webUtil.removeAssociations(existingParty); - webUtil.removeParty(existingParty); - } catch (Exception e) { - statusHandler.error("Error modifying user", e); - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Error removing associations to " + objectType + "\n" - + e.getLocalizedMessage()); - } - - // Send back a successful response to the requester - webUtil.sendSuccessResponse(request, response, - SUCCESS_RESPONSE_PAGE, partyId, objectType); - } catch (ServletException e) { - statusHandler.error("Error generating response", e); - response.sendError(1, - "Error generating response: " + e.getLocalizedMessage()); + // The EDEX internal user cannot be modified + if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Cannot remove EDEX Internal User"); } + + /* + * Check if the party exists. If not, the party obviously cannot be + * deleted + */ + + existingParty = partyDao.getById(partyId); + + if (existingParty == null) { + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Unable to delete " + objectType + " " + partyId + ". " + // + objectType + " does not exist"); + } + + /* + * Remove any associations to the party + */ + try { + webUtil.removeAssociations(existingParty); + webUtil.removeParty(existingParty); + } catch (Exception e) { + statusHandler.error("Error modifying user", e); + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Error removing associations to " + objectType + "\n" + // + e.getLocalizedMessage()); + } + + // Send back a successful response to the requester + // webUtil.sendSuccessResponse(request, response, + // SUCCESS_RESPONSE_PAGE, partyId, objectType); + return Response.ok().build(); } public void setPartyDao(PartyDao partyDao) { diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/ModifyRegistryParty.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/ModifyRegistryParty.java index dec99be32d..6907140832 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/ModifyRegistryParty.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/ModifyRegistryParty.java @@ -21,19 +21,22 @@ package com.raytheon.uf.edex.registry.ebxml.web; import java.io.IOException; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; import oasis.names.tc.ebxml.regrep.xsd.lcm.v4.SubmitObjectsRequest; import oasis.names.tc.ebxml.regrep.xsd.rim.v4.PartyType; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.raytheon.uf.common.registry.ebxml.RegistryUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.edex.registry.ebxml.dao.PartyDao; import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; import com.raytheon.uf.edex.registry.ebxml.services.lifecycle.LifecycleManagerImpl; @@ -41,6 +44,7 @@ import com.raytheon.uf.edex.registry.ebxml.services.lifecycle.LifecycleManagerIm /** * * Servlet implementation used to modify a user or organization in the registry + * FIXME: This class will be refactored in a later ticket * *
  * 
@@ -50,15 +54,17 @@ import com.raytheon.uf.edex.registry.ebxml.services.lifecycle.LifecycleManagerIm
  * ------------ ---------- ----------- --------------------------
  * 7/31/2012    #724       bphillip     Initial creation
  * 3/13/2013    1082       bphillip     Made transactional
+ * 4/19/2013    1931       bphillip     Refactored to use web application spring container and cxf services
  * 
  * 
* * @author bphillip * @version 1.0 */ +@Path("/DeleteRegistryParty") +@Service @Transactional -public class ModifyRegistryParty extends javax.servlet.http.HttpServlet - implements javax.servlet.Servlet { +public class ModifyRegistryParty { /** The serial ID */ private static final long serialVersionUID = -2361555059266130462L; @@ -69,93 +75,88 @@ public class ModifyRegistryParty extends javax.servlet.http.HttpServlet /** Page to display upon failure */ private static final String ERROR_RESPONSE_PAGE = "modifyPartyFailure"; - // FIXME: Add spring support to servlets + private PartyDao partyDao; - private PartyDao partyDao = (PartyDao) EDEXUtil.getESBComponent("partyDao"); + private LifecycleManagerImpl lcm; - private LifecycleManagerImpl lcm = (LifecycleManagerImpl) EDEXUtil - .getESBComponent("lcmServiceImpl"); - - private RegistryWebUtil webUtil = (RegistryWebUtil) EDEXUtil - .getESBComponent("webUtil"); + private RegistryWebUtil webUtil; /** The logger */ private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(ModifyRegistryParty.class); - @Override - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws IOException { + @POST + @Produces("text/html") + public Response doPost(@Context HttpServletRequest request) + throws IOException { - try { - String partyId = request.getParameter(WebFields.ID.fieldName()); - String objectType = request.getParameter(WebFields.OBJ_TYPE - .fieldName()); - PartyType existingParty = null; + String partyId = request.getParameter(WebFields.ID.fieldName()); + String objectType = request + .getParameter(WebFields.OBJ_TYPE.fieldName()); + PartyType existingParty = null; - // The EDEX internal user cannot be modified - if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Cannot modify EDEX Internal User"); - } - - /* - * Check if the party already exists. If the party does not exist, - * the party cannot be modified. An error response is sent to the - * requester - */ - existingParty = partyDao.getById(partyId); - - if (existingParty == null) { - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Unable to modify " + objectType + " " + partyId + ". " - + objectType + " does not exist"); - } - - /* - * Create the submit request - */ - SubmitObjectsRequest submitRequest = null; - try { - submitRequest = webUtil.createParty(request); - } catch (EbxmlRegistryException e) { - statusHandler.error("Error modifying user", e); - webUtil.sendErrorResponse( - request, - response, - ERROR_RESPONSE_PAGE, - partyId, - objectType, - "Error modifying " + objectType + "\n" - + e.getLocalizedMessage()); - } - - /* - * Remove any associations originating from the modified party - */ - try { - webUtil.removeAssociationsFrom(existingParty); - lcm.submitObjects(submitRequest); - webUtil.updatePC(request); - } catch (Exception e) { - statusHandler.error("Error modifying user", e); - webUtil.sendErrorResponse(request, response, - ERROR_RESPONSE_PAGE, partyId, objectType, - "Error removing associations to " + objectType + "\n" - + e.getLocalizedMessage()); - } - /* - * Send back success message to the requester - */ - webUtil.sendSuccessResponse(request, response, - SUCCESS_RESPONSE_PAGE, partyId, objectType); - } catch (ServletException e) { - statusHandler.error("Error generating response", e); - response.sendError(1, - "Error generating response: " + e.getLocalizedMessage()); + // The EDEX internal user cannot be modified + if (partyId.equals(RegistryUtil.DEFAULT_OWNER)) { + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Cannot modify EDEX Internal User"); } + + /* + * Check if the party already exists. If the party does not exist, the + * party cannot be modified. An error response is sent to the requester + */ + existingParty = partyDao.getById(partyId); + + if (existingParty == null) { + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Unable to modify " + objectType + " " + partyId + ". " + // + objectType + " does not exist"); + } + + /* + * Create the submit request + */ + SubmitObjectsRequest submitRequest = null; + try { + submitRequest = webUtil.createParty(request); + } catch (EbxmlRegistryException e) { + statusHandler.error("Error modifying user", e); + return Response.serverError().build(); + // webUtil.sendErrorResponse( + // request, + // response, + // ERROR_RESPONSE_PAGE, + // partyId, + // objectType, + // "Error modifying " + objectType + "\n" + // + e.getLocalizedMessage()); + } + + /* + * Remove any associations originating from the modified party + */ + try { + webUtil.removeAssociationsFrom(existingParty); + lcm.submitObjects(submitRequest); + webUtil.updatePC(request); + } catch (Exception e) { + statusHandler.error("Error modifying user", e); + return Response.serverError().build(); + // webUtil.sendErrorResponse(request, response, + // ERROR_RESPONSE_PAGE, partyId, objectType, + // "Error removing associations to " + objectType + "\n" + // + e.getLocalizedMessage()); + } + /* + * Send back success message to the requester + */ + // webUtil.sendSuccessResponse(request, response, SUCCESS_RESPONSE_PAGE, + // partyId, objectType); + return Response.ok().build(); } public void setPartyDao(PartyDao partyDao) { diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/RegistryWebUtil.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/RegistryWebUtil.java index d46be28786..3bbb7e3a64 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/RegistryWebUtil.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/web/RegistryWebUtil.java @@ -77,6 +77,10 @@ public class RegistryWebUtil { private LifecycleManagerImpl lcm; + private ClassificationNodeDao classificationNodeDao; + + private PersonDao personDao; + /** * Creates a party (user or organization) based on parameters contained in * the servlet request @@ -91,7 +95,6 @@ public class RegistryWebUtil { throws EbxmlRegistryException { List objectList = new ArrayList(); - ClassificationNodeDao dao = new ClassificationNodeDao(); String partyId = request.getParameter("id"); PartyType party = null; @@ -146,7 +149,6 @@ public class RegistryWebUtil { } // Creating an organization else { - PersonDao personDao = new PersonDao(); party = new OrganizationType(); party.setLid(partyId); party.setOwner(RegistryUtil.DEFAULT_OWNER); @@ -173,7 +175,7 @@ public class RegistryWebUtil { // Assign the postal address PostalAddressType address = new PostalAddressType(); - address.setType(dao.getNodeFromCode(request + address.setType(classificationNodeDao.getNodeFromCode(request .getParameter(WebFields.ADDRESS_TYPE.fieldName()))); address.setStreet(request.getParameter(WebFields.ADDRESS_1.fieldName())); address.setStreetNumber(request.getParameter(WebFields.ADDRESS_2 @@ -188,7 +190,7 @@ public class RegistryWebUtil { // Assign the telephone number TelephoneNumberType phone = new TelephoneNumberType(); - phone.setType(dao.getNodeFromCode(request + phone.setType(classificationNodeDao.getNodeFromCode(request .getParameter(WebFields.TELEPHONE_TYPE.fieldName()))); phone.setAreaCode(request.getParameter(WebFields.AREA_CODE.fieldName())); phone.setNumber(request.getParameter(WebFields.PHONE_1.fieldName()) @@ -198,7 +200,7 @@ public class RegistryWebUtil { // Assign the email address EmailAddressType email = new EmailAddressType(); - email.setType(dao.getNodeFromCode(request + email.setType(classificationNodeDao.getNodeFromCode(request .getParameter(WebFields.EMAIL_TYPE.fieldName()))); email.setAddress(request.getParameter(WebFields.EMAIL.fieldName())); party.getEmailAddress().add(email); @@ -537,4 +539,13 @@ public class RegistryWebUtil { this.lcm = lcm; } + public void setClassificationNodeDao( + ClassificationNodeDao classificationNodeDao) { + this.classificationNodeDao = classificationNodeDao; + } + + public void setPersonDao(PersonDao personDao) { + this.personDao = personDao; + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationInterface.html b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationInterface.html index c33b79aff3..05be8d447e 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationInterface.html +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationInterface.html @@ -11,11 +11,11 @@ - - - - - + + + + + Data Delivery Registry Admin: Add New Organization diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationMenu.html b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationMenu.html index 68cc06b13a..38d6c91b70 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationMenu.html +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryOrganizationMenu.html @@ -11,10 +11,10 @@ - - - - + + + + Data Delivery Registry Organization Admin diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserInterface.html b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserInterface.html index bda997b9a8..cbeee3dc8b 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserInterface.html +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserInterface.html @@ -11,11 +11,11 @@ - - - - - + + + + + Data Delivery Registry Admin: Add New User diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserMenu.html b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserMenu.html index 6dbf734067..1893f49a23 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserMenu.html +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/RegistryUserMenu.html @@ -11,10 +11,10 @@ - - - - + + + + Data Delivery Registry Admin diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/WEB-INF/web.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/WEB-INF/web.xml index 5d518df8da..1d64769836 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/WEB-INF/web.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/WEB-INF/web.xml @@ -13,31 +13,30 @@ Data Delivery - - AddRegistryParty - AddRegistryParty - com.raytheon.uf.edex.registry.ebxml.web.AddRegistryParty - + RegistryWebServiceServlet + org.apache.cxf.transport.servlet.CXFServlet + + config-location + /webServiceBeans.xml + + + static-welcome-file + /RegistryUserMenu.html + + + static-resources-list + .*\.html .*\.js .*\.css + + 1 - - - ModifyRegistryParty - ModifyRegistryParty - com.raytheon.uf.edex.registry.ebxml.web.ModifyRegistryParty - - + + RegistryWebServiceServlet + /* + - - DeleteRegistryParty - DeleteRegistryParty - com.raytheon.uf.edex.registry.ebxml.web.DeleteRegistryParty - - - - - DWR Servlet + DWR Servlet dwr-invoker uk.ltd.getahead.dwr.DWRServlet @@ -47,22 +46,7 @@ /dwr/* - - AddRegistryParty - /AddRegistryParty - - - - ModifyRegistryParty - /ModifyRegistryParty - - - - DeleteRegistryParty - /DeleteRegistryParty - - - /RegistryUserMenu.html + RegistryUserMenu.html diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/webServiceBeans.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/webServiceBeans.xml new file mode 100644 index 0000000000..416a021222 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/web/webServiceBeans.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java b/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java index 20075b0deb..7d9e523a20 100644 --- a/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java +++ b/tests/integration/com/raytheon/uf/edex/registry/ebxml/dao/LifecycleManagerSubmitObjectsTest.java @@ -71,7 +71,8 @@ import com.raytheon.uf.edex.database.dao.DatabaseUtil; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML, - "/spring/ebxml.xml", "/spring/ebxml-impl.xml", + "/spring/ebxml.xml", "/spring/ebxml-xacml.xml", + "/spring/ebxml-webservices.xml", "/spring/ebxml-impl.xml", "/spring/ebxml-querytypes.xml", "/spring/ebxml-registry-dao.xml", "/ebxml/unit-test-ebxml-beans.xml", "/unit-test-localization-beans.xml" }) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)