Java Code Examples for com.baidu.hugegraph.util.E#checkArgumentNotNull()

The following examples show how to use com.baidu.hugegraph.util.E#checkArgumentNotNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardAuthenticator.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
/**
 * Verify if a user is legal
 * @param username  the username for authentication
 * @param password  the password for authentication
 * @return String No permission if return ROLE_NONE else return a role
 */
@Override
public RolePermission authenticate(String username, String password) {
    E.checkArgumentNotNull(username,
                           "The username parameter can't be null");
    E.checkArgumentNotNull(password,
                           "The password parameter can't be null");

    RolePermission role = this.graph().userManager().loginUser(username,
                                                               password);
    if (role == null) {
        role = ROLE_NONE;
    } else if (username.equals(USER_ADMIN)) {
        role = ROLE_ADMIN;
    }
    return role;
}
 
Example 2
Source File: ConfigListConvOption.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public ConfigListConvOption(String name, boolean required, String desc,
                            Predicate<List<T>> pred, Function<T, R> convert,
                            Class<T> clazz, List<T> values) {
    super(name, required, desc, pred,
          (Class<List<T>>) values.getClass(), values);
    E.checkNotNull(convert, "convert");
    if (clazz == null && values.size() > 0) {
        clazz = (Class<T>) values.get(0).getClass();
    }
    E.checkArgumentNotNull(clazz, "Element class can't be null");
    this.elemClass = clazz;
    this.converter = convert;
}
 
Example 3
Source File: StandardTaskScheduler.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public <V> Future<?> restore(HugeTask<V> task) {
    E.checkArgumentNotNull(task, "Task can't be null");
    E.checkArgument(!this.tasks.containsKey(task.id()),
                    "Task '%s' is already in the queue", task.id());
    E.checkArgument(!task.isDone() && !task.completed(),
                    "No need to restore completed task '%s' with status %s",
                    task.id(), task.status());
    task.status(TaskStatus.RESTORING);
    task.retry();
    return this.submitTask(task);
}
 
Example 4
Source File: Line.java    From hugegraph-loader with Apache License 2.0 5 votes vote down vote up
public Line(String rawLine, Map<String, Object> keyValues) {
    E.checkArgumentNotNull(rawLine, "The rawLine can't be null");
    E.checkArgumentNotNull(keyValues, "The keyValues can't be null");
    this.rawLine = rawLine;
    this.keyValues = keyValues;
    this.names = getNames(keyValues);
    this.values = getValues(keyValues, this.names);
}
 
Example 5
Source File: DeleteExpiredJob.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static <V> void asyncDeleteExpiredObject(HugeGraphParams graph,
                                                V object) {
    E.checkArgumentNotNull(object, "The object can't be null");
    JobCounters.JobCounter jobCounter = JOB_COUNTERS.jobCounter(graph);
    if (!jobCounter.addAndTriggerDelete(object)) {
        return;
    }
    if (jobCounter.jobs() >= MAX_JOBS) {
        LOG.debug("Pending delete expired objects jobs size {} has " +
                  "reached the limit {}, abandon {}",
                  jobCounter.jobs(), MAX_JOBS, object);
        return;
    }
    jobCounter.increment();
    EphemeralJob<V> job = newDeleteExpiredElementJob(jobCounter, object);
    jobCounter.clear(object);
    HugeTask<?> task;
    try {
        task = EphemeralJobBuilder.<V>of(graph.graph())
                                  .name("delete_expired_object")
                                  .job(job)
                                  .schedule();
    } catch (Throwable e) {
        jobCounter.decrement();
        if (e.getMessage().contains("Pending tasks size") &&
            e.getMessage().contains("has exceeded the max limit")) {
            // Reach tasks limit, just ignore it
            return;
        }
        throw e;
    }
    /*
     * If TASK_SYNC_DELETION is true, wait async thread done before
     * continue. This is used when running tests.
     */
    if (graph.configuration().get(CoreOptions.TASK_SYNC_DELETION)) {
        task.syncWait();
    }
}
 
