コード例 #1
0
  private String findRoleUidByName(List<Role> roles, String roleName) {
    if (roleName == null || roleName.trim().isEmpty()) {
      return null;
    }

    for (Role role : roles) {
      if (roleName.equalsIgnoreCase(role.getName())) {
        return role.getId();
      }
    }

    return null;
  }
コード例 #2
0
  /**
   * Create a new package based on an existing template.
   *
   * @param packageId
   * @param aPackage
   * @return PackageId
   */
  public PackageId createPackageFromTemplate(PackageId packageId, Package aPackage) {
    String path =
        template
            .urlFor(UrlTemplate.TEMPLATE_PATH)
            .replace("{packageId}", packageId.getId())
            .build();

    List<Role> roles = aPackage.getRoles();

    aPackage.setRoles(Collections.<Role>emptyList());

    String packageJson = Serialization.toJson(aPackage);
    PackageId newPackageId = null;
    try {

      String response = client.post(path, packageJson);

      newPackageId = Serialization.fromJson(response, PackageId.class);
    } catch (RequestException e) {
      throw new EslServerException("Could not create a new package", e);
    } catch (Exception e) {
      throw new EslException("Could not create a new package", e);
    }

    Package createdPackage = getApiPackage(newPackageId.getId());

    for (Role role : roles) {
      String roleUid = findRoleUidByName(createdPackage.getRoles(), role.getName());

      if (roleUid == null) {
        continue;
      }

      role.setId(roleUid);
      updateRole(newPackageId, role);
    }

    return newPackageId;
  }