BCC Snapshot error fix

1. Click on Critical Reset (this may take several minutes)
2. Halt Deployments
3. In the “Overview” Section (Staging or Production – depending on which the error is occuring) click on the Projects tab and note the prdm id of the most latest project. You will need this id.
4. Go here: /nucleus/atg/epub/DeploymentServer/
5. Put the ID in step 4 in the “Force Snapshot ID” box and click Init.
6. This will force the snapshot.
7. Resume Deployments.
8. This will make the agents “healthy” but it will not resolve the initial issue that caused this. This “solution” is only to allow other deployments to go through. You will will need to resolve the issue that caused this.

Delete BCC Project

select * from epub_process where display_name = ‘ Name of your project‘; (this will give u processid)

select * from epub_process where display_name = ‘TEST1’

select * from epub_project where display_name = ‘Name of your project‘;(this will give u projectid)

select * from epub_project where display_name =  ‘TEST1’

 Go to publishing repository(atg/epub/publishingRepository in the dyn/admin of your BCC) and delete the process first by using remove-item then delete the project using remove-item

<remove-item item-descriptor=”process” id=”prc739000″></remove-item>

<remove-item item-descriptor=”project” id=”prj739000″></remove-item>

 

ATG application session implementation

Tools:

  • ATG 10.2
  • Weblogic 10.2.3

Target:

Handle time based session expiry and redirect user to home page.

Overview:

A servlet can be inserted into the dafpipeline through which all requests are passed, using out of the box component we can know if the session has expired for this request, once found we can take appropriate action like redirecting user to session time out page or home page.

Steps:

Configure time in weblogic

Home Page -> Domain Structure -> Deploymnets -> <Your deployment> -> Configuration tab -> Session Timeout (in seconds):

Default value is 1800 seconds i.e. 30 minutes

weblogictimeout

To apply session into atg app, we need to create pipeline servlet component using one of the following:

  1. projects.b2bstore.servlet. WACheckSessionExpiration
  2. projects.b2bstore.servlet. CheckSessionExpiration

 

If you are using WACheckSessionExpiration:

Create a property file like following:

$class=atg.projects.b2bstore.servlet.WACheckSessionExpiration
 # Specify where in the servlet pipeline this servlet should appear
insertAfterServlet=/atg/dynamo/servlet/dafpipeline/SessionSaverServlet
# Specify the root path (relative to the web app context root) of URLs'
# that we should check for session expiration
relativeExpirationPath=/checkout
# Specify the URL (relative to the web app context root) that we should
# redirect to if an expired session is detected.
relativeExpirationURL=/home
# Specify the web application registry where app is registered
webAppRegistry=/atg/registry/webappregistry/ServletContextWebAppRegistry
# Specify the name under which the web app is registered
webApplicationName=<Web App name>

If you are using CheckSessionExpiration:

Create a property file like following:

$class=atg.projects.b2bstore.servlet.CheckSessionExpiration
# Specify where in the servlet pipeline this servlet should appear
insertAfterServlet=/atg/dynamo/servlet/dafpipeline/SessionSaverServlet
#Complete URL where user would be redirected in case of session expiry
expirationURL=http://myhomepage.es
#Session would be checked for files under this directory only
sessionExpirationPath=/store/checkout

 

AJAX Calls:

Above solution would work for form submission but not for AJAX calls, by adding following to your JS file which is common for all pages you can handle the scenario.

$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
if(jqxhr.status == 0){
window.location.href = ‘http://myhomepage.es’;
}
});

 

This is a global error method for AJAX which would be called for all AJAX errors.

As pipeline would redirect the request to home page, it will cause AJAX calls to fail hence status would be 0 and then you can do any action you want.

BCC Snapshot error

In the BCC Admin Console (open BCC home > Admin Console > MySiteName), you will be able to see the current state of deployments to that site.  A snapshot mismatch is easy to see – the deployment will be halted and the following error message will be displayed below:

“Cannot perform a incremental deployment on target,  Check for snapshots mismatched on agents.”
This occurs when something has interrupted the publishing process and the DeploymentTarget (on the target we’re trying to publish to) has failed to update it’s latest snapshot id.  The snapshot id allows the DeploymentTarget to know what version of content it has received which in turns means the publishing process can verify if a project has aleady been published. Each snapshot id is mapped to a target and a project in the BCC server’s database schema.

So enough background, time to follow the steps to resolve the problem!  Firstly, we need that snapshot id and ideally, the target id so we can confirm it’s the right one.  A wise man once showed me an effective cheat to get this simply and quickly.  The links to previous projects in the site admin screen we opened contain the ids of our projects.  Therefore, copy the link for the previously deployed project and search through the params until you spot the id of the project as below:

http://<your_host>:<bcc_port>/atg/bcc/process?paf_portalId=default&paf_communityId=100001&paf_pageId=100004&paf_dm=shared&paf_gear_id=1000006&paf_gm=content&projectView=1&project=prjXXXXX&processPortlet=200002

Now, open your DB and connect to the BCC schema and execute the following statement, inserting the project id at the appropriate spot:

select * from EPUB_PRJ_TG_SNSHT where PROJECT_ID = ‘<id>’;

You can now open the BCC dyn/admin page for the DeploymentServer component, located at the following path:

http://<your_host>:<bcc_port>/dyn/admin/nucleus/atg/epub/DeploymentServer

