Spring & Activiti workflow: Get all informations from a Task - spring

working on a simple project using Activiti utility, I just started using it don't know much about it but I want to retrieve all the information from a Task, I did an example but it returns just the id and the name while I need more informations to be returned.
This is what I tried:
public List<Task> getTasks(String assignee) {
return taskService.createTaskQuery().taskAssignee(assignee).list();
}
This piece of code returns me this result:
But I need more inforamtions like Assigne, task properties ... Any help

Related

Why does Sonarqube mark try as a critical issue?

I'm currently facing an issue with some SonarQube's analysis being performed over some Kotlin code I wrote.
I'm trying to implement a method that connects to the database and returns accordingly to the query's result. I'm not sure how related this can be, but I added the following maven dependencies to my project:
Quarkus
Arrow
Ktorm
The code is the following:
#ApplicationScoped
class Repository(private val database: Database) {
override fun get(name: String): Either<Error, Brand> =
try {
database.brands.find { it.name eq name }.rightIfNotNull {
MissingBrandError("Missing brand")
}
} catch (e: Exception) {
Either.Left(DatabaseError(e.message))
}
}
class Error(val message: String)
class MissingUserError(val message: String) : Error(message)
class DatabaseError(val message: String? = null) : Error(message ?: "Some database error")
NOTE: Database object is of type org.ktorm.database.Database and brands is of type org.ktorm.entity.EntitySequence
The code is working and I also wrote unit tests for it that pass and give enough coverage (accordingly to the code coverage analysis tool), but at some point in my pipeline SonarQube marks the try as a critical issue with the following message:
Possible null pointer dereference in (...)Repository(String) due to return value of called method
I checked it online and I could find some related questions, but none of the provided answers worked for me. Amongst the many attempts these are the ones I can remember I tried without any success:
Not inlining any code (pretty much using Java style code)
Extracting the query result to a variable
Check with if/else statements for nullability instead (both with inlined try and without)
I'd also like to highlight that all I can see on Sonar is the generated report and CLI for the running build. I don't have access to any of its configuration or intended to change them (unless of course it comes down to that). The line I mentioned seems to be the only one affected by this problem according to Sonar's report, that's why this is the solo class I provided.
I hope I provided enough info and that any of you can help me with this. Thanks in advance.

Handling usertask in camunda/zeebe

I am new to Camunda/zeebe BPM. I am using the send-email workflow provided by Zeebe to test and play around. I am able to start the process from spring boot application and able to get the instance id information. I want to pass the message content which is defined in the user task using a RestAPI call to my custom spring boot application. It would be great if anyone can point in the right direction on the following
How to pass the variable input to the user task from a spring boot application?
Is there API to get the list of active task for a given instance id (for Zeebe)
Is it possible to make a REST API call to Zeebe directly to provide the input for the human task with help of instance id.
Also can you point some details on how to do with Camunda server instead of Zeebe.
You can define a system task with implementation as delegate expression and set the variable required in the java class. The scope of the variable would be throughout the process instance and is accessible from any user task. If you want you can specifically map variable from the Input/Output tab.
GET http://localhost:8080/engine-rest/task?processInstanceId=100001920009
You have to list the tasks with the api in point 2 then claim the task using task id which will be in the response of point 2
POST http://localhost:8080/engine-rest/task/7676a188-e0f4-11eb-bd9c-22a3117ba565/claim
Then can complete the task with
POST http://localhost:8080/engine-rest/task/7676a188-e0f4-11eb-bd9c-22a3117ba565/complete
if variables are to be passed use the below template as the body
{
"variables": {
"aVariable": {
"value": "aStringValue"
},
"anotherVariable": {
"value": 42
},
"aThirdVariable": {
"value": true
}
},
"withVariablesInReturn": true
}

Add list element to Spring properties at runtime

