Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
498 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.api.auth; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.baidu.hugegraph.client.RestClient; | ||
import com.baidu.hugegraph.rest.RestResult; | ||
import com.baidu.hugegraph.structure.auth.Project; | ||
import com.baidu.hugegraph.structure.constant.HugeType; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class ProjectAPI extends AuthAPI { | ||
|
||
private static final String ACTION_ADD_GRAPH = "add_graph"; | ||
private static final String ACTION_REMOVE_GRAPH = "remove_graph"; | ||
|
||
public ProjectAPI(RestClient client, String graph) { | ||
super(client, graph); | ||
} | ||
|
||
@Override | ||
protected String type() { | ||
return HugeType.PROJECT.string(); | ||
} | ||
|
||
public Project create(Project project) { | ||
RestResult result = this.client.post(this.path(), project); | ||
return result.readObject(Project.class); | ||
} | ||
|
||
public Project get(Object id) { | ||
RestResult result = this.client.get(this.path(), formatEntityId(id)); | ||
return result.readObject(Project.class); | ||
} | ||
|
||
public List<Project> list(long limit) { | ||
checkLimit(limit, "Limit"); | ||
Map<String, Object> params = ImmutableMap.of("limit", limit); | ||
RestResult result = this.client.get(this.path(), params); | ||
return result.readList(this.type(), Project.class); | ||
} | ||
|
||
public Project update(Project project) { | ||
String id = formatEntityId(project.id()); | ||
RestResult result = this.client.put(this.path(), id, project); | ||
return result.readObject(Project.class); | ||
} | ||
|
||
public void delete(Object id) { | ||
this.client.delete(this.path(), formatEntityId(id)); | ||
} | ||
|
||
public Project addGraphs(Object projectId, Set<String> graphs) { | ||
Project project = new Project(); | ||
project.graphs(graphs); | ||
RestResult result = this.client.put(this.path(), | ||
formatEntityId(projectId), | ||
project, | ||
ImmutableMap.of("action", | ||
ACTION_ADD_GRAPH)); | ||
return result.readObject(Project.class); | ||
} | ||
|
||
public Project removeGraphs(Object projectId, Set<String> graphs) { | ||
Project project = new Project(); | ||
project.graphs(graphs); | ||
RestResult result = this.client.put(this.path(), | ||
formatEntityId(projectId), | ||
project, | ||
ImmutableMap.of("action", | ||
ACTION_REMOVE_GRAPH)); | ||
return result.readObject(Project.class); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -57,6 +57,8 @@ public enum HugeResourceType { | ||
|
||
USER_GROUP, | ||
|
||
PROJECT, | ||
|
||
TARGET, | ||
|
||
METRICS, | ||
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,134 @@ | ||
/* | ||
* 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.structure.auth; | ||
|
||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import com.baidu.hugegraph.structure.constant.HugeType; | ||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class Project extends AuthElement { | ||
|
||
@JsonProperty("project_name") | ||
private String name; | ||
@JsonProperty("project_admin_group") | ||
private String adminGroup; | ||
@JsonProperty("project_op_group") | ||
private String opGroup; | ||
@JsonProperty("project_graphs") | ||
private Set<String> graphs; | ||
@JsonProperty("project_target") | ||
private String target; | ||
@JsonProperty("project_description") | ||
private String description; | ||
|
||
@JsonProperty("project_create") | ||
@JsonFormat(pattern = DATE_FORMAT) | ||
private Date create; | ||
@JsonProperty("project_update") | ||
@JsonFormat(pattern = DATE_FORMAT) | ||
private Date update; | ||
@JsonProperty("project_creator") | ||
private String creator; | ||
|
||
public Project() { | ||
} | ||
|
||
public Project(Object id) { | ||
this(id, null, null); | ||
} | ||
|
||
public Project(String name) { | ||
this(name, null); | ||
} | ||
|
||
public Project(String name, String description) { | ||
this(null, name, description); | ||
} | ||
|
||
public Project(Object id, String name, String description) { | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public String name() { | ||
return this.name; | ||
} | ||
|
||
public void name(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String adminGroup() { | ||
return this.adminGroup; | ||
} | ||
|
||
public String opGroup() { | ||
return this.opGroup; | ||
} | ||
|
||
public Set<String> graphs() { | ||
return this.graphs; | ||
} | ||
|
||
public void graphs(Set<String> graphs) { | ||
if (graphs != null) { | ||
this.graphs = new HashSet<>(graphs); | ||
} else { | ||
this.graphs = null; | ||
} | ||
} | ||
|
||
public String target() { | ||
return this.target; | ||
} | ||
|
||
public String description() { | ||
return this.description; | ||
} | ||
|
||
public void description(String description) { | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String type() { | ||
return HugeType.PROJECT.string(); | ||
} | ||
|
||
@Override | ||
public Date createTime() { | ||
return this.create; | ||
} | ||
|
||
@Override | ||
public Date updateTime() { | ||
return this.update; | ||
} | ||
|
||
@Override | ||
public String creator() { | ||
return this.creator; | ||
} | ||
} |
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.