package org.innovateuk.ifs.cache;

import org.innovateuk.ifs.commons.service.ServiceResult;

import java.util.Collection;

public class CacheHelper {

    public static boolean cacheResultIfCompetitionIsOpen(ServiceResult<?> result) {
        if (result.isFailure()) {
            return false;
        }

        Object payload = result.getSuccess();

        if (payload instanceof Collection) {
            CacheableWhenCompetitionOpen target = (CacheableWhenCompetitionOpen) ((Collection) payload).iterator().next();
            return target.isCompetitionOpen();
        }

        if (payload instanceof CacheableWhenCompetitionOpen) {
            return ((CacheableWhenCompetitionOpen) payload).isCompetitionOpen();
        }

        return false;
    }

}

@@ -387,24 +387,131 @@
 llection) %7B%0A
+            if (((Collection) payload).isEmpty()) %7B%0A                return false;%0A            %7D else %7B%0A    
             
@@ -629,24 +629,28 @@
             
+    
 return targe
@@ -664,32 +664,46 @@
 petitionOpen();%0A
+            %7D%0A
         %7D%0A%0A     

fix bug.