I have an application.yml file with the following:
topics:
input:
- name: topic1
partitions: 3
replicas: 1
- name: topic2
partitions: 6
replicas: 2
I would like to be able to update or add a new topic object at runtime.
I have tried the following for updating an existing object:
java -jar app.jar --topics.input[0].name="topicX"
and the following for adding another object to the list:
java -jar app.jar --topics.input[2].name="topicX" --topics.input[2].partitions=6 --topics.input[2].replicas=2
I am accessing the properties in the following way:
#Component
#ConfigurationProperties(prefix = "topics")
#Validated
public class TopicsConfiguration {
#NotEmpty
#NotNull
private List<TopicConfiguration> input = new ArrayList<>();
public List<TopicConfiguration> getInputTopics() {
return input;
}
public void setFacts(List<TopicConfiguration> input) {
this.input = input;
}
}
Where TopicConfiguration is just a POJO with the 3 fields listed.
When I don't try and modify any of the property objects at runtime this works exactly as I expect, however I can not update the property list at all. When I try and update an existing object I get an NPE. When I try and add a new object to the list I get:
Property: topics.input[2].name
Value: lmnop
Origin: "topics.input[2].name" from property source "commandLineArgs"
Reason: The elements [topics.input[2].name,topics.input[2].partitions,topics.input[2].replicas] were left unbound.
I would just like to know if there is any way to update or add an element to the list at runtime so that users of my project don't have to modify application.yml if they want to update this configuration.
okey so i did some research and some testing and came up with the following:
you cannot update a defined list in application.yml
if you run:
java -jar myApp.jar -my-list[2].name=foo
it will fail, because as soon as you want to pass the list the list will override the current list in application.yml and you are trying to pass in the 3rd item in the list when there is nothing at index 0 and 1.
it is not a dynamic list, it as an array.
You need to pass the entire list:
java -jar myApp.jar -my-list[0].name=foo -my-list[1].name=bar -my-list[2].name=foobar
So if you are going to pass a list in from cmd, you must always define the list from scratch.
So you want to reload your application.properties or application.yml in your Spring Boot application on the fly without having to make another code commit to another deployment? If I understood that right then here is how you can do it.
Read the these links and also google more on Spring Boot Actuator Reload Properties or Spring Scheduling. We can't provide you an out-written code to get this working but there is plenty of examples to examine and try out.
Links:
Actuator Refresh
Spring Scheduling
If I were you, I would prefer Actuator method as it avoids confusion and is cleaner.

How to create Apis on Spring, that are using up to date environment values

I want to create API, which takes part of its input from environment (urls etc..). Basically a Jar file.
I also wan't the values being auto updated when application.properties changes. When there is change, this is called:
org.springframework.cloud.endpoint.RefreshEndpoint#refresh
However, I consider it bad practice to have magic env variable keys like 'server.x.url' in the Api contract between client application and the jar. (Problem A)
That's why I'd like to use Api like this. But there's problem of old values.
public class MyC {
TheAPI theApi=null;
void MyC(){
theApi = new TheApi();
theApi.setUrl( env.get("server.x.url") );
}
doStuff() {
theApi.doStuff(); // fails as theApi has obsolete value of server.x.url, Problem B
}
So either I have ugly API contract or I get obsolete values in the API calls.
I'm sure there must be Spring way of solving this, but I cant get it to my head just now.

Twitter/Spring - post tweet in a #Scheduled job

I have already got some "Spring-scheduled" tasks up and running successfully.
What I would like now is to post some specific tweets to a known Twitter account (and already configured on Twitter side) based on some event recurrence.
However, all I see in the OAuth process, esp. in order to get an access token, is that it requires some callback URL before being able to do anything.
I might be mistaken but this seems hard to integrate in the context of a scheduled task.
Isn't there any other way to achieve tweeting?
In conjunction with Spring Scheduling features, I would use Twitter4j to post a tweet in a scheduled job.
Here is a sample:
#Componet
public class TwitterSender {
#Scheduled(fixedRate = 10000)
public void sendTweet() {
Twitter twitter = TwitterFactory.getSingleton();
Status status = twitter.updateStatus(latestStatus);
System.out.println("Status updated to: " + status.getText() + ".");
}
}
If you need more information you can check the test case for sending update status with Twitter4j. Or you can just dive and see the source.
It may be a bit of a leap in terms of learning curve, but have you looked at spring-integration's twitter:outbound-channel-adapter ?
<twitter:outbound-channel-adapter twitter-template="twitterTemplate"
channel="twitterChannel"/>
http://static.springsource.org/spring-integration/docs/latest-ga/reference/html/twitter.html

Resources