Commit 05fb4738 by lepdou

update item call new api

parent 66ca68f3
......@@ -101,13 +101,19 @@ public class AdminServiceAPI {
return Arrays.asList(itemDTOs);
}
public void updateItems(String appId, Env env, String clusterName, String namespace,
public void updateItemsByChangeSet(String appId, Env env, String clusterName, String namespace,
ItemChangeSets changeSets) {
restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset",
changeSets, Void.class, getAdminServiceHost(env), appId, clusterName, namespace);
}
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
public void updateItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
restTemplate.put("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
item, getAdminServiceHost(env), appId, clusterName, namespace);
}
public ItemDTO createItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
return restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
item, ItemDTO.class, getAdminServiceHost(env), appId, clusterName, namespace)
.getBody();
......
......@@ -61,17 +61,17 @@ public class ConfigController {
@RequestBody ItemDTO item){
checkModel(isValidItem(item));
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
return configService.createItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
}
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.PUT)
public ItemDTO updateItem(@PathVariable String appId, @PathVariable String env,
public void updateItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){
checkModel(isValidItem(item));
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
configService.updateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
}
......
......@@ -72,7 +72,7 @@ public class NamespaceController {
// TODO: 16/6/17 某些环境创建失败,统一处理这种场景
namespaceService.createNamespace(Env.valueOf(model.getEnv()), namespace);
} catch (Exception e) {
logger.error("create namespace error.", e);
logger.error("createItem namespace error.", e);
}
}
return ResponseEntity.ok().build();
......
......@@ -36,7 +36,7 @@ public class ServerConfigController {
ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());
if (storedConfig == null) {//create
if (storedConfig == null) {//createItem
serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(serverConfig);
......
......@@ -68,7 +68,9 @@ public class ConfigService {
long namespaceId = model.getNamespaceId();
String configText = model.getConfigText();
ConfigTextResolver resolver = model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver;
ConfigTextResolver
resolver =
model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver;
ItemChangeSets changeSets = resolver.resolve(namespaceId, configText,
itemAPI.findItems(appId, env, clusterName, namespaceName));
if (changeSets.isEmpty()) {
......@@ -76,23 +78,29 @@ public class ConfigService {
}
changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
itemAPI.updateItems(appId, env, clusterName, namespaceName, changeSets);
itemAPI.updateItemsByChangeSet(appId, env, clusterName, namespaceName, changeSets);
}
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
public ItemDTO createItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null) {
throw new BadRequestException(
"namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName);
}
item.setNamespaceId(namespace.getId());
String username = userInfoHolder.getUser().getUserId();
if (StringUtils.isEmpty(item.getDataChangeCreatedBy())) {
item.setDataChangeCreatedBy(username);
item.setDataChangeLastModifiedBy(username);
return itemAPI.createItem(appId, env, clusterName, namespaceName, item);
}
public void updateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
String username = userInfoHolder.getUser().getUserId();
item.setDataChangeLastModifiedBy(username);
item.setNamespaceId(namespace.getId());
return itemAPI.createOrUpdateItem(appId, env, clusterName, namespaceName, item);
itemAPI.updateItem(appId, env, clusterName, namespaceName, item);
}
public void deleteItem(Env env, long itemId) {
......@@ -120,7 +128,7 @@ public class ConfigService {
changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
try {
itemAPI
.updateItems(namespaceIdentifer.getAppId(), namespaceIdentifer.getEnv(),
.updateItemsByChangeSet(namespaceIdentifer.getAppId(), namespaceIdentifer.getEnv(),
namespaceIdentifer.getClusterName(),
namespaceIdentifer.getNamespaceName(), changeSets);
} catch (HttpClientErrorException e) {
......
......@@ -37,7 +37,7 @@ public class RoleInitializationService {
return;
}
String operaterUserId = userInfoHolder.getUser().getUserId();
//create app permissions
//createItem app permissions
createAppMasterRole(appId);
//assign master role to user
......@@ -75,7 +75,7 @@ public class RoleInitializationService {
appPermissionIds =
FluentIterable.from(createdAppPermissions).transform(permission -> permission.getId()).toSet();
//create app master role
//createItem app master role
Role appMasterRole = createRole(RoleUtils.buildAppMasterRoleName(appId));
rolePermissionService.createRoleWithPermissions(appMasterRole, appPermissionIds);
......
......@@ -15,7 +15,7 @@ import java.util.Set;
/**
* normal property file resolver.
* update comment and blank item implement by create new item and delete old item.
* update comment and blank item implement by createItem new item and delete old item.
* update normal key/value item implement by update.
*/
@Component("propertyResolver")
......@@ -105,7 +105,7 @@ public class PropertyResolver implements ConfigTextResolver {
private void handleCommentLine(Long namespaceId, ItemDTO oldItemByLine, String newItem, int lineCounter, ItemChangeSets changeSets) {
String oldComment = oldItemByLine == null ? "" : oldItemByLine.getComment();
//create comment. implement update comment by delete old comment and create new comment
//createItem comment. implement update comment by delete old comment and createItem new comment
if (!(isCommentItem(oldItemByLine) && newItem.equals(oldComment))) {
changeSets.addCreateItem(buildCommentItem(0l, namespaceId, newItem, lineCounter));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment