Ejemplo n.º 1
0
  /**
   * Update the passed in NCube. Only SNAPSHOT cubes can be updated.
   *
   * @param ncube NCube to be updated.
   * @return boolean true on success, false otherwise
   */
  public static boolean updateCube(ApplicationID appId, NCube ncube, String username) {
    validateAppId(appId);
    validateCube(ncube);

    if (appId.isRelease()) {
      throw new IllegalArgumentException(
          ReleaseStatus.RELEASE
              + " cubes cannot be updated, cube: "
              + ncube.getName()
              + ", app: "
              + appId);
    }

    appId.validateBranchIsNotHead();

    final String cubeName = ncube.getName();
    getPersister().updateCube(appId, ncube, username);
    ncube.setApplicationID(appId);

    if (CLASSPATH_CUBE.equalsIgnoreCase(
        cubeName)) { // If the sys.classpath cube is changed, then the entire class loader must be
                     // dropped.  It will be lazily rebuilt.
      clearCache(appId);
    }

    addCube(appId, ncube);
    broadcast(appId);
    return true;
  }
Ejemplo n.º 2
0
 private static void addAdviceToMatchedCube(Advice advice, String regex, NCube ncube, Axis axis) {
   if (axis != null) { // Controller methods
     for (Column column : axis.getColumnsWithoutDefault()) {
       String method = column.getValue().toString();
       String classMethod = ncube.getName() + '.' + method + "()";
       if (classMethod.matches(regex)) {
         ncube.addAdvice(advice, method);
       }
     }
   } else { // Expressions
     String classMethod = ncube.getName() + ".run()";
     if (classMethod.matches(regex)) {
       ncube.addAdvice(advice, "run");
     }
   }
 }
Ejemplo n.º 3
0
  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);
    }
  }
Ejemplo n.º 4
0
 private static NCube prepareCube(NCube cube) {
   applyAdvices(cube.getApplicationID(), cube);
   String cubeName = cube.getName().toLowerCase();
   if (!cube.getMetaProperties().containsKey("cache")
       || Boolean.TRUE.equals(
           cube.getMetaProperty(
               "cache"))) { // Allow cubes to not be cached by specified 'cache':false as a cube
                            // meta-property.
     getCacheForApp(cube.getApplicationID()).put(cubeName, cube);
   }
   return cube;
 }
Ejemplo n.º 5
0
  /**
   * Add a cube to the internal cache of available cubes.
   *
   * @param ncube NCube to add to the list.
   */
  public static void addCube(ApplicationID appId, NCube ncube) {
    validateAppId(appId);
    validateCube(ncube);

    String cubeName = ncube.getName().toLowerCase();

    if (!ncube.getMetaProperties().containsKey("cache")
        || Boolean.TRUE.equals(
            ncube.getMetaProperty(
                "cache"))) { // Allow cubes to not be cached by specified 'cache':false as a cube
                             // meta-property.
      getCacheForApp(appId).put(cubeName, ncube);
    }

    // Apply any matching advices to it
    applyAdvices(appId, ncube);
  }
Ejemplo n.º 6
0
  /**
   * Fetch all the n-cube names for the given ApplicationID. This API will load all cube records for
   * the ApplicationID (NCubeInfoDtos), and then get the names from them.
   *
   * @return Set<String> n-cube names. If an empty Set is returned, then there are no persisted
   *     n-cubes for the passed in ApplicationID.
   */
  public static Set<String> getCubeNames(ApplicationID appId) {
    Map<String, Object> options = new HashMap<>();
    options.put(SEARCH_ACTIVE_RECORDS_ONLY, true);
    List<NCubeInfoDto> cubeInfos = search(appId, null, null, options);
    Set<String> names = new TreeSet<>();

    for (NCubeInfoDto info : cubeInfos) {
      names.add(info.name);
    }

    if (names.isEmpty()) { // Support tests that load cubes from JSON files...
      // can only be in there as ncubes, not ncubeDtoInfo
      for (Object value : getCacheForApp(appId).values()) {
        if (value instanceof NCube) {
          NCube cube = (NCube) value;
          names.add(cube.getName());
        }
      }
    }
    return new CaseInsensitiveSet<>(names);
  }
Ejemplo n.º 7
0
 static void validateCube(NCube cube) {
   if (cube == null) {
     throw new IllegalArgumentException("NCube cannot be null");
   }
   NCube.validateCubeName(cube.getName());
 }