@Override
  public List<OrderProcessModel> findProcessesByActionIds(
      final String processName, final String processCurrentActions[]) {
    final String query =
        "select {bp.PK} "
            + "from {OrderProcess AS bp  JOIN ProcessTask AS pt ON {bp.pk} = {pt.process} } "
            + "WHERE {bp.processDefinitionName} = ?processDefinitionName and {pt.action} in (?processCurrentActions)";

    final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query);
    searchQuery.addQueryParameter("processDefinitionName", processName);
    searchQuery.addQueryParameter("processCurrentActions", Arrays.asList(processCurrentActions));
    final SearchResult<OrderProcessModel> processes = flexibleSearchService.search(searchQuery);
    return processes.getResult();
  }
  @Override
  public List<ProductModel> findProductsRelatedToPurchasedProductsByCategory(
      final CategoryModel category,
      final List<ProductReferenceTypeEnum> referenceTypes,
      final UserModel user,
      final boolean excludePurchased,
      final Integer limit) {
    Assert.notNull(category);
    Assert.notNull(user);

    final int maxResultCount = limit == null ? DEFAULT_LIMIT : limit.intValue();

    final Map<String, Object> params = new HashMap<String, Object>();
    final StringBuilder builder = new StringBuilder(REF_QUERY_CATEGORY_START);
    if (excludePurchased) {
      builder.append(REF_QUERY_SUB);
    }
    if (CollectionUtils.isNotEmpty(referenceTypes)) {
      builder.append(REF_QUERY_TYPES);
      params.put(REF_QUERY_PARAM_TYPES, referenceTypes);
    }
    builder.append(REF_QUERY_CATEGORY_ORDER);

    params.put(REF_QUERY_PARAM_USER, user);
    params.put(REF_QUERY_PARAM_CATEGORY, category);

    final FlexibleSearchQuery query = new FlexibleSearchQuery(builder.toString());
    query.addQueryParameters(params);
    query.setNeedTotal(false);
    query.setCount(maxResultCount);

    final SearchResult<ProductModel> result = getFlexibleSearchService().search(query);
    return result.getResult();
  }
Пример #3
0
 @Override
 public List<CourseModel> findCourseByCode(final String code) {
   validateParameterNotNull(code, "Product code must not be null!");
   final Map<String, Object> params = new HashMap<String, Object>();
   params.put("code", code);
   final SearchResult<CourseModel> result = flexibleSearchService.search(COURSES_BY_CODE, params);
   return result.getResult();
 }
