Search in sources :

Example 1 with IndexFieldTypeImpl

use of org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldDaoImpl method getIndexFieldTypesByAbbreviationAndEntityType.

@Override
public List<IndexFieldType> getIndexFieldTypesByAbbreviationAndEntityType(String abbreviation, FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexFieldType> criteria = builder.createQuery(IndexFieldType.class);
    Root<IndexFieldTypeImpl> root = criteria.from(IndexFieldTypeImpl.class);
    criteria.select(root);
    if (entityType == null) {
        criteria.where(builder.equal(root.get("indexField").get("field").get("abbreviation").as(String.class), abbreviation));
    } else {
        criteria.where(builder.and(builder.equal(root.get("indexField").get("field").get("abbreviation").as(String.class), abbreviation), builder.equal(root.get("indexField").get("field").get("entityType").as(String.class), entityType.getType())));
    }
    TypedQuery<IndexFieldType> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl)

Example 2 with IndexFieldTypeImpl

use of org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldCustomPersistenceHandler method getEntity.

protected Entity getEntity(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity, Map<String, FieldMetadata> adminProperties, IndexField adminInstance) throws ServiceException {
    adminInstance = (IndexField) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
    adminInstance = dynamicEntityDao.merge(adminInstance);
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (extensionManager != null) {
        result = extensionManager.getProxy().addtoSearchableFields(persistencePackage, adminInstance);
    }
    if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        // If there is no searchable field types then we need to add a default as String
        if (CollectionUtils.isEmpty(adminInstance.getFieldTypes())) {
            IndexFieldType indexFieldType = new IndexFieldTypeImpl();
            indexFieldType.setFieldType(FieldType.TEXT);
            indexFieldType.setIndexField(adminInstance);
            adminInstance.getFieldTypes().add(indexFieldType);
            adminInstance = dynamicEntityDao.merge(adminInstance);
        }
    }
    Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
    return adminEntity;
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) Entity(org.broadleafcommerce.openadmin.dto.Entity) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 3 with IndexFieldTypeImpl

use of org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldDaoImpl method getIndexFieldTypes.

@Override
public List<IndexFieldType> getIndexFieldTypes(FieldType facetFieldType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexFieldType> criteria = builder.createQuery(IndexFieldType.class);
    Root<IndexFieldTypeImpl> root = criteria.from(IndexFieldTypeImpl.class);
    criteria.select(root);
    criteria.where(builder.equal(root.get("fieldType").as(String.class), facetFieldType.getType()));
    TypedQuery<IndexFieldType> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl)

Example 4 with IndexFieldTypeImpl

use of org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldDaoImpl method getIndexFieldTypesByAbbreviationOrPropertyName.

@Override
public List<IndexFieldType> getIndexFieldTypesByAbbreviationOrPropertyName(String name) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexFieldType> criteria = builder.createQuery(IndexFieldType.class);
    Root<IndexFieldTypeImpl> root = criteria.from(IndexFieldTypeImpl.class);
    criteria.select(root);
    List<Predicate> restrictions = new ArrayList<>();
    restrictions.add(builder.or(builder.equal(root.get("indexField").get("field").get("abbreviation").as(String.class), name), builder.equal(root.get("indexField").get("field").get("propertyName").as(String.class), name)));
    restrictions.add(builder.or(builder.isNull(root.get("archiveStatus").get("archived")), builder.equal(root.get("archiveStatus").get("archived"), 'N')));
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<IndexFieldType> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Aggregations

IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 IndexFieldTypeImpl (org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ArrayList (java.util.ArrayList)1 Predicate (javax.persistence.criteria.Predicate)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1