Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #137 from RichardW98/scan-component-from-diff-package
Browse files Browse the repository at this point in the history
component scan from different packages
  • Loading branch information
lshannon committed Mar 22, 2023
2 parents be3d769 + 1623485 commit 9dac4f2
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022 Red Hat Developer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.parodos.workflow.examples;

import com.redhat.parodos.workflow.annotation.Infrastructure;
import com.redhat.parodos.workflow.consts.WorkFlowConstants;
import com.redhat.parodos.workflows.workflow.SequentialFlow;
import com.redhat.parodos.workflows.workflow.WorkFlow;
import org.parodos.workflow.examples.task.CustomWorkFlowTask;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Very simple workflow configurations in different package from Parodos main class
*
* @author Richard Wang (Github: richardW98)
*/

@Configuration
public class CustomWorkFlowConfiguration {

// START Custom Sequential Example (WorkflowTasks and Workflow Definitions)
@Bean
CustomWorkFlowTask customWorkFlowTask() {
return new CustomWorkFlowTask();
}

@Bean(name = "customWorkflow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW)
@Infrastructure
WorkFlow customWorkflow(@Qualifier("customWorkFlowTask") CustomWorkFlowTask customWorkFlowTask) {
// @formatter:off
return SequentialFlow
.Builder.aNewSequentialFlow()
.named("customWorkflow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW)
.execute(customWorkFlowTask)
.build();
// @formatter:on
}
// END Custom Sequential Example (WorkflowTasks and Workflow Definitions)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 Red Hat Developer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.parodos.workflow.examples.task;

import com.redhat.parodos.workflow.task.infrastructure.BaseInfrastructureWorkFlowTask;
import com.redhat.parodos.workflows.work.DefaultWorkReport;
import com.redhat.parodos.workflows.work.WorkContext;
import com.redhat.parodos.workflows.work.WorkReport;
import com.redhat.parodos.workflows.work.WorkStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
* very simple task for customWorkflow Configuration
*
* @author Richard Wang (Github: richardw98)
*/

@Slf4j
@Component
public class CustomWorkFlowTask extends BaseInfrastructureWorkFlowTask {

@Override
public WorkReport execute(WorkContext workContext) {
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}

}
29 changes: 29 additions & 0 deletions workflow-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,32 @@ Parodos

Yes. In this first release a configuration pattern widely used across many enterprise environments was chosen. However,
future release will include a DSL (domain specific language) for configuring Workflows without have to write Java code.

### How to configure my postgres database and my workflow configuration class in different package?

before starting this workflow-service application, set the following environment variables for the database:
* DATASOURCE_URL
* DATASOURCE_DRIVER
* DATASOURCE_USERNAME
* DATASOURCE_PASSWORD

example:
```
export DATASOURCE_URL="jdbc:postgresql://localhost:5432/postgres"
export DATASOURCE_DRIVER="org.postgresql.Driver"
export DATASOURCE_USERNAME="postgres"
export DATASOURCE_PASSWORD="postgres"
```

the environment variable for workflow configuration in different package:
* CONFIGURATION_PACKAGE

example:
```
export CONFIGURATION_PACKAGE=org.test.*
```

for multiple packages:
```
export CONFIGURATION_PACKAGE=org.test.*,dev.test2.*
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Luke Shannon (Github: lshannon)
*/
@SpringBootApplication
@SpringBootApplication(scanBasePackages = { "com.redhat.parodos", "${scan.packages}" })
@EnableScheduling
@EnableWebSecurity
@EnableAspectJAutoProxy
Expand Down
4 changes: 4 additions & 0 deletions workflow-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ spring:
springdoc:
swagger-ui:
tagsSorter: alpha


scan:
packages: ${CONFIGURATION_PACKAGE:-}

0 comments on commit 9dac4f2

Please sign in to comment.