Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): clean some code for release #2348

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,40 @@

package org.apache.hugegraph.api.auth;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Singleton;
import javax.security.sasl.AuthenticationException;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.NotAuthorizedException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;

import org.apache.commons.lang3.StringUtils;
import org.apache.hugegraph.core.GraphManager;
import org.apache.hugegraph.define.Checkable;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.api.API;
import org.apache.hugegraph.api.filter.AuthenticationFilter;
import org.apache.hugegraph.api.filter.StatusFilter.Status;
import org.apache.hugegraph.auth.AuthConstant;
import org.apache.hugegraph.auth.UserWithRole;
import org.apache.hugegraph.core.GraphManager;
import org.apache.hugegraph.define.Checkable;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;

import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Singleton;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.NotAuthorizedException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;

@Path("graphs/{graph}/auth")
@Singleton
@Tag(name = "LoginAPI")
Expand All @@ -63,8 +64,7 @@ public class LoginAPI extends API {
@Status(Status.OK)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String login(@Context GraphManager manager,
@PathParam("graph") String graph,
public String login(@Context GraphManager manager, @PathParam("graph") String graph,
JsonLogin jsonLogin) {
LOG.debug("Graph [{}] user login: {}", graph, jsonLogin);
checkCreatingBody(jsonLogin);
Expand Down Expand Up @@ -94,13 +94,10 @@ public void logout(@Context GraphManager manager,
LOG.debug("Graph [{}] user logout: {}", graph, auth);

if (!auth.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) {
throw new BadRequestException(
"Only HTTP Bearer authentication is supported");
throw new BadRequestException("Only HTTP Bearer authentication is supported");
}

String token = auth.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX
.length());

String token = auth.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX.length());
manager.authManager().logoutUser(token);
}

Expand All @@ -119,12 +116,10 @@ public String verifyToken(@Context GraphManager manager,
LOG.debug("Graph [{}] get user: {}", graph, token);

if (!token.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) {
throw new BadRequestException(
"Only HTTP Bearer authentication is supported");
throw new BadRequestException("Only HTTP Bearer authentication is supported");
}

token = token.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX
.length());
token = token.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX.length());
UserWithRole userWithRole = manager.authManager().validateUser(token);

HugeGraph g = graph(manager, graph);
Expand All @@ -144,8 +139,7 @@ private static class JsonLogin implements Checkable {

@Override
public void checkCreate(boolean isBatch) {
E.checkArgument(!StringUtils.isEmpty(this.name),
"The name of user can't be null");
E.checkArgument(!StringUtils.isEmpty(this.name), "The name of user can't be null");
E.checkArgument(!StringUtils.isEmpty(this.password),
"The password of user can't be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ private <T extends HugeElement> Iterator<T> filterUnmatchedRecords(
Iterator<T> results,
Query query) {
// Filter unused or incorrect records
return new FilterIterator<T>(results, elem -> {
return new FilterIterator<>(results, elem -> {
// TODO: Left vertex/edge should to be auto removed via async task
if (elem.schemaLabel().undefined()) {
LOG.warn("Left record is found: id={}, label={}, properties={}",
Expand Down Expand Up @@ -1861,7 +1861,7 @@ private Iterator<?> joinTxEdges(Query query, Iterator<HugeEdge> edges,
return edges;
}
// Filter edges that belong to deleted vertex
return new FilterIterator<HugeEdge>(edges, edge -> {
return new FilterIterator<>(edges, edge -> {
for (HugeVertex v : removingVertices.values()) {
if (edge.belongToVertex(v)) {
return false;
Expand Down Expand Up @@ -1917,7 +1917,7 @@ private <V extends HugeElement> Iterator<V> joinTxRecords(
!removedTxRecords.containsKey(id);
});

return new ExtendableIterator<V>(txResults.iterator(), backendResults);
return new ExtendableIterator<>(txResults.iterator(), backendResults);
}

private void checkTxVerticesCapacity() throws LimitExceedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.PropertyKey;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;

import org.apache.hugegraph.util.E;

public class HugeEdgeProperty<V> extends HugeProperty<V> {

public HugeEdgeProperty(HugeElement owner, PropertyKey key, V value) {
Expand Down Expand Up @@ -67,7 +66,7 @@ public int hashCode() {

public HugeEdgeProperty<V> switchEdgeOwner() {
assert this.owner instanceof HugeEdge;
return new HugeEdgeProperty<V>(((HugeEdge) this.owner).switchOwner(),
this.pkey, this.value);
return new HugeEdgeProperty<>(((HugeEdge) this.owner).switchOwner(),
this.pkey, this.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@

package org.apache.hugegraph.traversal.optimize;

import java.util.LinkedList;
import java.util.List;

import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.ProviderOptimizationStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.step.Mutating;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep;
import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality;

import java.util.LinkedList;
import java.util.List;

public class HugePrimaryKeyStrategy
extends AbstractTraversalStrategy<TraversalStrategy.ProviderOptimizationStrategy>
implements ProviderOptimizationStrategy {
Expand All @@ -53,17 +53,19 @@ public void apply(Traversal.Admin<?, ?> traversal) {
for (int i = 0, s = stepList.size(); i < s; i++) {
Step step = stepList.get(i);

if (i == 0 && AddVertexStartStep.class.isInstance(step)) {
if (i == 0 && step instanceof AddVertexStartStep) {
curAddStep = (Mutating) step;
continue;
} else if (curAddStep == null && AddVertexStep.class.isInstance((step))) {
} else if (curAddStep == null && (step) instanceof AddVertexStep) {
curAddStep = (Mutating) step;
continue;
}

if (curAddStep == null) continue;
if (curAddStep == null) {
continue;
}

if (!AddPropertyStep.class.isInstance(step)) {
if (!(step instanceof AddPropertyStep)) {
curAddStep = null;
continue;
}
Expand All @@ -89,8 +91,8 @@ public void apply(Traversal.Admin<?, ?> traversal) {

curAddStep.configure(kvs);

if (kvList.size() > 0) {
curAddStep.configure(kvList.toArray(new Object[kvList.size()]));
if (!kvList.isEmpty()) {
curAddStep.configure(kvList.toArray(new Object[0]));
}

removeSteps.add(step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum CollectionType implements SerialEnum {
this.name = name;
}

@Override
public byte code() {
return this.code;
}
Expand Down
Loading