All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.server.graphql.DeploymentResolver Maven / Gradle / Ivy

There is a newer version: 1.17.6
Show newest version
package com.xlrit.gears.server.graphql;

import java.util.List;

import lombok.RequiredArgsConstructor;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;

@Controller
@RequiredArgsConstructor
public class DeploymentResolver {
	private static final Logger LOG = LoggerFactory.getLogger(DeploymentResolver.class);
	public static final String CATEGORY_INACTIVE = "INACTIVE";

	private final RepositoryService repositoryService;

	// === queries === //

	@PreAuthorize("hasRole('admin')")
	@QueryMapping
	public List deployments() {
		return repositoryService
			.createDeploymentQuery()
			.list();
	}

	@PreAuthorize("hasRole('admin')")
	@QueryMapping
	public Deployment deployment(@Argument String id) {
		return repositoryService
			.createDeploymentQuery()
			.deploymentId(id)
			.singleResult();
	}

	// === mutations === //

	@PreAuthorize("hasRole('admin')")
	@MutationMapping
	public boolean activateDeployment(@Argument String id) {
		repositoryService.setDeploymentCategory(id, null);
		List defs = repositoryService.createProcessDefinitionQuery().deploymentId(id).suspended().list();
		for (ProcessDefinition def : defs) {
			LOG.info("Activating process definition {}", def.getId());
			repositoryService.activateProcessDefinitionById(def.getId());
		}
		return true;
	}

	@PreAuthorize("hasRole('admin')")
	@MutationMapping
	public boolean deactivateDeployment(@Argument String id) {
		repositoryService.setDeploymentCategory(id, CATEGORY_INACTIVE);
		List defs = repositoryService.createProcessDefinitionQuery().deploymentId(id).active().list();
		for (ProcessDefinition def : defs) {
			LOG.info("Suspending process definition {}", def.getId());
			repositoryService.suspendProcessDefinitionById(def.getId());
		}
		return true;
	}

	@PreAuthorize("hasRole('admin')")
	@MutationMapping
	public String removeDeployment(@Argument String id, @Argument boolean cascade) {
		repositoryService.deleteDeployment(id, cascade);
		// TODO return null if removal fails
		return id;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy