Author: smarru
Date: Mon Sep 23 22:25:39 2013
New Revision: 1525720

URL: http://svn.apache.org/r1525720
Log:
Applying Viknes's patch for AIRAVATA-880

Added:
    
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/UserRegistry.java
    
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/resourcemappings/UserList.java
    
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
Modified:
    
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
    
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
    
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
    
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryConstants.java
    
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
    
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java

Modified: 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
 (original)
+++ 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
 Mon Sep 23 22:25:39 2013
@@ -56,6 +56,7 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.resources.ProjectResource;
 import 
org.apache.airavata.persistance.registry.jpa.resources.PublishWorkflowResource;
 import 
org.apache.airavata.persistance.registry.jpa.resources.ServiceDescriptorResource;
+import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
 import 
org.apache.airavata.persistance.registry.jpa.resources.UserWorkflowResource;
 import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
 import 
org.apache.airavata.persistance.registry.jpa.resources.WorkflowDataResource;
@@ -74,6 +75,7 @@ import org.apache.airavata.registry.api.
 import org.apache.airavata.registry.api.ProvenanceRegistry;
 import org.apache.airavata.registry.api.PublishedWorkflowRegistry;
 import org.apache.airavata.registry.api.ResourceMetadata;
+import org.apache.airavata.registry.api.UserRegistry;
 import org.apache.airavata.registry.api.UserWorkflowRegistry;
 import org.apache.airavata.registry.api.WorkspaceProject;
 import 
org.apache.airavata.registry.api.exception.AiravataRegistryUninitializedException;
@@ -147,6 +149,7 @@ public class AiravataJPARegistry extends
     private ProvenanceRegistry provenanceRegistry;
     private UserWorkflowRegistry userWorkflowRegistry;
     private PublishedWorkflowRegistry publishedWorkflowRegistry;
+    private UserRegistry userRegistry;
     private PasswordCallback callback;
     
     @Override
@@ -217,6 +220,7 @@ public class AiravataJPARegistry extends
             provenanceRegistry = 
(ProvenanceRegistry)getClassInstance(ConfigurationRegistry.class,RegistryConstants.PROVENANCE_REGISTRY_ACCESSOR_CLASS);
             userWorkflowRegistry = 
(UserWorkflowRegistry)getClassInstance(ConfigurationRegistry.class,RegistryConstants.USER_WF_REGISTRY_ACCESSOR_CLASS);
             publishedWorkflowRegistry = 
(PublishedWorkflowRegistry)getClassInstance(ConfigurationRegistry.class,RegistryConstants.PUBLISHED_WF_REGISTRY_ACCESSOR_CLASS);
+            userRegistry = 
(UserRegistry)getClassInstance(ConfigurationRegistry.class,RegistryConstants.USER_REGISTRY_ACCESSOR_CLASS);
         } catch (AiravataConfigurationException e) {
             throw new RegistryException("An error occured when attempting to 
determine any custom implementations of the registries!!!", e);
         }
@@ -2460,6 +2464,21 @@ public class AiravataJPARegistry extends
                return statusData;
        }
        
