// Note: don't call this directly if the "wait" screen is desired
void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
                                                  int tid,
                                                  int pageIdx,
                                                  const QString & title,
                                                  const QString & searchString)
{

  if(m_tid != tid || m_searchString != searchString){
    m_collapsibleComponentList->firstPage();
  }

  m_filterType = filterType;

  m_tid = tid;

  m_searchString = searchString;

  //std::vector<Component *> components = m_collapsibleComponentList->components();
  std::vector<Component *> components = m_componentList->components();  // TODO replace with code above

  for( auto & comp : components)
  {
    delete comp;
  }

  RemoteBCL remoteBCL;
  std::vector<BCLSearchResult> responses;
  if (filterType == "components")
  {
    responses = remoteBCL.searchComponentLibrary(searchString.toStdString(),tid,pageIdx);
  }
  else if (filterType == "measures")
  {
    responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(),tid,pageIdx);
  }

  for( const auto & response : responses)
  {
    auto component = new Component(response);
    
    // TODO replace with a componentList owned by m_collapsibleComponentList
    m_componentList->addComponent(component);
  }

  // the parent taxonomy
  m_collapsibleComponentList->setText(title);

  // the total number of results
  int lastTotalResults = remoteBCL.lastTotalResults();
  m_collapsibleComponentList->setNumResults(lastTotalResults);

  // the number of pages of results
  int numResultPages = remoteBCL.numResultPages();
  m_collapsibleComponentList->setNumPages(numResultPages);

  // make sure the header is expanded
  if(m_collapsibleComponentList->checkedCollapsibleComponent()){
    m_collapsibleComponentList->checkedCollapsibleComponent()->setExpanded(true);
  }

  // select the first component
  if(m_componentList->firstComponent()){
    m_componentList->firstComponent()->setChecked(true);
  }
  else{
    emit noComponents();
  }

  emit componentsReady();

}
Ejemplo n.º 2
0
TEST_F(BCLFixture, RemoteBCLTest)
{
  RemoteBCL remoteBCL;

  // set temporary production auth key
  remoteBCL.setProdAuthKey(prodAuthKey);
  EXPECT_EQ(prodAuthKey, remoteBCL.prodAuthKey());
  EXPECT_EQ(remoteBCL.prodAuthKey(), remoteBCL.authKey());

  // Don't bother testing this since bcl7.development.nrel.gov is internal only
  // set temporary development auth key
  //remoteBCL.setDevAuthKey(devAuthKey);
  //EXPECT_EQ(devAuthKey, remoteBCL.devAuthKey());

  // check that defaults to production url
  EXPECT_EQ(remoteBCL.remoteProductionUrl(), remoteBCL.remoteUrl());

  // get all roofs (not children), via empty first arg and non-null second string
  std::vector<BCLSearchResult> responses = remoteBCL.searchComponentLibrary("","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // test total result and page functions
  EXPECT_GT(remoteBCL.resultsPerQuery(),0);
  EXPECT_LT(remoteBCL.resultsPerQuery(),101);
  EXPECT_GT(remoteBCL.lastTotalResults(),0);
  EXPECT_GT(remoteBCL.numResultPages(),0);
  EXPECT_GT(remoteBCL.lastTotalResults(),remoteBCL.numResultPages());

  // get all roofs (not children), via wildcard first arg and non-null second string
  responses = remoteBCL.searchComponentLibrary("*","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all nonresidential components, via non-null first arg and wildcard second string
  responses = remoteBCL.searchComponentLibrary("ashrae","*");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all nonresidential roofs (not children), via non-null first arg and non-null second string
  responses = remoteBCL.searchComponentLibrary("ashrae","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all things wall, via non-null first string and default arg second string
  responses = remoteBCL.searchComponentLibrary("wall","");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all constructions and children, via null first arg and tid
  responses = remoteBCL.searchComponentLibrary("",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all constructions and children, via wildcard first arg and tid
  responses = remoteBCL.searchComponentLibrary("*",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all constructions matching "office", via non-null first arg and tid
  responses = remoteBCL.searchComponentLibrary("office",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // verify that different pages of results are returning different uids
  responses = remoteBCL.searchComponentLibrary("",127,0);
  unsigned numResponsesSearch1 = responses.size();
  ASSERT_GT(static_cast<int>(numResponsesSearch1),0);
  std::vector<BCLSearchResult> responses2 = remoteBCL.searchComponentLibrary("",127,1);
  unsigned numResponsesSearch2 = responses2.size();
  ASSERT_GT(static_cast<int>(numResponsesSearch2),0);
  EXPECT_NE(responses[0].uid(), responses2[0].uid());

  // get all denver weather files
  responses = remoteBCL.searchComponentLibrary("Denver","Weather File");
  ASSERT_GT(static_cast<int>(responses.size()),0);

  /// Download an individual component by uid and extract
  /// returns true if a download is started
  bool success = remoteBCL.downloadComponent(responses[1].uid());
  ASSERT_TRUE(success);

  /// Returns the last downloaded component if there is one
  boost::optional<BCLComponent> completed = remoteBCL.waitForComponentDownload();
  ASSERT_TRUE(completed);

// Remove comment block to test development server
/*

  remoteBCL.useRemoteDevelopmentUrl();

  // verify dev url and that change was applied
  EXPECT_EQ(remoteBCL.remoteDevelopmentUrl(), remoteBCL.remoteUrl());
  EXPECT_EQ(remoteBCL.devAuthKey(), remoteBCL.authKey());

  // get all roofs (not children), via empty first arg and non-null second string
  responses = remoteBCL.searchComponentLibrary("","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // test total result and page functions
  EXPECT_GT(remoteBCL.resultsPerQuery(),0);
  EXPECT_LT(remoteBCL.resultsPerQuery(),101);
  EXPECT_GT(remoteBCL.lastTotalResults(),0);
  EXPECT_GT(remoteBCL.numResultPages(),0);
  EXPECT_GT(remoteBCL.lastTotalResults(),remoteBCL.numResultPages());

  // get all roofs (not children), via wildcard first arg and non-null second string
  responses = remoteBCL.searchComponentLibrary("*","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all nonresidential components, via non-null first arg and wildcard second string
  responses = remoteBCL.searchComponentLibrary("ashrae","*");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all nonresidential roofs (not children), via non-null first arg and non-null second string
  responses = remoteBCL.searchComponentLibrary("ashrae","Exterior Roof");
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all things wall, via non-null first string and default arg second string
  responses = remoteBCL.searchComponentLibrary("wall","");
  ASSERT_GT(static_cast<int>(responses.size()),0);

  // get all constructions and children, via null first arg and tid
  responses = remoteBCL.searchComponentLibrary("",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all constructions and children, via wildcard first arg and tid
  responses = remoteBCL.searchComponentLibrary("*",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // get all constructions matching "office", via non-null first arg and tid
  responses = remoteBCL.searchComponentLibrary("office",127);
  EXPECT_GT(static_cast<int>(responses.size()),0);

  // verify that different pages of results are returning different uids
  responses = remoteBCL.searchComponentLibrary("",127,0);
  numResponsesSearch1 = responses.size();
  EXPECT_GT(static_cast<int>(numResponsesSearch1),0);
  responses2 = remoteBCL.searchComponentLibrary("",127,1);
  numResponsesSearch2 = responses2.size();
  EXPECT_GT(static_cast<int>(numResponsesSearch2),0);
  EXPECT_NE(responses[0].uid(), responses2[0].uid());

  // get all denver weather files
  responses = remoteBCL.searchComponentLibrary("Denver","Weather File");
  ASSERT_GT(static_cast<int>(responses.size()),0);

  /// Download an individual component by uid and extract
  /// returns true if a download is started
  success = remoteBCL.downloadComponent(responses[1].uid());
  ASSERT_TRUE(success);

  /// Returns the last downloaded component if there is one
  completed = remoteBCL.waitForComponentDownload();
  ASSERT_TRUE(completed);
*/
}