use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class ConfigServiceTest method testCompare.
@Test
public void testCompare() {
// not modified
ItemDTO sourceItem1 = new ItemDTO("a", "b", "comment", 1);
// new item
ItemDTO sourceItem2 = new ItemDTO("newKey", "c", "comment", 2);
// update value
ItemDTO sourceItem3 = new ItemDTO("c", "newValue", "comment", 3);
// update comment
ItemDTO sourceItem4 = new ItemDTO("d", "b", "newComment", 4);
List<ItemDTO> sourceItems = Arrays.asList(sourceItem1, sourceItem2, sourceItem3, sourceItem4);
ItemDTO targetItem1 = new ItemDTO("a", "b", "comment", 1);
ItemDTO targetItem2 = new ItemDTO("c", "oldValue", "comment", 2);
ItemDTO targetItem3 = new ItemDTO("d", "b", "oldComment", 3);
List<ItemDTO> targetItems = Arrays.asList(targetItem1, targetItem2, targetItem3);
String appId = "6666", env = "LOCAL", clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
List<NamespaceIdentifier> namespaceIdentifiers = generateNamespaceIdentifier(appId, env, clusterName, namespaceName);
NamespaceDTO namespaceDTO = generateNamespaceDTO(appId, clusterName, namespaceName);
when(namespaceAPI.loadNamespace(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(namespaceDTO);
when(itemAPI.findItems(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(targetItems);
UserInfo userInfo = new UserInfo();
userInfo.setUserId("test");
when(userInfoHolder.getUser()).thenReturn(userInfo);
List<ItemDiffs> itemDiffses = configService.compare(namespaceIdentifiers, sourceItems);
assertEquals(1, itemDiffses.size());
ItemDiffs itemDiffs = itemDiffses.get(0);
ItemChangeSets changeSets = itemDiffs.getDiffs();
assertEquals(0, changeSets.getDeleteItems().size());
assertEquals(2, changeSets.getUpdateItems().size());
assertEquals(1, changeSets.getCreateItems().size());
NamespaceIdentifier namespaceIdentifier = itemDiffs.getNamespace();
assertEquals(appId, namespaceIdentifier.getAppId());
assertEquals(Env.valueOf("LOCAL"), namespaceIdentifier.getEnv());
assertEquals(clusterName, namespaceIdentifier.getClusterName());
assertEquals(namespaceName, namespaceIdentifier.getNamespaceName());
ItemDTO createdItem = changeSets.getCreateItems().get(0);
assertEquals("newKey", createdItem.getKey());
assertEquals("c", createdItem.getValue());
assertEquals("comment", createdItem.getComment());
assertEquals(4, createdItem.getLineNum());
List<ItemDTO> updateItems = changeSets.getUpdateItems();
ItemDTO updateItem1 = updateItems.get(0);
ItemDTO updateItem2 = updateItems.get(1);
assertEquals("c", updateItem1.getKey());
assertEquals("newValue", updateItem1.getValue());
assertEquals("comment", updateItem1.getComment());
assertEquals(2, updateItem1.getLineNum());
assertEquals("d", updateItem2.getKey());
assertEquals("b", updateItem2.getValue());
assertEquals("newComment", updateItem2.getComment());
assertEquals(3, updateItem2.getLineNum());
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class DefaultUserService method assembleDefaultUser.
private UserInfo assembleDefaultUser() {
UserInfo defaultUser = new UserInfo();
defaultUser.setUserId("apollo");
defaultUser.setName("apollo");
defaultUser.setEmail("apollo@acme.com");
return defaultUser;
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class AdditionalUserInfoEnrichServiceImpl method enrichAdditionalUserInfo.
@Override
public <T> void enrichAdditionalUserInfo(List<? extends T> list, Function<? super T, ? extends UserInfoEnrichedAdapter> mapper) {
if (CollectionUtils.isEmpty(list)) {
return;
}
if (CollectionUtils.isEmpty(this.enricherList)) {
return;
}
List<UserInfoEnrichedAdapter> adapterList = this.adapt(list, mapper);
if (CollectionUtils.isEmpty(adapterList)) {
return;
}
Set<String> userIdSet = this.extractOperatorId(adapterList);
if (CollectionUtils.isEmpty(userIdSet)) {
return;
}
List<UserInfo> userInfoList = this.userService.findByUserIds(new ArrayList<>(userIdSet));
if (CollectionUtils.isEmpty(userInfoList)) {
return;
}
Map<String, UserInfo> userInfoMap = userInfoList.stream().collect(Collectors.toMap(UserInfo::getUserId, Function.identity()));
for (UserInfoEnrichedAdapter adapter : adapterList) {
for (AdditionalUserInfoEnricher enricher : this.enricherList) {
enricher.enrichAdditionalUserInfo(adapter, userInfoMap);
}
}
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class AppService method updateAppInLocal.
@Transactional
public App updateAppInLocal(App app) {
String appId = app.getAppId();
App managedApp = appRepository.findByAppId(appId);
if (managedApp == null) {
throw new BadRequestException(String.format("App not exists. AppId = %s", appId));
}
managedApp.setName(app.getName());
managedApp.setOrgId(app.getOrgId());
managedApp.setOrgName(app.getOrgName());
String ownerName = app.getOwnerName();
UserInfo owner = userService.findByUserId(ownerName);
if (owner == null) {
throw new BadRequestException(String.format("App's owner not exists. owner = %s", ownerName));
}
managedApp.setOwnerName(owner.getUserId());
managedApp.setOwnerEmail(owner.getEmail());
String operator = userInfoHolder.getUser().getUserId();
managedApp.setDataChangeLastModifiedBy(operator);
return appRepository.save(managedApp);
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class UserPO method toUserInfo.
public UserInfo toUserInfo() {
UserInfo userInfo = new UserInfo();
userInfo.setUserId(this.getUsername());
userInfo.setName(this.getUserDisplayName());
userInfo.setEmail(this.getEmail());
return userInfo;
}
Aggregations