Topic
  • 8 replies
  • Latest Post - ‏2012-07-09T14:15:49Z by SystemAdmin
SystemAdmin
SystemAdmin
648 Posts

Pinned topic PrePostProcessingFunction Extension Point.

‏2012-07-04T14:18:13Z |
I'm trying to achieve is below but facing some problem.
•I have a validation framework which validates couple of attrib values of an item in a particular catalog and returns the error message on the screen.
•The validation gets triggered from a Catalog script attached to the postprocessingscript section which internally calls a java based validation framework.
•I'm now checking out one such item in to a collaboration area but everytime I'm doing so it's invoking the below method in my class file which is implementing "PrePostProcessingFunction" interface.
public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs)
.I don't want this to be called while checking out the item rather at the time when I'm modifying something on the item been already checked out and then clicking on save button. Ideally it should invoke the prePostProcessing method at this particular point not when I'm checking out the item itself.

Please suggest.

Thanks,
Abhijeet
Updated on 2012-07-09T14:15:49Z at 2012-07-09T14:15:49Z by SystemAdmin
  • babinag
    babinag
    91 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-05T05:03:47Z  
    Hi Abhijeet.M.

    The
    
    
    
    public 
    
    void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs)
    

    method invocation occurs because when you checkout some item into collArea there is "save" event on newly created colItem occurs.

    You may select when to call your validation framework in this method by:
    1. step name, where colItem currently exists(CollaborationItemPrePostProcessingFunctionArguments inArgs.getCollaborationStep()).
    One note, when checked item first appears in collabArea, it have no step( == null), than item is going to initial step and further.
    2. You may call validation framework only when colItem leaves colStep by checking exitValue
    (CollaborationItemPrePostProcessingFunctionArguments inArgs.getExitValueForItem()).
    Exit value is null when item saved, and == pressed button name when item leaves colStep.
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-05T10:10:16Z  
    • babinag
    • ‏2012-07-05T05:03:47Z
    Hi Abhijeet.M.

    The <pre class="jive-pre"> public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs) </pre>
    method invocation occurs because when you checkout some item into collArea there is "save" event on newly created colItem occurs.

    You may select when to call your validation framework in this method by:
    1. step name, where colItem currently exists(CollaborationItemPrePostProcessingFunctionArguments inArgs.getCollaborationStep()).
    One note, when checked item first appears in collabArea, it have no step( == null), than item is going to initial step and further.
    2. You may call validation framework only when colItem leaves colStep by checking exitValue
    (CollaborationItemPrePostProcessingFunctionArguments inArgs.getExitValueForItem()).
    Exit value is null when item saved, and == pressed button name when item leaves colStep.
    Thanks Babinag! I'm atleast able to control the invokation now.
    But now, on click of save I'm reading the attribute values which I have modified manually in the collaboration area itself, I'm always getting the attribute value of the source item in the container and not the one with which I have modified it. For instance see below.

    • Opens the collaboration area, clicks on the 1 item been checked out there to see item info of the same.
    • Changes the attribute value of attribute "Name" from "XYZ" to "ABC".
    • Clicks on save button on top.
    • Reads the value of "Name" attribute in one of the implementation class of validation framework and it gives me "XYZ" only instead of "ABC".

    Could you please help?

    Thanks,
    Abhijeet
  • babinag
    babinag
    91 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-05T11:02:28Z  
    Thanks Babinag! I'm atleast able to control the invokation now.
    But now, on click of save I'm reading the attribute values which I have modified manually in the collaboration area itself, I'm always getting the attribute value of the source item in the container and not the one with which I have modified it. For instance see below.

    • Opens the collaboration area, clicks on the 1 item been checked out there to see item info of the same.
    • Changes the attribute value of attribute "Name" from "XYZ" to "ABC".
    • Clicks on save button on top.
    • Reads the value of "Name" attribute in one of the implementation class of validation framework and it gives me "XYZ" only instead of "ABC".

    Could you please help?

    Thanks,
    Abhijeet
    Abhijeet.M, that is very strange behaviour of collaboration item i have not seen it before.
    Every time when my item saved, invocation of
    
    CollaborationItem collaborationItem = inArgs.getCollaborationItem(); 
    //StringUtil is utility to convert null value to empty string like checkString script function String value = StringUtil.CheckString(collaborationItem.getAttributeValue(
    "SPEC/Attribute"), 
    "");
    

    results in value i have changed.

    My thoughts is that you did not properly set collaborationStep "Attributes to validate".
    If your attribute not in "required" or "editable" attributeCollections of step, their values would never be saved at this step.
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-05T12:23:54Z  
    • babinag
    • ‏2012-07-05T11:02:28Z
    Abhijeet.M, that is very strange behaviour of collaboration item i have not seen it before.
    Every time when my item saved, invocation of
    <pre class="jive-pre"> CollaborationItem collaborationItem = inArgs.getCollaborationItem(); //StringUtil is utility to convert null value to empty string like checkString script function String value = StringUtil.CheckString(collaborationItem.getAttributeValue( "SPEC/Attribute"), ""); </pre>
    results in value i have changed.

    My thoughts is that you did not properly set collaborationStep "Attributes to validate".
    If your attribute not in "required" or "editable" attributeCollections of step, their values would never be saved at this step.
    My Bad. I was operating on the source item rather than the CollaborationItem object.
    I could read the changes value now. Working exactly as expected and I'm able to show the validation error messages against the particular attribute instances as well while updating the collaboration item.
    But when I'm calling the save operation through API I want those validation errors from the framwork to be fetched in return.

    I'm using below in my JAPI to save the collItem after setting the attribute value of a certain attribute. But it's not working.

    ExtendedValidationErrors saveErr = checkedOutItem.save();

    Thanks,
    Abhijeet
  • babinag
    babinag
    91 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-05T13:31:15Z  
    My Bad. I was operating on the source item rather than the CollaborationItem object.
    I could read the changes value now. Working exactly as expected and I'm able to show the validation error messages against the particular attribute instances as well while updating the collaboration item.
    But when I'm calling the save operation through API I want those validation errors from the framwork to be fetched in return.

    I'm using below in my JAPI to save the collItem after setting the attribute value of a certain attribute. But it's not working.

    ExtendedValidationErrors saveErr = checkedOutItem.save();

    Thanks,
    Abhijeet
    Hmm. All errors must be in ExtendedValidationErrors when you save collab item.

    You can get them like:
    
    ExtendedValidationErrors save = colItem.save(); 
    
    if(save!=
    
    null)
    { 
    
    for(ValidationError error:save.getErrors())
    { String attPath = error.getAttributeInstance().getPath(); String type = error.getType().toString(); String message = error.getMessage(); 
    } 
    }
    
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-06T11:45:02Z  
    • babinag
    • ‏2012-07-05T13:31:15Z
    Hmm. All errors must be in ExtendedValidationErrors when you save collab item.

    You can get them like:
    <pre class="jive-pre"> ExtendedValidationErrors save = colItem.save(); if(save!= null) { for(ValidationError error:save.getErrors()) { String attPath = error.getAttributeInstance().getPath(); String type = error.getType().toString(); String message = error.getMessage(); } } </pre>
    I have implemented the below but not in the calling class rather in my validation class and inside the method public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs).

    But my calling class is having the statement
    ExtendedValidationErrors saveErr = checkedOutItem.save();

    Which is invoking public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs) method.

    So how should I return the messages to the saveErr variable from the prePostProcessing() method. MY last lines in prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs) method reads below. As this is a void method I can't even return anything. Please note that the PIMRuleMessage and all are my user defined classes and are part of the validation framework.
    if((errors != null) && (!errors.isEmpty())){
    for (PIMRuleMessage message : errors) {
    String attrPath = message.getAttributePath();
    AttributeInstance attribInstance = oCollItem.getAttributeInstance(attrPath);
    inArgs.addValidationError(attribInstance, ValidationError.Type.VALIDATION_RULE, message.getRuleMessage());
    pimLogger.logInfo("CollaborationItemPrePostProcessingFunctionArguments | Post process Validation ERROR = " + message.getRuleMessage());
    System.out.println("CollaborationItemPrePostProcessingFunctionArguments | Post process Validation ERROR = " + message.getRuleMessage());
    }
    }
  • babinag
    babinag
    91 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-09T05:53:32Z  
    I have implemented the below but not in the calling class rather in my validation class and inside the method public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs).

    But my calling class is having the statement
    ExtendedValidationErrors saveErr = checkedOutItem.save();

    Which is invoking public void prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs) method.

    So how should I return the messages to the saveErr variable from the prePostProcessing() method. MY last lines in prePostProcessing(CollaborationItemPrePostProcessingFunctionArguments inArgs) method reads below. As this is a void method I can't even return anything. Please note that the PIMRuleMessage and all are my user defined classes and are part of the validation framework.
    if((errors != null) && (!errors.isEmpty())){
    for (PIMRuleMessage message : errors) {
    String attrPath = message.getAttributePath();
    AttributeInstance attribInstance = oCollItem.getAttributeInstance(attrPath);
    inArgs.addValidationError(attribInstance, ValidationError.Type.VALIDATION_RULE, message.getRuleMessage());
    pimLogger.logInfo("CollaborationItemPrePostProcessingFunctionArguments | Post process Validation ERROR = " + message.getRuleMessage());
    System.out.println("CollaborationItemPrePostProcessingFunctionArguments | Post process Validation ERROR = " + message.getRuleMessage());
    }
    }
    So you are invoking colItem.save() in postprocess on the same item, which postprocess was triggered?

    When i tried this, infinite loop appears.

    I'm not really understand problem you faced with.
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: PrePostProcessingFunction Extension Point.

    ‏2012-07-09T14:15:49Z  
    • babinag
    • ‏2012-07-09T05:53:32Z
    So you are invoking colItem.save() in postprocess on the same item, which postprocess was triggered?

    When i tried this, infinite loop appears.

    I'm not really understand problem you faced with.
    Well. I cracked it. Used the below snippet to grap the customized validations as well. Ran the class by Sandbox extension point method and it worked. Thanks again Babinag!

    ExtendedValidationErrors saveErr = checkedOutItem.save();
    if (saveErr != null) {
    List<String> errorList = new ArrayList<String>();
    for (ValidationError error : saveErr.getErrors()) {
    errorList.add("\n Attribute Path ::: Error Type ::: + Error Message --> " +error.getAttributeInstance().getPath() + " ::: " + error.getType()+ " ::: " + error.getMessage());
    }
    Iterator<String> iteratorErrorList = errorList.iterator();
    cpOut.write ("\n Errors Obtained - ");
    while (iteratorErrorList.hasNext()) {
    cpOut.write (iteratorErrorList.next());
    }
    cpOut.write ("\n Failed on Save");
    }