Search in sources :

Example 26 with POST

use of javax.ws.rs.POST 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 27 with POST

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

the class ClasspathUpdaterService method updateClasspath.

/**
     * Updates the information about classpath.
     *
     * @param projectPath
     *         path to the current project
     * @param entries
     *         list of classpath entries which need to set
     * @throws JavaModelException
     *         if JavaModel has a failure
     * @throws ServerException
     *         if some server error
     * @throws ForbiddenException
     *         if operation is forbidden
     * @throws ConflictException
     *         if update operation causes conflicts
     * @throws NotFoundException
     *         if Project with specified path doesn't exist in workspace
     * @throws IOException
     */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void updateClasspath(@QueryParam("projectpath") String projectPath, List<ClasspathEntryDto> entries) throws JavaModelException, ServerException, ForbiddenException, ConflictException, NotFoundException, IOException {
    IJavaProject javaProject = model.getJavaProject(projectPath);
    javaProject.setRawClasspath(createModifiedEntry(entries), javaProject.getOutputLocation(), new NullProgressMonitor());
    updateProjectConfig(projectPath);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 28 with POST

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

the class MavenServerService method reimportDependencies.

@POST
@Path("reimport")
@ApiOperation(value = "Re-import maven model")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response reimportDependencies(@ApiParam(value = "The paths to projects which need to be reimported") @QueryParam("projectPath") List<String> paths) throws ServerException {
    IWorkspace workspace = eclipseWorkspaceProvider.get();
    List<IProject> projectsList = paths.stream().map(projectPath -> workspace.getRoot().getProject(projectPath)).collect(Collectors.toList());
    mavenWorkspace.update(projectsList);
    return Response.ok().build();
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Inject(com.google.inject.Inject) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) Document(org.eclipse.jface.text.Document) MavenProgressNotifier(org.eclipse.che.plugin.maven.server.core.MavenProgressNotifier) QueryParam(javax.ws.rs.QueryParam) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Model(org.eclipse.che.ide.maven.tools.Model) BadLocationException(org.eclipse.jface.text.BadLocationException) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TEXT_XML(javax.ws.rs.core.MediaType.TEXT_XML) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Response(javax.ws.rs.core.Response) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 29 with POST

use of javax.ws.rs.POST 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 30 with POST

use of javax.ws.rs.POST 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)

Aggregations

POST (javax.ws.rs.POST)513 Path (javax.ws.rs.Path)360 Consumes (javax.ws.rs.Consumes)242 Produces (javax.ws.rs.Produces)222 ApiOperation (io.swagger.annotations.ApiOperation)133 ApiResponses (io.swagger.annotations.ApiResponses)107 IOException (java.io.IOException)74 URI (java.net.URI)63 WebApplicationException (javax.ws.rs.WebApplicationException)62 Timed (com.codahale.metrics.annotation.Timed)55 Response (javax.ws.rs.core.Response)50 TimedResource (org.killbill.commons.metrics.TimedResource)36 CallContext (org.killbill.billing.util.callcontext.CallContext)35 AuditEvent (org.graylog2.audit.jersey.AuditEvent)33 HashMap (java.util.HashMap)32 BadRequestException (co.cask.cdap.common.BadRequestException)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Account (org.killbill.billing.account.api.Account)22 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)20