use of com.ctrip.framework.apollo.portal.entity.bo.KVEntity in project apollo by ctripcorp.
the class ReleaseService method findAllReleases.
public List<ReleaseBO> findAllReleases(String appId, Env env, String clusterName, String namespaceName, int page, int size) {
List<ReleaseDTO> releaseDTOs = releaseAPI.findAllReleases(appId, env, clusterName, namespaceName, page, size);
if (CollectionUtils.isEmpty(releaseDTOs)) {
return Collections.emptyList();
}
List<ReleaseBO> releases = new LinkedList<>();
for (ReleaseDTO releaseDTO : releaseDTOs) {
ReleaseBO release = new ReleaseBO();
release.setBaseInfo(releaseDTO);
Set<KVEntity> kvEntities = new LinkedHashSet<>();
Map<String, String> configurations = GSON.fromJson(releaseDTO.getConfigurations(), GsonType.CONFIG);
Set<Map.Entry<String, String>> entries = configurations.entrySet();
for (Map.Entry<String, String> entry : entries) {
kvEntities.add(new KVEntity(entry.getKey(), entry.getValue()));
}
release.setItems(kvEntities);
// 为了减少数据量
releaseDTO.setConfigurations("");
releases.add(release);
}
return releases;
}
use of com.ctrip.framework.apollo.portal.entity.bo.KVEntity in project apollo by ctripcorp.
the class ReleaseService method compare.
public ReleaseCompareResult compare(ReleaseDTO baseRelease, ReleaseDTO toCompareRelease) {
Map<String, String> baseReleaseConfiguration = baseRelease == null ? new HashMap<>() : GSON.fromJson(baseRelease.getConfigurations(), GsonType.CONFIG);
Map<String, String> toCompareReleaseConfiguration = toCompareRelease == null ? new HashMap<>() : GSON.fromJson(toCompareRelease.getConfigurations(), GsonType.CONFIG);
ReleaseCompareResult compareResult = new ReleaseCompareResult();
// added and modified in firstRelease
for (Map.Entry<String, String> entry : baseReleaseConfiguration.entrySet()) {
String key = entry.getKey();
String firstValue = entry.getValue();
String secondValue = toCompareReleaseConfiguration.get(key);
// added
if (secondValue == null) {
compareResult.addEntityPair(ChangeType.DELETED, new KVEntity(key, firstValue), new KVEntity(key, null));
} else if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(ChangeType.MODIFIED, new KVEntity(key, firstValue), new KVEntity(key, secondValue));
}
}
// deleted in firstRelease
for (Map.Entry<String, String> entry : toCompareReleaseConfiguration.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (baseReleaseConfiguration.get(key) == null) {
compareResult.addEntityPair(ChangeType.ADDED, new KVEntity(key, ""), new KVEntity(key, value));
}
}
return compareResult;
}
Aggregations