Working with WorkflowPersistenceManager

36 views
Skip to first unread message

Sathish K

unread,
Jun 25, 2018, 10:15:37 AM6/25/18
to Hippo Community
Hi,

I'm just trying simple Restful component using 'JCR'.

I follow the reference link below 

I just create a 2 fields only, name & email.

the bean class are successfully generated.

  • then, i create a simple Form. this form have 2 text box(name and email) and submit button only.
  • then, i create a sample component, and i use a doAction method to get a Form value.

Bean class (Myform.java)
@HippoEssentialsGenerated(internalName = "gogreen:Myform")
@Node(jcrType = "gogreen:Myform")
public class Myform extends BaseDocument {

public String name, email;

@HippoEssentialsGenerated(internalName = "gogreen:name")
public String getName() {
return getProperty("gogreen:name");
}

@HippoEssentialsGenerated(internalName = "gogreen:email")
public String getEmail() {
return getProperty("gogreen:email");
}

public void setName(String name) {
this.name = name;
}

public void setEmail(String email) {
this.email = email;
}

}

Component class(SimpleFormComponent.java)

public class SimpleFormComponent extends BaseHstComponent {

public static final Logger log = LoggerFactory.getLogger(SimpleFormComponent.class);

@Persistable
@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {

System.out.println("********** Do Action ->>>>>>>>>>>>>>");
String name = null;
String email = null;

HstRequestContext requestContext = request.getRequestContext();

// Form Actions
FormMap formMap = new FormMap(request, new String[] { "name", "email" });

for (String fieldName : formMap.getFieldNames()) {
FormField field = formMap.getField(fieldName);
if (fieldName.equals("name"))
name = field.getValue();
if (fieldName.equals("email"))
email = field.getValue();
}

FormUtils.persistFormMap(request, response, formMap, null);

// Content actions
if (!name.isEmpty() && name != null) {

WorkflowPersistenceManager wpm = null;
try {
wpm = getWorkflowPersistenceManager(requestContext.getSession());

wpm.setWorkflowCallbackHandler(new BaseWorkflowCallbackHandler<DocumentWorkflow>() {
public void processWorkflow(DocumentWorkflow wf) throws Exception {
wf.requestPublication();
}
});

// get base path
String siteCanonicalBasePath = request.getRequestContext().getResolvedMount().getMount()
.getCanonicalContentPath();
Calendar currentDate = Calendar.getInstance();

// folderPath
String FolderPath = siteCanonicalBasePath + "/Form/" + currentDate.get(Calendar.YEAR) + "/"
+ currentDate.get(Calendar.MONTH) + "/" + currentDate.get(Calendar.DAY_OF_MONTH);

// Node Name
String NodeName = "form" + "-" + System.currentTimeMillis();

// create component
String beanPath = wpm.createAndReturn(FolderPath, "gogreen:Myform", NodeName, true);

// My Bean class 
Myform myform = (Myform) wpm.getObject(beanPath);

if (myform == null) {
System.out.println("-------------- Myform is null-------------------------");
}

// Set values
myform.setName(name);
myform.setEmail(email);

// update & save 
wpm.update(myform);
wpm.save();
System.out.println("Successfully updated..................");

} catch (Exception e) {
// log.warn("Failed to create a comment: ", e);
System.out.println(e);
e.printStackTrace();
if (wpm != null) {
try {
wpm.refresh();
} catch (ObjectBeanPersistenceException e1) {
// log.warn("Failed to refresh: ", e);
}
}
}

}

}
}

I successfully create a jcr component.
Folder name :  /content/documents/gogreen/Form/2018/5/25
File name     :  form-1529934138056

but, the Name and Email value is empty.
I attached image for your reference.











 
Name and Email fields are empty.
and also, its not published.

Question:
1. how to store the value from given filed.
2. how to publish the component.(i think filed value is empty, so, its not published.(this is correct or not)?)


Woonsan Ko

unread,
Jun 25, 2018, 10:30:25 AM6/25/18
to hippo-c...@googlegroups.com
You need to provide ContentNodeBinder by either the bean itself (Myform in your case) or a separate one.
HST WPM doesn't provide an automatic *binding* from the beans. It supports only *mapping*. Therefore you need to write manual code in ContentNodeBinder#bind(Object, Node) method like the example in the documentation.

 
2. how to publish the component.(i think filed value is empty, so, its not published.(this is correct or not)?)
Before wpm.update, you need to do wpm.setWorkflowCallbackHandler(...) and let your callback publish it. Also see the example in the documentation.

Regards,

Woonsan
 



P Protect the environment. Please print this only if absolutely required. 

Disclaimer: This message may contain confidential information and is intended only for the addressees named. If you are not the named addressee(s) we request you not to disseminate, distribute or copy this email. In the event this mail has been inadvertently sent to you, even if you are the addressee, please notify the sender immediately by email and delete this email from your system. Please also note that email transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of email transmission.
Rage Communications Pvt Ltd.,
www.whatarage.com

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--

Sathish K

unread,
Jun 26, 2018, 3:04:33 AM6/26/18
to Hippo Community
Thank You!!!!
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages