Search in sources :

Example 1 with ApiParam

use of io.swagger.annotations.ApiParam in project che by eclipse.

the class WorkspaceService method updateCommand.

@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(update, "Command update");
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    final List<CommandImpl> commands = workspace.getConfig().getCommands();
    if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
        throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
    }
    commands.add(new CommandImpl(update));
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) Consumes(javax.ws.rs.Consumes) Example(io.swagger.annotations.Example) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) WsAgentHealthChecker(org.eclipse.che.api.agent.server.WsAgentHealthChecker) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) LINK_REL_GET_WORKSPACES(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_WORKSPACES) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) LINK_REL_GET_BY_NAMESPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_BY_NAMESPACE) String.format(java.lang.String.format) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) DtoConverter.asDto(org.eclipse.che.api.workspace.server.DtoConverter.asDto) Response(javax.ws.rs.core.Response) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ConflictException(org.eclipse.che.api.core.ConflictException) Api(io.swagger.annotations.Api) Named(javax.inject.Named) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CHE_WORKSPACE_AUTO_START(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START) Maps(com.google.common.collect.Maps) NotFoundException(org.eclipse.che.api.core.NotFoundException) Collectors.toList(java.util.stream.Collectors.toList) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ExampleProperty(io.swagger.annotations.ExampleProperty) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) CHE_WORKSPACE_AUTO_SNAPSHOT(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_SNAPSHOT) PUT(javax.ws.rs.PUT) CHE_WORKSPACE_AUTO_RESTORE(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_RESTORE) LINK_REL_CREATE_WORKSPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_CREATE_WORKSPACE) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ApiParam

use of io.swagger.annotations.ApiParam in project che by eclipse.

the class MavenServerService method reconcilePom.

@GET
@Path("pom/reconcile")
@ApiOperation(value = "Reconcile pom.xml file")
@ApiResponses({ @ApiResponse(code = 200, message = "OK") })
@Produces("application/json")
public List<Problem> reconcilePom(@ApiParam(value = "The paths to pom.xml file which need to be reconciled") @QueryParam("pompath") String pomPath) {
    VirtualFileEntry entry = null;
    List<Problem> result = new ArrayList<>();
    try {
        entry = cheProjectManager.getProjectsRoot().getChild(pomPath);
        if (entry == null) {
            return result;
        }
        Model.readFrom(entry.getVirtualFile());
        org.eclipse.che.api.vfs.Path path = entry.getPath();
        String pomContent = entry.getVirtualFile().getContentAsString();
        MavenProject mavenProject = mavenProjectManager.findMavenProject(ResourcesPlugin.getWorkspace().getRoot().getProject(path.getParent().toString()));
        if (mavenProject == null) {
            return result;
        }
        List<MavenProjectProblem> problems = mavenProject.getProblems();
        int start = pomContent.indexOf("<project ") + 1;
        int end = start + "<project ".length();
        List<Problem> problemList = problems.stream().map(mavenProjectProblem -> DtoFactory.newDto(Problem.class).withError(true).withSourceStart(start).withSourceEnd(end).withMessage(mavenProjectProblem.getDescription())).collect(Collectors.toList());
        result.addAll(problemList);
    } catch (ServerException | ForbiddenException | IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (XMLTreeException exception) {
        Throwable cause = exception.getCause();
        if (cause != null && cause instanceof SAXParseException) {
            result.add(createProblem(entry, (SAXParseException) cause));
        }
    }
    return result;
}
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) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ArrayList(java.util.ArrayList) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) IOException(java.io.IOException) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) SAXParseException(org.xml.sax.SAXParseException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ApiParam

use of io.swagger.annotations.ApiParam 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 4 with ApiParam

use of io.swagger.annotations.ApiParam in project graylog2-server by Graylog2.

the class MessageResource method analyze.

@GET
@Path("/{index}/analyze")
@Timed
@ApiOperation(value = "Analyze a message string", notes = "Returns what tokens/terms a message string (message or full_message) is split to.")
@RequiresPermissions(RestPermissions.MESSAGES_ANALYZE)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified index does not exist.") })
public MessageTokens analyze(@ApiParam(name = "index", value = "The index the message containing the string is stored in.", required = true) @PathParam("index") String index, @ApiParam(name = "analyzer", value = "The analyzer to use.") @QueryParam("analyzer") @Nullable String analyzer, @ApiParam(name = "string", value = "The string to analyze.", required = true) @QueryParam("string") @NotEmpty String string) {
    final String indexAnalyzer = indexSetRegistry.getForIndex(index).map(indexSet -> indexSet.getConfig().indexAnalyzer()).orElse("standard");
    final String messageAnalyzer = analyzer == null ? indexAnalyzer : analyzer;
    try {
        return MessageTokens.create(messages.analyze(string, index, messageAnalyzer));
    } catch (IndexNotFoundException e) {
        final String message = "Index " + index + " does not exist.";
        LOG.error(message, e);
        throw new NotFoundException(message);
    }
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) PathParam(javax.ws.rs.PathParam) UUID(com.eaio.uuid.UUID) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MessageTokens(org.graylog2.rest.models.messages.responses.MessageTokens) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) CodecFactory(org.graylog2.inputs.codecs.CodecFactory) MessageParseRequest(org.graylog2.rest.models.messages.requests.MessageParseRequest) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ResultMessage(org.graylog2.indexer.results.ResultMessage) Consumes(javax.ws.rs.Consumes) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Objects.requireNonNull(java.util.Objects.requireNonNull) RawMessage(org.graylog2.plugin.journal.RawMessage) Messages(org.graylog2.indexer.messages.Messages) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Nullable(javax.annotation.Nullable) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) RestResource(org.graylog2.shared.rest.resources.RestResource) InetSocketAddress(java.net.InetSocketAddress) NotFoundException(javax.ws.rs.NotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Timed(com.codahale.metrics.annotation.Timed) Codec(org.graylog2.plugin.inputs.codecs.Codec) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) NotEmpty(org.hibernate.validator.constraints.NotEmpty) InetAddresses(com.google.common.net.InetAddresses) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Message(org.graylog2.plugin.Message) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with ApiParam