You should see one or more DeploymentTargets with various properties indicating their status. Below each one is an input field where you can type a snapshot id and click the “Init” button to force the snapshot.  Find the target that has a null in the snapshot field and use the form to input your snapshot id.  Assuming this works, you should now be able to return to the Production site page in the BCC Admin Console and Resume deployments.

ATG Override logging

We had the requirement to append Order ID for each logging statement. This is how we achieved that.

Create Component:

\atg\dynamo\service\logging\LogQueue.properties

$class=atg.nucleus.logging.CustomLogListenerQueue

logListeners=LogDispatch

customLogging=true

Path of property file should not be changed.

 

CustomLogListenerQueue.java

package atg.nucleus.logging;

import atg.commerce.order.OrderHolder;
import atg.core.util.StringUtils;
import atg.nucleus.logging.LogEvent;
import atg.nucleus.logging.LogListenerQueue;
import atg.servlet.ServletUtil;

public class CustomLogListenerQueue extends LogListenerQueue {

private boolean mCustomLogging;
private static String ORDER_PATH = “/atg/commerce/ShoppingCart”;

/**
* @return the customLogging
*/
public boolean isCustomLogging() {
return mCustomLogging;
}

/**
* @param pCustomLogging
* the customLogging to set
*/
public void setCustomLogging(boolean pCustomLogging) {
mCustomLogging = pCustomLogging;
}

/* (non-Javadoc)
* @see atg.nucleus.logging.LogListenerQueue#logEvent(atg.nucleus.logging.LogEvent)
* Following would append order id in front of all log messages
*/
@Override
public synchronized void logEvent(LogEvent pArg0) {

if (isCustomLogging()) {
String lCustomLogMessage = “”;

if (null != pArg0 && !StringUtils.isBlank(pArg0.mMessage) && null != ServletUtil.getCurrentRequest()) {

OrderHolder lOrderHolder = (OrderHolder) ServletUtil.getCurrentRequest().resolveName(ORDER_PATH);
if (null != lOrderHolder && null != lOrderHolder.getCurrent(Boolean.FALSE)) {
lCustomLogMessage = “OrderID: ” + lOrderHolder.getCurrent().getId() + ” “;
}

pArg0.mMessage = lCustomLogMessage + pArg0.mMessage;
}
}

super.logEvent(pArg0);
}

}

 

 

JSP pass and retrieve variables – ATG

 

Parent JSP:

<dsp:include page=”/common/getTaxedPrice.jsp”>
<dsp:param name=”freePrice” value=”${paymentCost}”/>
</dsp:include>

 

Child JSP:

Read passed value:

<dsp:getvalueof param=”freePrice” var=”freePrice”/>

 

Pass value to parent JSP:

Option 1 – DSP TAGS:

<dsp:getvalueof param=”intergerlVal” var=”integerValue” scope=”request” />
<dsp:getvalueof param=”decimalVal” var=”decimalValue” scope=”request”/>

Option 2 – JSTL:

<c:set var=”integerValue” scope=”request” value=”integerValue”></c:set>

<c:set var=”decimalValue” scope=”request” value=”decimalValue”></c:set>

 

Parent JSP:

Variables can be printed or used as:

${integerValue}

${decimalValue}

ATG formhandler AJAX call using Jquery, JSON

Story:

  1. Click on Anchor tag
  2. Anchor tag invokes javascript function using attribute onClick()
  3. Javascript function submits a jsp form using ajax, which calls formhandler
  4. This Javascript function also define success method
  5. formhandler sets some parameter values.
  6. Control is redirected to success page by form handler.
  7. Success JSP creates JSON object.
  8. Javascript success function recieves this JSON object as response.
  9. Javascript parse this JSON object as required.

 

JSP Anchor tag:
On click on this link, formhandler method should be invoked and should return some result.

<a href="#" onClick="invokeTestMethod();">Test</a>

Javascript function:

function invokeTestMethod(){
 
//define success method
 var options = {
 success : resultOfTestMethod
 }
 
 //submit form using ajax
 $('#<form ID>').ajaxSubmit(options); 
}

JSP Form:

In JSP i have created one form which will be submitted by JQurey on click on the link:

 <dsp:form id="<form name>" name="<form name>" method="post" action="${requestURI}">
              <dsp:input type="hidden" bean="MyFormHandler.updateAddressSuccessUrl" value="<Success JSP>"/>
              <dsp:input type="hidden" bean="MyFormHandler.updateAddressErrorURL" value="<Error JSP>"/>
              <dsp:input type="hidden" bean="MyFormHandler.testMethod" value=""/> 
 </dsp:form>

FormHandler method:

public final boolean handleTestMethod(final DynamoHttpServletRequest pRequest,
 final DynamoHttpServletResponse pResponse) throws ServletException,
 IOException {
setTestString("Mohut");
 return checkFormRedirect(updateAddressSuccessUrl,updateAddressErrorURL, pRequest,pResponse);
 }

Success JSP:

<dsp:page>
<dsp:importbean bean="/path/MyFormHandler"/>
 <json:array name="addressList">
 <json:object>
 <json:property name="<propert name>">
 <dsp:valueof bean="MyFormHandler.testString"/>
 </json:property>
 </json:object>
 </json:array>
</dsp:page>

Javascript success method:

function resultOfTestMethod(responseText, statusText, xhr, $form){
var addressArray = JSON.parse(responseText);
}