001
014
015 package com.liferay.portal.verify;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.search.SearchEngineUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.NotificationThreadLocal;
022 import com.liferay.portal.kernel.util.PropsKeys;
023 import com.liferay.portal.kernel.workflow.WorkflowThreadLocal;
024 import com.liferay.portal.staging.StagingAdvicesThreadLocal;
025 import com.liferay.portal.util.PropsUtil;
026 import com.liferay.portal.util.PropsValues;
027
028
033 public class VerifyProcessUtil {
034
035 public static boolean verifyProcess(
036 boolean ranUpgradeProcess, boolean verified)
037 throws VerifyException {
038
039 int verifyFrequency = GetterUtil.getInteger(
040 PropsUtil.get(PropsKeys.VERIFY_FREQUENCY));
041
042 if ((verifyFrequency == VerifyProcess.ALWAYS) ||
043 ((verifyFrequency == VerifyProcess.ONCE) && !verified) ||
044 ranUpgradeProcess) {
045
046 return _verifyProcess(ranUpgradeProcess);
047 }
048
049 return false;
050 }
051
052 private static boolean _verifyProcess(boolean ranUpgradeProcess)
053 throws VerifyException {
054
055 boolean ranVerifyProcess = false;
056
057 if (ranUpgradeProcess && PropsValues.INDEX_ON_UPGRADE) {
058 PropsUtil.set(PropsKeys.INDEX_ON_STARTUP, Boolean.TRUE.toString());
059
060 PropsValues.INDEX_ON_STARTUP = true;
061 }
062
063 boolean tempIndexReadOnly = SearchEngineUtil.isIndexReadOnly();
064
065 SearchEngineUtil.setIndexReadOnly(true);
066
067 NotificationThreadLocal.setEnabled(false);
068 StagingAdvicesThreadLocal.setEnabled(false);
069 WorkflowThreadLocal.setEnabled(false);
070
071 try {
072 String[] verifyProcessClassNames = PropsUtil.getArray(
073 PropsKeys.VERIFY_PROCESSES);
074
075 for (String verifyProcessClassName : verifyProcessClassNames) {
076 boolean tempRanVerifyProcess = _verifyProcess(
077 verifyProcessClassName);
078
079 if (tempRanVerifyProcess) {
080 ranVerifyProcess = true;
081 }
082 }
083 }
084 finally {
085 SearchEngineUtil.setIndexReadOnly(tempIndexReadOnly);
086
087 NotificationThreadLocal.setEnabled(true);
088 StagingAdvicesThreadLocal.setEnabled(true);
089 WorkflowThreadLocal.setEnabled(true);
090 }
091
092 return ranVerifyProcess;
093 }
094
095 private static boolean _verifyProcess(String verifyProcessClassName)
096 throws VerifyException {
097
098 if (_log.isDebugEnabled()) {
099 _log.debug("Initializing verification " + verifyProcessClassName);
100 }
101
102 try {
103 VerifyProcess verifyProcess = (VerifyProcess)Class.forName(
104 verifyProcessClassName).newInstance();
105
106 if (_log.isDebugEnabled()) {
107 _log.debug("Running verification " + verifyProcessClassName);
108 }
109
110 verifyProcess.verify();
111
112 if (_log.isDebugEnabled()) {
113 _log.debug("Finished verification " + verifyProcessClassName);
114 }
115
116 return true;
117 }
118 catch (ClassNotFoundException cnfe) {
119 _log.error(verifyProcessClassName + " cannot be found");
120 }
121 catch (IllegalAccessException iae) {
122 _log.error(verifyProcessClassName + " cannot be accessed");
123 }
124 catch (InstantiationException ie) {
125 _log.error(verifyProcessClassName + " cannot be initiated");
126 }
127
128 return false;
129 }
130
131 private static Log _log = LogFactoryUtil.getLog(VerifyProcessUtil.class);
132
133 }