[Registry-dev] svn commit r15488 - in
trunk/registry/modules/core/src: main/java/org/wso2/registry/app
main/resources/org/wso2/registry/i18n
test/java/org/wso2/registry/app
svn at wso2.org
svn at wso2.org
Wed Apr 2 04:51:47 PDT 2008
Author: deepal
Date: Wed Apr 2 04:51:32 2008
New Revision: 15488
Log:
added association support to APP as well
Added:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedDependecyTest.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java Wed Apr 2 04:51:32 2008
@@ -44,4 +44,8 @@
static final String PARAMETER_ASSOCIATE_ASPECT = "associateAspect";
static final String PARAMETER_INVOKE_ASPECT = "invokeAspect";
static final String PARAMETER_GET_ASPECT_ACTIONS = "getAspectActions";
+
+ static final String PARAMETER_ADD_ASSOCIATION = "associate";
+ static final String PARAMETER_GET_ALL_ASSOCIATION = "getAllassociations";
+ static final String PARAMETER_GET_ALL_ASSOCIATION_FOR_TYPE = "getAssociations";
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java Wed Apr 2 04:51:32 2008
@@ -303,16 +303,22 @@
String commentString = entry.getContent();
getSecureRegistry(request)
.editComment(values[0] + ";" + values[1], commentString);
- } else if (PARAMETER_INVOKE_ASPECT.equals(operation)) {
+ } else if (PARAMETER_INVOKE_ASPECT.equals(operation)) {
String acpectString = entry.getContent();
String action = entry.getSummary();
getSecureRegistry(request)
.invokeAspect(values[0] , acpectString , action);
- } else if (PARAMETER_ASSOCIATE_ASPECT.equals(operation)) {
+ } else if (PARAMETER_ASSOCIATE_ASPECT.equals(operation)) {
String acpectString = entry.getContent();
getSecureRegistry(request)
.associateAspect(values[0] , acpectString);
+ } else if (PARAMETER_ADD_ASSOCIATION.equals(operation)) {
+ String destinationPath = entry.getContent();
+ String associationType = entry.getSummary();
+ getSecureRegistry(request)
+ .addAssociation(values[0] , destinationPath ,associationType);
}
+
}
return new EmptyResponseContext(200);
} catch (Exception pe) {
@@ -457,8 +463,21 @@
} catch (RegistryException e) {
return new StringResponseContext(request.getAbdera(), e, 500);
}
+
} else if (PARAMETER_RESOURCE_EXIST.equals(operation)) {
feed = getFeedResourceExist(abdera, resourcePath, request);
+ } else if (PARAMETER_GET_ALL_ASSOCIATION.equals(operation)) {
+ try {
+ feed = getFeedAllAssociation(abdera, resourcePath, null ,request);
+ } catch (RegistryException e) {
+ return new StringResponseContext(request.getAbdera(), e, 500);
+ }
+ } else if (PARAMETER_GET_ALL_ASSOCIATION_FOR_TYPE.equals(operation)) {
+ try {
+ feed = getFeedAllAssociation(abdera, resourcePath , parameter, request);
+ } catch (RegistryException e) {
+ return new StringResponseContext(request.getAbdera(), e, 500);
+ }
} else if (PARAMETER_GET_ASPECT_ACTIONS.equals(operation)) {
try {
@@ -1005,6 +1024,38 @@
return feed;
}
+
+ private Feed getFeedAllAssociation(Abdera abdera,
+ String path,
+ String associateType,
+ RequestContext request) throws RegistryException {
+ Association associations [] ;
+ if(associateType == null ){
+ associations = getSecureRegistry(request).getAllAssociation(path);
+ } else {
+ associations = getSecureRegistry(request).getAllAssociation(path , associateType);
+ }
+
+ Feed feed = getFeedInstance(abdera);
+ feed.setId("http://wso2.org/jdbcregistry,2007:associations");
+ feed.setTitle("Logs for the resource" + path);
+ feed.addLink("", "self");
+ feed.setUpdated(new Date());
+
+ for (int i = 0; i < associations.length; i++) {
+ Association association = associations[i];
+ Entry entry = abdera.getFactory().newEntry();
+ entry.setContent(association.getDestinationPath());
+ if(associateType == null) {
+ entry.setSummary(association.getAssociationType()) ;
+ }
+ feed.addEntry(entry);
+
+ }
+
+ return feed;
+ }
+
/**
* This method to get a feed element representing , whether a feed exist or not
*
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java Wed Apr 2 04:51:32 2008
@@ -454,16 +454,77 @@
public void addAssociation(String sourcePath, String associationPaths, String associationType)
throws RegistryException {
- throw new UnsupportedOperationException();
+ Abdera abdera = new Abdera();
+ AbderaClient abderaClient = new AbderaClient(abdera);
+ Entry entry = abdera.getFactory().newEntry();
+ entry.setContent(associationPaths);
+ entry.setSummary(associationType);
+ ClientResponse resp = abderaClient.put(baseURI + encodeURL(sourcePath +
+ RegistryConstants.URL_SEPARATOR +
+ PARAMETER_ADD_ASSOCIATION),
+ entry,
+ getAuthorization());
+ if (resp.getType() == Response.ResponseType.SUCCESS) {
+ log.info(Messages.getMessage("resource.associated", sourcePath));
+ } else {
+ log.error(Messages.getMessage("resource.associated.fails", sourcePath));
+ throw new RegistryException(Messages.getMessage("resource.tag.fails", sourcePath));
+ }
}
public Association[] getAllAssociation(String resourcePath) throws RegistryException {
- throw new UnsupportedOperationException();
+ Abdera abdera = new Abdera();
+ AbderaClient abderaClient = new AbderaClient(abdera);
+ ClientResponse clientResponse = abderaClient.get(baseURI +
+ encodeURL(resourcePath +
+ RegistryConstants.URL_SEPARATOR +
+ PARAMETER_GET_ALL_ASSOCIATION),
+ getAuthorization());
+ Document introspection =
+ clientResponse.getDocument();
+ Feed feed = (Feed)introspection.getRoot();
+ List entries = feed.getEntries();
+ Association associations[] = null;
+ if (entries != null) {
+ associations = new Association[entries.size()];
+ for (int i = 0; i < entries.size(); i++) {
+ Entry entry = (Entry)entries.get(i);
+ Association association = new Association();
+ association.setSourcePath(resourcePath);
+ association.setDestinationPath(entry.getContent());
+ association.setAssociationType(entry.getSummary());
+ associations[i] = association;
+ }
+ }
+ return associations;
}
public Association[] getAllAssociation(String resourcePath, String associationType) throws RegistryException {
- throw new UnsupportedOperationException();
+ Abdera abdera = new Abdera();
+ AbderaClient abderaClient = new AbderaClient(abdera);
+ ClientResponse clientResponse = abderaClient.get(baseURI +
+ encodeURL(resourcePath +
+ RegistryConstants.URL_SEPARATOR +
+ PARAMETER_GET_ALL_ASSOCIATION_FOR_TYPE + ":" + associationType),
+ getAuthorization());
+ Document introspection =
+ clientResponse.getDocument();
+ Feed feed = (Feed)introspection.getRoot();
+ List entries = feed.getEntries();
+ Association associations[] = null;
+ if (entries != null) {
+ associations = new Association[entries.size()];
+ for (int i = 0; i < entries.size(); i++) {
+ Entry entry = (Entry)entries.get(i);
+ Association association = new Association();
+ association.setSourcePath(resourcePath);
+ association.setDestinationPath(entry.getContent());
+ association.setAssociationType(associationType);
+ associations[i] = association;
+ }
+ }
+ return associations;
}
public void applyTag(String resourcePath, String tag) throws RegistryException {
Modified: trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
==============================================================================
--- trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties (original)
+++ trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties Wed Apr 2 04:51:32 2008
@@ -87,6 +87,7 @@
resource.commented=Resource commented {0}
resource.rated=Resource rated {0}.
resource.associated=Resource {0} associate with {1}.
+resource.associated.fails=Resource {0} associate with {1} failled.
invokeAspect=Resource {0} invoke aspect {1} with action {2}.
invokeAspect.fails=Resource {0} invoke aspect {1} with action {2}.
resource.associated.fail=Resource {0} associate with {1}.
Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedDependecyTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedDependecyTest.java Wed Apr 2 04:51:32 2008
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.app;
+
+import org.wso2.registry.jdbc.DependencyTest;
+
+import java.net.URL;
+
+public class APPbasedDependecyTest extends DependencyTest {
+ RegistryServer server = new RegistryServer();
+
+ public void setUp() {
+ try {
+ if (registry == null) {
+ server.start();
+ registry = new RemoteRegistry(new URL("http://localhost:8081/wso2registry/atom"),
+ "admin", "admin");
+ }
+ } catch (Exception e) {
+ fail("Failed to initialize the registry.");
+ }
+ }
+}
More information about the Registry-dev
mailing list