public List<DHProductLookupModel> findProductbyCCsapProductId(final String code)
{
final String queryString = "SELECT {p:" + DHProductLookupModel.SAPPRODUCTID + "}" + "FROM{" + DHProductLookupModel._TYPECODE
+ " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";
final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
query.addQueryParameter("code", code);
return flexibleSearchService.<DHProductLookupModel> search(query).getResult();
}
search(query) throws Null Pointer Exception, how to handle this?
Output:
Caused by: java.lang.NullPointerException
at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.getJaloResult(DefaultFlexibleSearchService.java:396) ~[coreserver.jar:?]
at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.search(DefaultFlexibleSearchService.java:168) ~[coreserver.jar:?]
at com.cancom.core.productlookup.dao.impl.CCProductLookupDaoImpl.findProductbyCCmanufacturerProductId(CCProductLookupDaoImpl.java:39) ~[classes/:?]
at com.cancom.core.productlookup.service.impl.CCProductLookupServiceImpl.getProductforCCmanufacturerProductId(CCProductLookupServiceImpl.java:37) ~[classes/:?]
Thanks!
Change your flexible search query from
final String queryString = "SELECT {p:" + DHProductLookupModel.SAPPRODUCTID + "}" + "FROM{" + DHProductLookupModel._TYPECODE
+ " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";
to
final String queryString = "SELECT {p:" + DHProductLookupModel.PK + "}" + "FROM{" + DHProductLookupModel._TYPECODE
+ " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";
You should send DHProductLookupModel.PK in search result.
In your case, you can use getModelsByExample of flexibleSearchService instead of writing the query.
Your method will be like
public List<DHProductLookupModel> findProductbyCCsapProductId(final String code)
{
DHProductLookupModel dhProductLookupModel = new DHProductLookupModel();
dhProductLookupModel.setSapProductID(code);
return getFlexibleSearchService().getModelsByExample(dhProductLookupModel);
}
find the example here
Thanks everyone!
I found the Problem. It was in my spring.I just had to put :
<context:component-scan base-package="myPackage"/>
I changed also the query with DHProductLookupModel.PK for safety. Now it´s work!
Related
I am working on Power mockito for the first time.
Here is my code
#SuppressWarnings("unchecked")
public List<CurrencyBasedTotalCharges> getCurrencyBasedTotalChargesforCustomerSuperGroupforOperatingAccount(String customerSuperGroupId)
{
Session session =getSessionFromContext();
String sql = "SELECT ROUND(SUM(qst),2) ||'`'||ROUND(SUM(pst),2)||'`'||ROUND(SUM(gst),2)||'`'||ROUND(SUM(hst),2)||'`'||ROUND(SUM(converted_val),2)||'`'||currency " +
"FROM (" +
"SELECT CASE WHEN cr.oper_acc_curr is null or cr.oper_acc_curr='NA'" +
"THEN cr.charge_account_curr" +
"ELSE cr.oper_acc_curr END AS currency," +
"nvl ((select case when cr.DR_CR_FLAG='C' then -mcr.value else mcr.value end from mi_charge_record mcr where mcr.original_charge_record_id=cr.reference_id and substr(mcr.charge_code,3,length(mcr.charge_code))='GST'), 0" +
" ) AS gst," +
"nvl((select case when cr.DR_CR_FLAG='C' then -mcr.value else mcr.value end from mi_charge_record mcr where mcr.original_charge_record_id=cr.reference_id and substr(mcr.charge_code,3,length(mcr.charge_code))='PST'), 0" +
" ) AS pst," +
"nvl((select case when cr.DR_CR_FLAG='C' then -mcr.value else mcr.value end from mi_charge_record mcr where mcr.original_charge_record_id=cr.reference_id and substr(mcr.charge_code,3,length(mcr.charge_code))='QST'), 0" +
" ) AS qst," +
"nvl((select case when cr.DR_CR_FLAG='C' then -mcr.value else mcr.value end from mi_charge_record mcr where mcr.original_charge_record_id=cr.reference_id and substr(mcr.charge_code,3,length(mcr.charge_code))='HST'), 0" +
" ) AS hst," +
"CASE WHEN cr.DR_CR_FLAG='C'" +
" THEN (-cr.value) ELSE cr.value END AS converted_val," +
"cr.reference_id FROM mi_charge_record cr, mi_bl_billing_preference bp, account acc, customer c," +
"mii_customer_group cg"+
"WHERE acc.account_number=cr.account_number AND acc.customer_id=c.customer_id AND c.customer_group_id=cg.id AND cg.customer_super_group_id=:superGroupId AND" +
"to_date(cr.BILLED_DATE) BETWEEN to_date(bp.billing_cycle_start_date,'yyyymmdd') AND to_date(bp.billing_cycle_end_date,'yyyymmdd') AND CR.PRODUCT_SHORT_NAME<> 'TAX'" +
"AND CR.IS_COST <> 'Y'"+
") z" +
"GROUP BY currency having SUM(ROUND(converted_val,2)) != 0";
List<String> totalchargedetails=session.createSQLQuery(sql).setString("superGroupId", customerSuperGroupId).list();
LinkedHashMap<String, String> paramMap=new LinkedHashMap<>();
paramMap.put(CHARGE_LEVEL, CHARGE_BY_OPERATING_ACCOUNT);
paramMap.put(LINKED_ENTITY_GUID, customerSuperGroupId);
paramMap.put(STATEMENT_LEVEL, CUSTOMER_SUPER_GROUP_STATEMENT_LEVEL);
return getFinalCurrencyBasedTotalCharges(setCurrencyBasedTotalCharges(totalchargedetails),paramMap);
}
I am trying to test above functionality using mockito as below:
public void getCurrencyBasedTotalChargesforCustomerGroupforOperatingAccountTest() throws Exception
{
String customerGroupId = "CG-100001-01";
PowerMockito.doReturn(session).when(implStatementDAOImpl, "getSessionFromContext");
Mockito.when(query.setString(anyString(), anyString())).thenReturn(query);
Mockito.when(session.createQuery(anyString())).thenReturn(query);
Mockito.doReturn(entityObjectBuilder.currencyBasedTotalCharges()).when(query).list();
List<String> totalchargedetails = new ArrayList<String>();
List<CurrencyBasedTotalCharges> test = implStatementDAOImpl.getCurrencyBasedTotalChargesforCustomerGroupforOperatingAccount(customerGroupId);
//given( implStatementDAOImpl.getCurrencyBasedTotalChargesforCustomerGroupforOperatingAccount(customerGroupId).t, session)).willReturn(new ArrayList<CurrencyBasedTotalCharges>());
//Assert.assertFalse(test.isEmpty());
Mockito.verify(session).createQuery(anyString());
Mockito.verify(query).setString(anyString(), anyString());
Mockito.verify(query).list();
System.out.println(test);
}
I am getting NullPointer exception on session.createQuery line. Plesae guide me how shall I mock this and test.
Thanks.
where is session initialized?
You could do the initialization as follows:
#Mock
private Session session;
#Before
public void setup(){
MockitoAnnotations.initMocks(this);
}
It is important to init the mocks when using Annotations for mocking/spying
Another option is to init the session like this, e.g directly in your test method:
Session session = Mockito.mock(Session.class);
I made an xpage element for ftsearch using a tutorial from IBM
My request: is there possible having 2 date fields ( as input requirements for the search ) to find those documents having the creation date inside the interval consisting of those 2 dates?
Should I create a computed field dtCreated where I will store the creation date and then in the search property of the view I should add something like this:
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "(Field dtCreated > \"" + sessionScope.searhcDate1 + "\")" && "(Field dtCreated < \"" + sessionScope.searhcDate2 + "\")";
}
....
....
Or there is another alternative?
My 2 session variables are having Short (5/5/14) Date format. Also, my default value for those 2 dates (session variables) are "" but of course I add some values before clicking the Submit button.
Thanks for your time!
You can use the special field _creationDate as creation date (see answer from Tommy). Based on this the following example query will work in the Notes client:
Field _creationDate > 01-01-2014 AND Field _creationDate < 01-03-2014
In order to get this query to work with your specific code do this:
var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "dd-MM-yyyy" );
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
tmpArray[cTerms++] = "Field _creationDate > " + dateFormatter.format(sessionScope.searchDate1) + " AND Field _creationDate < " + dateFormatter.format(sessionScope.searchDate2);
}
If you want to do an FTSearch, _CreationDate can be used
Documentation (scroll to Searching for Header Information):
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_CUSTOMIZING_SEARCH_FORMS_7304.html
E.g. (there might be typos):
tmpArray[cTerms++] = "(Field _creationDate>" + sessionScope.searhcDate1 + ") AND (Field _creationDate<" + sessionScope.searhcDate2 + ")";
Or my preferred syntax:
tmpArray[cTerms++] = "[_creationDate>" + sessionScope.searhcDate1 + "] AND [_creationDate<" + sessionScope.searhcDate2 + "]";
To build on Tommy's answer:
Specifically, try "yyyy/m/d" as the format. If those values in sessionScope are java.util.Date (the type that date fields use), you could try something like this (typing off the top of my head, not in an app, so my apologies for typos):
var tmpArray = [];
var cTerms = 0;
if(sessionScope.searchDate1 && sessionScope.searchDate2) {
var formatter = new java.text.SimpleDateFormat("yyyy/M/d");
tmpArray[cTerms++] = "[_CreationDate] >= " + formatter.format(sessionScope.searchDate1) + " and [_CreaationDate] <= " + formatter.format(sessionScope.searchDate2)
}
What you want to end up with is a FT query like:
[_CreationDate] >= 2014/1/1 and [_CreationDate] <= 2014/2/1
I am trying to populate a look-up column in a list, via the web service.
I am getting my data from an asp.net web form and using the web service method UpdateListItems and sending batch XML.
However, unless the user enters the exact data that the look up uses, the web service returns an error.
Is there anyway i can give the user of the web form, similar look-up functionality in order that the data passed will be identical?
i'm using share point 2007
The data source for the look-up column in share point is active directory.
_x0028_HR_x0029__x0020_Partner is the look up column, entering the users login name will look up their full name/ you can pick from a list.
Your help is much appreciated.
ClasService.Lists NewStarterList = new ClasService.Lists();
NewStarterList.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SPUserName"].ToString(),
ConfigurationManager.AppSettings["SPPassword"].ToString(), ConfigurationManager.AppSettings["SPDomain"].ToString());
NewStarterList.Url = ConfigurationManager.AppSettings["SPUrl"].ToString() + ConfigurationManager.AppSettings["SPServicePath"].ToString();
try
{
string strBatch = "<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>" + clasStarter.ClasID + "</Field>" +
"<Field Name='Title'>" + clasStarter.Name + "</Field>" +
"<Field Name='_x0028_HR_x0029__x0020_Job_x0020'>" + clasStarter.JobTitle + "</Field>" +
"<Field Name='Entity'>" + clasStarter.Entity + "</Field>" +
"<Field Name='Practice_x0020_Groups'>" + clasStarter.PracticeGroup + "</Field>" +
"<Field Name='Dept'>" + clasStarter.Department + "</Field>" +
"<Field Name='Physical_x0020_Desk_x0020_Locati'>" + clasStarter.Location + ", " + clasStarter.LocationInBuilding + ", " + clasStarter.Department + "</Field>" +
"<Field Name='_x0028_HR_x0029__x0020_Line_x002'>" + clasStarter.LineManager + "</Field>" +
"<Field Name='_x0028_HR_x0029__x0020_Buddy'>" + clasStarter.Buddy + "</Field>" +
"<Field Name='_x0028_HR_x0029__x0020_Partner'>" + clasStarter.Partner + "</Field>" +//is a look up
"</Method>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.SetAttribute("ViewName", ConfigurationManager.AppSettings["SPViewID"].ToString());
elBatch.InnerXml = strBatch;
XmlNode ndReturn = NewStarterList.UpdateListItems(ConfigurationManager.AppSettings["SPListID"].ToString(), elBatch);
}
catch (Exception exp)
{
throw new Exception("NewStarterForm - Clas Update failed ", exp);
}
I haven't figured out a full solution my problem, but i have figured out part of it.
Share point look-up columns have two parts, an id and a value. If you don't know the value then you can just use -1;# as a substitute for the ID
an example of this is
"<Field Name='Partner'>-1;#" + partnerLogOnId + "</Field>"
I will probably use a list, that allows users of my form to select people, and will pass the partnerLogOnId to my web service method.
i have a problem, when i m run my code then error is occured that "Object reference not set to an instance of an object."
plz suggest me regarding that.
Code
protected void btn_Save_Click(object sender, EventArgs e)
{
string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Geeta/Desktop/eTimeTrackLite1.mdb;Persist Security Info=False;");
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
string query = "insert into Employees ([EmployeeName],EmployeeCode,DeviceCode,Company,Department,Designation,Grade,Team,Location,EmploymentType,Category,HolidayGroup,ShiftGroup,ShiftRoster,Dateofjoining,Dateofconfirmation,Status,DateofResigning,[Sex]) values ('" + txt_empname.Text + "','" + txt_code.Text + "', '" + txt_dcode.Text + "', '" + dp_company.SelectedItem.ToString() + "', '" + dp_department.SelectedItem.ToString() + "', '"+dp_designation.SelectedItem.ToString()+"', '"+dp_grade.SelectedItem.ToString()+"', '"+dp_team.SelectedItem.ToString()+"', '"+dp_location.SelectedItem.ToString()+"', '"+dp_emptype.SelectedItem.ToString()+"', '"+dp_category.SelectedItem.ToString()+"', '"+dp_holigroup.SelectedItem.ToString()+"', '"+dp_shiftgroup.SelectedItem.ToString()+"', '"+dp_shiftroster.SelectedItem.ToString()+"', '"+dp_day.SelectedItem.ToString()+"', '"+dp_month.SelectedItem.ToString()+"', '"+dp_year.SelectedItem.ToString()+"', '"+dp_cday.SelectedItem.ToString()+"', '"+dp_cmonth.SelectedItem.ToString()+"', '"+dp_cyear.SelectedItem.ToString()+"', '"+dp_status.SelectedItem.ToString()+"', '"+dp_rday.SelectedItem.ToString()+"', '"+dp_rmonth.SelectedItem.ToString()+"', '"+dp_ryear.SelectedItem.ToString()+"', '"+rdbtn_male.Checked.ToString()+"', '"+rdbtn_female.Checked.ToString()+"')";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
BindGridData();
}
"Thanks"
In order to avoid this kind of problems, don't use ToString is there is a risk of the calling object to be null, use Convert.ToString() instead.
http://msdn.microsoft.com/en-us/library/system.convert.tostring.aspx
Pagination (Next button) doesn't work for custom BusinessDataListWebPart.
I am adding BusinessDataListWebPart using code. Everything works fine. I can see 20 data raw at the same time but when I click "Next Button", I can not see next 20-40 data. A postback occurs, but the pageindex never changes.
I am using following code to add BusinessDataListWebPart to the Sharepoint site.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
OK..I found the answer.
For pagination I needed to add "ParameterBindings" to the business data list webpart.
My final code is, It works perfect.
BusinessDataListWebPart consumer = new BusinessDataListWebPart();
ServerContext serverContext = ServerContext.GetContext(site);
SqlSessionProvider.Instance().SetSharedResourceProviderToUse(serverContext);
LobSystemInstance instance = ApplicationRegistry.GetLobSystemInstanceByName(applicationName);
Entity projEntity = instance.GetEntities()[entityName];
consumer.Title = title;
consumer.Application = instance.Name;
consumer.Entity = projEntity.Name;
consumer.XslLink = "/Style%20Library/XSL%20Style%20Sheets/" + xslFileName;
consumer.PageSize = 20;
consumer.ParameterBindings = "<ParameterBinding Name=" + "\"dvt_firstrow\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortdir\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_sortfield\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_filterfields\"" + " Location=" + "\"Postback;Connection\"" + "/>" +
" <ParameterBinding Name=" + "\"dvt_partguid\"" + " Location=" + "\"Postback;Connection\"" + "/>";