Unverified Commit d0bbf0da by Jason Song Committed by GitHub

Merge pull request #881 from renlulu/xiaohuo.ren-dev

write builder function for entity App and optimization some null judge
parents 3cf3755e e2b5f086
...@@ -86,4 +86,53 @@ public class App extends BaseEntity { ...@@ -86,4 +86,53 @@ public class App extends BaseEntity {
.add("ownerName", ownerName) .add("ownerName", ownerName)
.add("ownerEmail", ownerEmail).toString(); .add("ownerEmail", ownerEmail).toString();
} }
public static class Builder {
public Builder() {
}
private App app = new App();
public Builder name(String name) {
app.setName(name);
return this;
}
public Builder appId(String appId) {
app.setAppId(appId);
return this;
}
public Builder orgId(String orgId) {
app.setOrgId(orgId);
return this;
}
public Builder orgName(String orgName) {
app.setOrgName(orgName);
return this;
}
public Builder ownerName(String ownerName) {
app.setOrgName(ownerName);
return this;
}
public Builder ownerEmail(String ownerEmail) {
app.setOwnerEmail(ownerEmail);
return this;
}
public App build() {
return app;
}
}
public static Builder builder() {
return new Builder();
}
} }
...@@ -178,13 +178,13 @@ public class AppController { ...@@ -178,13 +178,13 @@ public class AppController {
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 app = new App(); return App.builder()
app.setAppId(appId); .appId(appId)
app.setName(appName); .name(appName)
app.setOwnerName(ownerName); .ownerName(ownerName)
app.setOrgId(orgId); .orgId(orgId)
app.setOrgName(orgName); .orgName(orgName)
.build();
return app;
} }
} }
...@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel; import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;
@RestController @RestController
...@@ -32,7 +34,7 @@ public class ClusterController { ...@@ -32,7 +34,7 @@ public class ClusterController {
public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String env, public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String env,
@RequestBody ClusterDTO cluster) { @RequestBody ClusterDTO cluster) {
checkModel(cluster != null); checkModel(Objects.nonNull(cluster));
RequestPrecondition.checkArgumentsNotEmpty(cluster.getAppId(), cluster.getName()); RequestPrecondition.checkArgumentsNotEmpty(cluster.getAppId(), cluster.getName());
if (!InputValidator.isValidClusterNamespace(cluster.getName())) { if (!InputValidator.isValidClusterNamespace(cluster.getName())) {
......
...@@ -53,7 +53,7 @@ public class ConsumerController { ...@@ -53,7 +53,7 @@ public class ConsumerController {
Consumer createdConsumer = consumerService.createConsumer(consumer); Consumer createdConsumer = consumerService.createConsumer(consumer);
if (expires == null) { if (Objects.isNull(expires)) {
expires = DEFAULT_EXPIRES; expires = DEFAULT_EXPIRES;
} }
......
...@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel; import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;
...@@ -128,7 +129,7 @@ public class ItemController { ...@@ -128,7 +129,7 @@ public class ItemController {
@RequestMapping(value = "/namespaces/{namespaceName}/diff", method = RequestMethod.POST, consumes = { @RequestMapping(value = "/namespaces/{namespaceName}/diff", method = RequestMethod.POST, consumes = {
"application/json"}) "application/json"})
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) { public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid()); checkModel(Objects.nonNull(model) && !model.isInvalid());
return configService.compare(model.getSyncToNamespaces(), model.getSyncItems()); return configService.compare(model.getSyncToNamespaces(), model.getSyncItems());
} }
...@@ -138,14 +139,14 @@ public class ItemController { ...@@ -138,14 +139,14 @@ public class ItemController {
"application/json"}) "application/json"})
public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName, public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName,
@RequestBody NamespaceSyncModel model) { @RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid()); checkModel(Objects.nonNull(model) && !model.isInvalid());
configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems()); configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
return ResponseEntity.status(HttpStatus.OK).build(); return ResponseEntity.status(HttpStatus.OK).build();
} }
private boolean isValidItem(ItemDTO item) { private boolean isValidItem(ItemDTO item) {
return item != null && !StringUtils.isContainEmpty(item.getKey()); return Objects.nonNull(item) && !StringUtils.isContainEmpty(item.getKey());
} }
......
...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Objects;
import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel; import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;
...@@ -41,7 +42,7 @@ public class ReleaseController { ...@@ -41,7 +42,7 @@ public class ReleaseController {
@PathVariable String env, @PathVariable String clusterName, @PathVariable String env, @PathVariable String clusterName,
@PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) { @PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {
checkModel(model != null); checkModel(Objects.nonNull(model));
model.setAppId(appId); model.setAppId(appId);
model.setEnv(env); model.setEnv(env);
model.setClusterName(clusterName); model.setClusterName(clusterName);
...@@ -74,7 +75,7 @@ public class ReleaseController { ...@@ -74,7 +75,7 @@ public class ReleaseController {
@PathVariable String namespaceName, @PathVariable String branchName, @PathVariable String namespaceName, @PathVariable String branchName,
@RequestBody NamespaceReleaseModel model) { @RequestBody NamespaceReleaseModel model) {
checkModel(model != null); checkModel(Objects.nonNull(model));
model.setAppId(appId); model.setAppId(appId);
model.setEnv(env); model.setEnv(env);
model.setClusterName(branchName); model.setClusterName(branchName);
...@@ -142,7 +143,7 @@ public class ReleaseController { ...@@ -142,7 +143,7 @@ public class ReleaseController {
@PathVariable long releaseId) { @PathVariable long releaseId) {
releaseService.rollback(Env.valueOf(env), releaseId); releaseService.rollback(Env.valueOf(env), releaseId);
ReleaseDTO release = releaseService.findReleaseById(Env.valueOf(env), releaseId); ReleaseDTO release = releaseService.findReleaseById(Env.valueOf(env), releaseId);
if (release == null) { if (Objects.isNull(release)) {
return; return;
} }
......
...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel; import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkModel;
/** /**
...@@ -31,14 +33,14 @@ public class ServerConfigController { ...@@ -31,14 +33,14 @@ public class ServerConfigController {
@RequestMapping(value = "/server/config", method = RequestMethod.POST) @RequestMapping(value = "/server/config", method = RequestMethod.POST)
public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) { public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) {
checkModel(serverConfig != null); checkModel(Objects.nonNull(serverConfig));
RequestPrecondition.checkArgumentsNotEmpty(serverConfig.getKey(), serverConfig.getValue()); RequestPrecondition.checkArgumentsNotEmpty(serverConfig.getKey(), serverConfig.getValue());
String modifiedBy = userInfoHolder.getUser().getUserId(); String modifiedBy = userInfoHolder.getUser().getUserId();
ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey()); ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());
if (storedConfig == null) {//create if (Objects.isNull(storedConfig)) {//create
serverConfig.setDataChangeCreatedBy(modifiedBy); serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy); serverConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(serverConfig); return serverConfigRepository.save(serverConfig);
......
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