[Registry-dev] svn commit r15426 - 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
Tue Apr 1 01:13:13 PDT 2008


Author: deepal
Date: Tue Apr  1 01:12:06 2008
New Revision: 15426

Log:

adding lifecycle handling into APP level

Added:
   trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedLifeCycleTest.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/RegistryAtomProviderManager.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	Tue Apr  1 01:12:06 2008
@@ -39,4 +39,9 @@
     static final String PARAMETER_LOGS = "logs";
     static final String PARAMETER_QUERY = "query";
     static final String PARAMETER_RESOURCE_EXIST = "resourceExists";
+    
+    //Lifecycle
+    static final String PARAMETER_ASSOCIATE_ASPECT = "associateAspect";
+    static final String PARAMETER_INVOKE_ASPECT = "invokeAspect";
+    static final String PARAMETER_GET_ASPECT_ACTIONS = "getAspectActions";
 }

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	Tue Apr  1 01:12:06 2008
@@ -49,7 +49,6 @@
 import javax.xml.namespace.QName;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.net.URLEncoder;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.Map;
@@ -249,18 +248,6 @@
         if (!"".equals(entry_id)) {
             try {
                 getSecureRegistry(request).delete(entry_id);
-//                String values[] = splitPath(entry_id);
-//                if (values.length > 1) {
-//                    String operation = values[1];
-////                    String resourcePath = values[0];
-//                    if (PARAMETER_TAGS.equals(operation)) {
-//                        //TODO Need to implement this
-//                    }
-//                    //deleting something else, not a resource like Tag or comment
-//                } else {
-//                    // deleting a resource
-//                    getSecureRegistry(request).delete(entry_id);
-//                }
                 return new EmptyResponseContext(204);
             } catch (RegistryException e) {
                 return new StringResponseContext(request.getAbdera(), e, 500);
@@ -316,6 +303,15 @@
                     String commentString = entry.getContent();
                     getSecureRegistry(request)
                             .editComment(values[0] + ";" + values[1], commentString);
+                }   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)) {
+                    String acpectString = entry.getContent();
+                    getSecureRegistry(request)
+                            .associateAspect(values[0] , acpectString);
                 }
             }
             return new EmptyResponseContext(200);
@@ -463,6 +459,25 @@
                 }
             } else if (PARAMETER_RESOURCE_EXIST.equals(operation)) {
                 feed = getFeedResourceExist(abdera, resourcePath, request);
+            } else if (PARAMETER_GET_ASPECT_ACTIONS.equals(operation)) {
+                try {
+
+                    String[] versions = getSecureRegistry(request).getAspectActions(resourcePath ,parameter);
+                    Factory factory = abdera.getFactory();
+                    feed = factory.newFeed();
+                    feed.setId("http://wso2.org/jdbcregistry,atom:AspectActions");
+                    feed.setTitle("Available versions for " + resourcePath);
+                    feed.setSubtitle("AspectActions for " + resourcePath);
+                    feed.setUpdated(new Date());
+                    feed.addLink(request.getBaseUri() + "atom" + resourcePath);
+                    feed.addLink(request.getBaseUri() + "atom" + resourcePath, "self");
+                    //Versions will be added as entries
+                    createEntriesFromStringArray(versions, request.getBaseUri().toString(),
+                            abdera, "aspectActionsLink",
+                            feed);
+                } catch (RegistryException e) {
+                    return new StringResponseContext(request.getAbdera(), e, 500);
+                }
             } else {
                 return createErrorResponse();
             }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProviderManager.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProviderManager.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProviderManager.java	Tue Apr  1 01:12:06 2008
