-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee42aea
commit f94f17b
Showing
20 changed files
with
860 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
hubble-be/src/main/java/com/baidu/hugegraph/controller/project/ProjectController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.controller.project; | ||
|
||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.baidu.hugegraph.common.Constant; | ||
import com.baidu.hugegraph.entity.project.ProjectEntity; | ||
import com.baidu.hugegraph.service.project.ProjectService; | ||
import com.baidu.hugegraph.util.Ex; | ||
import com.baomidou.mybatisplus.core.metadata.IPage; | ||
|
||
@RestController | ||
@RequestMapping(Constant.API_VERSION + "graph-connections/project") | ||
public class ProjectController { | ||
|
||
@Autowired | ||
private ProjectService projectService; | ||
|
||
@PostMapping | ||
public ProjectEntity createProject(@RequestBody ProjectEntity project) { | ||
this.checkParamsValid(project, true); | ||
return this.projectService.createProject(project); | ||
} | ||
|
||
@PutMapping | ||
public ProjectEntity updateProject(@RequestBody ProjectEntity project) { | ||
this.checkParamsValid(project, false); | ||
return this.projectService.updateProject(project); | ||
} | ||
|
||
@DeleteMapping("{id}") | ||
public void deleteProject(@PathVariable("id") String projectId) { | ||
this.projectService.deleteProject(projectId); | ||
} | ||
|
||
@GetMapping("/list") | ||
public IPage<ProjectEntity> list(@RequestParam(value = "project_name", | ||
required = false) | ||
String projectName, | ||
@RequestParam(name = "page_no", | ||
required = false, | ||
defaultValue = "1") | ||
int pageNo, | ||
@RequestParam(name = "page_size", | ||
required = false, | ||
defaultValue = "10") | ||
int pageSize) { | ||
return this.projectService.list(projectName, pageNo, pageSize); | ||
} | ||
|
||
private void checkParamsValid(ProjectEntity entity, boolean create) { | ||
Ex.check(StringUtils.isNotEmpty(entity.getName()), | ||
"common.param.cannot-be-null-or-empty", "project_name"); | ||
Ex.check(CollectionUtils.isNotEmpty(entity.getAdminUsers()), | ||
"common.param.cannot-be-null-or-empty", "admin_users"); | ||
Ex.check(CollectionUtils.isNotEmpty(entity.getOpUsers()), | ||
"common.param.cannot-be-null-or-empty", "op_users"); | ||
if (create) { | ||
Ex.check(entity.getId() == null, | ||
"common.param.must-be-null", "id"); | ||
} else { | ||
Ex.check(entity.getId() != null, | ||
"common.param.cannot-be-null", "id"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
hubble-be/src/main/java/com/baidu/hugegraph/controller/user/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.controller.user; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.baidu.hugegraph.common.Constant; | ||
import com.baidu.hugegraph.entity.user.UserEntity; | ||
import com.baidu.hugegraph.service.user.UserService; | ||
import com.baidu.hugegraph.util.Ex; | ||
import com.baomidou.mybatisplus.core.metadata.IPage; | ||
|
||
@RestController | ||
@RequestMapping(Constant.API_VERSION + "graph-connections/user") | ||
public class UserController { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@PostMapping | ||
public UserEntity create(@RequestBody UserEntity user) { | ||
this.checkUser(user, true); | ||
return this.userService.createUser(user); | ||
} | ||
|
||
@PutMapping | ||
public UserEntity update(@RequestBody UserEntity user) { | ||
this.checkUser(user, false); | ||
return this.userService.updateUser(user); | ||
} | ||
|
||
@DeleteMapping | ||
public void delete(@RequestBody List<String> userIds) { | ||
this.userService.deleteUser(userIds); | ||
} | ||
|
||
@GetMapping | ||
public IPage<UserEntity> list(@RequestParam(value = "user_name", | ||
required = false) | ||
String userName, | ||
@RequestParam(name = "page_no", | ||
required = false, | ||
defaultValue = "1") | ||
int pageNo, | ||
@RequestParam(name = "page_size", | ||
required = false, | ||
defaultValue = "10") | ||
int pageSize) { | ||
return this.userService.list(userName, pageNo, pageSize); | ||
} | ||
|
||
private void checkUser(UserEntity entity, boolean create) { | ||
Ex.check(StringUtils.isNotEmpty(entity.getUsername()), | ||
"common.param.cannot-be-null-or-empty", "user_name"); | ||
Ex.check(StringUtils.isNotEmpty(entity.getPassword()), | ||
"common.param.cannot-be-null-or-empty", "user_password"); | ||
if (create) { | ||
Ex.check(entity.getId() == null, | ||
"common.param.must-be-null", "id"); | ||
} else { | ||
Ex.check(entity.getId() != null, | ||
"common.param.cannot-be-null", "id"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.