Example 6
Source File: GraphIndexTransaction.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private RemoveLeftIndexJob(ConditionQuery query, HugeElement element) {
    E.checkArgumentNotNull(query, "query");
    E.checkArgumentNotNull(element, "element");
    this.query = query;
    this.element = element;
    this.tx = null;
}
 
Example 7
Source File: DataTypeUtil.java    From hugegraph-loader with Apache License 2.0 5 votes vote down vote up
private static List<Object> split(String key, String rawValue,
                                  InputSource source) {
    List<Object> valueColl = new ArrayList<>();
    if (rawValue.isEmpty()) {
        return valueColl;
    }
    E.checkState(AbstractSource.class.isAssignableFrom(source.getClass()),
                 "Only accept AbstractSource when parse multi values, " +
                 "but got '%s'", source.getClass().getName());
    ListFormat listFormat = ((AbstractSource) source).listFormat();
    E.checkArgumentNotNull(listFormat, "The list_format must be set when " +
                                       "parse list or set values");

    String startSymbol = listFormat.startSymbol();
    String endSymbol = listFormat.endSymbol();
    E.checkArgument(rawValue.length() >=
                    startSymbol.length() + endSymbol.length(),
                    "The value(key='%s') '%s' length(%s) must be >= " +
                    "start symbol '%s' + end symbol '%s' length",
                    key, rawValue, rawValue.length(),
                    startSymbol, endSymbol);
    E.checkArgument(rawValue.startsWith(startSymbol) &&
                    rawValue.endsWith(endSymbol),
                    "The value(key='%s') must start with '%s' and " +
                    "end with '%s', but got '%s'",
                    key, startSymbol, endSymbol, rawValue);
    rawValue = rawValue.substring(startSymbol.length(),
                                  rawValue.length() - endSymbol.length());
    String elemDelimiter = listFormat.elemDelimiter();
    Splitter.on(elemDelimiter).split(rawValue).forEach(value -> {
        if (!listFormat.ignoredElems().contains(value)) {
            valueColl.add(value);
        }
    });
    return valueColl;
}
 
Example 8
Source File: CountRequest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
public CountRequest build() {
    E.checkArgumentNotNull(this.request.source,
                           "The source can't be null");
    for (Step.Builder builder : this.stepBuilders) {
        this.request.steps.add(builder.build());
    }
    E.checkArgument(this.request.steps != null &&
                    !this.request.steps.isEmpty(),
                    "The steps can't be null or empty");
    checkDedupSize(this.request.dedupSize);
    return this.request;
}
 
Example 9
Source File: IndexLabel.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Override
public Builder userdata(String key, Object val) {
    E.checkArgumentNotNull(key, "The user data key can't be null");
    E.checkArgumentNotNull(val, "The user data value can't be null");
    this.indexLabel.userdata.put(key, val);
    return this;
}
 
Example 10
Source File: VertexLabel.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Override
public Builder userdata(String key, Object val) {
    E.checkArgumentNotNull(key, "The user data key can't be null");
    E.checkArgumentNotNull(val, "The user data value can't be null");
    this.vertexLabel.userdata.put(key, val);
    return this;
}
 
Example 11
Source File: SchemaManager.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public VertexLabel getVertexLabel(String name) {
    E.checkArgumentNotNull(name, "The name parameter can't be null");
    VertexLabel vertexLabel = this.transaction.getVertexLabel(name);
    checkExists(HugeType.VERTEX_LABEL, vertexLabel, name);
    return vertexLabel;
}
 
Example 12
Source File: VertexLabelAPI.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public void checkCreate(boolean isBatch) {
    E.checkArgumentNotNull(this.name,
                           "The name of vertex label can't be null");
}
 
