Search in sources :

Example 11 with Consumes

use of javax.ws.rs.Consumes in project druid by druid-io.

the class OverlordResource method taskPost.

@POST
@Path("/task")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response taskPost(final Task task, @Context final HttpServletRequest req) {
    if (authConfig.isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String dataSource = task.getDataSource();
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) req.getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        Access authResult = authorizationInfo.isAuthorized(new Resource(dataSource, ResourceType.DATASOURCE), Action.WRITE);
        if (!authResult.isAllowed()) {
            return Response.status(Response.Status.FORBIDDEN).header("Access-Check-Result", authResult).build();
        }
    }
    return asLeaderWith(taskMaster.getTaskQueue(), new Function<TaskQueue, Response>() {

        @Override
        public Response apply(TaskQueue taskQueue) {
            try {
                taskQueue.add(task);
                return Response.ok(ImmutableMap.of("task", task.getId())).build();
            } catch (EntryExistsException e) {
                return Response.status(Response.Status.BAD_REQUEST).entity(ImmutableMap.of("error", String.format("Task[%s] already exists!", task.getId()))).build();
            }
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) TaskQueue(io.druid.indexing.overlord.TaskQueue) EntryExistsException(io.druid.metadata.EntryExistsException) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 12 with Consumes

use of javax.ws.rs.Consumes in project che by eclipse.

the class ProjectService method createFile.

@POST
@Path("/file/{parent:.*}")
@Consumes({ MediaType.MEDIA_TYPE_WILDCARD })
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Create file", notes = "Create a new file in a project. If file type isn't specified the server will resolve its type.")
@ApiResponses({ @ApiResponse(code = 201, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "File already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response createFile(@ApiParam(value = "Path to a target directory", required = true) @PathParam("parent") String parentPath, @ApiParam(value = "New file name", required = true) @QueryParam("name") String fileName, InputStream content) throws NotFoundException, ConflictException, ForbiddenException, ServerException {
    final FolderEntry parent = projectManager.asFolder(parentPath);
    if (parent == null) {
        throw new NotFoundException("Parent not found for " + parentPath);
    }
    final FileEntry newFile = parent.createFile(fileName, content);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.CREATED, workspace, newFile.getProject(), newFile.getPath().toString(), false));
    final URI location = getServiceContext().getServiceUriBuilder().clone().path(getClass(), "getFile").build(new String[] { newFile.getPath().toString().substring(1) }, false);
    return Response.created(location).entity(injectFileLinks(asDto(newFile))).build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with Consumes

use of javax.ws.rs.Consumes in project che by eclipse.

the class ProjectService method updateFile.

@PUT
@Path("/file/{path:.*}")
@Consumes({ MediaType.MEDIA_TYPE_WILDCARD })
@ApiOperation(value = "Update file", notes = "Update an existing file with new content")
@ApiResponses({ @ApiResponse(code = 200, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response updateFile(@ApiParam(value = "Full path to a file", required = true) @PathParam("path") String path, InputStream content) throws NotFoundException, ForbiddenException, ServerException {
    final FileEntry file = projectManager.asFile(path);
    if (file == null) {
        throw new NotFoundException("File not found for " + path);
    }
    file.updateContent(content);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.UPDATED, workspace, file.getProject(), file.getPath().toString(), false));
    return Response.ok().build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with Consumes

use of javax.ws.rs.Consumes in project che by eclipse.

the class ProjectService method createBatchProjects.

@POST
@Path("/batch")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates batch of projects according to their configurations", notes = "A project will be created by importing when project configuration contains source object. " + "For creating a project by generator options should be specified.", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Path for new project should be defined"), @ApiResponse(code = 403, message = "Operation is forbidden"), @ApiResponse(code = 409, message = "Project with specified name already exist in workspace"), @ApiResponse(code = 500, message = "Server error") })
@GenerateLink(rel = LINK_REL_CREATE_BATCH_PROJECTS)
public List<ProjectConfigDto> createBatchProjects(@Description("list of descriptors for projects") List<NewProjectConfigDto> projectConfigList, @ApiParam(value = "Force rewrite existing project", allowableValues = "true,false") @QueryParam("force") boolean rewrite) throws ConflictException, ForbiddenException, ServerException, NotFoundException, IOException, UnauthorizedException, BadRequestException {
    List<ProjectConfigDto> result = new ArrayList<>(projectConfigList.size());
    final ProjectOutputLineConsumerFactory outputOutputConsumerFactory = new ProjectOutputLineConsumerFactory(workspace, 300);
    for (RegisteredProject registeredProject : projectManager.createBatchProjects(projectConfigList, rewrite, outputOutputConsumerFactory)) {
        ProjectConfigDto projectConfig = injectProjectLinks(asDto(registeredProject));
        result.add(projectConfig);
        eventService.publish(new ProjectCreatedEvent(workspace, registeredProject.getPath()));
    }
    return result;
}
Also used : NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with Consumes

use of javax.ws.rs.Consumes in project che by eclipse.

the class ProjectService method createProject.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates new project", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 403, message = "Operation is forbidden"), @ApiResponse(code = 409, message = "Project with specified name already exist in workspace"), @ApiResponse(code = 500, message = "Server error") })
@GenerateLink(rel = LINK_REL_CREATE_PROJECT)
public /**
     * NOTE: parentPath is added to make a module
     */
ProjectConfigDto createProject(@ApiParam(value = "Add to this project as module", required = false) @Context UriInfo uriInfo, @Description("descriptor of project") ProjectConfigDto projectConfig) throws ConflictException, ForbiddenException, ServerException, NotFoundException {
    Map<String, String> options = new HashMap<>();
    MultivaluedMap<String, String> map = uriInfo.getQueryParameters();
    for (String key : map.keySet()) {
        options.put(key, map.get(key).get(0));
    }
    String pathToProject = projectConfig.getPath();
    String pathToParent = pathToProject.substring(0, pathToProject.lastIndexOf("/"));
    if (!pathToParent.equals("/")) {
        VirtualFileEntry parentFileEntry = projectManager.getProjectsRoot().getChild(pathToParent);
        if (parentFileEntry == null) {
            throw new NotFoundException("The parent folder with path " + pathToParent + " does not exist.");
        }
    }
    final RegisteredProject project = projectManager.createProject(projectConfig, options);
    final ProjectConfigDto configDto = asDto(project);
    eventService.publish(new ProjectCreatedEvent(workspace, project.getPath()));
    return injectProjectLinks(configDto);
}
Also used : HashMap(java.util.HashMap) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Consumes (javax.ws.rs.Consumes)1565 Path (javax.ws.rs.Path)1221 Produces (javax.ws.rs.Produces)1217 POST (javax.ws.rs.POST)892 ApiOperation (io.swagger.annotations.ApiOperation)503 ApiResponses (io.swagger.annotations.ApiResponses)445 PUT (javax.ws.rs.PUT)417 GET (javax.ws.rs.GET)223 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)215 URI (java.net.URI)202 IOException (java.io.IOException)147 WebApplicationException (javax.ws.rs.WebApplicationException)139 Response (javax.ws.rs.core.Response)136 ArrayList (java.util.ArrayList)134 Authorizable (org.apache.nifi.authorization.resource.Authorizable)100 DELETE (javax.ws.rs.DELETE)86 TimedResource (org.killbill.commons.metrics.TimedResource)84 CallContext (org.killbill.billing.util.callcontext.CallContext)83 Timed (com.codahale.metrics.annotation.Timed)78 HashMap (java.util.HashMap)76