public static List<NCube> getNCubesFromResource(String name) { String lastSuccessful = ""; try { Object[] cubes = getJsonObjectFromResource(name); List<NCube> cubeList = new ArrayList<>(cubes.length); for (Object cube : cubes) { JsonObject ncube = (JsonObject) cube; String json = JsonWriter.objectToJson(ncube); NCube nCube = NCube.fromSimpleJson(json); nCube.sha1(); addCube(nCube.getApplicationID(), nCube); lastSuccessful = nCube.getName(); cubeList.add(nCube); } return cubeList; } catch (Exception e) { String s = "Failed to load cubes from resource: " + name + ", last successful cube: " + lastSuccessful; LOG.warn(s); throw new RuntimeException(s, e); } }
private static void cacheCubes(ApplicationID appId, List<NCubeInfoDto> cubes) { Map<String, Object> appCache = getCacheForApp(appId); for (NCubeInfoDto cubeInfo : cubes) { String key = cubeInfo.name.toLowerCase(); if (!cubeInfo.revision.startsWith("-")) { Object cachedItem = appCache.get(key); if (cachedItem == null || cachedItem instanceof NCubeInfoDto) { // If cube not in cache or already in cache as infoDto, overwrite it appCache.put(key, cubeInfo); } else if (cachedItem instanceof NCube) { // If cube is already cached, make sure the SHA1's match - if not, then cache // the new cubeInfo NCube ncube = (NCube) cachedItem; if (!ncube.sha1().equals(cubeInfo.sha1)) { appCache.put(key, cubeInfo); } } } } }
public static NCube getNCubeFromResource(ApplicationID id, String name) { try { String json = getResourceAsString(name); NCube ncube = NCube.fromSimpleJson(json); ncube.setApplicationID(id); ncube.sha1(); addCube(id, ncube); return ncube; } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException("Failed to load cube from resource: " + name, e); } }