Example 13
Source File: SchemaManager.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public EdgeLabel getEdgeLabel(String name) {
    E.checkArgumentNotNull(name, "The name parameter can't be null");
    EdgeLabel edgeLabel = this.transaction.getEdgeLabel(name);
    checkExists(HugeType.EDGE_LABEL, edgeLabel, name);
    return edgeLabel;
}
 
Example 14
Source File: SchemaTransaction.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Watched(prefix = "schema")
public VertexLabel getVertexLabel(Id id) {
    E.checkArgumentNotNull(id, "Vertex label id can't be null");
    return this.getSchema(HugeType.VERTEX_LABEL, id);
}
 
Example 15
Source File: LoadProgress.java    From hugegraph-loader with Apache License 2.0 4 votes vote down vote up
public void markLoaded(InputStruct struct, boolean markAll) {
    InputProgress progress = this.inputProgress.get(struct.id());
    E.checkArgumentNotNull(progress, "Invalid mapping '%s'", struct);
    progress.markLoaded(markAll);
}
 
Example 16
Source File: EdgeLabelAPI.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public void checkCreate(boolean isBatch) {
    E.checkArgumentNotNull(this.name,
                           "The name of edge label can't be null");
}
 
Example 17
Source File: SchemaTransaction.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Watched(prefix = "schema")
public PropertyKey getPropertyKey(Id id) {
    E.checkArgumentNotNull(id, "Property key id can't be null");
    return this.getSchema(HugeType.PROPERTY_KEY, id);
}
 
Example 18
Source File: SchemaTransaction.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Watched(prefix = "schema")
public IndexLabel getIndexLabel(Id id) {
    E.checkArgumentNotNull(id, "Index label id can't be null");
    return this.getSchema(HugeType.INDEX_LABEL, id);
}
 
Example 19
Source File: HugeTraverser.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public Node(Id id, Node parent) {
    E.checkArgumentNotNull(id, "Id of Node can't be null");
    this.id = id;
    this.parent = parent;
}
 
Example 20
Source File: PersonalRankAPI.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@POST
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String personalRank(@Context GraphManager manager,
                           @PathParam("graph") String graph,
                           RankRequest request) {
    E.checkArgumentNotNull(request, "The rank request body can't be null");
    E.checkArgument(request.source != null,
                    "The source vertex id of rank request can't be null");
    E.checkArgument(request.label != null,
                    "The edge label of rank request can't be null");
    E.checkArgument(request.alpha > 0 && request.alpha <= 1.0,
                    "The alpha of rank request must be in range (0, 1], " +
                    "but got '%s'", request.alpha);
    E.checkArgument(request.degree > 0 || request.degree == NO_LIMIT,
                    "The degree of rank request must be > 0, but got: %s",
                    request.degree);
    E.checkArgument(request.limit > 0 || request.limit == NO_LIMIT,
                    "The limit of rank request must be > 0, but got: %s",
                    request.limit);
    E.checkArgument(request.maxDepth > 0 &&
                    request.maxDepth <= Long.valueOf(DEFAULT_MAX_DEPTH),
                    "The max depth of rank request must be " +
                    "in range (0, %s], but got '%s'",
                    DEFAULT_MAX_DEPTH, request.maxDepth);

    LOG.debug("Graph [{}] get personal rank from '{}' with " +
              "edge label '{}', alpha '{}', degree '{}', " +
              "max depth '{}' and sorted '{}'",
              graph, request.source, request.label, request.alpha,
              request.degree, request.maxDepth, request.sorted);

    Id sourceId = HugeVertex.getIdValue(request.source);
    HugeGraph g = graph(manager, graph);

    PersonalRankTraverser traverser;
    traverser = new PersonalRankTraverser(g, request.alpha, request.degree,
                                          request.maxDepth);
    Map<Id, Double> ranks = traverser.personalRank(sourceId, request.label,
                                                   request.withLabel);
    ranks = HugeTraverser.topN(ranks, request.sorted, request.limit);
    return manager.serializer(g).writeMap(ranks);
}