Пример #4
0
 /*
  * (non-Javadoc)
  *
  * @see org.training.dao.TrainingDao#getAllCoursesByTraining()
  */
 @Override
 public List<CourseModel> getAllCoursesByTraining(final String code) {
   final Map<String, Object> params = new HashMap<String, Object>();
   params.put("code", code);
   final SearchResult<CourseModel> result =
       flexibleSearchService.search(COURSES_BY_TRAINING, params);
   return result.getResult();
 }
 @Override
 public List<OrderModel> findAllOrdersInStatus(final OrderStatus orderStatus) {
   final String query =
       "SELECT {pk} FROM {Order} WHERE  {status} = ?status AND {versionID} IS NULL";
   final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query);
   searchQuery.addQueryParameter("status", orderStatus);
   final SearchResult<OrderModel> orderList = flexibleSearchService.search(searchQuery);
   return orderList.getResult();
 }
  @Test
  public void testIfAggregatedStatisticsAreSavedToDb() {
    // given
    final Date date1 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(10)
            .withDayOfMonth(15)
            .withHourOfDay(12)
            .withMinuteOfHour(20)
            .toDate();
    final Date date2 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(10)
            .withDayOfMonth(15)
            .withHourOfDay(12)
            .withMinuteOfHour(45)
            .toDate();
    final Date date3 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(11)
            .withDayOfMonth(19)
            .withHourOfDay(12)
            .withMinuteOfHour(45)
            .toDate();
    final List<AggregatedSearchQueryInfo> aggrResults = new ArrayList<AggregatedSearchQueryInfo>();
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "monitor", "en", 5, date1));
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "monitor lcd", "en", 3, date2));
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "canon", "en", 2, date3));

    Mockito.when(mockSolrQueryStatisticsAggregator.aggregate()).thenReturn(aggrResults);

    solrQueryStatisticsCollectorJob.setSolrQueryStatisticsAggregator(
        mockSolrQueryStatisticsAggregator);

    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.SUCCESS);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).hasSize(3);
  }
 @Override
 public List<ClassificationAttributeValueModel> findAttributeValuesByCode(final String code) {
   final SearchResult<ClassificationAttributeValueModel> results =
       search( //
           "SELECT {"
               + ClassificationAttributeValueModel.PK
               + "} " //
               + "FROM {"
               + ClassificationAttributeValueModel._TYPECODE
               + "} " //
               + "WHERE {"
               + ClassificationAttributeValueModel.CODE
               + "} = ?code", //
           Collections.singletonMap(ClassificationAttributeValueModel.CODE, code));
   return results.getResult();
 }
  @Test
  public void testDisableCollectingStatistics() {
    // given
    solrQueryStatisticsCollectorJob.setEnableCollectingStatistics(false);

    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.SUCCESS);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).isEmpty();
  }
  @Override
  public CreditCardPaymentInfoModel findCreditCartPaymentBySubscription(
      final String subscriptionId) {
    validateParameterNotNull(subscriptionId, "subscriptionId must not be null!");

    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(PAYMENT_QUERY);
    fQuery.addQueryParameter("subscriptionId", subscriptionId);

    final SearchResult<CreditCardPaymentInfoModel> searchResult =
        getFlexibleSearchService().search(fQuery);
    final List<CreditCardPaymentInfoModel> results = searchResult.getResult();

    if (results != null && results.iterator().hasNext()) {
      return results.iterator().next();
    }

    return null;
  }
  @Override
  public CCPaySubValidationModel findSubscriptionValidationBySubscription(
      final String subscriptionId) {
    validateParameterNotNull(subscriptionId, "subscriptionId must not be null!");

    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(SUBSCRIPTION_QUERY);
    fQuery.addQueryParameter("subscriptionId", subscriptionId);

    final SearchResult<CCPaySubValidationModel> searchResult =
        getFlexibleSearchService().search(fQuery);
    final List<CCPaySubValidationModel> results = searchResult.getResult();

    if (results != null && results.iterator().hasNext()) {
      return results.iterator().next();
    }

    return null;
  }
  public List<OrderProcessModel> findAllProcessModelsToRepair(
      final String processName, final String endMessage) {
    final String query =
        "select {PK} from {OrderProcess} WHERE {"
            + BusinessProcess.PROCESSDEFINITIONNAME
            + "} = ?processDefinitionName "
            + "and {"
            + BusinessProcess.STATE
            + "} = ?statusValue and {"
            + BusinessProcess.ENDMESSAGE
            + "} = ?processResult";

    final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query);
    searchQuery.addQueryParameter("processDefinitionName", processName);
    searchQuery.addQueryParameter("processResult", endMessage);
    searchQuery.addQueryParameter("statusValue", ProcessState.ERROR);
    final SearchResult<OrderProcessModel> processes = flexibleSearchService.search(searchQuery);
    return processes.getResult();
  }
  @SocketEvent(socketId = "mail")
  public void displaySearchresult(MailInternalData mailData) {

    FlexibleSearchQuery query =
        new FlexibleSearchQuery(
            "Select {pk} from {EmailPage} where {uid}='" + mailData.getUid() + "'");
    SearchResult<EmailPageModel> searhResult = flexibleSearchService.search(query);
    final EmailPageModel emailPageModel = searhResult.getResult().get(0);

    FlexibleSearchQuery querybm =
        new FlexibleSearchQuery(
            "Select {pk} from {BusinessProcess } where {code}='"
                + mailData.getBusinessOrderCode()
                + "'");
    SearchResult<BusinessProcessModel> searhResultBs = flexibleSearchService.search(querybm);
    final BusinessProcessModel businessProcessModel = searhResultBs.getResult().get(0);

    final EmailPageTemplateModel emailPageTemplateModel =
        (EmailPageTemplateModel) emailPageModel.getMasterTemplate();
    currentBodyRenderTemplate = emailPageTemplateModel.getHtmlTemplate();
    currentEmailContext =
        this.executeInContext(
            new ImpersonationService.Executor<
                AbstractEmailContext<BusinessProcessModel>, RuntimeException>() {
              @Override
              public AbstractEmailContext<BusinessProcessModel> execute() throws RuntimeException {
                return emailContextFactory.create(
                    businessProcessModel, emailPageModel, currentBodyRenderTemplate);
              }
            });

    final StringWriter body = new StringWriter();
    rendererService.render(currentBodyRenderTemplate, currentEmailContext, body);
    html.setContent(body.toString());
    // label.setValue(emailPageTemplateModel.getHtmlTerendererServicemplate().getTemplateScript());
    VmEmailTemplateData vmData = new VmEmailTemplateData();
    vmData.setBody(emailPageTemplateModel.getHtmlTemplate().getTemplateScript());
    this.sendOutput("selectVmTemplate", vmData);
  }
  @Test
  public void testIfErrorDuringPerformance() {
    // given
    Mockito.when(mockSolrQueryStatisticsAggregator.aggregate()).thenThrow(new RuntimeException());
    solrQueryStatisticsCollectorJob.setSolrQueryStatisticsAggregator(
        mockSolrQueryStatisticsAggregator);

    TestUtils.disableFileAnalyzer("test for an error during job execution");
    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    TestUtils.enableFileAnalyzer();

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.ERROR);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).isEmpty();
  }
  @Override
  public List<ClassificationAttributeUnitModel> findAttributeUnits(
      final ClassificationSystemVersionModel systemVersion) {
    final Map<String, Object> params = new HashMap<String, Object>();
    params.put("code", systemVersion.getPk());

    final String query =
        "SELECT {"
            + Item.PK
            + "} FROM {"
            + CatalogConstants.TC.CLASSIFICATIONATTRIBUTEUNIT
            + "} "
            + "WHERE {"
            + ClassificationAttributeUnit.SYSTEMVERSION
            + "}= ?code ";

    final FlexibleSearchQuery flexibleSearchQuery = new FlexibleSearchQuery(query);
    flexibleSearchQuery.addQueryParameters(params);
    flexibleSearchQuery.setCount(-1);
    flexibleSearchQuery.setStart(0);
    flexibleSearchQuery.setNeedTotal(true);
    final SearchResult<ClassificationAttributeUnitModel> results = search(flexibleSearchQuery);
    return results.getResult();
  }
  /**
   * Finds all delivery cost values for China in CNY for the specified delivery mode
   *
   * @param mode the delivery mode
   * @return all found {@link de.hybris.platform.deliveryzone.model.ZoneDeliveryModeValueModel}s, or
   *     empty list if not found.
   */
  protected Collection<ZoneDeliveryModeValueModel> findDeliveryValues(
      final DeliveryModeModel mode) {
    final StringBuilder strBdr = new StringBuilder();
    strBdr
        .append("SELECT {dmv.")
        .append(ZoneDeliveryModeValueModel.PK)
        .append("} ")
        .append("FROM {")
        .append(ZoneDeliveryModeValueModel._TYPECODE)
        .append(" AS dmv JOIN ")
        .append(ZoneDeliveryModeConstants.Relations.ZONECOUNTRYRELATION)
        .append(" z2cRel ON {dmv.")
        .append(ZoneDeliveryModeValueModel.ZONE)
        .append("} = {z2cRel.")
        .append(Link.SOURCE)
        .append("}}, ")
        .append("{")
        .append(ZoneDeliveryModeModel._TYPECODE)
        .append(" AS zdm}, ")
        .append("{")
        .append(CurrencyModel._TYPECODE)
        .append(" AS cur}, ")
        .append("{")
        .append(CountryModel._TYPECODE)
        .append(" AS c} ")
        .append("WHERE {dmv.")
        .append(ZoneDeliveryModeValueModel.CURRENCY)
        .append("} = {cur.")
        .append(CurrencyModel.PK)
        .append("} ")
        .append("AND {dmv.")
        .append(ZoneDeliveryModeValueModel.DELIVERYMODE)
        .append("} = {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} ")
        .append("AND {z2cRel.")
        .append(Link.TARGET)
        .append("} = {c.")
        .append(CountryModel.PK)
        .append("} ")
        .append("AND {cur.")
        .append(CurrencyModel.ISOCODE)
        .append("} = 'CNY' ")
        .append("AND {c.")
        .append(CountryModel.ISOCODE)
        .append("} = 'CN' ")
        .append("AND {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} = ?mode ");

    final HashMap<String, Object> params = new HashMap<>();
    params.put("mode", mode);

    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(strBdr.toString());
    fQuery.addQueryParameters(params);
    fQuery.setResultClassList(Collections.singletonList(ZoneDeliveryModeValueModel.class));
    final SearchResult<ZoneDeliveryModeValueModel> result =
        getFlexibleSearchService().search(fQuery);
    final Collection<ZoneDeliveryModeValueModel> values = result.getResult();
    return values;
  }
  @Override
  public Collection<ZoneDeliveryModeValueModel> findDeliveryValues(
      final DeliveryModeModel mode, final DistrictModel district) {
    final StringBuilder strBdr = new StringBuilder();
    strBdr
        .append("SELECT {dmv.")
        .append(ZoneDeliveryModeValueModel.PK)
        .append("} ")
        .append("FROM {")
        .append(ZoneDeliveryModeValueModel._TYPECODE)
        .append(" AS dmv}, ")
        .append("{")
        .append(ZoneModel._TYPECODE)
        .append(" AS z}, ")
        .append("{")
        .append(ZoneDeliveryModeModel._TYPECODE)
        .append(" AS zdm}, ")
        .append("{")
        .append(CurrencyModel._TYPECODE)
        .append(" AS cur}, ")
        .append("{")
        .append(DistrictModel._TYPECODE)
        .append(" AS d} ")
        .append("WHERE {dmv.")
        .append(ZoneDeliveryModeValueModel.CURRENCY)
        .append("} = {cur.")
        .append(CurrencyModel.PK)
        .append("} ")
        .append("AND {dmv.")
        .append(ZoneDeliveryModeValueModel.DELIVERYMODE)
        .append("} = {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} ")
        .append("AND {dmv.")
        .append(ZoneDeliveryModeValueModel.ZONE)
        .append("} = {z.")
        .append(ZoneModel.PK)
        .append("} ")
        .append("AND {z.")
        .append(ZoneModel.DISTRICT)
        .append("} = {d.")
        .append(DistrictModel.PK)
        .append("} ")
        .append("AND {cur.")
        .append(CurrencyModel.ISOCODE)
        .append("} = 'CNY' ")
        .append("AND {d.")
        .append(DistrictModel.PK)
        .append("} = ?district ")
        .append("AND {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} = ?mode ")
        .append("AND {z.")
        .append(ZoneModel.REGION)
        .append("} IS NULL ")
        .append("AND {z.")
        .append(ZoneModel.CITY)
        .append("} IS NULL");

    final HashMap<String, Object> params = new HashMap<>();
    params.put("mode", mode);
    params.put("district", district);

    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(strBdr.toString());
    fQuery.addQueryParameters(params);
    fQuery.setResultClassList(Collections.singletonList(ZoneDeliveryModeValueModel.class));
    final SearchResult<ZoneDeliveryModeValueModel> result =
        getFlexibleSearchService().search(fQuery);
    final Collection<ZoneDeliveryModeValueModel> vs1 = result.getResult();

    if (CollectionUtils.isNotEmpty(vs1)) {
      return vs1;
    } else {
      final CityModel city = district.getCity();
      final Collection<ZoneDeliveryModeValueModel> vs2 = findDeliveryValues(mode, city);

      if (CollectionUtils.isNotEmpty(vs2)) {
        return vs2;
      } else {
        final RegionModel region = city.getRegion();
        final Collection<ZoneDeliveryModeValueModel> vs3 = findDeliveryValues(mode, region);

        if (CollectionUtils.isNotEmpty(vs3)) {
          return vs3;
        } else {
          return findDeliveryValues(mode);
        }
      }
    }
  }
