Search in sources :

Example 1 with IndexField

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

the class IndexFieldDaoImpl method readIndexFieldByAbbreviationAndEntityType.

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

Example 2 with IndexField

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

the class IndexFieldDaoImpl method readFieldsByEntityType.

@Override
public List<IndexField> readFieldsByEntityType(FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
    Root<IndexFieldImpl> root = criteria.from(IndexFieldImpl.class);
    criteria.select(root);
    criteria.where(root.get("field").get("entityType").as(String.class).in(entityType.getAllLookupTypes()));
    TypedQuery<IndexField> 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) IndexFieldImpl(org.broadleafcommerce.core.search.domain.IndexFieldImpl) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Example 3 with IndexField

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

the class IndexFieldCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        IndexField adminInstance = (IndexField) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        return getEntity(persistencePackage, dynamicEntityDao, helper, entity, adminProperties, adminInstance);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform update for entity: " + IndexField.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 4 with IndexField

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

the class SolrHelperServiceImpl method getSearchableIndexFields.

@Override
public List<IndexField> getSearchableIndexFields() {
    List<IndexField> fields = new ArrayList<>();
    ExtensionResultStatusType status = searchExtensionManager.getProxy().getSearchableIndexFields(fields);
    if (ExtensionResultStatusType.NOT_HANDLED.equals(status)) {
        if (useSku) {
            fields = indexFieldDao.readSearchableFieldsByEntityType(FieldEntity.SKU);
        } else {
            fields = indexFieldDao.readSearchableFieldsByEntityType(FieldEntity.PRODUCT);
        }
    }
    return fields;
}
Also used : ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Example 5 with IndexField

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

the class IndexFieldCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        IndexField adminInstance = (IndexField) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
        return getEntity(persistencePackage, dynamicEntityDao, helper, entity, adminProperties, adminInstance);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform add for entity: " + IndexField.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Aggregations

IndexField (org.broadleafcommerce.core.search.domain.IndexField)10 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 ServiceException (org.broadleafcommerce.common.exception.ServiceException)4 IndexFieldImpl (org.broadleafcommerce.core.search.domain.IndexFieldImpl)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoResultException (javax.persistence.NoResultException)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Locale (org.broadleafcommerce.common.locale.domain.Locale)1 StopWatch (org.broadleafcommerce.common.util.StopWatch)1 Indexable (org.broadleafcommerce.core.catalog.domain.Indexable)1 FieldEntity (org.broadleafcommerce.core.search.domain.FieldEntity)1 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)1 FieldType (org.broadleafcommerce.core.search.domain.solr.FieldType)1