Пример #1
0
  public static ApplicationID getApplicationID(
      String tenant, String app, Map<String, Object> coord) {
    ApplicationID.validateTenant(tenant);
    ApplicationID.validateApp(tenant);

    if (coord == null) {
      coord = new HashMap<>();
    }

    NCube bootCube = getCube(ApplicationID.getBootVersion(tenant, app), SYS_BOOTSTRAP);

    if (bootCube == null) {
      throw new IllegalStateException(
          "Missing " + SYS_BOOTSTRAP + " cube in the 0.0.0 version for the app: " + app);
    }

    ApplicationID bootAppId = (ApplicationID) bootCube.getCell(coord);
    String version = bootAppId.getVersion();
    String status = bootAppId.getStatus();
    String branch = bootAppId.getBranch();

    if (!tenant.equalsIgnoreCase(bootAppId.getTenant())) {
      LOG.warn(
          "sys.bootstrap cube for tenant '"
              + tenant
              + "', app '"
              + app
              + "' is returning a different tenant '"
              + bootAppId.getTenant()
              + "' than requested. Using '"
              + tenant
              + "' instead.");
    }

    if (!app.equalsIgnoreCase(bootAppId.getApp())) {
      LOG.warn(
          "sys.bootstrap cube for tenant '"
              + tenant
              + "', app '"
              + app
              + "' is returning a different app '"
              + bootAppId.getApp()
              + "' than requested. Using '"
              + app
              + "' instead.");
    }

    return new ApplicationID(tenant, app, version, status, branch);
  }
Пример #2
0
  /**
   * Get List<NCubeInfoDto> of n-cube record DTOs for the given ApplicationID (branch only). If
   * using For any cube record loaded, for which there is no entry in the app's cube cache, an entry
   * is added mapping the cube name to the cube record (NCubeInfoDto). This will be replaced by an
   * NCube if more than the name is required. one (1) character. This is universal whether using a
   * SQL perister or Mongo persister.
   */
  public static List<NCubeInfoDto> getBranchChangesFromDatabase(ApplicationID appId) {
    validateAppId(appId);
    if (appId.getBranch().equals(ApplicationID.HEAD)) {
      throw new IllegalArgumentException("Cannot get branch changes from HEAD");
    }

    ApplicationID headAppId = appId.asHead();
    Map<String, NCubeInfoDto> headMap = new TreeMap<>();

    Map<String, Object> searchChangedRecordOptions = new HashMap<>();
    searchChangedRecordOptions.put(SEARCH_CHANGED_RECORDS_ONLY, true);
    List<NCubeInfoDto> branchList = search(appId, null, null, searchChangedRecordOptions);

    Map<String, Object> options = new HashMap<>();
    options.put(SEARCH_ACTIVE_RECORDS_ONLY, false);
    List<NCubeInfoDto> headList = search(headAppId, null, null, options);

    List<NCubeInfoDto> list = new ArrayList<>();

    //  build map of head objects for reference.
    for (NCubeInfoDto info : headList) {
      headMap.put(info.name, info);
    }

    // Loop through changed (added, deleted, created, restored, updated) records
    for (NCubeInfoDto info : branchList) {
      long revision = (long) Converter.convert(info.revision, long.class);
      NCubeInfoDto head = headMap.get(info.name);

      if (head == null) {
        if (revision >= 0) {
          info.changeType = ChangeType.CREATED.getCode();
          list.add(info);
        }
      } else if (info.headSha1 == null) { //  we created this guy locally
        // someone added this one to the head already
        info.changeType = ChangeType.CONFLICT.getCode();
        list.add(info);
      } else {
        if (StringUtilities.equalsIgnoreCase(info.headSha1, head.sha1)) {
          if (StringUtilities.equalsIgnoreCase(info.sha1, info.headSha1)) {
            // only net change could be revision deleted or restored.  check head.
            long headRev = Long.parseLong(head.revision);

            if (headRev < 0 != revision < 0) {
              if (revision < 0) {
                info.changeType = ChangeType.DELETED.getCode();
              } else {
                info.changeType = ChangeType.RESTORED.getCode();
              }

              list.add(info);
            }
          } else {
            info.changeType = ChangeType.UPDATED.getCode();
            list.add(info);
          }
        } else {
          info.changeType = ChangeType.CONFLICT.getCode();
          list.add(info);
        }
      }
    }

    cacheCubes(appId, list);
    return list;
  }