Пример #17
0
 /*
  * (non-Javadoc)
  *
  * @see org.training.dao.TrainingDao#getAllCourses()
  */
 @Override
 public List<CourseModel> getAllCourses() {
   final SearchResult<CourseModel> result = flexibleSearchService.search(ALL_COURSES);
   return result.getResult();
 }
Пример #18
0
 /*
  * (non-Javadoc)
  *
  * @see org.training.dao.TrainingDao#getAllTraining()
  */
 @Override
 public List<TrainingModel> getAllTraining() {
   final SearchResult<TrainingModel> result = flexibleSearchService.search(ALL_TRAININGS);
   return result.getResult();
 }
  /**
   * Finds all delivery cost values for a given city in CNY for the specified delivery mode
   *
   * @param mode the delivery mode
   * @param city the city
   * @return all found {@link de.hybris.platform.deliveryzone.model.ZoneDeliveryModeValueModel}s, or
   *     empty list if not found.
   */
  protected Collection<ZoneDeliveryModeValueModel> findDeliveryValues(
      final DeliveryModeModel mode, final CityModel city) {
    final StringBuilder strBdr = new StringBuilder();
    strBdr
        .append("SELECT {dmv.")
        .append(ZoneDeliveryModeValueModel.PK)
        .append("} ")
        .append("FROM {")
        .append(ZoneDeliveryModeValueModel._TYPECODE)
        .append(" AS dmv}, ")
        .append("{")
        .append(ZoneModel._TYPECODE)
        .append(" AS z}, ")
        .append("{")
        .append(ZoneDeliveryModeModel._TYPECODE)
        .append(" AS zdm}, ")
        .append("{")
        .append(CurrencyModel._TYPECODE)
        .append(" AS cur}, ")
        .append("{")
        .append(CityModel._TYPECODE)
        .append(" AS c} ")
        .append("WHERE {dmv.")
        .append(ZoneDeliveryModeValueModel.CURRENCY)
        .append("} = {cur.")
        .append(CurrencyModel.PK)
        .append("} ")
        .append("AND {dmv.")
        .append(ZoneDeliveryModeValueModel.DELIVERYMODE)
        .append("} = {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} ")
        .append("AND {dmv.")
        .append(ZoneDeliveryModeValueModel.ZONE)
        .append("} = {z.")
        .append(ZoneModel.PK)
        .append("} ")
        .append("AND {z.")
        .append(ZoneModel.CITY)
        .append("} = {c.")
        .append(CityModel.PK)
        .append("} ")
        .append("AND {cur.")
        .append(CurrencyModel.ISOCODE)
        .append("} = 'CNY' ")
        .append("AND {c.")
        .append(CityModel.PK)
        .append("} = ?city ")
        .append("AND {zdm.")
        .append(ZoneDeliveryModeModel.PK)
        .append("} = ?mode ")
        .append("AND {z.")
        .append(ZoneModel.REGION)
        .append("} IS NULL ")
        .append("AND {z.")
        .append(ZoneModel.DISTRICT)
        .append("} IS NULL");

    final HashMap<String, Object> params = new HashMap<>();
    params.put("mode", mode);
    params.put("city", city);

    final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(strBdr.toString());
    fQuery.addQueryParameters(params);
    fQuery.setResultClassList(Collections.singletonList(ZoneDeliveryModeValueModel.class));
    final SearchResult<ZoneDeliveryModeValueModel> result =
        getFlexibleSearchService().search(fQuery);
    final Collection<ZoneDeliveryModeValueModel> values = result.getResult();
    return values;
  }