http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java index 0ccc472,0000000..f03b47f mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java @@@ -1,200 -1,0 +1,200 @@@ +/** + * 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.ambari.server.api.services.groups; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.MemberResponse; +import org.apache.ambari.server.controller.spi.Resource; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * Service responsible for user membership requests. + */ +@Path("/groups/{groupName}/members") +@Api(value = "Groups", description = "Endpoint for group specific operations") +public class MemberService extends BaseService { + /** + * Creates new members. + * Handles: POST /groups/{groupname}/members requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @return information regarding the created member + */ + @POST + @Produces("text/plain") + public Response createMember(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("groupName") String groupName) { + return handleRequest(headers, body, ui, Request.Type.POST, createMemberResource(groupName, null)); + } + + /** + * Creates a new member. + * Handles: POST /groups/{groupname}/members/{username} requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @param userName the user name + * @return information regarding the created member + */ + @POST + @Path("{userName}") + @Produces("text/plain") + public Response createMember(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("groupName") String groupName, + @PathParam("userName") String userName) { + return handleRequest(headers, body, ui, Request.Type.POST, createMemberResource(groupName, userName)); + } + + /** + * Deletes a member. + * Handles: DELETE /groups/{groupname}/members/{username} requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @param userName the user name + * @return information regarding the deleted group + */ + @DELETE + @Path("{userName}") + @Produces("text/plain") + @ApiOperation(value = "Delete group member", nickname = "MemberService#deleteMember", notes = "Delete member resource.") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response deleteMember(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName, + @ApiParam(value = "user name", required = true) @PathParam("userName") String userName) { + return handleRequest(headers, null, ui, Request.Type.DELETE, createMemberResource(groupName, userName)); + } + + /** + * Gets all members. + * Handles: GET /groups/{groupname}/members requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @return information regarding all members + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all group members", nickname = "MemberService#getMembers", notes = "Returns details of all members.", response = MemberResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter member details", defaultValue = "MemberInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort members (asc | desc)", defaultValue = "MemberInfo/user_name.asc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = MemberResponse.class, responseContainer = "List")} + ) + public Response getMembers(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName) { + return handleRequest(headers, null, ui, Request.Type.GET, createMemberResource(groupName, null)); + } + + /** + * Gets member. + * Handles: GET /groups/{groupname}/members/{username} requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @param userName the user name + * @return information regarding the specific member + */ + @GET + @Path("{userName}") + @Produces("text/plain") + @ApiOperation(value = "Get group member", nickname = "MemberService#getMember", notes = "Returns member details.", response = MemberResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter member details", defaultValue = "MemberInfo", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = MemberResponse.class)} + ) + public Response getMember(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName, + @ApiParam(value = "user name", required = true) @PathParam("userName") String userName) { + return handleRequest(headers, null, ui, Request.Type.GET, createMemberResource(groupName, userName)); + } + + /** + * Updates all members. + * Handles: PUT /groups/{groupname}/members requests. + * + * @param headers http headers + * @param ui uri info + * @param groupName group name + * @return status of the request + */ + @PUT + @Produces("text/plain") + @ApiOperation(value = "Update group members", nickname = "MemberService#updateMembers", notes = "Updates group member resources.", responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.MemberRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response updateMembers(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) + @PathParam("groupName") String groupName) { + return handleRequest(headers, body, ui, Request.Type.PUT, createMemberResource(groupName, null)); + } + + /** + * Create a member resource instance. + * + * @param groupName group name + * @param userName user name + * + * @return a member resource instance + */ + private ResourceInstance createMemberResource(String groupName, String userName) { - final Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); ++ final Map<Resource.Type, String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.Group, groupName); + mapIds.put(Resource.Type.Member, userName); + return createResource(Resource.Type.Member, mapIds); + } +}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java index 3dea1ca,0000000..561e7d3 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java @@@ -1,111 -1,0 +1,111 @@@ +/** + * 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.ambari.server.api.services.users; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.ActiveWidgetLayoutResponse; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.commons.lang.StringUtils; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * WidgetLayout Service + */ +@Path("/users/{userName}/activeWidgetLayouts") +@Api(value = "Users", description = "Endpoint for User specific operations") +public class ActiveWidgetLayoutService extends BaseService { + + /** + * Handles URL: /users/{userName}/activeWidgetLayouts + * Get all instances for a view. + * + * @param headers http headers + * @param ui uri info + * @param userName user name + * + * @return instance collection resource representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get user widget layouts", nickname = "ActiveWidgetLayoutService#getServices", notes = "Returns all active widget layouts for user.", response = ActiveWidgetLayoutResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter user layout details", defaultValue = "WidgetLayoutInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort layouts (asc | desc)", defaultValue = "WidgetLayoutInfo/user_name.asc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + public Response getServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) + @PathParam("userName") String userName) { + + return handleRequest(headers, body, ui, Request.Type.GET, createResource(userName)); + } + + /** + * + * @param body body + * @param headers http headers + * @param ui uri info + * @param userName user name + * @return + */ + @PUT + @Produces("text/plain") + @ApiOperation(value = "Update user widget layouts", nickname = "ActiveWidgetLayoutService#updateServices", notes = "Updates user widget layout.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ActiveWidgetLayoutRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response updateServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) + @PathParam("userName") String userName) { + + return handleRequest(headers, body, ui, Request.Type.PUT, createResource(userName)); + } + + private ResourceInstance createResource(String userName) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName)); + return createResource(Resource.Type.ActiveWidgetLayout, mapIds); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java index 195f2e7,0000000..505108e mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java @@@ -1,120 -1,0 +1,120 @@@ +/* + * 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.ambari.server.api.services.users; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.UserAuthorizationResponse; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.commons.lang.StringUtils; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * UserAuthorizationService is a read-only service responsible for user authorization resource requests. + * <p/> + * The result sets returned by this service represent the set of authorizations assigned to a given user. + * Authorizations are tied to a resource, so a user may have the multiple authorization entries for the + * same authorization id (for example VIEW.USE), however each will represnet a different view instance. + */ +@Path("/users/{userName}/authorizations") +@Api(value = "Users", description = "Endpoint for user specific operations") +public class UserAuthorizationService extends BaseService { + + /** + * Handles: GET /users/{user_name}/authorizations + * Get all authorizations for the relative user. + * + * @param headers http headers + * @param ui uri info + * @param userName user name + * @return authorizations collection resource representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all authorizations", nickname = "UserAuthorizationService#getAuthorizations", notes = "Returns all authorization for user.", response = UserAuthorizationResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter user authorization details", defaultValue = "AuthorizationInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort user authorizations (asc | desc)", defaultValue = "AuthorizationInfo/user_name.asc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + public Response getAuthorizations(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) + @PathParam ("userName") String userName) { + return handleRequest(headers, null, ui, Request.Type.GET, createAuthorizationResource(userName,null)); + } + + /** + * Handles: GET /users/{userName}/authorizations/{authorization_id} + * Get a specific authorization. + * + * @param headers http headers + * @param ui uri info + * @param userName user name + * @param authorizationId authorization ID + * @return authorization instance representation + */ + @GET + @Path("{authorization_id}") + @Produces("text/plain") + @ApiOperation(value = "Get user authorization", nickname = "UserAuthorizationService#getAuthorization", notes = "Returns user authorization details.", response = UserAuthorizationResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter user authorization details", defaultValue = "AuthorizationInfo/*", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = UserAuthorizationResponse.class)} + ) + public Response getAuthorization(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) + @PathParam ("userName") String userName, @ApiParam(value = "Authorization Id", required = true) @PathParam("authorization_id") String authorizationId) { + return handleRequest(headers, null, ui, Request.Type.GET, createAuthorizationResource(userName, authorizationId)); + } + + /** + * Create an authorization resource. + * @param userName user name + * @param authorizationId authorization id + * @return an authorization resource instance + */ + protected ResourceInstance createAuthorizationResource(String userName, String authorizationId) { - Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type, String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName)); + mapIds.put(Resource.Type.UserAuthorization, authorizationId); + return createResource(Resource.Type.UserAuthorization, mapIds); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java index 293b45f,0000000..c0079d4 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java @@@ -1,113 -1,0 +1,113 @@@ +/** + * 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 privileges and + * limitations under the License. + */ + +package org.apache.ambari.server.api.services.users; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.UserPrivilegeResponse; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.commons.lang.StringUtils; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * Service responsible for user privilege resource requests. + */ +@Path("/users/{userName}/privileges") +@Api(value = "Users", description = "Endpoint for user specific operations") +public class UserPrivilegeService extends BaseService { + + + /** + * Handles: GET /users/{userName}/privileges + * Get all privileges. + * @param headers + * @param ui + * @param userName + * @return + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all privileges", nickname = "UserPrivilegeService#getPrivileges", notes = "Returns all privileges for user.", response = UserPrivilegeResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter user privileges", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort user privileges (asc | desc)", defaultValue = "PrivilegeInfo/user_name.asc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + + public Response getPrivileges(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "user name", required = true, defaultValue = "admin") @PathParam("userName") String userName) { + return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(userName, null)); + } + + /** + * Handles: GET /users/{userName}/privileges/{privilegeID} + * Get a specific privilege. + * + * @param headers http headers + * @param ui uri info + * @param userName user name + * @param privilegeId privilege id + * + * @return privilege instance representation + */ + @GET + @Path("{privilegeId}") + @Produces("text/plain") + @ApiOperation(value = "Get user privilege", nickname = "UserPrivilegeService#getPrivilege", notes = "Returns user privilege details.", response = UserPrivilegeResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter user privilege details", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = UserPrivilegeResponse.class)} + ) + public Response getPrivilege(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) @PathParam ("userName") String userName, + @ApiParam(value = "privilege id", required = true) @PathParam("privilegeId") String privilegeId) { + return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(userName, privilegeId)); + } + + + protected ResourceInstance createPrivilegeResource(String userName, String privilegeId) { - final Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); ++ final Map<Resource.Type, String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName)); + mapIds.put(Resource.Type.UserPrivilege, privilegeId); + return createResource(Resource.Type.UserPrivilege, mapIds); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewExternalSubResourceService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewExternalSubResourceService.java index bca0f05,0000000..27b4463 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewExternalSubResourceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewExternalSubResourceService.java @@@ -1,148 -1,0 +1,148 @@@ +/** + * 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.ambari.server.api.services.views; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.orm.entities.ViewEntity; +import org.apache.ambari.server.orm.entities.ViewInstanceEntity; + +/** + * Service responsible for view sub-resource requests. + */ +public class ViewExternalSubResourceService extends BaseService { + + /** + * The resource type. + */ + private final Resource.Type type; + + /** + * The view name. + */ + private final String viewName; + + /** + * The view version. + */ + private final String version; + + /** + * The instance name. + */ + private final String instanceName; + + /** + * Mapping of resource names to services. + */ - private final Map<String, Object> resourceServiceMap = new HashMap<String, Object>(); ++ private final Map<String, Object> resourceServiceMap = new HashMap<>(); + + + // ----- Constructors ------------------------------------------------------ + + public ViewExternalSubResourceService(Resource.Type type, ViewInstanceEntity viewInstanceDefinition) { + ViewEntity viewEntity = viewInstanceDefinition.getViewEntity(); + + this.type = type; + this.viewName = viewEntity.getCommonName(); + this.version = viewEntity.getVersion(); + this.instanceName = viewInstanceDefinition.getName(); + } + + /** + * Handles URL: /resources + * Get all external resources for a view. + * + * @param headers http headers + * @param ui uri info + * + * @return instance collection resource representation + */ + @GET + @Produces("text/plain") + public Response getResources(String body, @Context HttpHeaders headers, @Context UriInfo ui) { + return handleRequest(headers, body, ui, Request.Type.GET, + createResource(viewName, instanceName)); + } + + /** + * Handles: GET /resources/{resourceName} Get a specific external resource. + * + * @param resourceName resource name + * + * @return resource service instance representation + * + * @throws IllegalArgumentException if the given resource name is unknown + */ + @Path("{resourceName}") + public Object getResource(@PathParam("resourceName") String resourceName) throws IOException { + + Object service = resourceServiceMap.get(resourceName); + if (service == null) { + throw new IllegalArgumentException("A resource type " + resourceName + " for view instance " + + viewName + "/" + instanceName + " can not be found."); + } + + return service; + } + + + // ----- helper methods ---------------------------------------------------- + + /** + * Register a sub-resource service. + * + * @param resourceName the resource name + * @param service the service + */ + public void addResourceService(String resourceName, Object service) { + resourceServiceMap.put(resourceName, service); + } + + /** + * Create an view instance resource. + * + * @param viewName view name + * @param instanceName instance name + * + * @return a view instance resource + */ + private ResourceInstance createResource(String viewName, String instanceName) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, version); + mapIds.put(Resource.Type.ViewInstance, instanceName); + return createResource(type, mapIds); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java index 639933a,0000000..8e87e6f mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java @@@ -1,313 -1,0 +1,313 @@@ +/* + * 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.ambari.server.api.services.views; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.ViewInstanceResponse; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.orm.entities.ViewInstanceEntity; +import org.apache.ambari.server.security.authorization.AuthorizationException; +import org.apache.ambari.server.view.ViewRegistry; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * Service responsible for instances resource requests. + */ +@Path("/views/{viewName}/versions/{version}/instances") +@Api(tags = "Views", description = "Endpoint for view specific operations") +public class ViewInstanceService extends BaseService { + /** + * The view registry; + */ + private final ViewRegistry viewRegistry = ViewRegistry.getInstance(); + + /** + * Handles URL: /views/{viewName}/versions/{version}/instances + * Get all instances for a view. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return instance collection resource representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all view instances", nickname = "ViewInstanceService#getServices", notes = "Returns all instances for a view version.", response = ViewInstanceResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter view instance details", defaultValue = "ViewInstanceInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort users (asc | desc)", defaultValue = "ViewInstanceInfo/instance_name.desc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewInstanceResponse.class, responseContainer = "List")} + ) + public Response getServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @PathParam("viewName") String viewName, @PathParam("version") String version) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version, null)); + } + + + /** + * Handles URL: /views/{viewName}/versions/{version}/instances/{instanceID} + * Get a specific instance. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return instance resource representation + */ + @GET + @Path("{instanceName}") + @Produces("text/plain") + @ApiOperation(value = "Get single view instance", nickname = "ViewInstanceService#getService", notes = "Returns view instance details.", response = ViewInstanceResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter view instance details", defaultValue = "ViewInstanceInfo", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewInstanceResponse.class)} + ) + public Response getService(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version, instanceName)); + } + + + /** + * Handles: POST /views/{viewName}/versions/{version}/instances/{instanceId} + * Create a specific instance. + * + * @param body http body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the created instance + */ + @POST + @Path("{instanceName}") + @Produces("text/plain") + @ApiOperation(value = "Create view instance", nickname = "ViewInstanceService#createService", notes = "Creates view instance resource.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ViewInstanceRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response createService(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version, instanceName)); + } + + /** + * Handles: POST /views/{viewName}/versions/{version}/instances + * Create multiple instances. + * + * @param body http body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return information regarding the created instances + */ + @POST + @Produces("text/plain") + public Response createServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @PathParam("viewName") String viewName, @PathParam("version") String version) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version, null)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version}/instances/{instanceId} + * Update a specific instance. + * + * @param body http body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the updated instance + */ + @PUT + @Path("{instanceName}") + @Produces("text/plain") + @ApiOperation(value = "Update view instance detail", nickname = "ViewInstanceService#updateService", notes = "Updates view instance resource.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ViewInstanceRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response updateService(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version, instanceName)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version}/instances + * Update multiple instances. + * + * @param body http body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return information regarding the updated instance + */ + @PUT + @Produces("text/plain") + public Response updateServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @PathParam("viewName") String viewName, @PathParam("version") String version) throws AuthorizationException { + return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version, null)); + } + + /** + * Handles: DELETE /views/{viewName}/versions/{version}/instances/{instanceId} + * Delete a specific instance. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the deleted instance + */ + @DELETE + @Path("{instanceName}") + @Produces("text/plain") + @ApiOperation(value = "Delete view instance", nickname = "ViewInstanceService#deleteService", notes = "Delete view resource.") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response deleteService(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) throws AuthorizationException { + return handleRequest(headers, null, ui, Request.Type.DELETE, createResource(viewName, version, instanceName)); + } + + /** + * Get the sub-resource + * + * @param instanceName the instance id + * + * @return the service + */ + @Path("{instanceName}/{resources}") + public Object getResourceHandler(@Context javax.ws.rs.core.Request request, + @PathParam("viewName") String viewName, @PathParam("version") String version, + @PathParam("instanceName") String instanceName, + @PathParam("resources") String resources) { + + hasPermission(viewName, version, Request.Type.valueOf(request.getMethod()), instanceName); + + ViewInstanceEntity instanceDefinition = + ViewRegistry.getInstance().getInstanceDefinition(viewName, version, instanceName); + + if (instanceDefinition == null) { + throw new IllegalArgumentException("A view instance " + + viewName + "/" + instanceName + " can not be found."); + } + + Object service = instanceDefinition.getService(resources); + + if (service == null) { + throw new IllegalArgumentException("A resource type " + resources + " for view instance " + + viewName + "/" + instanceName + " can not be found."); + } + return service; + } + + // ----- helper methods ---------------------------------------------------- + + /** + * Create an view instance resource. + * + * @param viewName view name + * @param instanceName instance name + * + * @return a view instance resource + */ + private ResourceInstance createResource(String viewName, String viewVersion, String instanceName) { - Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type, String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, viewVersion); + mapIds.put(Resource.Type.ViewInstance, instanceName); + return createResource(Resource.Type.ViewInstance, mapIds); + } + + /** + * Determine whether or not the access specified by the given request type + * is permitted for the current user on the view instance resource identified + * by the given instance name. + * + * @param requestType the request method type + * @param instanceName the name of the view instance resource + * + * @throws WebApplicationException if access is forbidden + */ + private void hasPermission(String viewName, String version, Request.Type requestType, String instanceName) { + if (!viewRegistry.checkPermission(viewName, version, instanceName, requestType == Request.Type.GET)) { + throw new WebApplicationException(Response.Status.FORBIDDEN); + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPermissionService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPermissionService.java index f8e2a56,0000000..c8499e3 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPermissionService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPermissionService.java @@@ -1,208 -1,0 +1,208 @@@ +/** + * 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.ambari.server.api.services.views; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.ViewPermissionResponse; +import org.apache.ambari.server.controller.spi.Resource; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + + +/** + * Service responsible for custom view permission resource requests. + */ +@Path("/views/{viewName}/versions/{version}/permissions") +@Api(value = "Views", description = "Endpoint for view specific operations") +public class ViewPermissionService extends BaseService { + + /** + * Handles: GET /permissions + * Get all permissions. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return permission collection resource representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all permissions for a view", nickname = "ViewPermissionService#getPermissions", notes = "Returns all permission details for the version of a view.", response = ViewPermissionResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter privileges", defaultValue = "PermissionInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewPermissionResponse.class, responseContainer = "List")} + ) + public Response getPermissions(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version) { + return handleRequest(headers, null, ui, Request.Type.GET, createPermissionResource( + viewName, version, null)); + } + + /** + * Handles: GET /views/{viewName}/versions/{version}/permissions/{permissionID} + * Get a specific permission. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param permissionId permission id + * + * @return permission instance representation + */ + @GET + @Path("{permissionId}") + @Produces("text/plain") + @ApiOperation(value = "Get single view permission", nickname = "ViewPermissionService#getPermission", notes = "Returns permission details for a single version of a view.", response = ViewPermissionResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter view permission details", defaultValue = "PermissionInfo", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewPermissionResponse.class)} + ) + public Response getPermission(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "permission id") @PathParam("permissionId") String permissionId) { + + return handleRequest(headers, null, ui, Request.Type.GET, createPermissionResource( + viewName, version, permissionId)); + } + + /** + * Handles: POST /views/{viewName}/versions/{version}/permissions/{permissionID} + * Create a specific permission. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param permissionId permission id + * + * @return information regarding the created permission + */ + @POST + @Path("{permissionId}") + @Produces("text/plain") + public Response createPermission(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "permission id") @PathParam("permissionId") String permissionId) { + + return handleRequest(headers, body, ui, Request.Type.POST, createPermissionResource( + viewName, version, permissionId)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version}/permissions/{permissionID} + * Update a specific permission. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param permissionId permission id + * @return information regarding the updated permission + */ + @PUT + @Path("{permissionId}") + @Produces("text/plain") + public Response updatePermission(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "permission id") @PathParam("permissionId") String permissionId) { + + return handleRequest(headers, body, ui, Request.Type.PUT, createPermissionResource( + viewName, version, permissionId)); + } + + /** + * Handles: DELETE /views/{viewName}/versions/{version}/permissions/{permissionID} + * Delete a specific permission. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param permissionId permission id + * + * @return information regarding the deleted permission + */ + @DELETE + @Path("{permissionId}") + @Produces("text/plain") + public Response deletePermission(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "permission id") @PathParam("permissionId") String permissionId) { + + return handleRequest(headers, null, ui, Request.Type.DELETE, createPermissionResource( + viewName, version, permissionId)); + } + + + // ----- helper methods ---------------------------------------------------- + + /** + * Create a permission resource. + * + * @param permissionId permission name + * + * @return a permission resource instance + */ + protected ResourceInstance createPermissionResource(String viewName, String viewVersion, String permissionId) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, viewVersion); + mapIds.put(Resource.Type.ViewPermission, permissionId); + + return createResource(Resource.Type.ViewPermission, mapIds); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPrivilegeService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPrivilegeService.java index 047d463,0000000..08e250b mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPrivilegeService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewPrivilegeService.java @@@ -1,268 -1,0 +1,268 @@@ +/** + * 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 privileges and + * limitations under the License. + */ + +package org.apache.ambari.server.api.services.views; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.ViewPrivilegeResponse; +import org.apache.ambari.server.controller.spi.Resource; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +/** + * Service responsible for view privilege resource requests. + */ +@Api(tags = "Views", description = "Endpoint for view specific operations") +@Path("/views/{viewName}/versions/{version}/instances/{instanceName}/privileges") +public class ViewPrivilegeService extends BaseService { + /** + * Handles: GET /views/{viewName}/versions/{version}/instances/{instanceName}/privileges + * Get all privileges. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return privilege collection representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all view instance privileges", nickname = "ViewPrivilegeService#getPrivileges", notes = "Returns all privileges for the resource.", response = ViewPrivilegeResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter privileges", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort privileges (asc | desc)", defaultValue = "PrivilegeInfo/user_name.asc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + public Response getPrivileges(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) { + return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(viewName, version, instanceName,null)); + } + + /** + * Handles: GET /views/{viewName}/versions/{version}/instances/{instanceName}/privileges/{privilegeID} + * Get a specific privilege. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * @param privilegeId privilege id + * + * @return privilege instance representation + */ + @GET + @Path("/{privilegeId}") + @Produces("text/plain") + @ApiOperation(value = "Get single view instance privilege", nickname = "ViewPrivilegeService#getPrivilege", notes = "Returns privilege details.", response = ViewPrivilegeResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter privilege details", defaultValue = "PrivilegeInfo", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewPrivilegeResponse.class)} + ) + public Response getPrivilege(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName, + @ApiParam(value = "privilege id", required = true) @PathParam("privilegeId") String privilegeId) { + + return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(viewName, version, instanceName,privilegeId)); + } + + /** + * Handles: POST /views/{viewName}/versions/{version}/instances/{instanceName}/privileges + * Create a privilege. + * + * @param body request body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the created privilege + */ + @POST + @Produces("text/plain") + @ApiOperation(value = "Create view instance privilege", nickname = "ViewPrivilegeService#createPrivilege", notes = "Create privilege resource for view instance.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ViewPrivilegeRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response createPrivilege(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) { + + return handleRequest(headers, body, ui, Request.Type.POST, createPrivilegeResource(viewName, version, instanceName,null)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version}/instances/{instanceName}/privileges/{privilegeID} + * Update a specific privilege. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * @param privilegeId privilege id + * + * @return information regarding the updated privilege + */ + @PUT + // Remove comments when the below API call is fixed + /*@Path("{privilegeId}") + @Produces("text/plain") + @ApiOperation(value = "Update view instance privilege", notes = "Update privilege resource for view instance.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ViewPrivilegeRequest", paramType = "body") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) */ + public Response updatePrivilege(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName, + @ApiParam(value = "privilege id") @PathParam("privilegeId") String privilegeId) { + + return handleRequest(headers, body, ui, Request.Type.PUT, createPrivilegeResource(viewName, version, instanceName, privilegeId)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version}/instances/{instanceName}/privileges + * Update a set of privileges for the resource. + * + * @param body request body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the updated privileges + */ + @PUT + @Produces("text/plain") + public Response updatePrivileges(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) { + return handleRequest(headers, body, ui, Request.Type.PUT, createPrivilegeResource(viewName, version, instanceName,null)); + } + + /** + * Handles: DELETE /views/{viewName}/versions/{version}/instances/{instanceName}/privileges + * Delete privileges. + * + * @param body request body + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * + * @return information regarding the deleted privileges + */ + @DELETE + @Produces("text/plain") + public Response deletePrivileges(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("viewVersion") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName) { + + return handleRequest(headers, body, ui, Request.Type.DELETE, createPrivilegeResource(viewName, version, instanceName,null)); + } + + /** + * Handles: DELETE /views/{viewName}/versions/{version}/instances/{instanceName}/privileges/{privilegeID} + * Delete a specific privilege. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * @param instanceName instance id + * @param privilegeId privilege id + * + * @return information regarding the deleted privilege + */ + @DELETE + @Path("{privilegeId}") + @Produces("text/plain") + @ApiOperation(value = "Delete view instance privilege", nickname = "ViewPrivilegeService#deletePrivilege", notes = "Delete view instance privilege resource.") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation"), + @ApiResponse(code = 500, message = "Server Error")} + ) + public Response deletePrivilege(@Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @ApiParam(value = "view version") @PathParam("version") String version, + @ApiParam(value = "instance name") @PathParam("instanceName") String instanceName, + @ApiParam(value = "privilege id") @PathParam("privilegeId") String privilegeId) { + + return handleRequest(headers, null, ui, Request.Type.DELETE, createPrivilegeResource(viewName, version, instanceName, privilegeId)); + } + + + protected ResourceInstance createPrivilegeResource(String viewName, String viewVersion, String instanceName, String privilegeId) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, viewVersion); + mapIds.put(Resource.Type.ViewInstance, instanceName); + mapIds.put(Resource.Type.ViewPrivilege, privilegeId); + + return createResource(Resource.Type.ViewPrivilege, mapIds); + } +} + http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewSubResourceService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewSubResourceService.java index 081d699,0000000..d680f04 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewSubResourceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewSubResourceService.java @@@ -1,136 -1,0 +1,136 @@@ +/** + * 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.ambari.server.api.services.views; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.orm.entities.ViewEntity; +import org.apache.ambari.server.orm.entities.ViewInstanceEntity; +import org.apache.ambari.view.ViewResourceHandler; + +/** + * View sub-resource service. + */ +public class ViewSubResourceService extends BaseService implements ViewResourceHandler { + /** + * The type of the sub-resource. + */ + private final Resource.Type type; + + /** + * The associated view name. + */ + private final String viewName; + + /** + * The view version. + */ + private final String version; + + /** + * The associated view instance name. + */ + private final String instanceName; + + + // ----- Constructors ------------------------------------------------------ + + /** + * Construct a view sub-resource service. + */ + public ViewSubResourceService(Resource.Type type, ViewInstanceEntity viewInstanceDefinition) { + ViewEntity viewEntity = viewInstanceDefinition.getViewEntity(); + + this.type = type; + this.viewName = viewEntity.getCommonName(); + this.version = viewEntity.getVersion(); + this.instanceName = viewInstanceDefinition.getName(); + } + + + // ----- ViewResourceHandler ----------------------------------------------- + + @Override + public Response handleRequest(HttpHeaders headers, UriInfo ui, + RequestType requestType, MediaType mediaType, + String resourceId) { + return handleRequest(headers, null, ui, getRequestType(requestType), + getMediaType(mediaType), createResource(resourceId)); + } + + @Override + public Response handleRequest(HttpHeaders headers, UriInfo ui, String resourceId) { + return handleRequest(headers, null, ui, Request.Type.GET, + createResource(resourceId)); + } + + + // ----- helper methods ---------------------------------------------------- + + // create a resource with the given id + protected ResourceInstance createResource(String resourceId) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type,String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, version); + mapIds.put(Resource.Type.ViewInstance, instanceName); + + if (resourceId != null) { + mapIds.put(type, resourceId); + } + return super.createResource(type, mapIds); + } + + // get the internal request type from the view API request type + private Request.Type getRequestType(RequestType type) { + switch (type) { + case GET: + return Request.Type.GET; + case POST: + return Request.Type.POST; + case PUT: + return Request.Type.PUT; + case DELETE: + return Request.Type.DELETE; + case QUERY_POST: + return Request.Type.QUERY_POST; + } + throw new IllegalArgumentException("Unknown resource type " + type); + } + + // get the JAX-RS media type from the view media type + private javax.ws.rs.core.MediaType getMediaType(MediaType type) { + switch (type) { + case TEXT_PLAIN: + return javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; + case APPLICATION_JSON: + return javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; + } + throw new IllegalArgumentException("Unknown media type " + type); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewVersionService.java ---------------------------------------------------------------------- diff --cc ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewVersionService.java index 95ebb39,0000000..ab329f8 mode 100644,000000..100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewVersionService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewVersionService.java @@@ -1,208 -1,0 +1,208 @@@ +/** + * 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.ambari.server.api.services.views; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.services.BaseService; +import org.apache.ambari.server.api.services.Request; +import org.apache.ambari.server.controller.ViewVersionResponse; +import org.apache.ambari.server.controller.spi.Resource; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + + +/** + * Service responsible for view version resource requests. + */ +@Path("/views/{viewName}/versions") +@Api(value = "Views", description = "Endpoint for view specific operations") +public class ViewVersionService extends BaseService { + + /** + * Handles: GET /views/{viewName}/versions + * Get all views versions. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * + * @return view collection resource representation + */ + @GET + @Produces("text/plain") + @ApiOperation(value = "Get all versions for a view", nickname = "ViewVersionService#getVersions", notes = "Returns details of all versions for a view.", response = ViewVersionResponse.class, responseContainer = "List") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter view version details", defaultValue = "ViewVersionInfo/*", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "sortBy", value = "Sort users (asc | desc)", defaultValue = "ViewVersionInfo/version.desc", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"), + @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"), + @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewVersionResponse.class, responseContainer = "List")} + ) + public Response getVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName) { + + return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, null)); + } + + + /** + * Handles: GET /views/{viewName}/versions/{version} + * Get a specific view version. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return view instance representation + */ + @GET + @Path("{version}") + @Produces("text/plain") + @ApiOperation(value = "Get single view version", nickname = "ViewVersionService#getVersion", notes = "Returns view details.", response = ViewVersionResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "fields", value = "Filter view details", defaultValue = "ViewVersionInfo", dataType = "string", paramType = "query") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successful operation", response = ViewVersionResponse.class)} + ) + public Response getVersion(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @PathParam("version") String version) { + + return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version)); + } + + /** + * Handles: POST /views/{viewName}/versions/{version} + * Create a specific view version. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version the version + * + * @return information regarding the created view + */ + @POST + @Path("{version}") + @Produces("text/plain") + public Response createVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @PathParam("version") String version) { + + return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version)); + } + + /** + * Handles: PUT /views/{viewName}/versions/{version} + * Update a specific view version. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version the version + * + * @return information regarding the updated view + */ + @PUT + @Path("{version}") + @Produces("text/plain") + public Response updateVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(value = "view name") @PathParam("viewName") String viewName, + @PathParam("version") String version) { + + return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version)); + } + + /** + * Handles: DELETE /views/{viewName}/versions/{version} + * Delete a specific view version. + * + * @param headers http headers + * @param ui uri info + * @param viewName view id + * @param version version id + * + * @return information regarding the deleted view version + */ + @DELETE + @Path("{version}") + @Produces("text/plain") + public Response deleteVersions(@Context HttpHeaders headers, @Context UriInfo ui, + @PathParam("viewName") String viewName, @PathParam("version") String version) { + + return handleRequest(headers, null, ui, Request.Type.DELETE, createResource(viewName, version)); + } + + + /** + * Get the permissions sub-resource + * + * @param version the version + * + * @return the permission service + + @Path("{version}/permissions") + public ViewPermissionService getPermissionHandler(@PathParam("version") String version) { + + return new ViewPermissionService(viewName, version); + } + + + // ----- helper methods ---------------------------------------------------- + + /** + * Create a view resource. + * + * @param viewName view name + * + * @return a view resource instance + */ + private ResourceInstance createResource(String viewName, String version) { - Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>(); ++ Map<Resource.Type,String> mapIds = new HashMap<>(); + mapIds.put(Resource.Type.View, viewName); + mapIds.put(Resource.Type.ViewVersion, version); + return createResource(Resource.Type.ViewVersion, mapIds); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/3acd2e6d/ambari-server/src/main/java/org/apache/ambari/server/controller/UserRequest.java ----------------------------------------------------------------------
