{
logger.info("contentTypeDefinitionNamesString:" + contentTypeDefinitionNamesString);
String[] contentTypeDefinitionNames = contentTypeDefinitionNamesString.split(",");
for(String contentTypeDefinitionName : contentTypeDefinitionNames)
{
ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName(contentTypeDefinitionName, getDatabase());
if(contentTypeDefinitionVO != null)
{
logger.info("Do not throw page cache on this if it's not a content of type:" + contentTypeDefinitionVO.getName());
if(deliveryContext != null)
deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionVO.getId());
}
}
}
catch (Exception e)
{
logger.error("Could not set correct selectiveCacheUpdateNonApplicable-type: " + e.getMessage(), e);
}
}
else
{
if(deliveryContext != null)
deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable");
}
if(cacheResult == true && toDate != null)
{
Calendar toDateCalendar = Calendar.getInstance();
toDateCalendar.setTime(toDate);
toDateCalendar.set(Calendar.MINUTE, 30);
toDateCalendar.set(Calendar.SECOND, 30);
toDateCalendar.set(Calendar.MILLISECOND, 0);
toDate = toDateCalendar.getTime();
}
if(cacheResult == true && fromDate != null)
{
Calendar fromDateCalendar = Calendar.getInstance();
fromDateCalendar.setTime(fromDate);
fromDateCalendar.set(Calendar.MINUTE, 30);
fromDateCalendar.set(Calendar.SECOND, 30);
fromDateCalendar.set(Calendar.MILLISECOND, 0);
fromDate = fromDateCalendar.getTime();
}
logger.info("toDate:" + toDate);
logger.info("fromDate:" + fromDate);
if((freeText != null && !freeText.equals("")) || (freeTextAttributeNames != null && freeTextAttributeNames.size() > 0) || expireFromDate != null || expireToDate != null || (versionModifier != null && !versionModifier.equals("")) || !deliveryContext.getOperatingMode().equals(CmsPropertyHandler.getOperatingMode()))
cacheResult = false;
logger.info("cacheResult:" + cacheResult);
//TODO - add cache here
if(cacheName == null || cacheName.equals(""))
cacheName = "matchingContentsCache";
Integer localLanguageId = this.getLanguageId();
if(languageId != null)
localLanguageId = languageId;
StringBuffer repositoryIdString = new StringBuffer();
if(repositoryIdList != null)
{
Iterator repositoryIdListIterator = repositoryIdList.iterator();
while(repositoryIdListIterator.hasNext())
repositoryIdString.append("," + repositoryIdListIterator.next());
}
StringBuffer attributeNamesString = new StringBuffer();
if(freeTextAttributeNames != null)
{
Iterator freeTextAttributeNamesIterator = freeTextAttributeNames.iterator();
while(freeTextAttributeNamesIterator.hasNext())
attributeNamesString.append("," + freeTextAttributeNamesIterator.next());
}
String userName = this.getPrincipal().getName();
if(!CmsPropertyHandler.getOperatingMode().equals("3") || validateAccessRightsAsAnonymous)
userName = CmsPropertyHandler.getAnonymousUser();
String key = "sortedMatchingContents" + contentTypeDefinitionNamesString + "_" + categoryConditionString + "_publishDateTime_languageId_" + localLanguageId + "_" + useLanguageFallback + "_" + maximumNumberOfItems + "_" + repositoryIdString + "_" + skipLanguageCheck + "_" + sortColumn + "_" + sortOrder + "_" + userName + (fromDate != null ? "_" + fromDate.getTime() : "") + (toDate != null ? "_" + toDate.getTime() : "");
if(cacheKey != null && !cacheKey.equals(""))
key = cacheKey;
if(scheduleFetch && !preventQueueBean)
{
MatchingContentsQueueBean bean = new MatchingContentsQueueBean();
bean.setCacheInterval(cacheInterval);
bean.setCacheKey(cacheKey);
bean.setCacheName(cacheName);
bean.setCacheResult(cacheResult);
bean.setCategoryCondition(categoryConditionString);
bean.setContentTypeDefinitionNames(contentTypeDefinitionNamesString);
bean.setExpireFromDate(expireFromDate);
bean.setExpireToDate(expireToDate);
bean.setFreeText(freeText);
bean.setFreeTextAttributeNames(attributeNamesString.toString());
bean.setFromDate(fromDate);
bean.setToDate(toDate);
bean.setLanguageId(languageId);
bean.setMaximumNumberOfItems(maximumNumberOfItems);
bean.setRepositoryIds(repositoryIdString.toString());
bean.setScheduleFetch(scheduleFetch);
bean.setScheduleInterval(scheduleInterval);
bean.setSkipLanguageCheck(skipLanguageCheck);
bean.setStartNodeId(startNodeId);
bean.setVersionModifier(versionModifier);
bean.setSortColumn(sortColumn);
bean.setSortOrder(sortOrder);
bean.setValidateAccessRightsAsAnonymous(validateAccessRightsAsAnonymous);
bean.setLastFetched(System.currentTimeMillis());
//We cache on real username if in published mode - otherwise in anonymous mode
if(CmsPropertyHandler.getOperatingMode().equals("3"))
bean.setUserName(getPrincipal().getName());
else
bean.setUserName(CmsPropertyHandler.getAnonymousUser());
MatchingContentsQueue.getMatchingContentsQueue().addMatchingContentsQueueBean(key, bean);
}
logger.info("key: " + key);
logger.info("forceRefetch:" + forceRefetch);
List cachedMatchingContents = (List)CacheController.getCachedObjectFromAdvancedCache(cacheName, key/*, cacheInterval*/);
//List cachedMatchingContents = (List)CacheController.getCachedObjectFromAdvancedCache(cacheName, ""+key.hashCode()/*, cacheInterval*/);
if(logger.isInfoEnabled())
{
logger.info("cacheInterval:" + cacheInterval);
logger.info("scheduleFetch:" + scheduleFetch);
logger.info("scheduleInterval:" + scheduleInterval);
logger.info("cachedMatchingContents:" + (cachedMatchingContents == null ? "null" : cachedMatchingContents.size()));
logger.info("cacheResult:" + cacheResult);
logger.info("forceRefetch:" + forceRefetch);
logger.info("key:" + key);
logger.info("key.hash:" + key.hashCode());
logger.info("returnOnlyCachedResult:" + returnOnlyCachedResult);
}
if((cachedMatchingContents == null || !cacheResult || forceRefetch) && !returnOnlyCachedResult)
{
/*
System.out.println("CacheSize:" + CacheController.getCacheSize("matchingContentsCache"));
System.out.println("Getting matching contents from db for key:" + key);
System.out.println("cachedMatchingContents:" + cachedMatchingContents);
System.out.println("cacheResult:" + cacheResult);
System.out.println("forceRefetch:" + forceRefetch);
System.out.println("returnOnlyCachedResult:" + returnOnlyCachedResult);
Thread.dumpStack();
*/
try
{
List contentTypeDefinitionVOList = new ArrayList();
Set<String> groups = new HashSet<String>();
String[] contentTypeDefinitionNames = contentTypeDefinitionNamesString.split(",");
for(int i=0; i<contentTypeDefinitionNames.length; i++)
{
ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName(contentTypeDefinitionNames[i], getDatabase());
if(contentTypeDefinitionVO != null)
{
contentTypeDefinitionVOList.add(contentTypeDefinitionVO);
logger.info("Do not throw page cache on this if it's not a content of type:" + contentTypeDefinitionVO.getName());
if(deliveryContext != null)
deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionVO.getId());
if(!scheduleFetch)
{
groups.add("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionVO.getId());
}
else
groups.add("none");
}
}