Sie sind auf Seite 1von 36

Oracle Utilities Customer Care & Billing V.2.3.

AP-RAPDRP
(SDK KT Document)

Prepared By
Last Update

: SivaRamakrishna Battula
: 21 July 2016

Revision History
Version & Rev ID

Date

Changed By

Changes Made

1.0

10/08/11

SivaRamakris
hna Battula

Initial Draft

02/05/12

SivaRamakris
hna

Added Additional Information like


common SDK code

22/05/12

SivaRamakris
hna

Added Junit Test Cases For Algorithms


&Different HQL Codes For Reference

06/06/12

SivaRamakris
hna

Related Documents
Version & Rev ID

Related Documents

CCB_SDK_Java Development PPT

Source Release Date

1 Table of Contents
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Revision History............................................................................................................................. 2
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
Related Documents....................................................................................................................... 3
1 Table of Contents......................................................................................................................... 4
2 CC&B KT Documentation ........................................................................................................... 6
2.1 BusinessEntity : .................................................................................................................. 7
2.2 SDK Common Code ............................................................................................................. 8
2.3 BussinessComponent:......................................................................................................... 13
2.4 Algorithms Implementaion................................................................................................... 14
2.5 Algorithm Example............................................................................................................... 14
2.6 Algoritm Junit Testing.......................................................................................................... 21
2.7 JavaBussiness Service ....................................................................................................... 24
2.8 Error Handling..................................................................................................................... 30
2.9 SDK File Deployment in the CC&B Server .........................................................................35

MP-RAPDRP

2 CC&B KT Documentation

Deposit Recommendation
Technical Design

2.1 BusinessEntity :
In All OUAF Projects Every Transaction will be happened through BussinessObject or Bussines Service
only. BusinessObect or Bussiness Service Internally call Maintenance Object.

Maintenance Object
Maintenance Objects are logical transactions that are made up of several tables.The Term Maintenance
Object refers to the group of tables that relatedd each other.
Maintenance Object Consist of All Related Tables ,in that at leas one primary table and remaining child
Tables optional.
For Creating Maintenace The Steps need to follow are
1.
2.
3.
4.
5.

Create the Table&Fields in Meta Data of The CCB


Create The Same Table in Data Base Also
add the Referential Integrity Constraints in both MetaData and DataBase
Create A ServiceProgram Admin->Service Program.
Create MaintenaceObject And Attache the ServiceProgram Name and Add the Primary And Child
tables to that MaintenaceObject.

Business Entity is The Entity class for a database table .Generally Per Table Business Entity will Exist.
Syntax of the Business Entity is like
Example of the Business Entity is
package com.splwg.cm.domain.meterReader;
/**
*
@BusinessEntity (tableName=CM_MTRR_MSTR,
*
oneToManyCollections = { @Child (collectionName = readerSBM, childTableName =
CM_MTRR_SBM,
*
orderByColumnNames = {"CRE_DTTM"})
*
})
*
*/
public class MeterReader_Impl extends MeterReader_Gen
{
}
package com.splwg.cm.domain.meterReader;
/**
* @author suraj
*
@EntityPageMaintenance (entity = meterReader, service = CM_MTRR_MSTR, program =
CM_MTRR_MSTR,
*
body = @DataElement (contents = { @RowField (entity = meterReader, name = meterReader)
*
, @ListField (name = SBMREADER, owner = meterReader,property = readerSBM)}),
*
modules = { "billing"},

*
actions = { "add"
*
, "read"
*
, "delete"
*
, "change"},
*
lists = { @List (name = SBMREADER, size = 50,
*
body = @DataElement (contents = { @RowField (entity = readerSBM, name =
readerSBM)}))})
*/
public class MeterReaderMaintenance extends MeterReaderMaintenance_Gen
{
}

2.2 SDK Common Code


Fetching Data from a Bussiness Entity The Code Will be as fallows
Here First We need to fetch the primary key of the Bussiness Entity Instance.
Example is like I am want to get the person data whose person id is like 12345
Person _Id perId=new Person_Id(123456);
Person objPer=perId.getEntity();
Person_DTo perDto=objPer.getDTO();
String name=perDto.getName();
String add=perDto.getAddress();
(or)
Person_DTo perDto
Updating Data of BusinessEntity
For Updating the BusinessEntity First you need to fetc h the primaykey class object and using that need
to get Bussiness entity and Dto class Object .we can do the modification by using setMethods().
Example is as fallows
I want to update person details whose Person id is 12345
Person_Id perId=new Person_Id(12345);
Person perObj=perId.getEntity();
Person_DTO perDto=perObj.getDto();
perDto.setName(siva);
perDto.setAddress(Hyderabad);
perObj=perObj .setDTO(perDto);
Inserting New Record into BusinessEntity
Here I want to insert a new record into a Business Entity as fallows
If the key is user defined you need to generate the id object , if it is a system generated key then it will be
created automatically.
Person_Id perId=new Person_Id(12345);
Person _DTo perDto=perId.newDTo();
perDto.setId(perId);
perDto.setName(siva);
perDto.setAddress(Hyderabad);
Person perObj=perDto.newEntity();

Getting Characterstic of Perticular Entity using CharacteristicType