@@ -20,6 +20,7 @@
 
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.impl.AbstractSingletonProviderManager;
+import org.apache.abdera.model.Link;
 
 
 public class RegistryAtomProviderManager extends AbstractSingletonProviderManager {

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	Tue Apr  1 01:12:06 2008
@@ -825,31 +825,71 @@
         entry.addSimpleExtension(new QName(NAMESPACE, "rolename"), roleName);
         entry.addSimpleExtension(new QName(NAMESPACE, "friendlyName"), friendlyName);
 
-        ClientResponse resp = abderaClient.post(baseURI + encodeURL(RegistryConstants.URL_SEPARATOR +
+        abderaClient.post(baseURI + encodeURL(RegistryConstants.URL_SEPARATOR +
 
                 PARAMETER_ADD_USER),
                 entry,
                 getAuthorization());
-
-//        if (resp.getType() == Response.ResponseType.SUCCESS) {
-//            log.info(Messages.getMessage("user.created", "/"));
-//        } else {
-//            log.error(Messages.getMessage("user.createation.failed", "/"));
-//            throw new RegistryException(Messages.getMessage("user.createation.failed", "/"));
-//        }
     }
 
 
     public void associateAspect(String resourcePath, String aspect) throws RegistryException {
-        throw new UnsupportedOperationException();
+        Abdera abdera = new Abdera();
+        AbderaClient abderaClient = new AbderaClient(abdera);
+        Entry entry = abdera.getFactory().newEntry();
+        entry.setContent("" + aspect);
+        ClientResponse resp = abderaClient.put(baseURI + encodeURL(resourcePath +
+                RegistryConstants.URL_SEPARATOR +
+                PARAMETER_ASSOCIATE_ASPECT),
+                entry,
+                getAuthorization());
+        if (resp.getType() == Response.ResponseType.SUCCESS) {
+            log.info(Messages.getMessage("resource.associated", resourcePath , aspect));
+        } else {
+            log.error(Messages.getMessage("resource.associated.fail", resourcePath , aspect));
+            throw new RegistryException(Messages.getMessage("resource.associated", resourcePath , aspect));
+        }
     }
 
     public void invokeAspect(String resourcePath, String aspectName, String action) throws RegistryException {
-        throw new UnsupportedOperationException();
+        Abdera abdera = new Abdera();
+        AbderaClient abderaClient = new AbderaClient(abdera);
+        Entry entry = abdera.getFactory().newEntry();
+        entry.setContent("" + aspectName);
+        entry.setSummary(action);
+        ClientResponse resp = abderaClient.put(baseURI + encodeURL(resourcePath +
+                RegistryConstants.URL_SEPARATOR +
+                PARAMETER_INVOKE_ASPECT),
+                entry,
+                getAuthorization());
+        if (resp.getType() == Response.ResponseType.SUCCESS) {
+            log.info(Messages.getMessage("invokeAspect", resourcePath , aspectName , action));
+        } else {
+            log.error(Messages.getMessage("resource.associated.fail", resourcePath , aspectName , action));
+            throw new RegistryException(Messages.getMessage("resource.associated", resourcePath , aspectName , action));
+        }
     }
 
     public String[] getAspectActions(String resourcePath, String aspectName)
             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_ASPECT_ACTIONS + ":" + aspectName),
+                        getAuthorization());
+        Document introspection =
+                clientResponse.getDocument();
+        Feed feed = (Feed)introspection.getRoot();
+        List entries = feed.getEntries();
+        if (entries != null) {
+            String[] aspectActions = new String[entries.size()];
+            for (int i = 0; i < entries.size(); i++) {
+                Entry entry = (Entry)entries.get(i);
+                aspectActions[i] = entry.getLink("aspectActionsLink").getHref().toString();
+            }
+            return aspectActions;
+        }
+        return new String[0];
     }
 }

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	Tue Apr  1 01:12:06 2008
@@ -86,6 +86,10 @@
 tag.removed=Resource tagged {0}.
 resource.commented=Resource commented {0}
 resource.rated=Resource rated {0}.
+resource.associated=Resource {0} associate with {1}.
+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}.
 add.resource.fail=Failed to add the resource to the path : {0}.
 rename.resource.fail=Failed to add the resource to the path : {0}.
 resource.tag.fails=Failed to tag the resource to the path : {0}.
@@ -100,44 +104,44 @@
 could.not.found.versionpath=Could not get the version paths of the resource {0} . Caused by: {1}
 unable.to.open.db=Couldn't open db connection
 not.a.valid.verion.path=Given path is not a path of a versioned resource.
