Search in sources :

Example 26 with UserInfo

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());
}
Also used : NamespaceIdentifier(com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) ItemDiffs(com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 27 with UserInfo

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;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 28 with UserInfo

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);
        }
    }
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) AdditionalUserInfoEnricher(com.ctrip.framework.apollo.portal.enricher.AdditionalUserInfoEnricher) UserInfoEnrichedAdapter(com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter)

Example 29 with UserInfo

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);
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with UserInfo

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;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Aggregations

UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)36 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Test (org.junit.Test)7 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)6 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)3 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 App (com.ctrip.framework.apollo.common.entity.App)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Consumer (com.ctrip.framework.apollo.openapi.entity.Consumer)2 Role (com.ctrip.framework.apollo.portal.entity.po.Role)2 ItemDiffs (com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs)2 NamespaceIdentifier (com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier)2 Sets (com.google.common.collect.Sets)2 Collections (java.util.Collections)2 Set (java.util.Set)2 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)1