use of io.swagger.annotations.ApiParam in project nifi by apache.

the class ControllerServiceResource method updateControllerServiceReferences.

/**
 * Updates the references of the specified controller service.
 *
 * @param httpServletRequest     request
 * @param requestUpdateReferenceRequest The update request
 * @return A controllerServiceReferencingComponentsEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/references")
@ApiOperation(value = "Updates a controller services references", response = ControllerServiceReferencingComponentsEntity.class, authorizations = { @Authorization(value = "Write - /{component-type}/{uuid} - For each referencing component specified") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateControllerServiceReferences(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The controller service id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The controller service request update request.", required = true) final UpdateControllerServiceReferenceRequestEntity requestUpdateReferenceRequest) {
    if (requestUpdateReferenceRequest.getId() == null) {
        throw new IllegalArgumentException("The controller service identifier must be specified.");
    }
    if (requestUpdateReferenceRequest.getReferencingComponentRevisions() == null) {
        throw new IllegalArgumentException("The controller service referencing components revisions must be specified.");
    }
    // parse the state to determine the desired action
    // need to consider controller service state first as it shares a state with
    // scheduled state (disabled) which is applicable for referencing services
    // but not referencing schedulable components
    ControllerServiceState requestControllerServiceState = null;
    try {
        requestControllerServiceState = ControllerServiceState.valueOf(requestUpdateReferenceRequest.getState());
    } catch (final IllegalArgumentException iae) {
    // ignore
    }
    ScheduledState requestScheduledState = null;
    try {
        requestScheduledState = ScheduledState.valueOf(requestUpdateReferenceRequest.getState());
    } catch (final IllegalArgumentException iae) {
    // ignore
    }
    // ensure an action has been specified
    if (requestScheduledState == null && requestControllerServiceState == null) {
        throw new IllegalArgumentException("Must specify the updated state. To update referencing Processors " + "and Reporting Tasks the state should be RUNNING or STOPPED. To update the referencing Controller Services the " + "state should be ENABLED or DISABLED.");
    }
    // ensure the controller service state is not ENABLING or DISABLING
    if (requestControllerServiceState != null && (ControllerServiceState.ENABLING.equals(requestControllerServiceState) || ControllerServiceState.DISABLING.equals(requestControllerServiceState))) {
        throw new IllegalArgumentException("Cannot set the referencing services to ENABLING or DISABLING");
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestUpdateReferenceRequest);
    }
    // convert the referencing revisions
    final Map<String, Revision> requestReferencingRevisions = requestUpdateReferenceRequest.getReferencingComponentRevisions().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> {
        final RevisionDTO rev = e.getValue();
        return new Revision(rev.getVersion(), rev.getClientId(), e.getKey());
    }));
    final Set<Revision> requestRevisions = new HashSet<>(requestReferencingRevisions.values());
    final ScheduledState verifyScheduledState = requestScheduledState;
    final ControllerServiceState verifyControllerServiceState = requestControllerServiceState;
    return withWriteLock(serviceFacade, requestUpdateReferenceRequest, requestRevisions, lookup -> {
        requestReferencingRevisions.entrySet().stream().forEach(e -> {
            final Authorizable controllerService = lookup.getControllerServiceReferencingComponent(id, e.getKey());
            controllerService.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        });
    }, () -> serviceFacade.verifyUpdateControllerServiceReferencingComponents(requestUpdateReferenceRequest.getId(), verifyScheduledState, verifyControllerServiceState), (revisions, updateReferenceRequest) -> {
        ScheduledState scheduledState = null;
        try {
            scheduledState = ScheduledState.valueOf(updateReferenceRequest.getState());
        } catch (final IllegalArgumentException e) {
        // ignore
        }
        ControllerServiceState controllerServiceState = null;
        try {
            controllerServiceState = ControllerServiceState.valueOf(updateReferenceRequest.getState());
        } catch (final IllegalArgumentException iae) {
        // ignore
        }
        final Map<String, Revision> referencingRevisions = updateReferenceRequest.getReferencingComponentRevisions().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> {
            final RevisionDTO rev = e.getValue();
            return new Revision(rev.getVersion(), rev.getClientId(), e.getKey());
        }));
        // update the controller service references
        final ControllerServiceReferencingComponentsEntity entity = serviceFacade.updateControllerServiceReferencingComponents(referencingRevisions, updateReferenceRequest.getId(), scheduledState, controllerServiceState);
        return generateOkResponse(entity).build();
    });
}
Also used : Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) StringUtils(org.apache.commons.lang3.StringUtils) ClientIdParameter(org.apache.nifi.web.api.request.ClientIdParameter) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) AuthorizeControllerServiceReference(org.apache.nifi.authorization.AuthorizeControllerServiceReference) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) UiExtension(org.apache.nifi.ui.extension.UiExtension) DefaultValue(javax.ws.rs.DefaultValue) UiExtensionType(org.apache.nifi.web.UiExtensionType) DELETE(javax.ws.rs.DELETE) ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) Context(javax.ws.rs.core.Context) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Set(java.util.Set) LongParameter(org.apache.nifi.web.api.request.LongParameter) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) ScheduledState(org.apache.nifi.controller.ScheduledState) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) PathParam(javax.ws.rs.PathParam) Revision(org.apache.nifi.web.Revision) GET(javax.ws.rs.GET) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) PropertyDescriptorEntity(org.apache.nifi.web.api.entity.PropertyDescriptorEntity) ApiResponses(io.swagger.annotations.ApiResponses) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) HttpMethod(javax.ws.rs.HttpMethod) HashSet(java.util.HashSet) HttpServletRequest(javax.servlet.http.HttpServletRequest) UpdateControllerServiceReferenceRequestEntity(org.apache.nifi.web.api.entity.UpdateControllerServiceReferenceRequestEntity) Api(io.swagger.annotations.Api) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RequestAction(org.apache.nifi.authorization.RequestAction) Authorizer(org.apache.nifi.authorization.Authorizer) ApiResponse(io.swagger.annotations.ApiResponse) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) ComponentStateDTO(org.apache.nifi.web.api.dto.ComponentStateDTO) ComponentStateEntity(org.apache.nifi.web.api.entity.ComponentStateEntity) ServletContext(javax.servlet.ServletContext) PUT(javax.ws.rs.PUT) Authorization(io.swagger.annotations.Authorization) ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Revision(org.apache.nifi.web.Revision) ScheduledState(org.apache.nifi.controller.ScheduledState) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) Map(java.util.Map) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiParam (io.swagger.annotations.ApiParam)68 ApiOperation (io.swagger.annotations.ApiOperation)64 Api (io.swagger.annotations.Api)63 Path (javax.ws.rs.Path)56 ApiResponse (io.swagger.annotations.ApiResponse)51 PathParam (javax.ws.rs.PathParam)51 ApiResponses (io.swagger.annotations.ApiResponses)50 GET (javax.ws.rs.GET)50 List (java.util.List)49 Produces (javax.ws.rs.Produces)49 Response (javax.ws.rs.core.Response)49 Collectors (java.util.stream.Collectors)42 PUT (javax.ws.rs.PUT)42 Logger (org.slf4j.Logger)40 LoggerFactory (org.slf4j.LoggerFactory)40 POST (javax.ws.rs.POST)39 DELETE (javax.ws.rs.DELETE)38 Inject (javax.inject.Inject)37 MediaType (javax.ws.rs.core.MediaType)37 QueryParam (javax.ws.rs.QueryParam)36