Skip to content

Commit

Permalink
Merge pull request #1266 from khoahp/rc-1.8-issues-fix
Browse files Browse the repository at this point in the history
Rc 1.8 issues fix
  • Loading branch information
khoahp authored Apr 4, 2017
2 parents 30d4964 + 5188047 commit 668b6cc
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,14 @@ public ServiceProcess getServiceProcess(long groupId, String processNo)
return serviceProcessPersistence.findByG_P(groupId, processNo);
}

public List<ServiceProcess> searchServiceProcess(long groupId,String keyword,int start,int end){

return serviceProcessFinder.searchServiceProcess(groupId, keyword, start, end);
}

public int countServiceProcess(long groupId,String keyword){

return serviceProcessFinder.countServiceProcess(groupId, keyword);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
*/
package org.opencps.processmgt.service.persistence;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.opencps.dossiermgt.model.ServiceConfig;
import org.opencps.processmgt.model.ServiceProcess;
import org.opencps.processmgt.model.impl.ServiceProcessImpl;
import org.opencps.processmgt.service.ServiceProcessLocalServiceUtil;
import org.opencps.servicemgt.model.ServiceInfo;

import com.liferay.portal.kernel.dao.orm.Criterion;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.dao.orm.Type;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
Expand All @@ -32,13 +43,13 @@
/**
* @author khoavd
*/
public class ServiceProcessFinderImpl
extends BasePersistenceImpl<ServiceProcess> implements ServiceProcessFinder {
public class ServiceProcessFinderImpl extends
BasePersistenceImpl<ServiceProcess> implements ServiceProcessFinder {

public final static String SQL_PROCESS_FINDER =
ServiceProcessFinder.class.getName() + ".searchProcess";
public final static String SQL_PROCESS_COUNT =
ServiceProcessFinder.class.getName() + ".countProcess";
public final static String SQL_PROCESS_FINDER = ServiceProcessFinder.class
.getName() + ".searchProcess";
public final static String SQL_PROCESS_COUNT = ServiceProcessFinder.class
.getName() + ".countProcess";

/**
* Search Process with keywords
Expand All @@ -49,16 +60,15 @@ public class ServiceProcessFinderImpl
* @param end
* @return
*/
public List<ServiceProcess> searchProcess(
long groupId, String keywords, int start, int end) {
public List<ServiceProcess> searchProcess(long groupId, String keywords,
int start, int end) {

String[] names = null;
boolean andOperator = false;

if (Validator.isNotNull(keywords)) {
names = CustomSQLUtil.keywords(keywords);
}
else {
} else {
andOperator = true;
}

Expand All @@ -80,8 +90,7 @@ public int countProcess(long groupId, String keywords) {

if (Validator.isNotNull(keywords)) {
names = CustomSQLUtil.keywords(keywords);
}
else {
} else {
andOperator = true;
}

Expand All @@ -101,15 +110,13 @@ private List<ServiceProcess> _searchProcess(

String sql = CustomSQLUtil.get(SQL_PROCESS_FINDER);

sql =
CustomSQLUtil.replaceKeywords(
sql, "lower(opencps_serviceprocess.processName)",
StringPool.LIKE, true, keywords);
sql = CustomSQLUtil.replaceKeywords(sql,
"lower(opencps_serviceprocess.processName)",
StringPool.LIKE, true, keywords);

sql =
CustomSQLUtil.replaceKeywords(
sql, "lower(opencps_serviceprocess.processNo)",
StringPool.LIKE, true, keywords);
sql = CustomSQLUtil.replaceKeywords(sql,
"lower(opencps_serviceprocess.processNo)", StringPool.LIKE,
true, keywords);

sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

Expand All @@ -126,27 +133,24 @@ private List<ServiceProcess> _searchProcess(
qPos.add(keywords, 2);
qPos.add(keywords, 2);

return (List<ServiceProcess>) QueryUtil.list(
q, getDialect(), start, end);
}
catch (Exception e) {
return (List<ServiceProcess>) QueryUtil.list(q, getDialect(),
start, end);
} catch (Exception e) {
try {
throw new SystemException(e);
}
catch (SystemException se) {
} catch (SystemException se) {
se.printStackTrace();
}
}
finally {
} finally {
closeSession(session);
}

return null;

}

private int _countProcess(
long groupId, boolean andOperator, String[] keywords) {
private int _countProcess(long groupId, boolean andOperator,
String[] keywords) {

keywords = CustomSQLUtil.keywords(keywords);

Expand All @@ -155,15 +159,13 @@ private int _countProcess(
session = openSession();

String sql = CustomSQLUtil.get(SQL_PROCESS_COUNT);
sql =
CustomSQLUtil.replaceKeywords(
sql, "lower(opencps_serviceprocess.processName)",
StringPool.LIKE, true, keywords);
sql = CustomSQLUtil.replaceKeywords(sql,
"lower(opencps_serviceprocess.processName)",
StringPool.LIKE, true, keywords);

sql =
CustomSQLUtil.replaceKeywords(
sql, "lower(opencps_serviceprocess.processNo)",
StringPool.LIKE, true, keywords);
sql = CustomSQLUtil.replaceKeywords(sql,
"lower(opencps_serviceprocess.processNo)", StringPool.LIKE,
true, keywords);

sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

Expand All @@ -189,20 +191,187 @@ private int _countProcess(
}

return 0;
}
catch (Exception e) {
} catch (Exception e) {
try {
throw new SystemException(e);
}
catch (SystemException se) {
} catch (SystemException se) {
se.printStackTrace();
}
}
finally {
} finally {
closeSession(session);
}

return 0;

}

public List<ServiceProcess> searchServiceProcess(long groupId,
String keyword, int start, int end) {


/*
* SELECT * FROM opencps_serviceprocess as A
*
* WHERE A.serviceProcessId IN (
*
* SELECT B.serviceProcessId FROM opencps_service_config as B
*
* WHERE B.serviceInfoId in(
*
* SELECT serviceinfoId FROM opencps_serviceinfo WHERE serviceNo LIKE'%%'
* OR serviceName LIKE '%%'
* )
* )
* OR processNo LIKE '%%' OR
* processName LIKE '%%'
*
*/

try {


keyword = StringPool.PERCENT + keyword + StringPool.PERCENT;

// child query serviceInfo
DynamicQuery serviceInfoQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceInfo.class);

Criterion serviceInfocriterion = null;

serviceInfocriterion = PropertyFactoryUtil.forName("serviceNo")
.like(keyword);
serviceInfocriterion = RestrictionsFactoryUtil.or(
serviceInfocriterion,
PropertyFactoryUtil.forName("serviceName").like(keyword));

serviceInfoQuery.add(serviceInfocriterion);
serviceInfoQuery.setProjection(PropertyFactoryUtil
.forName("serviceinfoId"));

// parent query serviceConfig

DynamicQuery serviceConfigQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceConfig.class);
serviceConfigQuery.setProjection(PropertyFactoryUtil
.forName("serviceProcessId"));
serviceConfigQuery.add(PropertyFactoryUtil.forName("serviceInfoId")
.in(serviceInfoQuery));

// root query serviceProcess

DynamicQuery serviceProcessQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceProcess.class);

Criterion serviceProcessCriterion = null;

serviceProcessCriterion = PropertyFactoryUtil.forName(
"serviceProcessId").in(serviceConfigQuery);
serviceProcessCriterion = RestrictionsFactoryUtil.or(
serviceProcessCriterion,
PropertyFactoryUtil.forName("processNo").like(keyword));
serviceProcessCriterion = RestrictionsFactoryUtil.or(
serviceProcessCriterion,
PropertyFactoryUtil.forName("processName").like(keyword));

serviceProcessQuery.add(serviceProcessCriterion);

List<ServiceProcess> list = ServiceProcessLocalServiceUtil
.dynamicQuery(serviceProcessQuery,start,end);


return list;

} catch (Exception e) {
_log.error(e);
}

return new ArrayList<ServiceProcess>();
}

public int countServiceProcess(long groupId,
String keyword) {


/*
* SELECT COUNT(*) FROM opencps_serviceprocess as A
*
* WHERE A.serviceProcessId IN (
*
* SELECT B.serviceProcessId FROM opencps_service_config as B
*
* WHERE B.serviceInfoId in(
*
* SELECT serviceinfoId FROM opencps_serviceinfo WHERE serviceNo LIKE'%%'
* OR serviceName LIKE '%%'
* )
* )
* OR processNo LIKE '%%' OR
* processName LIKE '%%'
*
*/

try {


keyword = StringPool.PERCENT + keyword + StringPool.PERCENT;

// child query serviceInfo
DynamicQuery serviceInfoQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceInfo.class);

Criterion serviceInfocriterion = null;

serviceInfocriterion = PropertyFactoryUtil.forName("serviceNo")
.like(keyword);
serviceInfocriterion = RestrictionsFactoryUtil.or(
serviceInfocriterion,
PropertyFactoryUtil.forName("serviceName").like(keyword));

serviceInfoQuery.add(serviceInfocriterion);
serviceInfoQuery.setProjection(PropertyFactoryUtil
.forName("serviceinfoId"));

// parent query serviceConfig

DynamicQuery serviceConfigQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceConfig.class);
serviceConfigQuery.setProjection(PropertyFactoryUtil
.forName("serviceProcessId"));
serviceConfigQuery.add(PropertyFactoryUtil.forName("serviceInfoId")
.in(serviceInfoQuery));

// root query serviceProcess

DynamicQuery serviceProcessQuery = DynamicQueryFactoryUtil
.getDynamicQueryFactory().forClass(ServiceProcess.class);

Criterion serviceProcessCriterion = null;

serviceProcessCriterion = PropertyFactoryUtil.forName(
"serviceProcessId").in(serviceConfigQuery);
serviceProcessCriterion = RestrictionsFactoryUtil.or(
serviceProcessCriterion,
PropertyFactoryUtil.forName("processNo").like(keyword));
serviceProcessCriterion = RestrictionsFactoryUtil.or(
serviceProcessCriterion,
PropertyFactoryUtil.forName("processName").like(keyword));

serviceProcessQuery.add(serviceProcessCriterion);

String countString = String.valueOf(ServiceProcessLocalServiceUtil
.dynamicQueryCount(serviceProcessQuery));

int count = Integer.valueOf(countString);

return count;

} catch (Exception e) {
_log.error(e);
}

return 0;
}

private Log _log = LogFactoryUtil.getLog(ServiceProcessFinderImpl.class
.getName());
}
Loading

0 comments on commit 668b6cc

Please sign in to comment.