-unable.to.restore=Could not restore the version {0} . Caused by: {1}
-######################## Error Messages Regarding Users ################
-errorAddingUserToRole = Error adding user to role. {0}
-duplicateUser = User name already exists. Please select another user name!
-exceptionOnConnectionOpen = Error occuered while connecting to Userstore
-sqlFileNotFound = SQL file not found for Default Realm
-errorModifyingUserStore = Error modifying the database
-errorReadingFromUserStore = Error reading users from database
-nullData = Invalid or Null data provided
-nullUser = Invalid user name provided
-nullRole = Invalid role name provided
-beanMappingNotfound = AuthenticationProvider Bean Mapping must be provided in file
-nullAuthProvider = AuthenticationProvider id must be present
-unsupportedCredential = Credential type unsupported
-initVerifier = Please call init() method in the verifier
-sendingMailProblems = Problems encountered while trying to send mail
-error= Error
-pendingAdd = Error occured while adding you. Please try again.
-invalidOrExpired = Invalid or expired
-exceptionOnAuthenticate = Exception on Authenticate
-getProperties = Getting properties of user
-unknownUserNameFormatInLDAP= Unknown format of Users in LDAP. We expect boo=username : object.class
-errorOpeningLDAP = Error opening connection to the LDAP directory. Please check connection name, password and url.
-bindFailedBecauseAuthenticationException = Failed to Authenticate because of bind failure
-errorInitializingConnection = Error Initializing Connection.
-copyAuthorizationFailedPermissionExist = Copying Authorizations failed, because permissions exist for the destination Resource
-errorCopyingAuthorizations = Error copying authorizations
-errorCreatingPasswordDigest = Error creating password digest
-unAuthorized = User is unauthorized to perform the action. Resource {0} action {1}
-authorizerNullatAuthorizer = Authorizer is null at AuthorizingRealm. This cannot be
-errorClosingConnection = Error closing connection!
-oldPasswordIncorrect = Cannot update password of user. Invalid user name password!
-nullRealm = Null Realm not permitted.
+unable.to.restore=Could not restore the version {0} . Caused by: {1}
+######################## Error Messages Regarding Users ################
+errorAddingUserToRole = Error adding user to role. {0}
+duplicateUser = User name already exists. Please select another user name!
+exceptionOnConnectionOpen = Error occuered while connecting to Userstore
+sqlFileNotFound = SQL file not found for Default Realm
+errorModifyingUserStore = Error modifying the database
+errorReadingFromUserStore = Error reading users from database
+nullData = Invalid or Null data provided
+nullUser = Invalid user name provided
+nullRole = Invalid role name provided
+beanMappingNotfound = AuthenticationProvider Bean Mapping must be provided in file
+nullAuthProvider = AuthenticationProvider id must be present
+unsupportedCredential = Credential type unsupported
+initVerifier = Please call init() method in the verifier
+sendingMailProblems = Problems encountered while trying to send mail
+error= Error
+pendingAdd = Error occured while adding you. Please try again.
+invalidOrExpired = Invalid or expired
+exceptionOnAuthenticate = Exception on Authenticate
+getProperties = Getting properties of user
+unknownUserNameFormatInLDAP= Unknown format of Users in LDAP. We expect boo=username : object.class
+errorOpeningLDAP = Error opening connection to the LDAP directory. Please check connection name, password and url.
+bindFailedBecauseAuthenticationException = Failed to Authenticate because of bind failure
+errorInitializingConnection = Error Initializing Connection.
+copyAuthorizationFailedPermissionExist = Copying Authorizations failed, because permissions exist for the destination Resource
+errorCopyingAuthorizations = Error copying authorizations
+errorCreatingPasswordDigest = Error creating password digest
+unAuthorized = User is unauthorized to perform the action. Resource {0} action {1}
+authorizerNullatAuthorizer = Authorizer is null at AuthorizingRealm. This cannot be
+errorClosingConnection = Error closing connection!
+oldPasswordIncorrect = Cannot update password of user. Invalid user name password!
+nullRealm = Null Realm not permitted.
 verifierUserDatabaseInit = Cannot create the Email Verifier Database
-errorSpecialCharactor = A special character in your data. Please remove {0}. 
-######### Users - only log messages
-getGenericUserByPattern = Searching user by generic pattern
-validatingCredentials = Validating users
-dbCreationNotSupported = Database creation not supported for this driver
-nullConnection = Cannot get connection. Contact Administrator
+errorSpecialCharactor = A special character in your data. Please remove {0}. 
+######### Users - only log messages
+getGenericUserByPattern = Searching user by generic pattern
+validatingCredentials = Validating users
+dbCreationNotSupported = Database creation not supported for this driver
+nullConnection = Cannot get connection. Contact Administrator
 unableToResetPool = Unable to reset realm. There are people holding instances of PoolManager

Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedLifeCycleTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedLifeCycleTest.java	Tue Apr  1 01:12:06 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008, 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.Registry;
+import org.wso2.registry.jdbc.LifeCycleTest;
+
+import java.net.URL;
+
+
+public class APPBasedLifeCycleTest extends LifeCycleTest {
+    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