@Test public void testSerializeOperatingSystems() throws Exception { final List<RepositoryInfo> repositories = new ArrayList<RepositoryInfo>(); final RepositoryInfo repository = new RepositoryInfo(); repository.setBaseUrl("baseurl"); repository.setOsType("os"); repository.setRepoId("repoId"); repository.setUnique(true); repository.setAmbariManagedRepositories(true); repositories.add(repository); final String serialized = helper.serializeOperatingSystems(repositories); Assert.assertEquals("[{\"OperatingSystems/ambari_managed_repositories\":true,\"repositories\":[{\"Repositories/base_url\":\"baseurl\",\"Repositories/repo_id\":\"repoId\",\"Repositories/unique\":true}],\"OperatingSystems/os_type\":\"os\"}]", serialized); }
public String serializeOperatingSystems(List<RepositoryInfo> repositories) { final JsonArray rootJson = new JsonArray(); final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create(); for (RepositoryInfo repository: repositories) { operatingSystems.put(repository.getOsType(), repository); } for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet()) { final JsonObject operatingSystemJson = new JsonObject(); final JsonArray repositoriesJson = new JsonArray(); for (RepositoryInfo repository : operatingSystem.getValue()) { final JsonObject repositoryJson = new JsonObject(); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique()); repositoriesJson.add(repositoryJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories()); } operatingSystemJson.add(RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, operatingSystem.getKey()); rootJson.add(operatingSystemJson); } return gson.toJson(rootJson); }
RepositoryVersionHelper { public String serializeOperatingSystems(List<RepositoryInfo> repositories) { final JsonArray rootJson = new JsonArray(); final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create(); for (RepositoryInfo repository: repositories) { operatingSystems.put(repository.getOsType(), repository); } for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet()) { final JsonObject operatingSystemJson = new JsonObject(); final JsonArray repositoriesJson = new JsonArray(); for (RepositoryInfo repository : operatingSystem.getValue()) { final JsonObject repositoryJson = new JsonObject(); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique()); repositoriesJson.add(repositoryJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories()); } operatingSystemJson.add(RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, operatingSystem.getKey()); rootJson.add(operatingSystemJson); } return gson.toJson(rootJson); } }
RepositoryVersionHelper { public String serializeOperatingSystems(List<RepositoryInfo> repositories) { final JsonArray rootJson = new JsonArray(); final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create(); for (RepositoryInfo repository: repositories) { operatingSystems.put(repository.getOsType(), repository); } for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet()) { final JsonObject operatingSystemJson = new JsonObject(); final JsonArray repositoriesJson = new JsonArray(); for (RepositoryInfo repository : operatingSystem.getValue()) { final JsonObject repositoryJson = new JsonObject(); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique()); repositoriesJson.add(repositoryJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories()); } operatingSystemJson.add(RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, operatingSystem.getKey()); rootJson.add(operatingSystemJson); } return gson.toJson(rootJson); }  }
RepositoryVersionHelper { public String serializeOperatingSystems(List<RepositoryInfo> repositories) { final JsonArray rootJson = new JsonArray(); final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create(); for (RepositoryInfo repository: repositories) { operatingSystems.put(repository.getOsType(), repository); } for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet()) { final JsonObject operatingSystemJson = new JsonObject(); final JsonArray repositoriesJson = new JsonArray(); for (RepositoryInfo repository : operatingSystem.getValue()) { final JsonObject repositoryJson = new JsonObject(); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique()); repositoriesJson.add(repositoryJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories()); } operatingSystemJson.add(RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, operatingSystem.getKey()); rootJson.add(operatingSystemJson); } return gson.toJson(rootJson); }  List<OperatingSystemEntity> parseOperatingSystems(String repositoriesJson); String serializeOperatingSystems(List<RepositoryInfo> repositories); String serializeOperatingSystemEntities(List<OperatingSystemEntity> operatingSystems); String getUpgradePackageName(String stackName, String stackVersion, String repositoryVersion, UpgradeType upgradeType); }
RepositoryVersionHelper { public String serializeOperatingSystems(List<RepositoryInfo> repositories) { final JsonArray rootJson = new JsonArray(); final Multimap<String, RepositoryInfo> operatingSystems = ArrayListMultimap.create(); for (RepositoryInfo repository: repositories) { operatingSystems.put(repository.getOsType(), repository); } for (Entry<String, Collection<RepositoryInfo>> operatingSystem : operatingSystems.asMap().entrySet()) { final JsonObject operatingSystemJson = new JsonObject(); final JsonArray repositoriesJson = new JsonArray(); for (RepositoryInfo repository : operatingSystem.getValue()) { final JsonObject repositoryJson = new JsonObject(); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList()); repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique()); repositoriesJson.add(repositoryJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories()); } operatingSystemJson.add(RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, repositoriesJson); operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, operatingSystem.getKey()); rootJson.add(operatingSystemJson); } return gson.toJson(rootJson); }  List<OperatingSystemEntity> parseOperatingSystems(String repositoriesJson); String serializeOperatingSystems(List<RepositoryInfo> repositories); String serializeOperatingSystemEntities(List<OperatingSystemEntity> operatingSystems); String getUpgradePackageName(String stackName, String stackVersion, String repositoryVersion, UpgradeType upgradeType);  }