Search in sources :

Example 11 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class GraphController method checkParamsValid.

private void checkParamsValid(int connId, VertexEntity entity, boolean create) {
    Ex.check(!StringUtils.isEmpty(entity.getLabel()), "common.param.cannot-be-null-or-empty", "label");
    // If schema doesn't exist, it will throw exception
    VertexLabelEntity vlEntity = this.vlService.get(entity.getLabel(), connId);
    IdStrategy idStrategy = vlEntity.getIdStrategy();
    if (create) {
        Ex.check(idStrategy.isCustomize(), () -> entity.getId() != null, "common.param.cannot-be-null", "id");
    } else {
        Ex.check(entity.getId() != null, "common.param.cannot-be-null", "id");
    }
    Set<String> nonNullableProps = vlEntity.getNonNullableProps();
    Map<String, Object> properties = entity.getProperties();
    Ex.check(properties.keySet().containsAll(nonNullableProps), "graph.vertex.all-nonnullable-prop.should-be-setted");
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Example 12 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class FileMappingController method checkVertexMappingValid.

private void checkVertexMappingValid(int connId, VertexMapping vertexMapping, FileMapping fileMapping) {
    VertexLabelEntity vl = this.vlService.get(vertexMapping.getLabel(), connId);
    Ex.check(!vl.getIdStrategy().isAutomatic(), "load.file-mapping.vertex.automatic-id-unsupported");
    Ex.check(!CollectionUtils.isEmpty(vertexMapping.getIdFields()), "load.file-mapping.vertex.id-fields-cannot-be-empty");
    FileSetting fileSetting = fileMapping.getFileSetting();
    List<String> columnNames = fileSetting.getColumnNames();
    Ex.check(columnNames.containsAll(vertexMapping.getIdFields()), "load.file-mapping.vertex.id-fields-should-in-column-names", vertexMapping.getIdFields(), columnNames);
    if (vl.getIdStrategy().isPrimaryKey()) {
        Ex.check(vertexMapping.getIdFields().size() == vl.getPrimaryKeys().size(), "load.file-mapping.vertex.id-fields-should-same-size-pks");
        Ex.check(!CollectionUtils.containsAny(vertexMapping.fieldMappingToMap().values(), vl.getPrimaryKeys()), "load.file-mapping.vertex.mapping-fields-cannot-contains-pk");
    } else {
        Ex.check(vertexMapping.getIdFields().size() == 1, "load.file-mapping.vertex.id-fields-should-only-one");
    }
    Ex.check(CollectionUtil.allUnique(vertexMapping.fieldMappingToMap().values()), "load.file-mapping.mapping-fields-should-no-duplicate");
    this.checkMappingValid(vertexMapping, fileMapping);
}
Also used : FileSetting(com.baidu.hugegraph.entity.load.FileSetting) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Example 13 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class VertexLabelController method checkConflicts.

@PostMapping("check_conflict")
public ConflictDetail checkConflicts(@PathVariable("connId") int connId, @RequestParam("reused_conn_id") int reusedConnId, @RequestBody ConflictCheckEntity entity) {
    Ex.check(!CollectionUtils.isEmpty(entity.getVlEntities()), "common.param.cannot-be-empty", "vertexlabels");
    Ex.check(CollectionUtils.isEmpty(entity.getPkEntities()), "common.param.must-be-null", "propertykeys");
    Ex.check(CollectionUtils.isEmpty(entity.getPiEntities()), "common.param.must-be-null", "propertyindexes");
    Ex.check(CollectionUtils.isEmpty(entity.getElEntities()), "common.param.must-be-null", "edgelabels");
    Ex.check(connId != reusedConnId, "schema.conn.cannot-reuse-self");
    Set<String> pkNames = new HashSet<>();
    Set<String> piNames = new HashSet<>();
    for (VertexLabelEntity e : entity.getVlEntities()) {
        pkNames.addAll(e.getPropNames());
        piNames.addAll(e.getIndexProps());
    }
    entity.setPkEntities(this.pkService.list(pkNames, reusedConnId, false));
    entity.setPiEntities(this.piService.list(piNames, reusedConnId, false));
    return this.vlService.checkConflict(entity, connId, false);
}
Also used : VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) HashSet(java.util.HashSet) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)13 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 HugeClient (com.baidu.hugegraph.driver.HugeClient)2 FileSetting (com.baidu.hugegraph.entity.load.FileSetting)2 IdStrategy (com.baidu.hugegraph.structure.constant.IdStrategy)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 GraphManager (com.baidu.hugegraph.driver.GraphManager)1 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)1 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 IllegalGremlinException (com.baidu.hugegraph.exception.IllegalGremlinException)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 ServerException (com.baidu.hugegraph.exception.ServerException)1 ClientException (com.baidu.hugegraph.rest.ClientException)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1