+       @Override
+       public List<AiravataUser> getUsers() throws RegistryException {
+               if (userRegistry != null){
+                       return userRegistry.getUsers();
+               }
+               List<AiravataUser> result=new ArrayList<AiravataUser>();
+               List<Resource> users = jpa.getGateway().get(ResourceType.USER);
+               for (Resource resource : users) {
+                       UserResource userRes = (UserResource) resource;
+                       AiravataUser user = new 
AiravataUser(userRes.getUserName());
+                       result.add(user);
+               }
+               return result;
+       }
+       
        private void addApplicationJobStatusData(String jobId, 
ApplicationJobStatus status, Date updatedTime, GFacJobDataResource 
dataResource) throws RegistryException {
                if (RegistrySettings.isApplicationJobStatusHistoryEnabled()){
                        if (dataResource==null){

Modified: 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
 (original)
+++ 
airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
 Mon Sep 23 22:25:39 2013
@@ -399,6 +399,16 @@ public class GatewayResource extends Abs
                     }
                 }
                 break;
+            case USER:
+                       generator = new QueryGenerator(USERS);
+                       q = generator.selectQuery(em);
+                       for (Object o : q.getResultList()) {
+                               Users user = (Users) o;
+                               UserResource userResource =
+                               
(UserResource)Utils.getResource(ResourceType.USER, user);
+                               resourceList.add(userResource);
+                       }
+                       break;
             default:
                 em.getTransaction().commit();
                 em.close();

Modified: 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
 (original)
+++ 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/AiravataRegistry2.java
 Mon Sep 23 22:25:39 2013
@@ -27,7 +27,7 @@ import java.net.URI;
 import java.util.Observable;
 
 
-public abstract class AiravataRegistry2 extends Observable implements 
DescriptorRegistry, ProjectsRegistry, PublishedWorkflowRegistry, 
UserWorkflowRegistry, ConfigurationRegistry, ProvenanceRegistry{
+public abstract class AiravataRegistry2 extends Observable implements 
DescriptorRegistry, ProjectsRegistry, PublishedWorkflowRegistry, 
UserWorkflowRegistry, ConfigurationRegistry, ProvenanceRegistry, UserRegistry{
        private Gateway gateway;
        private AiravataUser user;
        

Added: 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/UserRegistry.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/UserRegistry.java?rev=1525720&view=auto
==============================================================================
--- 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/UserRegistry.java
 (added)
+++ 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/UserRegistry.java
 Mon Sep 23 22:25:39 2013
@@ -0,0 +1,39 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.registry.api;
+
+import java.util.List;
+
+import org.apache.airavata.registry.api.exception.RegistryException;
+
+public interface UserRegistry extends AiravataSubRegistry{
+
+               
+       /**
+        * Retrieve all the users in the registry
+        * @return a list of airavata users from the registry
+        * @throws RegistryException
+        */
+       
+       public List<AiravataUser> getUsers() throws RegistryException;
+    
+}
\ No newline at end of file

Modified: 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryConstants.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryConstants.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryConstants.java
 (original)
+++ 
airavata/trunk/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistryConstants.java
 Mon Sep 23 22:25:39 2013
@@ -31,5 +31,6 @@ public class RegistryConstants {
     public static final String PROVENANCE_REGISTRY_ACCESSOR_CLASS = 
"class.provenance.registry.accessor";
     public static final String USER_WF_REGISTRY_ACCESSOR_CLASS = 
"class.user.workflow.registry.accessor";
     public static final String PUBLISHED_WF_REGISTRY_ACCESSOR_CLASS = 
"class.published.workflow.registry.accessor";
+    public static final String USER_REGISTRY_ACCESSOR_CLASS = 
"class.user.registry.accessor";
 
 }

Modified: 
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
 (original)
+++ 
airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/RegistryClient.java
 Mon Sep 23 22:25:39 2013
@@ -39,6 +39,7 @@ import org.apache.airavata.registry.api.
 import org.apache.airavata.registry.api.ResourceMetadata;
 import org.apache.airavata.registry.api.WorkspaceProject;
 import org.apache.airavata.registry.api.exception.RegistryException;
+import 
org.apache.airavata.registry.api.exception.UnimplementedRegistryOperationException;
 import 
org.apache.airavata.registry.api.exception.worker.ExperimentDoesNotExistsException;
 import org.apache.airavata.registry.api.workflow.*;
 import 
org.apache.airavata.registry.api.workflow.ApplicationJob.ApplicationJobStatus;
@@ -985,4 +986,9 @@ public class RegistryClient extends Aira
                        String jobId) throws RegistryException {
                return 
getProvenanceResourceClient().getApplicationJobStatusHistory(jobId);
        }
+
+       @Override
+       public List<AiravataUser> getUsers() throws RegistryException {
+        throw new UnimplementedRegistryOperationException();
+       }
 }

Added: 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/resourcemappings/UserList.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/resourcemappings/UserList.java?rev=1525720&view=auto
==============================================================================
--- 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/resourcemappings/UserList.java
 (added)
+++ 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/resourcemappings/UserList.java
 Mon Sep 23 22:25:39 2013
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.rest.mappings.resourcemappings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.airavata.registry.api.AiravataUser;
+
+@XmlRootElement
+public class UserList {
+    private List<AiravataUser> userList = new ArrayList<AiravataUser>();
+
+    public UserList() {
+    }
+
+    public List<AiravataUser> getUserList() {
+        return userList;
+    }
+
+    public void setUserList(List<AiravataUser> userList) {
+        this.userList = userList;
+    }
+}

Modified: 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java?rev=1525720&r1=1525719&r2=1525720&view=diff
==============================================================================
--- 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
 (original)
+++ 
airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java
 Mon Sep 23 22:25:39 2013
@@ -190,6 +190,12 @@ public class ResourcePathConstants {
         public static final String GET_WORKFLOWS = "get/workflows";
         public static final String REMOVE_WORKFLOW = "remove/workflow";
     }
+    
+    public final class UserRegistryConstants {
+
+        public static final String REGISTRY_API_USERREGISTRY = 
"/userregistry/";
+        public static final String GET_ALL_USERS = "get/user/all";
+    }
 
     public final class BasicRegistryConstants {
 

Added: 
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
URL: 
http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java?rev=1525720&view=auto
==============================================================================
--- 
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
 (added)
+++ 
airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserRegistryResource.java
 Mon Sep 23 22:25:39 2013
@@ -0,0 +1,85 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.services.registry.rest.resources;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+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.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.registry.api.AiravataUser;
+import org.apache.airavata.rest.mappings.resourcemappings.UserList;
+import org.apache.airavata.rest.mappings.utils.RegPoolUtils;
+import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.services.registry.rest.utils.WebAppUtil;
+
+/**
+ * This class is a REST interface to all the operations related to user 
workflows that has been
+ * exposed by Airavata Registry API
+ */
+@Path(ResourcePathConstants.UserRegistryConstants.REGISTRY_API_USERREGISTRY)
+public class UserRegistryResource {
+
+    @Context
+    ServletContext context;
+
+    /**---------------------------------User Workflow 
Registry----------------------------------**/
+
+    /**
+     * This method will check whether a given user workflow name already exists
+     *
+     * @param workflowName workflow name
+     * @return HTTP response
+     */
+    @GET
+    @Path(ResourcePathConstants.UserRegistryConstants.GET_ALL_USERS)
+    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+    public Response getAllUsers() {
+        AiravataRegistry2 airavataRegistry = 
RegPoolUtils.acquireRegistry(context);
+        try {
+               List<AiravataUser> users = airavataRegistry.getUsers();
+               UserList userList = new UserList();
+               userList.setUserList(users);
+            if (users.size() != 0) {
+                Response.ResponseBuilder builder = 
Response.status(Response.Status.OK);
+                builder.entity(userList);
+                return builder.build();
+            } else {
+                Response.ResponseBuilder builder = 
Response.status(Response.Status.NO_CONTENT);
+                return builder.build();
+            }
+        } catch (Throwable e) {
+            return 
WebAppUtil.reportInternalServerError(ResourcePathConstants.UserRegistryConstants.GET_ALL_USERS,
 e);
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(context, airavataRegistry);
+            }
+        }
+    }
+
+}


Reply via email to