Here I want to retrieve Characterstic value of Characterstictype like meter
Status 'MTRSTS' [in General MeterRead Consist of status like 01,02,04 etc ]
CharactersticType_Id strCharTypeId=new CharactersticType_Id(MTRSTS);
String charValue=null;
MeterReadCharacteristics
mrChars=mrId.getEntity().getCharacteristics();
Iterator<MeterReadCharacteristic>mrCharIter=mrChars.iterator();
MeterReadCharacteristic mrChar;
String strCharTypeId=null;
while(mrCharIter.hasNext())
{
mrChar=mrCharIter.next();
strCharTypeId=mrChar.getDTO().getId().getCharacteristicType().getId().getIdVal
ue();
if(strCharTypeId.equalsIgnoreCase(charTypeId.getIdValue()))
{
charValue=mrChar.getDTO().getAdhocCharacteristicValue();
}
Not only Getting CharacteristicTypes for retrieving any list items code will be same.
Sample Code For Retrieving Feature Configuration
String fcValue=null,strSaType=null;
if(objCisDivision_Id.getIdValue().equalsIgnoreCase("NPDCL"))
{
fcValue="NPDC";
}
else
if(objCisDivision_Id.getIdValue().equalsIgnoreCase("SPDCL"))
{
fcValue="SPDC";
}
FeatureConfiguration_Id fcId=new FeatureConfiguration_Id("CM_BILLROUND");
FeatureConfiguration fcObj=fcId.getEntity();
FeatureConfigurationOptions fcOpts=fcObj.getOptions();
Iterator<FeatureConfigurationOption> list=fcOpts.iterator();
while(list.hasNext())
{
FeatureConfigurationOption fcOption=list.next();

if(fcOption.fetchIdOptionType().toString().trim().equalsIgnoreCase(fcValue))
{
strSaType=fcOption.getValue();

}
}
logger.info("strSaType"+strSaType);
if(strSaType.split(",").length>1)
{
saList=strSaType.split(",");
for(String saType:saList)
{
objSa=getSaUsingSaTypeandAcct(objAcct,saType);
logger.info("TotalAMount"+totalAmount+"SaType"+saType+"sa"+objSa);
if(objSa!=null)
totalAmount=totalAmount.add(retriveAdjAmountofPresentBill(objSa));

}
Sample Code For Using BO or BS in Side Algorithm or Batch
For Bussiness Service
BusinessServiceInstance bs=BusinessServiceInstance.create("CM_MTR_REG");
bs.set("mtrid", mrId.getIdValue());
logger.info("MeterId"+mrId);
bs = BusinessServiceDispatcher.execute(bs);
COTSInstanceList retrieveBS1= bs.getList("results");
java.util.Iterator<COTSInstanceListNode> list=retrieveBS1.iterator();
while(list.hasNext())
{
COTSInstanceListNode node=list.next();
regVal=node.getString("kwh");
kwhRegId=new Register_Id(regVal);
regVal=node.getString("kvah");
kVahRegId=new Register_Id(regVal);
regVal=node.getString("pf");
pfRegId=new Register_Id(regVal);
regVal=node.getString("rmd");
rmdRegId=new Register_Id(regV
For Bussiness Object
BusinessObjectInstance
boInstance=BusinessObjectInstance.create("CM_EstimateRead");
boInstance.set("meterReadId",meterReadId.getIdValue());
boInstance=BusinessObjectDispatcher.read(boInstance);
COTSInstanceList regList=boInstance.getList("registerRead");
Iterator<COTSInstanceListNode> objIterator=regList.iterator();
while(objIterator.hasNext())
{
COTSInstanceListNode regNode=objIterator.next();
regId=regNode.getXMLString("registerId");

if(objRegMap.get("kwh").getIdValue().trim().equalsIgnoreCase(regId))
{
kwhRegReadId=new
RegisterRead_Id(regNode.getXMLString("registerReadingId"));
kwhSeq=new BigDecimal(regNode.getXMLString("seq"));
kwhregReadNode=regNode;
System.out.println("kwhRegReadId Register Read"+kwhRegReadId);
}
else
if(objRegMap.get("kvah").getIdValue().trim().equalsIgnoreCase(regId))
{
kvahRegReadId=new
RegisterRead_Id(regNode.getXMLString("registerReadingId"));
kvahSeq=new BigDecimal(regNode.getXMLString("seq"));
kvahregReadNode=regNode;
System.out.println("kvahRegReadId Register Read"+kwhRegReadId);
}
else
if(objRegMap.get("pf").getIdValue().trim().equalsIgnoreCase(regId))
{
pfRegReadId=new
RegisterRead_Id(regNode.getXMLString("registerReadingId"));
pfSeq=new BigDecimal(regNode.getXMLString("seq"));
pfregReadNode=regNode;
System.out.println("pfRegReadId Register Read"+kwhRegReadId);
}

else

if(objRegMap.get("rmd").getIdValue().trim().equalsIgnoreCase(regId))
{
rmdRegReadId=new
RegisterRead_Id(regNode.getXMLString("registerReadingId"));
rmdSeq=new BigDecimal(regNode.getXMLString("seq"));
rmdregReadNode=regNode;
System.out.println("pfRegReadId Register Read"+rmdRegReadId);
}
}
/* Updating the KWH Based Register Read*/
kwhregReadNode.set("registerId", objRegMap.get("kwh").getIdValue());
kwhregReadNode.set("registerReadingId", kwhRegReadId.getIdValue());
kwhregReadNode.set("readType",
ReadTypeLookup.constants.OFFICE_ESTIMATE);
kwhregReadNode.set("registerReading", estimateKwhRead);
kwhregReadNode.set("seq",kwhSeq);

/* Updating The KVAH Based Register Read */


kvahregReadNode.set("registerId", objRegMap.get("kvah").getIdValue());
kvahregReadNode.set("registerReadingId", kvahRegReadId.getIdValue());
kvahregReadNode.set("readType",
ReadTypeLookup.constants.OFFICE_ESTIMATE);
kvahregReadNode.set("registerReading", estimateKahRead);
kvahregReadNode.set("seq",kvahSeq);
/* Updating The PF Based Register Read */
pfregReadNode.set("registerId", objRegMap.get("pf").getIdValue());
pfregReadNode.set("registerReadingId" , pfRegReadId.getIdValue());
pfregReadNode.set("readType",
ReadTypeLookup.constants.OFFICE_ESTIMATE);
pfregReadNode.set("registerReading" , estimatePfRead);
pfregReadNode.set("seq",pfSeq);
/* Updating The RMD Based Register Read */
rmdregReadNode.set("registerId",objRegMap.get("rmd").getIdValue());
rmdregReadNode.set("registerReadingId" , rmdRegReadId.getIdValue());
rmdregReadNode.set("readType",
ReadTypeLookup.constants.OFFICE_ESTIMATE);
rmdregReadNode.set("registerReading" , estimateRmdRead);
rmdregReadNode.set("seq",rmdSeq);
/* Updating The Meter Read Details Using Business Object */
boInstance=BusinessObjectDispatcher.update(boInstance);

Query Using HQL


We can Fetch the Data in SDK using Query Statement
Example is as follows
StringBuffer queryString1=new StringBuffer("from ServiceAgreement sa where ");
queryString1.append(" sa.account=:acctId and
sa.serviceAgreementType.id.saType not like '%DEP%'");
queryString1.append(" and sa.serviceAgreementType.id.saType not like
'%ADV%'");
queryString1.append(" and sa.serviceAgreementType.id.saType not like
'%SURCHARGE%' ");
queryString1.append(" and sa.serviceAgreementType.id.saType not like
'%MISC%' ");
Query query1=createQuery(queryString1.toString());
query1.addResult("sa", "sa.id");
query1.bindId("acctId", objAccount.getId());
for(Iterator iter=query1.list().iterator(); iter.hasNext();)
{
objSaId=((ServiceAgreement_Id)iter.next());
}

Query Using SQL


We can do curd operations using SQL statements also
try {

String charValue=null;
String qureryString1="select CHAR_VAL from ci_sp_char where
char_type_cd=:serviceType and sp_id=:spId";
PreparedStatement
prepStatement1=createPreparedStatement(qureryString1.toString());
prepStatement1.bindId("serviceType", charTypeId);
prepStatement1.bindId("spId", spId);
String SerivceType=null;
String categoryName=null;
charValue=prepStatement1.firstRow().getString("CHAR_VAL");
return charValue;
} catch (Exception e)
{

e.printStackTrace();
return null;

2.3 BussinessComponent:
The Main Purpose of the Business Component is for Reusability . The common Code Which is useful in
the algorithms and batches you can place that code in business component .
Syntax of the BusinessComponent is
/**
@BusinessComponent (customizationReplaceable=false, customizationCallable=true)
*/
public class CmBillCalculation_Impl extends GenericBusinessComponent implements CmBillCalculation
{
//write the reusablity code
}
Example is like
public class CmBillCalculation_Impl extends GenericBusinessComponent
implements CmBillCalculation
{
private static final Logger
logger=LoggerFactory.getLogger(CmBillCalculation_Impl.class);
private ServiceAgreement objSa=null;
private ServiceAgreementType saType=null;
private RateSchedule rateSchedule=null;
private Date calculationDate;
private Account_Id acctId=null;
private BigDecimal calUnits=BigDecimal.ZERO;
public ServicePoint retrieveServicePoint(ServiceAgreement objSa )

ServicePoint_Id spId=null;
StringBuffer queryString2=new StringBuffer("from
ServiceAgreementServicePoint sasp where ");
queryString2.append(" sasp.serviceAgreement=:sa ");
Query query2=createQuery(queryString2.toString());
query2.addResult("spId", "sasp.servicePoint");
query2.bindEntity("sa",objSa);
for(Iterator iter=query2.list().iterator(); iter.hasNext();)
{
spId=((ServicePoint)iter.next()).getId();
}
return spId.getEntity();
}
}

2.4 Algorithms Implementaion


For Creating Algorithms in SDK we require the Algorithm Spot.
We can Implement Algorithm implementations using
AlgorithmImplementaion Wizard as fallows
FilenewAlgorithmImplementation
There We need to select the algorithm spot from algorithmspot
interface
When you extend the algorithm spot it will give some methods like
invoke(),setMethods() and getMethods()
Note:SetMethods() represents the Input coming into Algorithm
getMethods() represents outputs which will go out from the
Algorithm.
SoftParameteres are used for Maintaing constants inside
algorithm.
Syntax is

@AlgorithmComponent
(softParameters={@AlgorithmSoftParameter(name=rateSchedule,required=true,type=
entity,entityName = rateSchedule)
*
*
,
@AlgorithmSoftParameter(name=UOM,required=true,type=entity,entityName =
unitOfMeasure)
*
SoftParameters is like

static type variable

2.5 Algorithm Example


Here See the Customerclass Bill Eligiblity Algoritm

})

package com.splwg.cm.domain.bills;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import com.ibm.icu.math.BigDecimal;
import com.splwg.base.api.Query;
import com.splwg.base.api.QueryResultRow;
import com.splwg.base.api.datatypes.Bool;
import com.splwg.base.api.datatypes.Date;
import com.splwg.base.api.datatypes.DateTime;
import com.splwg.base.api.datatypes.Money;
import com.splwg.base.domain.common.currency.Currency;
import com.splwg.base.support.context.FrameworkSession;
import com.splwg.base.support.context.SessionHolder;
import com.splwg.ccb.api.lookup.AdjustmentStatusLookup;
import com.splwg.ccb.api.lookup.BillCompletionActionLookup;
import com.splwg.ccb.domain.adjustment.adjustment.Adjustment;
import com.splwg.ccb.domain.adjustment.adjustment.Adjustment_DTO;
import com.splwg.ccb.domain.admin.adjustmentType.AdjustmentType_Id;
import com.splwg.ccb.domain.admin.customerClass.CustomerClassPreBillCompletionAlgorithmSpot;
import com.splwg.ccb.domain.admin.unitOfMeasure.UnitOfMeasure_Id;
import com.splwg.ccb.domain.billing.bill.Bill;
import com.splwg.ccb.domain.billing.billSegment.BillSegment;
import com.splwg.ccb.domain.billing.billSegment.BillSegment_Id;
import com.splwg.ccb.domain.customerinfo.account.Account;
import com.splwg.ccb.domain.customerinfo.serviceAgreement.ServiceAgreement;
import com.splwg.ccb.domain.customerinfo.serviceAgreement.ServiceAgreement_Id;
import com.splwg.ccb.domain.customerinfo.servicePoint.ServicePoint;
import com.splwg.cm.domain.billingutil.CmBillCalculation;
import com.splwg.shared.common.ServerMessage;
/**
*The descriptive text that explaining the purpose and use of the class.
* @version 1.0 01 AUG 2011
* @author SivaRamakrishna Battula
* Class : CmSaEdPreBillCompAlg_Impl
* Description : Calculating Ed Charges For LT Consumers
* Other Info :
* Creation Date : 01-AUG-2011
* History[FunctionalDesc]:
* Date Modified by Description
* ---------------------------------------------------------------------------------------------------------* SNO
dd-mmm-yyyy
<Name>
[Multiline / Precise description]
* ----------------------------------------------------------------------------------------------------------* 01
15/05/2012
Siva Battula
*
*
* --------------------------------------------------------------------------------------------------------* @AlgorithmComponent (softParameters = { @AlgorithmSoftParameter (entityName=adjustmentType,
name = adjType, required = true, type =entity)

*
,@AlgorithmSoftParameter (entityName=currency, name = currencyCode,
required = true, type =entity)
*
,@AlgorithmSoftParameter ( name = saType, required = true, type =string)
*
,@AlgorithmSoftParameter ( name = edFactor, required = true, type =string)
*
,@AlgorithmSoftParameter ( name = uomCode, entityName=unitOfMeasure,
type =entity)
*
})
*/
public class CmSaEdPreBillCompAlg_Impl extends CmSaEdPreBillCompAlg_Gen
implements CustomerClassPreBillCompletionAlgorithmSpot
{
private Bill objBill=null;
private BigDecimal totalAmount=BigDecimal.ZERO;
private Currency objCurrency=null;
private AdjustmentType_Id adjTypeId=null;
private ServiceAgreement objServiceAgreement=null;
private Account obtAcct=null;
private String saType;
private BillSegment bseg=null;
private UnitOfMeasure_Id uomId=null;
private java.sql.PreparedStatement prepStatment=null;
public void invoke()
{
try{
initializeParameters();
bseg=getBillSegmentUsingBillId(objBill);
totalAmount=getTotalBillSq(bseg,uomId);
String tempVal=this.getEdFactor();
totalAmount=totalAmount.multiply(new BigDecimal(tempVal));
totalAmount=roundingBigDecimal(totalAmount);
raiseAdjustment(new Money(totalAmount,objCurrency.getId()));
}catch(Exception e)
{
e.printStackTrace();
}

}
/** Initializing Values Required in Algo
* @return void
*/
public void initializeParameters()
{
//objBill=new Bill_Id("462370264262").getEntity();
adjTypeId=this.getAdjType().getId();
objCurrency=this.getCurrencyCode();
saType=this.getSaType();
objServiceAgreement=retrieveServiceAgreement();
System.out.println("Service Agrement new"+objServiceAgreement);
if(this.getUomCode()!=null)

{
uomId=this.getUomCode().getId();
}
else
{
CmBillCalculation objBillCal;
objBillCal=CmBillCalculation.Factory.newInstance();
ServiceAgreement objUtilSa=objBillCal.retrieveServiceAgreement(obtAcct);
ServicePoint objSp=objBillCal.retrieveServicePoint(objUtilSa);
uomId =objBillCal.retrieveUom(objSp.getId());
System.out.println("Sp"+objSp.getId().getIdValue());
}
}
/**
* Retrieving ED ServiceAgreement
*
* @return ServiceAgreement
*/
public ServiceAgreement retrieveServiceAgreement()
{
ServiceAgreement_Id objSaId=null;
StringBuffer queryString1=new StringBuffer("from ServiceAgreement sa where ");
queryString1.append(" sa.account=:acctId and
sa.serviceAgreementType.id.saType='"+saType.trim()+"'");
System.out.println("sa Type"+saType+"adjtype"+adjTypeId);
Query<QueryResultRow> query1=createQuery(queryString1.toString());
query1.addResult("sa", "sa.id");
query1.bindId("acctId", obtAcct.getId());
Iterator<QueryResultRow> iter=query1.list().iterator();
while(iter.hasNext())
{
objSaId=((ServiceAgreement_Id)iter.next());
System.out.println("ServiceAgreement"+objSaId.getIdValue());
}
return objSaId.getEntity();
}
/**
* Raising Calculated Amount as Adjustment On ED Service Agreement
* @param adjustAmt is Calculated Amount
*/
public void raiseAdjustment(Money adjustAmt)
{
Adjustment_DTO adjustmentDTO=new Adjustment_DTO();
Adjustment adjustment=null;
adjustmentDTO.setAdjustmentTypeId(adjTypeId);
adjustmentDTO.setAdjustmentStatus(AdjustmentStatusLookup.constants.FREEZABLE);
//adjustAmt=new Money(new BigDecimal(1.75),objCurrency.getId());

adjustmentDTO.setCurrentAmount(adjustAmt);
DateTime curdate= DateTime.getSystemDateTime();
System.out.println(""+ DateTime.getSystemDateTime().getDate());
adjustmentDTO.setCalculationDate(curdate.getDate());
adjustmentDTO.setComments("some comments");
adjustmentDTO.setCurrencyId(objCurrency.getId());
adjustmentDTO.setVersion(2);
System.out.println("raising Adjustment"+objServiceAgreement);
adjustment=objServiceAgreement.addAdjustment(adjustmentDTO);
adjustment.generate(this.getSystemDateTime().getDate() ,this.getProcessDateTime().getDate());
adjustment.freeze(curdate.getDate());
System.out.println("i have generated adjustment"+adjustment.getId()+"adjustement
Amount"+adjustment.getCurrentAmount());
}
/**
* Retrieving The BillSegment Using Bill
* @param objBill Bill
* @return BillSegment
*/
public BillSegment getBillSegmentUsingBillId(Bill objBill)
{
BillSegment objBillSeg=null;
StringBuffer queryString=new StringBuffer("from BillSegment bseg where ");
queryString.append(" bseg.billId=:billId");
Query<QueryResultRow> query=createQuery(queryString.toString());
query.bindId("billId", objBill.getId());
query.addResult("bsegment", "bseg.id");
Iterator<QueryResultRow> iter=query.list().iterator();
while(iter.hasNext())
{
objBillSeg=((BillSegment_Id)iter.next()).getEntity();
System.out.println("BillSegment"+objBillSeg.getId().getIdValue());
}
return objBillSeg;
}

/**
* To Get The Billed Units
* @param Billed Units in BigDecimal
*/
public BigDecimal getTotalBillSq(BillSegment bsegObj,UnitOfMeasure_Id uom_Id)
{
BigDecimal totalAmount=BigDecimal.ZERO;
StringBuffer queryString=null;
ResultSet rs1=null;
try
{

queryString=new StringBuffer("from BillSegmentServiceQuantity bsegSQ where


bsegSQ.id.unitOfMeasure=:uomId");
queryString.append(" and bsegSQ.id.timeOfUse=' "+" ' and
bsegSQ.id.serviceQuantityIdentifier='"+ " ' and bsegSQ.id.billSegment=:bsegId ");
Query<QueryResultRow> query=createQuery(queryString.toString());
query.bindId("bsegId",bsegObj.getId());
query.bindId("uomId",uom_Id );
query.addResult("billSQUnits", "bsegSQ.billableServiceQuantity");
Iterator<QueryResultRow> iter=query.list().iterator();
while(iter.hasNext())
{
totalAmount=totalAmount.add((BigDecimal)iter.next());
System.out.println("Billed Units"+totalAmount);
}

}
catch(NullPointerException e)
{
e.printStackTrace();
return null;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
if(rs1!=null)
rs1.close();
if(prepStatment!=null)
prepStatment.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return totalAmount;
}

public BigDecimal roundingBigDecimal(BigDecimal roundAmount)


{
Double doubleValue;
BigDecimal roundedValue=null;
doubleValue=roundAmount.doubleValue();
int tempVal = (int)(doubleValue * 100.0); // scale it
doubleValue = ((double)tempVal)/100.0;
roundedValue=new BigDecimal(doubleValue.toString());
return roundedValue;
}
@Override
public Bool getAllowReopeningOfBills()
{
return null;
}
@Override
public BillCompletionActionLookup getBillCompletionAction()
{
return null;
}
@Override
public ServerMessage getServerMessage() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setAccount(Account arg0)
{
this.obtAcct=arg0;
}
@Override
public void setAccountingDate(Date arg0)
{
}
@Override
public void setAllowReopeningOfBills(Bool arg0)
{
}

@Override
public void setBill(Bill arg0)
{
this.objBill=arg0;
}
@Override
public void setBillDate(Date arg0)
{
}
@Override
public void setBillSegments(List<BillSegment> objBillSeg)
{
}
@Override
public void setCreditNoteForBill(Bill arg0)
{
}
}
This Algorithm Is For Calculating The ED.
Here The Given Set Parameters Are the input parameters to the algorithm means the input coming
Dynamicalu at the time of the Exectuion.
Get Parameters are the out put parameters expecting by the framework during the bill processing.
Framework call the interface which will be generated by Artifact generator.
When Algorithm Processing happen first framework pass values to setMethods and Execute The Invoke
method after processing of invoke method it will fetch the results from getMethods().

2.6 Algoritm Junit Testing


You Can Test What ever logic you has Created Using JUNIT As Fallows
Consider The Above Algorithm
package com.splwg.cm.domain.bills;
import java.util.ArrayList;
import java.util.List;

import com.splwg.base.api.testers.AlgorithmImplementationTestCase;
import com.splwg.base.domain.common.algorithm.Algorithm;
import com.splwg.base.domain.common.algorithm.Algorithm_Id;
import com.splwg.ccb.domain.billing.bill.Bill;
import com.splwg.ccb.domain.billing.bill.Bill_DTO;
import com.splwg.ccb.domain.billing.bill.Bill_Id;
import com.splwg.ccb.domain.billing.billSegment.BillSegment;
import com.splwg.ccb.domain.billing.billSegment.BillSegment_Id;
import com.splwg.ccb.domain.customerinfo.account.Account_Id;
public class CmSaEdPreBillCompAlg_Test extends AlgorithmImplementationTestCase
{
public void testInvoke()
{
System.out.println("We are at invoke method");
try {
Bill_Id billId=new Bill_Id("869160573044");
System.out.println("billId"+billId);
Bill objBill=billId.getEntity();
Bill_DTO billDto=objBill.getDTO();
billDto.setAccountId(new Account_Id("7874677562"));
objBill.setDTO(billDto);
BillSegment_Id bsegid=new BillSegment_Id("462838673192");
List<BillSegment>billSegList=new ArrayList<BillSegment>();
billSegList.add(0, bsegid.getEntity());
CmSaEdPreBillCompAlg algRec = getAlgComp();
algRec.setBill(objBill);
algRec.setAccount(new Account_Id("7874677562").getEntity());
algRec.setBillSegments(billSegList);
algRec.invoke();
System.out.println("Message"+algRec.getServerMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected Class getAlgorithmImplementationClass()
{
return CmPostBillRoundingAlgComp_Impl.class;
}
private CmSaEdPreBillCompAlg getAlgComp() {
CmSaEdPreBillCompAlg algComp;
try {
Algorithm algorithm = new Algorithm_Id("CM-SP-ED-LT").getEntity();
if(algorithm!=null){
algComp = algorithm.getAlgorithmComponent(CmSaEdPreBillCompAlg.class);
return algComp;

}
return null;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
}

One More Way To Test Any OUAF Class is using ContestTestCase .


public class CmBarCodeGeneratonAlgo_Test extends ContextTestCase
{
public void testInvoke()
{
System.out.println("We are at invoke method");
try {
CmBarCodeGeneratonAlgo_Impl algRec = new CmBarCodeGeneratonAlgo_Impl();
Bill objBill=new Bill_Id("462378165082").getEntity();
BillData billData= BillData.Factory.newInstance();
Bill_DTO billDto= Bill_DTO.class.newInstance();
billDto.setAccountId(new Account_Id("4623767868"));
billData.setBillDTO(billDto);
algRec.setBillData(billData);
algRec.invoke();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

2.7 JavaBussiness Service


Sample Java Bussiness Service Is As Fallows

public class AdjRetrieve extends AdjRetrieve_Gen {


private StringBuffer queryString;
// private PreparedStatement objPreparedStatement;
private Query<QueryResultRow> queryObj;
private PreparedStatement prepStatement;
protected void change(DataElement element) throws ApplicationError {
System.out.println("Entered to the Program");
queryString = new StringBuffer(
"FROM AdjUpload adj WHERE adj.status='P'");
queryObj = createQuery(queryString.toString());
queryObj.addResult("adjUploadId", "adj.id");
Iterator<QueryResultRow> iterator = queryObj.list().iterator();
// queryString=new
// StringBuffer("SELECT ADJ_UPD_ID FROM CM_ADJ_UPLOAD WHERE
BO_STATUS_CD='P'");
// objPreparedStatement=createPreparedStatement(queryString.toString());
// Iterator<SQLResultRow>
// iterator=objPreparedStatement.list().iterator();
AdjUpload_Id adjUploadId;
System.out.println(" iterator :::::"+ iterator.hasNext());
while (iterator.hasNext()) {
System.out.println("while");
BigDecimal count = new BigDecimal(0.0);
BigDecimal amount = new BigDecimal(0.0);
Money m = Money.ZERO;
BusinessObjectInstance boInstanceSummary = BusinessObjectInstance
.create("CM_ADJSTGCTL");
boInstanceSummary.set("adjustmentStagingControlStatus",
AdjustmentStagingControlStatusLookup.constants.PENDING);
boInstanceSummary.set("adjustmentUploadRecordCount",
new BigDecimal(10));
boInstanceSummary.set("totalAdjustmentAmount", new Money(
new BigDecimal(10), new Currency_Id("INR")));

boInstanceSummary.set("currency", "INR");
boInstanceSummary.set("messageCategory", new BigDecimal(1));
boInstanceSummary.set("messageNumber", new BigDecimal(101));
boInstanceSummary.set("version", new BigDecimal(1));
boInstanceSummary = BusinessObjectDispatcher.add(boInstanceSummary);
adjUploadId = (AdjUpload_Id) iterator.next();
// System.out.println("adjUploadId : "+adjUploadId.toString());
// AdjUpload_Id adjupload_id
// =(AdjUpload_Id)adjUploadId.getId("ADJ_UPD_ID",AdjUpload.class);
BusinessObjectInstance boInstanceClob = BusinessObjectInstance
.create("CM_ADJUPLOAD");
boInstanceClob.set("adjUploadId", adjUploadId.getIdValue());
boInstanceClob = BusinessObjectDispatcher.read(boInstanceClob);
COTSInstanceNode cotins = boInstanceClob.getGroup("dataAreaSchema");
COTSInstanceList cotinslinst = cotins.getList("dataList");
COTSInstanceListNode cotsinstlistnode = null;
int isize = cotinslinst.getSize();
for (Iterator<COTSInstanceListNode> it = cotinslinst.iterator(); it
.hasNext();) {
System.out.println("for loop");
BusinessObjectInstance boInstanceDetail = BusinessObjectInstance
.create("CM_ADJSTGUP");
cotsinstlistnode = it.next();
String rjdesc = cotsinstlistnode.getString("rjType");
String discom = cotsinstlistnode.getString("discom");
queryString = new StringBuffer(
"select adjl.adj_type_cd from ci_adj_type_l adjl ");
queryString
.append("where adjl.descr like '%"+rjdesc +"%'");
prepStatement = createPreparedStatement(queryString.toString());
String adjTypeCode = prepStatement.firstRow().getString(
"ADJ_TYPE_CD");
adjTypeCode = adjTypeCode.trim();
System.out.println(" adjTypeCode : " + adjTypeCode);
String str = cotsinstlistnode.getString("rjAmount");
System.out.println("oBJECT" + str);
Integer strLength = str.length();
Pattern p = Pattern
.compile("^([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$");
Matcher match = p.matcher(str);
System.out.println("output: " + match.matches());
match.matches(); // TRUE

System.out.println("flag ::::: " + match.matches());


System.out.println("cotsinstlistnode.getString()"
+ cotsinstlistnode.getString("rjAmount"));
Money curAmountMoney = new Money(str);
String uscno = cotsinstlistnode.getString("uscno");
String saTypeCode = null;
if (adjTypeCode.equalsIgnoreCase("SRJ_ED")
|| adjTypeCode.equalsIgnoreCase("RJ_ED")
|| adjTypeCode.equalsIgnoreCase("SED")) {
saTypeCode = "('ED')";
saTypeCode = saTypeCode.trim();
System.out.println("ED" + saTypeCode);
}
if (adjTypeCode.trim().equalsIgnoreCase("SRJ_EDI")
|| adjTypeCode.equalsIgnoreCase("RJ_EDI")) {
saTypeCode = "('EDI')";
saTypeCode = saTypeCode.trim();
}
if (adjTypeCode.equalsIgnoreCase("SRJ_FSA")
|| adjTypeCode.equalsIgnoreCase("RJ_FSA")) {
saTypeCode = "('FSA')";
saTypeCode = saTypeCode.trim();
} else if (adjTypeCode.equalsIgnoreCase("SRJ_EC")
|| adjTypeCode.equalsIgnoreCase("RJ_EC")
|| adjTypeCode.equalsIgnoreCase("RJ_CC")
|| adjTypeCode.equalsIgnoreCase("SRJ_CC ")
|| adjTypeCode.equalsIgnoreCase("SRJ_FXC")
|| adjTypeCode.equalsIgnoreCase("RJ_FXC")
|| adjTypeCode.equalsIgnoreCase(" SRJ_CPCG")
|| adjTypeCode.equalsIgnoreCase(" RJ_CPCG")) {
saTypeCode =
"('LT1','LT2','LT3','LT4','LT5','LT6','LT7','LT8','HT1','HT2','HT3')";
saTypeCode = saTypeCode.trim();
}
queryString = new StringBuffer(
"select t1.SA_ID from ci_sa t1, ci_acct_char t2 ");
queryString
.append(" where t1.acct_id=t2.acct_id and t2.char_type_cd='SCNO' ");
queryString
.append(" and t2.adhoc_char_val=:uscno and t1.sa_type_cd in "
+ saTypeCode + " and t1.sa_status_flg='20' ");
prepStatement = createPreparedStatement(queryString.toString());
// prepStatement.bindString("saTypeCode",saTypeCode,"sa_type_cd");
prepStatement.bindString("uscno", uscno, "adhoc_char_val");

SQLResultRow row = prepStatement.firstRow();


String sid = null;
queryString = new StringBuffer(
"select ac.acct_id from ci_acct_char ac ");
queryString.append("where ac.char_type_cd='SCNO' ");
queryString.append("AND ac.adhoc_char_val=:uscno ");
prepStatement = createPreparedStatement(queryString.toString());
// prepStatement.bindString("saTypeCode",saTypeCode,"sa_type_cd");
prepStatement.bindString("uscno", uscno, "adhoc_char_val");
SQLResultRow acctRow = prepStatement.firstRow();
if (acctRow == null) {
System.out
.println("Account Id Not Existed For this Service Number");
BusinessObjectInstance boInstanceError = BusinessObjectInstance
.create("CM_ADJUPERR");
boInstanceError.set("businessObject", "CM_ADJUPERR");
boInstanceError.set("discom",
cotsinstlistnode.getString("discom"));
boInstanceError.set("ero",
cotsinstlistnode.getString("ero"));
boInstanceError.set("errorType", "20003");
boInstanceError.set("rjAmt", curAmountMoney);
boInstanceError.set("rjType",
cotsinstlistnode.getString("rjType"));
boInstanceError.set("section",
cotsinstlistnode.getString("section"));
boInstanceError.set("uniqueServiceNumber",
cotsinstlistnode.getString("uscno"));
boInstanceError.set("status", "P");
// boInstanceError.set("errId","3243244234");
System.out.println("done");
boInstanceError = BusinessObjectDispatcher
.add(boInstanceError);
System.out.println("inserted");
boInstanceError = null;
} else if (row == null) {
System.out
.println("Service Agreement Not exist for this adjTypeCode");
BusinessObjectInstance boInstanceError = BusinessObjectInstance
.create("CM_ADJUPERR");
boInstanceError.set("businessObject", "CM_ADJUPERR");
boInstanceError.set("discom",
cotsinstlistnode.getString("discom"));

boInstanceError.set("ero",
cotsinstlistnode.getString("ero"));
boInstanceError.set("errorType", "20001");
boInstanceError.set("rjAmt", curAmountMoney);
boInstanceError.set("rjType",
cotsinstlistnode.getString("rjType"));
boInstanceError.set("section",
cotsinstlistnode.getString("section"));
boInstanceError.set("uniqueServiceNumber",
cotsinstlistnode.getString("uscno"));
boInstanceError.set("status", "P");
boInstanceError = BusinessObjectDispatcher
.add(boInstanceError);
boInstanceError = null;
}
else if (!match.matches()) {
System.out.println("not a number");
// addError(CustomMessageRepository.saIdMissing(adjTypeCode));
BusinessObjectInstance boInstanceError = BusinessObjectInstance
.create("CM_ADJUPERR");
boInstanceError.set("businessObject", "CM_ADJUPERR");
boInstanceError.set("discom",
cotsinstlistnode.getString("discom"));
boInstanceError.set("ero",
cotsinstlistnode.getString("ero"));
boInstanceError.set("errorType", "20002");
boInstanceError.set("rjAmt", new Money(BigDecimal.ZERO));
boInstanceError.set("rjType",
cotsinstlistnode.getString("rjType"));
boInstanceError.set("section",
cotsinstlistnode.getString("section"));
boInstanceError.set("uniqueServiceNumber",
cotsinstlistnode.getString("uscno"));
boInstanceError.set("status", "P");
boInstanceError = BusinessObjectDispatcher
.add(boInstanceError);
boInstanceError = null;
} else {
boInstanceDetail.set("currentAmount", curAmountMoney);
boInstanceDetail.set("adjustmentType", adjTypeCode);
boInstanceDetail
.set("adjustmentUploadStatus",
AdjustmentStagingControlStatusLookup.constants.PENDING);

boInstanceDetail.set("adjustmentSuspense",
AdjustmentSuspenseLookup.constants.NOT_IN_SUSPENSE);
sid = row.get("SA_ID").toString();
boInstanceDetail.set("serviceAgreement", sid);
boInstanceDetail.set("adjustmentId", " ");
boInstanceDetail.set("suspenseAdjustmentId", " ");
boInstanceDetail.set("adjustmentStagingControlID",
boInstanceSummary
.getNumber("adjustmentStagingControlID"));
boInstanceDetail.set("messageCategory", new BigDecimal(1));
boInstanceDetail.set("messageNumber", new BigDecimal(101));
boInstanceDetail.set("version", new BigDecimal(1));
boInstanceDetail = BusinessObjectDispatcher
.add(boInstanceDetail);
count = count.add(new BigDecimal(1));
System.out.println("count :::" + count);
System.out.println("Current Amount::::"
+ boInstanceDetail.getMoney("currentAmount"));
m = m.add(boInstanceDetail.getMoney("currentAmount"));
System.out.println("Amount :::" + m.getAmount());
boInstanceDetail = null;
}
}
BusinessObjectInstance boInstanceSummary1 = BusinessObjectInstance
.create("CM_ADJSTGCTL");
boInstanceSummary1.set("adjustmentStagingControlID",
boInstanceSummary.getNumber("adjustmentStagingControlID"));
boInstanceSummary1.set("totalAdjustmentAmount", m);
boInstanceSummary1.set("adjustmentUploadRecordCount", count);
boInstanceSummary1 = BusinessObjectDispatcher
.update(boInstanceSummary1);
System.out.println("
"
+ boInstanceSummary1
.getNumber("adjustmentStagingControlID"));
System.out.println("
"
+ boInstanceSummary1.getMoney("totalAdjustmentAmount"));
System.out.println("
"
+ boInstanceSummary1
.getNumber("adjustmentUploadRecordCount"));
BusinessObjectInstance boStatusUpdate = BusinessObjectInstance
.create("CM_ADJUPLOAD");
boStatusUpdate.set("adjUploadId",
boInstanceClob.getString("adjUploadId"));
boStatusUpdate.set("status", "C");
boStatusUpdate = BusinessObjectDispatcher.update(boStatusUpdate);

System.out.println("Update Bo :: "
+ boStatusUpdate.getString("status"));
boInstanceSummary = null;
boInstanceClob = null;
boStatusUpdate = null;
}
setOverrideResultForChange(element);
}
}
Junit For Java Bussiness Service

Junit Test Case For Java Bussiness Service Is As Fallows


public class AdjRetrieve_Test extends ServiceTestCase {

protected String getServiceName() {


return "CM_ADJRETRIEVE";
}
public void privateTestServiceAuto() {
PageBody pageBody = new PageBody();
//pageHeader.put(HEADER.ACCT_ID, "5181123257");
RequestContext rc =getSession().getRequestContext();
System.out.println("::::::::::"+getServiceName());
pageBody.put(AdjRetrieve.STRUCTURE.ACCT_ID,"324324");
pageBody.put(AdjRetrieve.STRUCTURE.ADHOC_CHAR_VAL, "234234");
pageBody.put(AdjRetrieve.STRUCTURE.ENTITY_NAME,"56765765");
PageBody newBody = TestApplicationService.changeItem(getServiceName(), pageBody, rc);
System.out.println("newBody :: "+newBody);
System.out.println("end::::::::::::::");
}
}

2.8 Error Handling


try

{
adjustment=objServiceAgreement.addAdjustment(adjustmentDTO);

adjustment.generate(this.getSystemDateTime().getDate()
,this.getProcessDateTime().getDate());
adjustment.freeze(curdate.getDate());
System.out.println("i have generated adjustment"+adjustment.getId()
+"adjustement Amount"+adjustment.getCurrentAmount());
}catch(NullPointerException e)
{
updateBillException(e,objBill,"AverageUnits","ED Algorithm");
}
private void updateBillException(Exception exception, Bill objBill,String
strMessage1,String strMessage2)
{
ServerMessage exceptionMsg;
BillExceptions billExcp = objBill.getExceptions();
BillException_DTO billExcpDTO = new BillException_DTO();
exceptionMsg =
CustomMessageRepository.exceptionMessages(strMessage1,strMessage2);
billExcpDTO.setMessageId(exceptionMsg.getMessageId());
billExcpDTO.setCreationDateTime(this.getProcessDateTime());
billExcpDTO.setBillExceptionType(BillExceptionTypeLookup.constants.BILLING_ERR
OR);
billExcpDTO.setExpandedMessage(exceptionMsg.getMessageText());
billExcpDTO.setUserId(this.getActiveContextUser().getId());
billExcpDTO.setMessageParameter1(exceptionMsg.getMessageText());
//
if (!isNull(myParams)) populateMessageParms(myParams,billExcpDTO);
billExcp.add(billExcpDTO);
Bill_DTO billDto = objBill.getDTO();
System.out.println(billDto.getLatePaymentChargeDate());
billDto.setBillStatus(BillStatusLookup.constants.PENDING);
objBill.setDTO(billDto);

Different Types HQL Codes For Reference

StringBuffer queryHql = new StringBuffer();


140
queryHql.append("FROM Measurement MEASUREMENT ");
141
queryHql.append("WHERE MEASUREMENT.id.measuringComponent.id =
:measuringComponentId ");
142
queryHql.append("AND MEASUREMENT.id.measurementDateTime >= :startDate ");
143
queryHql.append("AND MEASUREMENT.id.measurementDateTime <= :endDate ");
144
Query<QueryResultRow> query = createQuery(queryHql.toString());
145
query.bindId("measuringComponentId", measuringComponentId);
146
query.bindDateTime("startDate", startDt);
147
query.bindDateTime("endDate", endDt);
148
query.addResult("measurementDateTime", "MEASUREMENT.id.measurementDateTime");
149
query.addResult("userEditedFlag", "MEASUREMENT.userEdited");
150

StringBuffer queryString = new StringBuffer();


294
queryString.append("from Measurement ms where ms.id.measuringComponent = :mc ");
295
queryString.append(" and ms.useMeasurement != :doNotUse");
296
297
if (findPrevious) {
298
queryString.append(" and ms.id.measurementDateTime < :measurementDateTime ");
299
} else {
300
queryString.append(" and ms.id.measurementDateTime > :measurementDateTime ");
301
queryString.append(" and not (ms.measurementCondition between :noReadBottomRange
and :noReadTopRange) ");
302
}
303
Query<QueryResultRow> measurementQuery = createQuery(queryString.toString());
304
measurementQuery.bindEntity("mc", mc);
305
measurementQuery.bindDateTime("measurementDateTime", measurementDateTime);
306
measurementQuery.bindLookup("doNotUse",
UseMeasurementLookup.constants.DO_NOT_USE);
307
measurementQuery.addResult("measuringComponentId", "ms.id.measuringComponent.id");
308
measurementQuery.addResult("dateTime", "ms.id.measurementDateTime");
309
if (findPrevious) {
310
measurementQuery.orderBy("dateTime", Query.DESCENDING);
311
} else {
312
measurementQuery.bindStringProperty("noReadBottomRange",
Measurement.properties.measurementCondition,
313
noReadBottomRangeCondition);
314
measurementQuery.bindStringProperty("noReadTopRange",
Measurement.properties.measurementCondition,
315
noReadTopRangeCondition);
316
measurementQuery.orderBy("dateTime", Query.ASCENDING);
317
}
318
319
if (measurementQuery.list().isEmpty()) {
320
return null;
321
}
322
QueryResultRow row = measurementQuery.firstRow();
323
MeasuringComponent_Id mcId = (MeasuringComponent_Id)
row.get("measuringComponentId");
324
return new Measurement_Id(mcId.getEntity(), row.getDateTime("dateTime")).getEntity();
325
}
326 }

private DateTime getLatestMapDataDttm(String touMapId, DateTime busDttm) {


169
TimeOfUseMapD1_Id touMapDynId = new TimeOfUseMapD1_Id(touMapId);
170
StringBuffer queryHql = new StringBuffer();
171
queryHql.append("FROM TimeOfUseMapData touData ");

172
173
174
175
176
177
178
179
180
181
182
183
184

queryHql.append(" WHERE touData.id.timeOfUseMap =:touMapId ");


queryHql.append(" AND touData.id.timeOfUseMapDataDateTime <=:busDttm");
Query query = createQuery(queryHql.toString());
query.bindId("touMapId", touMapDynId);
query.bindDateTime("busDttm", busDttm);
query.addResult("maxValue", "MAX(touData.id.timeOfUseMapDataDateTime)");
if (query.list().size() > 0) {
DateTime result = (DateTime) query.firstRow();
return result;
}
return null;
}

private void deleteFutureTOUMapData(TimeOfUseMapD1_Id touMap) {


224
DateTime latestDt = null;
225
StringBuffer queryHql = new StringBuffer();
226
227
queryHql.append("FROM TimeOfUseMapData touData ");
228
queryHql.append(" WHERE touData.id.timeOfUseMap =:touMapId ");
229
Query query = createQuery(queryHql.toString());
230
query.bindId("touMapId", touMap);
231
query.addResult("maxValue", "MAX(touData.id.timeOfUseMapDataDateTime)");
232
if (query.list().size() > 0) {
233
latestDt = (DateTime) query.firstRow();
234
}
235
if (latestDt != null) {
236
if (latestDt.isSameOrAfter(startDateTime)) {
237
StringBuffer queryTou = new StringBuffer();
238
queryTou.append("FROM TimeOfUseMapData touData ");
239
queryTou.append(" WHERE touData.id.timeOfUseMap =:touMapId ");
240
queryTou.append(" AND touData.id.timeOfUseMapDataDateTime <= :endDttm");
241
queryTou.append(" AND touData.id.timeOfUseMapDataDateTime >= :startDttm");
242
Query query1 = createQuery(queryTou.toString());
243
query1.bindId("touMapId", touMap);
244
query1.bindDateTime("startDttm", startDateTime);
245
query1.bindDateTime("endDttm", endDateTime);
246
query1.delete();
247
}
248
}

private List getSortedFactorOverride(UsageSubscription_Id usageSubscription) {


156
StringBuilder queryString = new StringBuilder();
157
queryString.append("from UsageSubscriptionFactorOverride
usageSubscriptionFactorOverride ");
158
queryString.append(" where usageSubscriptionFactorOverride.id.usageSubscription.id =
:usageSubscription ");
159
160
Query query = createQuery(queryString.toString());
161

162
163
164
165
166
167
168
169
170
171

query.bindId(USAGE_SUBSCRIPTION_HQL, usageSubscription);
query.addResult(US_FACTOR_ID_HQL, "usageSubscriptionFactorOverride.id.factor.id");
query.addResult(START_DATE_HQL, "usageSubscriptionFactorOverride.id.startDateTime");
query.addResult(END_DATE_HQL, "usageSubscriptionFactorOverride.endDateTime");
query.orderBy(US_FACTOR_ID_HQL);
query.orderBy(START_DATE_HQL);
List result = query.list();
return result;
}
}

String checkForOverlappingPeriods(String usId) {


149
StringBuffer queryHql = new StringBuffer();
150
queryHql.append("from UsageSubscriptionServicePoint usSp ");
151
queryHql.append(" where usSp.id.usageSubscription.id = :usId");
152
Query query = createQuery(queryHql.toString());
153
UsageSubscription_Id us_Id = new UsageSubscription_Id(usId);
154
query.bindId(US_ID_HQL, us_Id);
155
query.addResult(SP_ID_HQL, "usSp.id.servicePoint");
156
query.addResult(SP_START_DATE_TIME_HQL, "usSp.id.startDateTime");
157
query.addResult(SP_STOP_DATE_TIME_HQL, "usSp.stopDateTime");
158
query.orderBy(SP_ID_HQL);
159
query.orderBy(SP_START_DATE_TIME_HQL);
160
List usSPListSorted = query.list();
161
String faultySP = null;
162
if (!(usSPListSorted.isEmpty())) {
163
boolean firstTime = true;
164
ServicePointD1_Id sp_Id_current = null;
165
DateTime spStopDateTime_current = null;
166
int endDateCount = 0;
167
ServicePointD1_Id sp_Id_next = null;
168
DateTime spStartDateTime_next = null;
169
DateTime spStopDateTime_next = null;
170
for (Iterator iterator = usSPListSorted.iterator(); iterator.hasNext();) {
171
if (firstTime) {
172
QueryResultRow currentRow = (QueryResultRow) iterator.next();
173
sp_Id_current = ((ServicePointD1) currentRow.get(SP_ID_HQL)).getId();
174
spStopDateTime_current = currentRow.getDateTime(SP_STOP_DATE_TIME_HQL);
175
if (isNull(spStopDateTime_current)) {
176
endDateCount = 1;
177
}
178
firstTime = false;
179
} else {
180
QueryResultRow nextRow = (QueryResultRow) iterator.next();
181
sp_Id_next = ((ServicePointD1) nextRow.get(SP_ID_HQL)).getId();
182
spStartDateTime_next = nextRow.getDateTime(SP_START_DATE_TIME_HQL);
183
spStopDateTime_next = nextRow.getDateTime(SP_STOP_DATE_TIME_HQL);
184
if ((sp_Id_next != null && sp_Id_current != null)
185
&& sp_Id_current.getIdValue().equals(sp_Id_next.getIdValue())) {
186
if (spStopDateTime_current != null &&
spStopDateTime_current.isAfter(spStartDateTime_next)) {
187
faultySP = sp_Id_current.getIdValue();
188
break;
189
}
190
if (isNull(spStopDateTime_next)) {

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

endDateCount++;
if (endDateCount > 1) {
faultySP = sp_Id_current.getIdValue();
break;
}
}
} else {
if (isNull(spStopDateTime_next)) {
endDateCount = 1;
} else {
endDateCount = 0;
}
}
sp_Id_current = sp_Id_next;
spStopDateTime_current = spStopDateTime_next;
}
}
}
return faultySP;
}
}

private List getSortedUsageGroup(UsageSubscription_Id usageSubscription) {


165
StringBuilder queryString = new StringBuilder();
166
queryString.append("from UsageSubscriptionUsageGroup usageSubscriptionUsageGroup");
167
queryString.append(" where usageSubscriptionUsageGroup.id.usageSubscription.id =
:usageSubscription");
168
169
Query query = createQuery(queryString.toString());
170
171
query.bindId(USAGE_SUBSCRIPTION_HQL, usageSubscription);
172
query.addResult(EFFT_DATE_HQL, "usageSubscriptionUsageGroup.id.effectiveDateTime");
173
query.addResult(EXP_DATE_HQL, "usageSubscriptionUsageGroup.expirationDateTime");
174
query.addResult(US_USAGE_GROUP_ID_HQL,
"usageSubscriptionUsageGroup.usageGroup.id");
175
//query.orderBy(US_USAGE_GROUP_ID_HQL);
176
query.orderBy(EFFT_DATE_HQL);
177
List result = query.list();
178
return result;
179
}

2.9 SDK File Deployment in the CC&B


Server
For Deploying Java Files in The CC&B Server you need to follow the given points

You May See To Folder structures Called SDK_Packaging and CM_Packaging folders
SDK_Packaging Folder Consist of the packaging structure of all the packages involved in the CM Jar.
What ever packaging structure you have in eclipse you can find in the SDK Packaging folder also

In java folder the structure is like as follows

Place All the java files in the corresponding package folders,


Once you place in SDK Packaging just go to console prompt
Ex: if your CC&B Server is running on D:\spl\DEV1 then fallow the fallowing commands
1. just go to the following path CD D:\spl\DEV1\bin
2. D:\spl\DEV1\bin>splenviron -e DEV1

It will start the environment required for our project


3. Next From the same command prompt go the folder location where sdk_packaging folder location
is available .Example if your both Sdk_Packaging,CM_Packaging folder is available in D Drive
D:\spl\DEV1\bin> cd D:\sdk_packaging>
4. Run the following command D:\sdk_packaging> D:\> CM_Packaging\applyCm.cmd
Note: When Deployment is going take care not to close the command prompt ,becuase the war files will
be currpted.
5. Once it shows Build Success Full ,Run the server as usual.

Das könnte Ihnen auch gefallen