July 11, 2012

[Liferay] - Dynamic Query with projections with expando


public int getActiveFileEntryCount(long scopeGroupId, long folderId, long companyId,int status) throws Exception{
int activeFoldersCount =  DLFolderServiceUtil.getFileEntriesAndFileShortcutsCount(scopeGroupId, folderId, -1);
if(activeFoldersCount>0){
long classNameId = ClassNameLocalServiceUtil.getClassNameId(DLFileEntry.class.getName());
DynamicQuery folderFileEntriesQuery = DynamicQueryFactoryUtil.forClass( DLFileEntryImpl.class, "fileEntries",PortalClassLoaderUtil.getClassLoader());
folderFileEntriesQuery.setProjection(ProjectionFactoryUtil.property("fileEntries.fileEntryId"));
folderFileEntriesQuery.add(RestrictionsFactoryUtil.eq("fileEntries.folderId", folderId));
folderFileEntriesQuery.add(PropertyFactoryUtil.forName("fileEntries.companyId").eqProperty("fileVersion.companyId"));
folderFileEntriesQuery.add(PropertyFactoryUtil.forName("fileEntries.groupId").eqProperty("fileVersion.groupId"));
DynamicQuery fileEntryVersionQuery = DynamicQueryFactoryUtil.forClass( DLFileVersionModelImpl.class, "fileVersion",PortalClassLoaderUtil.getClassLoader());
fileEntryVersionQuery.setProjection(ProjectionFactoryUtil.property("fileVersion.fileVersionId"));
fileEntryVersionQuery.add(RestrictionsFactoryUtil.eq("fileVersion.companyId", companyId));
fileEntryVersionQuery.add(RestrictionsFactoryUtil.eq("fileVersion.groupId", scopeGroupId));
fileEntryVersionQuery.add(PropertyFactoryUtil.forName("fileVersion.fileEntryId").in(folderFileEntriesQuery));

List<Long> expfiles = DLFileVersionLocalServiceUtil.dynamicQuery(fileEntryVersionQuery,0,Integer.MAX_VALUE);
System.out.println(" -----------classNameId---------- "+classNameId);
System.out.println(" -----------companyId---------- "+companyId);
System.out.println(" -----------folderId---------- "+folderId);
System.out.println(" -----------Total Documents---------- "+expfiles.size()+ "-- Data --"+ expfiles);
if(expfiles.size()>0){

DynamicQuery expiredfolderQuery = DynamicQueryFactoryUtil.forClass( ExpandoValueModelImpl.class, "expandovalue",PortalClassLoaderUtil.getClassLoader());
expiredfolderQuery.add(RestrictionsFactoryUtil.eq("expandovalue.companyId", companyId));
expiredfolderQuery.add(RestrictionsFactoryUtil.eq("expandovalue.classNameId", classNameId));
expiredfolderQuery.add(RestrictionsFactoryUtil.in("classPK", expfiles.toArray()));
expiredfolderQuery.add(RestrictionsFactoryUtil.eq("data","true"));

int expiredDocumentCount = (int)ExpandoValueLocalServiceUtil.dynamicQueryCount(expiredfolderQuery);
System.out.println(" -----------expiredFileEntries Count---------- "+expiredDocumentCount);
activeFoldersCount=activeFoldersCount-expiredDocumentCount;
}
}
return activeFoldersCount;
}

2 comments:

  1. Salut, il n'y a que dans l'ext que c'est possible de faire cela ou dans une portlet également ?

    ReplyDelete