Commit cd4e4759 by lepdou

rename createOrUpdate to create

parent b0513014
...@@ -31,19 +31,18 @@ public class AppController { ...@@ -31,19 +31,18 @@ public class AppController {
private AdminService adminService; private AdminService adminService;
@RequestMapping(path = "/apps", method = RequestMethod.POST) @RequestMapping(path = "/apps", method = RequestMethod.POST)
public AppDTO createOrUpdate(@RequestBody AppDTO dto) { public AppDTO create(@RequestBody AppDTO dto) {
if (!InputValidator.isValidClusterNamespace(dto.getAppId())) { if (!InputValidator.isValidClusterNamespace(dto.getAppId())) {
throw new BadRequestException(String.format("AppId格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE)); throw new BadRequestException(String.format("AppId格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
} }
App entity = BeanUtils.transfrom(App.class, dto); App entity = BeanUtils.transfrom(App.class, dto);
App managedEntity = appService.findOne(entity.getAppId()); App managedEntity = appService.findOne(entity.getAppId());
if (managedEntity != null) { if (managedEntity != null) {
BeanUtils.copyEntityProperties(entity, managedEntity); throw new BadRequestException("app already exist.");
entity = appService.update(managedEntity);
} else {
entity = adminService.createNewApp(entity);
} }
entity = adminService.createNewApp(entity);
dto = BeanUtils.transfrom(AppDTO.class, entity); dto = BeanUtils.transfrom(AppDTO.class, entity);
return dto; return dto;
} }
...@@ -51,13 +50,15 @@ public class AppController { ...@@ -51,13 +50,15 @@ public class AppController {
@RequestMapping(path = "/apps/{appId}", method = RequestMethod.DELETE) @RequestMapping(path = "/apps/{appId}", method = RequestMethod.DELETE)
public void delete(@PathVariable("appId") String appId, @RequestParam String operator) { public void delete(@PathVariable("appId") String appId, @RequestParam String operator) {
App entity = appService.findOne(appId); App entity = appService.findOne(appId);
if (entity == null) throw new NotFoundException("app not found for appId " + appId); if (entity == null) {
throw new NotFoundException("app not found for appId " + appId);
}
appService.delete(entity.getId(), operator); appService.delete(entity.getId(), operator);
} }
@RequestMapping("/apps") @RequestMapping("/apps")
public List<AppDTO> find(@RequestParam(value = "name", required = false) String name, public List<AppDTO> find(@RequestParam(value = "name", required = false) String name,
Pageable pageable) { Pageable pageable) {
List<App> app = null; List<App> app = null;
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(name)) {
app = appService.findAll(pageable); app = appService.findAll(pageable);
...@@ -70,7 +71,9 @@ public class AppController { ...@@ -70,7 +71,9 @@ public class AppController {
@RequestMapping("/apps/{appId}") @RequestMapping("/apps/{appId}")
public AppDTO get(@PathVariable("appId") String appId) { public AppDTO get(@PathVariable("appId") String appId) {
App app = appService.findOne(appId); App app = appService.findOne(appId);
if (app == null) throw new NotFoundException("app not found for appId " + appId); if (app == null) {
throw new NotFoundException("app not found for appId " + appId);
}
return BeanUtils.transfrom(AppDTO.class, app); return BeanUtils.transfrom(AppDTO.class, app);
} }
......
...@@ -22,17 +22,17 @@ public class AppNamespaceController { ...@@ -22,17 +22,17 @@ public class AppNamespaceController {
private AppNamespaceService appNamespaceService; private AppNamespaceService appNamespaceService;
@RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST) @RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST)
public AppNamespaceDTO createOrUpdate( @RequestBody AppNamespaceDTO appNamespace){ public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace) {
AppNamespace entity = BeanUtils.transfrom(AppNamespace.class, appNamespace); AppNamespace entity = BeanUtils.transfrom(AppNamespace.class, appNamespace);
AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName()); AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName());
if (managedEntity != null){ if (managedEntity != null) {
throw new BadRequestException("app namespaces already exist."); throw new BadRequestException("app namespaces already exist.");
}else {
entity = appNamespaceService.createAppNamespace(entity, entity.getDataChangeCreatedBy());
} }
entity = appNamespaceService.createAppNamespace(entity, entity.getDataChangeCreatedBy());
return BeanUtils.transfrom(AppNamespaceDTO.class, entity); return BeanUtils.transfrom(AppNamespaceDTO.class, entity);
} }
......
...@@ -25,7 +25,7 @@ public class ClusterController { ...@@ -25,7 +25,7 @@ public class ClusterController {
private ClusterService clusterService; private ClusterService clusterService;
@RequestMapping(path = "/apps/{appId}/clusters", method = RequestMethod.POST) @RequestMapping(path = "/apps/{appId}/clusters", method = RequestMethod.POST)
public ClusterDTO createOrUpdate(@PathVariable("appId") String appId, @RequestBody ClusterDTO dto) { public ClusterDTO create(@PathVariable("appId") String appId, @RequestBody ClusterDTO dto) {
if (!InputValidator.isValidClusterNamespace(dto.getName())) { if (!InputValidator.isValidClusterNamespace(dto.getName())) {
throw new BadRequestException(String.format("Cluster格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE)); throw new BadRequestException(String.format("Cluster格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
} }
...@@ -33,9 +33,8 @@ public class ClusterController { ...@@ -33,9 +33,8 @@ public class ClusterController {
Cluster managedEntity = clusterService.findOne(appId, entity.getName()); Cluster managedEntity = clusterService.findOne(appId, entity.getName());
if (managedEntity != null) { if (managedEntity != null) {
throw new BadRequestException("cluster already exist."); throw new BadRequestException("cluster already exist.");
} else {
entity = clusterService.save(entity);
} }
entity = clusterService.save(entity);
dto = BeanUtils.transfrom(ClusterDTO.class, entity); dto = BeanUtils.transfrom(ClusterDTO.class, entity);
return dto; return dto;
...@@ -43,10 +42,11 @@ public class ClusterController { ...@@ -43,10 +42,11 @@ public class ClusterController {
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName:.+}", method = RequestMethod.DELETE) @RequestMapping(path = "/apps/{appId}/clusters/{clusterName:.+}", method = RequestMethod.DELETE)
public void delete(@PathVariable("appId") String appId, public void delete(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName, @RequestParam String operator) { @PathVariable("clusterName") String clusterName, @RequestParam String operator) {
Cluster entity = clusterService.findOne(appId, clusterName); Cluster entity = clusterService.findOne(appId, clusterName);
if (entity == null) if (entity == null) {
throw new NotFoundException("cluster not found for clusterName " + clusterName); throw new NotFoundException("cluster not found for clusterName " + clusterName);
}
clusterService.delete(entity.getId(), operator); clusterService.delete(entity.getId(), operator);
} }
...@@ -58,15 +58,17 @@ public class ClusterController { ...@@ -58,15 +58,17 @@ public class ClusterController {
@RequestMapping("/apps/{appId}/clusters/{clusterName:.+}") @RequestMapping("/apps/{appId}/clusters/{clusterName:.+}")
public ClusterDTO get(@PathVariable("appId") String appId, public ClusterDTO get(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) { @PathVariable("clusterName") String clusterName) {
Cluster cluster = clusterService.findOne(appId, clusterName); Cluster cluster = clusterService.findOne(appId, clusterName);
if (cluster == null) throw new NotFoundException("cluster not found for name " + clusterName); if (cluster == null) {
throw new NotFoundException("cluster not found for name " + clusterName);
}
return BeanUtils.transfrom(ClusterDTO.class, cluster); return BeanUtils.transfrom(ClusterDTO.class, cluster);
} }
@RequestMapping("/apps/{appId}/cluster/{clusterName}/unique") @RequestMapping("/apps/{appId}/cluster/{clusterName}/unique")
public boolean isAppIdUnique(@PathVariable("appId") String appId, public boolean isAppIdUnique(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) { @PathVariable("clusterName") String clusterName) {
return clusterService.isClusterNameUnique(appId, clusterName); return clusterService.isClusterNameUnique(appId, clusterName);
} }
} }
...@@ -25,7 +25,7 @@ public class NamespaceController { ...@@ -25,7 +25,7 @@ public class NamespaceController {
private NamespaceService namespaceService; private NamespaceService namespaceService;
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces", method = RequestMethod.POST) @RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces", method = RequestMethod.POST)
public NamespaceDTO createOrUpdate(@PathVariable("appId") String appId, public NamespaceDTO create(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName, @RequestBody NamespaceDTO dto) { @PathVariable("clusterName") String clusterName, @RequestBody NamespaceDTO dto) {
if (!InputValidator.isValidClusterNamespace(dto.getNamespaceName())) { if (!InputValidator.isValidClusterNamespace(dto.getNamespaceName())) {
throw new BadRequestException(String.format("Namespace格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE)); throw new BadRequestException(String.format("Namespace格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
...@@ -34,10 +34,10 @@ public class NamespaceController { ...@@ -34,10 +34,10 @@ public class NamespaceController {
Namespace managedEntity = namespaceService.findOne(appId, clusterName, entity.getNamespaceName()); Namespace managedEntity = namespaceService.findOne(appId, clusterName, entity.getNamespaceName());
if (managedEntity != null) { if (managedEntity != null) {
throw new BadRequestException("namespace already exist."); throw new BadRequestException("namespace already exist.");
} else {
entity = namespaceService.save(entity);
} }
entity = namespaceService.save(entity);
dto = BeanUtils.transfrom(NamespaceDTO.class, entity); dto = BeanUtils.transfrom(NamespaceDTO.class, entity);
return dto; return dto;
} }
......
...@@ -8,7 +8,6 @@ import org.springframework.util.CollectionUtils; ...@@ -8,7 +8,6 @@ import org.springframework.util.CollectionUtils;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Commit; import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.repository.ItemRepository;
import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder; import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.dto.ItemChangeSets; import com.ctrip.framework.apollo.core.dto.ItemChangeSets;
...@@ -20,9 +19,6 @@ import com.ctrip.framework.apollo.core.utils.StringUtils; ...@@ -20,9 +19,6 @@ import com.ctrip.framework.apollo.core.utils.StringUtils;
public class ItemSetService { public class ItemSetService {
@Autowired @Autowired
private ItemRepository itemRepository;
@Autowired
private AuditService auditService; private AuditService auditService;
@Autowired @Autowired
...@@ -53,7 +49,7 @@ public class ItemSetService { ...@@ -53,7 +49,7 @@ public class ItemSetService {
for (ItemDTO item : changeSet.getUpdateItems()) { for (ItemDTO item : changeSet.getUpdateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item); Item entity = BeanUtils.transfrom(Item.class, item);
Item beforeUpdateItem = itemRepository.findOne(entity.getId()); Item beforeUpdateItem = itemService.findOne(entity.getId());
entity.setDataChangeLastModifiedBy(operator); entity.setDataChangeLastModifiedBy(operator);
Item updatedItem = itemService.update(entity); Item updatedItem = itemService.update(entity);
......
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