This post is about how to capture and display all the validation exceptions , So here we have to check for different validation exception instances which can occur on an entity row .
------------------------------------------------------------------------------------------------------------
Sample Code , In this method we are capturing the error messages on update operation
public String doUpdate( Row r,ApplicationModule am,boolean selected, Long batchNumber,String TargetVo,String IntrVo, Number ParentID,oracle.jbo.AttributeDef[] attrDefsArg, Row interfacerow)
{
String[] targetAttribs = { "StartDate", "EndDate", "AuthorizedQuantityLimit",
"AuthorizationCostLimit", "CumulativeCost", "CumulativeQuantity",
"RestrictByProfile", "AllowInduction", "OrderTypeCode","UomCode","RepairWipScenario","RepairShipToCode","AutoWipWorkCenter"};
String error = "";
String entityType= (String)r.getAttribute("EntityType");
ApplicationModuleImpl impl = this.getRootApplicationModule();
r.setAttribute("StatusCode",STATUS_IMPORT_INPROGRESS );
ViewObjectImpl vo = (ViewObjectImpl)am.findViewObject(TargetVo);
ViewObjectImpl intfVo = (ViewObjectImpl)am.findViewObject(IntrVo);
Row rowToupdate = null;
ViewObjectImpl rprprofilesVo2 =(ViewObjectImpl) am.findViewObject("IdcRepairProfilesVO2");
rprprofilesVo2.executeQuery();
RowQualifier qualf= getRowQualifier(impl,r,entityType);
Row[] rows = rprprofilesVo2.getFilteredRows(qualf);
if(rows.length==1) {
rowToupdate = rows[0];
for (String attr : targetAttribs) {
Object attrValue = r.getAttribute(attr);
rowToupdate.setAttribute(attr, attrValue);
}
try{
am.getTransaction().validate();
Key key1 =null;
if(intfVo != null){
key1 = r.getKey();
}
Row[] intfRows2Delete = intfVo.findByKey(key1, -1);
for(Row intfRow2Delete: intfRows2Delete){
intfRow2Delete.remove();
}
am.getTransaction().commit();
}
catch(ValidationException e) {
error= getEntityValidatinExceptnMsg(e);
am.getTransaction().rollback();
}
catch(Exception ex) {
error= ex.getMessage();
am.getTransaction().rollback();
}
}
else if(rows.length>1) {
error= "ERROR: Multiple matching records found to update";
}else if(rows.length<1){
error= "ERROR: No matching record found to update";
}
------------------------------------------------------------------------------------------------------------
public String getEntityValidatinExceptnMsg(ValidationException e ) {
String error="";
String str ="";
for (int i = 0; i < e.getDetails().length; i++) {
ValidationException invalidValidation = (ValidationException)
e.getDetails()[i];
if (invalidValidation instanceof RowValException) {
RowValException invalidRow = (RowValException)invalidValidation;
for (int j = 0; j < invalidRow.getDetails().length; j++) {
if(invalidRow.getDetails()[j]!=null){
str =invalidRow.getDetails()[j].toString();
}
error = error +"\n"+ str;
}//end of for loop
}
else if(invalidValidation instanceof AttrSetValException) {
AttrSetValException invalidAttr = (AttrSetValException)
invalidValidation;
error= error+"\n"+ invalidAttr.getDetailMessage();
}
else if (invalidValidation instanceof AttrValException) {
AttrValException invalidAttr = (AttrValException)
invalidValidation;
error= error+"\n"+ invalidAttr.getDetailMessage();
}
}
return error;
}
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
Sample Code , In this method we are capturing the error messages on update operation
public String doUpdate( Row r,ApplicationModule am,boolean selected, Long batchNumber,String TargetVo,String IntrVo, Number ParentID,oracle.jbo.AttributeDef[] attrDefsArg, Row interfacerow)
{
String[] targetAttribs = { "StartDate", "EndDate", "AuthorizedQuantityLimit",
"AuthorizationCostLimit", "CumulativeCost", "CumulativeQuantity",
"RestrictByProfile", "AllowInduction", "OrderTypeCode","UomCode","RepairWipScenario","RepairShipToCode","AutoWipWorkCenter"};
String error = "";
String entityType= (String)r.getAttribute("EntityType");
ApplicationModuleImpl impl = this.getRootApplicationModule();
r.setAttribute("StatusCode",STATUS_IMPORT_INPROGRESS );
ViewObjectImpl vo = (ViewObjectImpl)am.findViewObject(TargetVo);
ViewObjectImpl intfVo = (ViewObjectImpl)am.findViewObject(IntrVo);
Row rowToupdate = null;
ViewObjectImpl rprprofilesVo2 =(ViewObjectImpl) am.findViewObject("IdcRepairProfilesVO2");
rprprofilesVo2.executeQuery();
RowQualifier qualf= getRowQualifier(impl,r,entityType);
Row[] rows = rprprofilesVo2.getFilteredRows(qualf);
if(rows.length==1) {
rowToupdate = rows[0];
for (String attr : targetAttribs) {
Object attrValue = r.getAttribute(attr);
rowToupdate.setAttribute(attr, attrValue);
}
try{
am.getTransaction().validate();
Key key1 =null;
if(intfVo != null){
key1 = r.getKey();
}
Row[] intfRows2Delete = intfVo.findByKey(key1, -1);
for(Row intfRow2Delete: intfRows2Delete){
intfRow2Delete.remove();
}
am.getTransaction().commit();
}
catch(ValidationException e) {
error= getEntityValidatinExceptnMsg(e);
am.getTransaction().rollback();
}
catch(Exception ex) {
error= ex.getMessage();
am.getTransaction().rollback();
}
}
else if(rows.length>1) {
error= "ERROR: Multiple matching records found to update";
}else if(rows.length<1){
error= "ERROR: No matching record found to update";
}
------------------------------------------------------------------------------------------------------------
public String getEntityValidatinExceptnMsg(ValidationException e ) {
String error="";
String str ="";
for (int i = 0; i < e.getDetails().length; i++) {
ValidationException invalidValidation = (ValidationException)
e.getDetails()[i];
if (invalidValidation instanceof RowValException) {
RowValException invalidRow = (RowValException)invalidValidation;
for (int j = 0; j < invalidRow.getDetails().length; j++) {
if(invalidRow.getDetails()[j]!=null){
str =invalidRow.getDetails()[j].toString();
}
error = error +"\n"+ str;
}//end of for loop
}
else if(invalidValidation instanceof AttrSetValException) {
AttrSetValException invalidAttr = (AttrSetValException)
invalidValidation;
error= error+"\n"+ invalidAttr.getDetailMessage();
}
else if (invalidValidation instanceof AttrValException) {
AttrValException invalidAttr = (AttrValException)
invalidValidation;
error= error+"\n"+ invalidAttr.getDetailMessage();
}
}
return error;
}
------------------------------------------------------------------------------------------------------------
0 comments:
Post a Comment