-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
293 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
designer/server/src/main/scala/pl/touk/nussknacker/ui/api/ActionInfoHttpService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pl.touk.nussknacker.ui.api | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import pl.touk.nussknacker.engine.api.process.ProcessName | ||
import pl.touk.nussknacker.restmodel.BaseEndpointDefinitions | ||
import pl.touk.nussknacker.ui.api.ActionInfoHttpService.ActionInfoError | ||
import pl.touk.nussknacker.ui.api.ActionInfoHttpService.ActionInfoError.{NoPermission, NoScenario} | ||
import pl.touk.nussknacker.ui.api.BaseHttpService.CustomAuthorizationError | ||
import pl.touk.nussknacker.ui.api.description.ActionInfoEndpoints | ||
import pl.touk.nussknacker.ui.api.utils.ScenarioHttpServiceExtensions | ||
import pl.touk.nussknacker.ui.process.ProcessService | ||
import pl.touk.nussknacker.ui.process.newactivity.ActionInfoService | ||
import pl.touk.nussknacker.ui.process.processingtype.provider.ProcessingTypeDataProvider | ||
import pl.touk.nussknacker.ui.security.api.AuthManager | ||
import sttp.tapir.{Codec, CodecFormat} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class ActionInfoHttpService( | ||
authManager: AuthManager, | ||
processingTypeToActionInfoService: ProcessingTypeDataProvider[ActionInfoService, _], | ||
protected override val scenarioService: ProcessService | ||
)(implicit val executionContext: ExecutionContext) | ||
extends BaseHttpService(authManager) | ||
with ScenarioHttpServiceExtensions | ||
with LazyLogging { | ||
|
||
override protected type BusinessErrorType = ActionInfoError | ||
override protected def noScenarioError(scenarioName: ProcessName): ActionInfoError = NoScenario(scenarioName) | ||
override protected def noPermissionError: ActionInfoError with CustomAuthorizationError = NoPermission | ||
|
||
private val securityInput = authManager.authenticationEndpointInput() | ||
|
||
private val endpoints = new ActionInfoEndpoints(securityInput) | ||
|
||
expose { | ||
endpoints.actionParametersEndpoint | ||
.serverSecurityLogic(authorizeKnownUser[ActionInfoError]) | ||
.serverLogicEitherT { implicit loggedUser => actionParametersInput => | ||
val (scenarioName, scenarioGraph) = actionParametersInput | ||
for { | ||
scenarioWithDetails <- getScenarioWithDetailsByName(scenarioName) | ||
actionInfoService = processingTypeToActionInfoService.forProcessingTypeUnsafe( | ||
scenarioWithDetails.processingType | ||
) | ||
actionParameters = actionInfoService.getActionParameters( | ||
scenarioGraph, | ||
scenarioWithDetails.processVersionUnsafe, | ||
scenarioWithDetails.isFragment | ||
) | ||
} yield actionParameters | ||
} | ||
} | ||
|
||
} | ||
|
||
object ActionInfoHttpService { | ||
|
||
sealed trait ActionInfoError | ||
|
||
object ActionInfoError { | ||
final case class NoScenario(scenarioName: ProcessName) extends ActionInfoError | ||
final case object NoPermission extends ActionInfoError with CustomAuthorizationError | ||
|
||
implicit val noScenarioCodec: Codec[String, NoScenario, CodecFormat.TextPlain] = { | ||
BaseEndpointDefinitions.toTextPlainCodecSerializationOnly[NoScenario](e => s"No scenario ${e.scenarioName} found") | ||
} | ||
|
||
} | ||
|
||
} |
45 changes: 0 additions & 45 deletions
45
designer/server/src/main/scala/pl/touk/nussknacker/ui/api/ActionInfoResources.scala
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...er/server/src/main/scala/pl/touk/nussknacker/ui/api/description/ActionInfoEndpoints.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package pl.touk.nussknacker.ui.api.description | ||
|
||
import pl.touk.nussknacker.engine.api.deployment.ScenarioActionName | ||
import pl.touk.nussknacker.engine.api.{NodeId, StreamMetaData} | ||
import pl.touk.nussknacker.engine.api.graph.{ProcessProperties, ScenarioGraph} | ||
import pl.touk.nussknacker.engine.api.process.ProcessName | ||
import pl.touk.nussknacker.restmodel.BaseEndpointDefinitions | ||
import pl.touk.nussknacker.restmodel.BaseEndpointDefinitions.SecuredEndpoint | ||
import pl.touk.nussknacker.restmodel.definition.UiActionParameterConfig | ||
import pl.touk.nussknacker.security.AuthCredentials | ||
import pl.touk.nussknacker.ui.api.ActionInfoHttpService.ActionInfoError | ||
import pl.touk.nussknacker.ui.api.ActionInfoHttpService.ActionInfoError.NoScenario | ||
import pl.touk.nussknacker.ui.api.TapirCodecs.ScenarioNameCodec._ | ||
import pl.touk.nussknacker.ui.api.TapirCodecs.ScenarioGraphCodec._ | ||
import pl.touk.nussknacker.ui.api.description.ActionInfoEndpoints.Examples.noScenarioExample | ||
import pl.touk.nussknacker.ui.api.description.ActionInfoEndpoints._ | ||
import pl.touk.nussknacker.ui.process.newactivity.ActionInfoService.{UiActionNodeParameters, UiActionParameters} | ||
import sttp.model.StatusCode.{NotFound, Ok} | ||
import sttp.tapir.EndpointIO.Example | ||
import sttp.tapir._ | ||
import sttp.tapir.json.circe.jsonBody | ||
|
||
class ActionInfoEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndpointDefinitions { | ||
|
||
lazy val actionParametersEndpoint | ||
: SecuredEndpoint[(ProcessName, ScenarioGraph), ActionInfoError, UiActionParameters, Any] = | ||
baseNuApiEndpoint | ||
.summary("Get action parameters") | ||
.tag("Deployments") | ||
.post | ||
.in("actionInfo" / path[ProcessName]("scenarioName") / "actionParameters") | ||
.in( | ||
jsonBody[ScenarioGraph] | ||
.example(simpleGraphExample) | ||
) | ||
.out( | ||
statusCode(Ok).and( | ||
jsonBody[UiActionParameters] | ||
.examples( | ||
List( | ||
Example.of( | ||
summary = Some("Valid action parameters for given scenario"), | ||
value = Map( | ||
ScenarioActionName.Deploy -> List( | ||
UiActionNodeParameters( | ||
NodeId("sample node id"), | ||
Map("param name" -> UiActionParameterConfig.empty) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
.errorOut( | ||
oneOf[ActionInfoError]( | ||
noScenarioExample | ||
) | ||
) | ||
.withSecurity(auth) | ||
|
||
private val simpleGraphExample: Example[ScenarioGraph] = Example.of( | ||
ScenarioGraph( | ||
ProcessProperties(StreamMetaData()), | ||
List(), | ||
List(), | ||
) | ||
) | ||
|
||
} | ||
|
||
object ActionInfoEndpoints { | ||
|
||
implicit val uiActionParametersSchema: Schema[UiActionParameters] = Schema.anyObject | ||
|
||
object Examples { | ||
|
||
val noScenarioExample: EndpointOutput.OneOfVariant[NoScenario] = | ||
oneOfVariantFromMatchType( | ||
NotFound, | ||
plainBody[NoScenario] | ||
.example( | ||
Example.of( | ||
summary = Some("No scenario {scenarioName} found"), | ||
value = NoScenario(ProcessName("'example scenario'")) | ||
) | ||
) | ||
) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.