com.liferay.portal.search.IndexableAdvice Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.search;
import com.liferay.portal.kernel.aop.AopMethodInvocation;
import com.liferay.portal.kernel.aop.ChainableMethodAdvice;
import com.liferay.portal.kernel.dependency.manager.DependencyManagerSyncUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.BaseModel;
import com.liferay.portal.kernel.search.IndexWriterHelperUtil;
import com.liferay.portal.kernel.search.Indexable;
import com.liferay.portal.kernel.search.IndexableType;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.search.SearchException;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.service.ServiceContext;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;
/**
* @author Shuyang Zhou
*/
public class IndexableAdvice extends ChainableMethodAdvice {
@Override
public Object createMethodContext(
Class> targetClass, Method method,
Map, Annotation> annotations) {
Indexable indexable = (Indexable)annotations.get(Indexable.class);
if (indexable == null) {
return null;
}
Class> returnType = method.getReturnType();
if (!BaseModel.class.isAssignableFrom(returnType)) {
if (_log.isWarnEnabled()) {
_log.warn(method + " does not have a valid return type");
}
return null;
}
return new IndexableContext(
returnType.getName(), indexable.type(),
_getServiceContextParameterIndex(method));
}
@Override
protected void afterReturning(
AopMethodInvocation aopMethodInvocation, Object[] arguments,
Object result)
throws Throwable {
if (result == null) {
return;
}
if (CompanyThreadLocal.isDeleteInProcess() ||
IndexWriterHelperUtil.isIndexReadOnly()) {
if (_log.isDebugEnabled()) {
if (CompanyThreadLocal.isDeleteInProcess()) {
_log.debug(
"Skip indexing because company delete is in process");
}
else if (IndexWriterHelperUtil.isIndexReadOnly()) {
_log.debug("Skip indexing because the index is read only");
}
}
return;
}
IndexableContext indexableContext =
aopMethodInvocation.getAdviceMethodContext();
String name = indexableContext._name;
Indexer © 2015 - 2025 Weber Informatics LLC | Privacy Policy