Hi All,
I am new to CQ, just started few weeks back.
I have to create a workflow wherein asset[say single/multiple .jpeg image] in one of the folder in DAM has to be moved to another folder[source and destination folders for now are say some dedicated folders], to get started with.
I have created a service [.java file with the basic framework of implementing interface,execute() method] and in the workflow console[ for a new workflow in the process step], I am able to tag my workflow to the service I have created.
However, I am struggling to write the logic here.
If someone could guide me here, to get started with . It would be really helpful.
Regards,
askdctm
Solved! Go to Solution.
To get the session object, a much easier way is: the execute method is passed the workflowSession object, so you can adapt it to the JCR Session object:
Session jcrSession = session.adaptTo(Session.
class
);
But beyond that, session.move requires that the parameters are paths to nodes. Is that the case for these?
String source = "/content/dam/dropfolder/drop";
String dest = "/content/dam/Destination/dest";
Are you using a Launcher relationship to start the workflow?
scott
Views
Replies
Total Likes
I'm not sure what you mean by:
askdctm wrote...
I am able to tag my workflow to the service I have created.
Have you added the Process Step to your workflow model?
http://dev.day.com/docs/en/cq/current/workflows/wf-ref.html#Process%20Step
scott
Views
Replies
Total Likes
Hi Scott,
Yes, I have added a process step.
"I have created a service [.java file with the basic framework of implementing interface,execute() method] and in the workflow console[ for a new workflow in the process step]"
In the process step, my custom "Migrationnn Workflow" is appearing. However I am not able to generate a logic/code as to how, it needs to be done.
The annotations used in my java class file are as below:
@Component
@Service
@Properties(value = {
@Property(name="service.description", value="Migrationnn Workflow"),
@Property(name="service.vendor", value="xxxxxxxxx"),
@Property(name="process.label", value="Migrationnn Workflow") })
Regards,
askdctm
Views
Replies
Total Likes
I guess the workflow would be started using the asset as the payload. You can get the JCR path of the payload (as shown in the code example here: https://dev.day.com/docs/en/cq/current/workflows/wf-extending.html#Developing%20Process%20Step%20Imp...). That example also shows how to get the JCR session object, and you can then use the Session.move method to move it (http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Session.html).
scott
Views
Replies
Total Likes
Hi Scott,
Thank you for your reply.
Just saw your latest reply.
However, what I tried is as below[not working]
@Component
@Service
@Properties(value = {
@Property(name="service.description", value="Migrationnn Workflow"),
@Property(name="service.vendor", value="xxxxxxx"),
@Property(name="process.label", value="Migrationnn Workflow") })
public class workflow implements WorkflowProcess
{
@Reference
private ResourceResolverFactory resolverFactory;
@Reference
private SlingRepository repository;
private Session session;
private static final Logger log = LoggerFactory.getLogger(workflow.class);
@Activate
public void activate() throws Exception{
session=repository.loginAdministrative(null);
}
@Deactivate
public void deactivate() throws Exception{
session.logout();
}
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaData) throws WorkflowException
{
//WorkflowData workflowData = workItem.getWorkflowData();
// System.out.println("workflow data is " +workflowdata);
try{
String source = "/content/dam/dropfolder/drop";
String dest = "/content/dam/Destination/dest";
// damPath = workflowData.getPayload().toString();
//workflowSession.getSession().move(source, dest);
//workflowSession.getSession().save();
/*
Repository repository = JcrUtils.getRepository("http://localhost:4503/crx/server");
//Create a Session
javax.jcr.Session Session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
Session userSession = resourceResolver.adaptTo(Session.class);*/
session.move(source,dest);
}
catch(Exception ex)
{
log.error("workflow error"+ex.getMessage());
ex.printStackTrace();
}
finally
{
//workflowSession.complete(workItem, (Route) routes.get(0));
log.info(" workflow complete");
}
}
}
Regards,
askdctm
To get the session object, a much easier way is: the execute method is passed the workflowSession object, so you can adapt it to the JCR Session object:
Session jcrSession = session.adaptTo(Session.
class
);
But beyond that, session.move requires that the parameters are paths to nodes. Is that the case for these?
String source = "/content/dam/dropfolder/drop";
String dest = "/content/dam/Destination/dest";
Are you using a Launcher relationship to start the workflow?
scott
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies