--- /dev/null
+package com.pentila.entSavoie.cartable.service.persistence;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
+import com.liferay.portal.kernel.dao.orm.FinderPath;
+import com.liferay.portal.kernel.dao.orm.QueryPos;
+import com.liferay.portal.kernel.dao.orm.SQLQuery;
+import com.liferay.portal.kernel.dao.orm.Session;
+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.service.persistence.impl.BasePersistenceImpl;
+import com.liferay.util.dao.orm.CustomSQLUtil;
+import com.pentila.entSavoie.cartable.model.CasierEntry;
+import com.pentila.entSavoie.cartable.model.impl.CasierEntryImpl;
+import com.pentila.entSavoie.cartable.model.impl.CasierEntryModelImpl;
+import com.pentila.entSavoie.casier.Constants;
+
+public class CasierEntryFinderImpl extends BasePersistenceImpl<CasierEntry> implements CasierEntryFinder {
+
+ private static Log logger = LogFactoryUtil.getLog(CasierEntryFinderImpl .class);
+
+ public static final String FINDER_CLASS_NAME_ENTITY = CasierEntryImpl.class.getName();
+ public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY + ".List2";
+
+ public static String GET_GROUP_SPACE = "com.pentila.entSavoie.cartable.service.persistence.CasierEntryFinderImpl.getGroupSpace";
+ public static String QUERY_GET_ROOT_CARTABLE_FOLDER = "getCartableRootFolder";
+ public static String QUERY_GET_HIDDEN_CASIER_ENTRY = "getHiddenCasierEntry";
+
+ public static final FinderPath FINDER_PATH_GET_GROUP_SPACE = new FinderPath(
+ CasierEntryModelImpl.ENTITY_CACHE_ENABLED,
+ CasierEntryModelImpl.FINDER_CACHE_ENABLED,
+ Long.class,
+ FINDER_CLASS_NAME_LIST,
+ GET_GROUP_SPACE,
+ new String[] { Long.class.getName(), String.class.getName() });
+
+ public Long getGroupSpace(long groupId, String fileType) throws SystemException {
+ Object[] finderArgs = new Object[] {
+ new Long(groupId),
+ fileType
+ };
+
+ BigDecimal sumSizeBD = null;
+ Long sumSize = (Long) FinderCacheUtil.getResult(FINDER_PATH_GET_GROUP_SPACE,
+ finderArgs, this);
+
+ if(sumSize == null){
+ Session session = null;
+
+ try {
+ session = openSession();
+
+ String sql = CustomSQLUtil.get(GET_GROUP_SPACE);
+ SQLQuery query = session.createSQLQuery(sql);
+
+ QueryPos qPos = QueryPos.getInstance(query);
+ qPos.add(groupId);
+ qPos.add(fileType);
+
+ sumSizeBD = (BigDecimal) query.uniqueResult();
+ }catch (Exception e) {
+ } finally {
+ if (sumSizeBD == null) {
+ sumSize = new Long(0);
+ }
+ else {
+ sumSize = sumSizeBD.longValue();
+ }
+
+
+ FinderCacheUtil.putResult(FINDER_PATH_GET_GROUP_SPACE,
+ finderArgs, sumSize);
+
+ closeSession(session);
+ }
+ }
+
+ return sumSize;
+ }
+
+
+ /**
+ * Get the root folder for a user or a group
+ * @param pUserId long which represent a userId, In case you need the a user cartable it's the user Id, in case you search a group cartable, it's the userid of creator of this group
+ * @param pGroupId long which represent the grouope id, for a user it's the groupe attach to this user, for a groupe it's his id
+ * @param pIsUser boolean true if the method is used for a user, false otherwise
+ * @return long, the folder if of the cartable root
+ */
+ public long getRootFolderCartable(long pUserId, long pGroupId, boolean pIsUser) {
+ Session session = null;
+ long folderId = Long.valueOf(0);
+ try {
+ session = openSession();
+ String sqlCalculateSendingBox = CustomSQLUtil
+ .get(CasierEntryFinderImpl.QUERY_GET_ROOT_CARTABLE_FOLDER);
+ SQLQuery query = session.createSQLQuery(sqlCalculateSendingBox);
+ QueryPos qPos = QueryPos.getInstance(query);
+ qPos.add(pUserId);
+ qPos.add(pGroupId);
+ if(pIsUser){
+ qPos.add(Constants.SCHOOL_BAG_FOLDER_NAME);
+ }
+ else{
+ qPos.add(Constants.GROUP_FOLDER_NAME);
+ }
+ // get result and if it's is not empty convert it as long
+ Object queryResult = query.uniqueResult();
+ if (queryResult != null) {
+ folderId += ((BigInteger) queryResult).longValue();
+ }
+ } catch (Exception e) {
+ folderId = Long.valueOf(0);
+ logger.error(e);
+ } finally {
+ closeSession(session);
+ }
+ return folderId;
+ }
+
+ /**
+ * Get the hidden entries in table cartable_casierentry
+ * @return long, the folder if of the cartable root
+ */
+ public List<CasierEntry> getHiddenCasierEntry() {
+ Session session = null;
+ List<CasierEntry> casierEntries = new ArrayList<CasierEntry>();
+ try {
+ session = openSession();
+ String sqlCalculateSendingBox = CustomSQLUtil
+ .get(CasierEntryFinderImpl.QUERY_GET_HIDDEN_CASIER_ENTRY);
+ SQLQuery query = session.createSQLQuery(sqlCalculateSendingBox);
+
+ casierEntries = new ArrayList<CasierEntry>();
+
+ query.addEntity("ce", CasierEntryImpl.class);
+
+ casierEntries = (List<CasierEntry>) query.list();
+ } catch (Exception e) {
+ casierEntries = null;
+ logger.error(e);
+ } finally {
+ closeSession(session);
+ }
+ return casierEntries;
+ }
+
+}