use of com.baidu.hugegraph.entity.load.EdgeMapping in project incubator-hugegraph-toolchain by apache.
the class LoadTaskService method buildEdgeMappings.
private List<com.baidu.hugegraph.loader.mapping.EdgeMapping> buildEdgeMappings(GraphConnection connection, FileMapping fileMapping) {
int connId = connection.getId();
List<com.baidu.hugegraph.loader.mapping.EdgeMapping> eMappings = new ArrayList<>();
for (EdgeMapping mapping : fileMapping.getEdgeMappings()) {
List<String> sourceFields = mapping.getSourceFields();
List<String> targetFields = mapping.getTargetFields();
EdgeLabelEntity el = this.elService.get(mapping.getLabel(), connId);
VertexLabelEntity svl = this.vlService.get(el.getSourceLabel(), connId);
VertexLabelEntity tvl = this.vlService.get(el.getTargetLabel(), connId);
Map<String, String> fieldMappings = mapping.fieldMappingToMap();
/*
* When id strategy is customize or primaryKeys contains
* just one field, the param 'unfold' can be true
*/
boolean unfoldSource = true;
if (svl.getIdStrategy().isPrimaryKey()) {
List<String> primaryKeys = svl.getPrimaryKeys();
Ex.check(sourceFields.size() >= 1 && sourceFields.size() == primaryKeys.size(), "When the source vertex ID strategy is CUSTOMIZED, " + "you must select at least one column in the file " + "as the id");
for (int i = 0; i < primaryKeys.size(); i++) {
fieldMappings.put(sourceFields.get(i), primaryKeys.get(i));
}
if (sourceFields.size() > 1) {
unfoldSource = false;
}
}
boolean unfoldTarget = true;
if (tvl.getIdStrategy().isPrimaryKey()) {
List<String> primaryKeys = tvl.getPrimaryKeys();
Ex.check(targetFields.size() >= 1 && targetFields.size() == primaryKeys.size(), "When the target vertex ID strategy is CUSTOMIZED, " + "you must select at least one column in the file " + "as the id");
for (int i = 0; i < primaryKeys.size(); i++) {
fieldMappings.put(targetFields.get(i), primaryKeys.get(i));
}
if (targetFields.size() > 1) {
unfoldTarget = false;
}
}
com.baidu.hugegraph.loader.mapping.EdgeMapping eMapping;
eMapping = new com.baidu.hugegraph.loader.mapping.EdgeMapping(sourceFields, unfoldSource, targetFields, unfoldTarget);
// set label
eMapping.label(mapping.getLabel());
// set field_mapping
eMapping.mappingFields(fieldMappings);
// set value_mapping
eMapping.mappingValues(mapping.valueMappingToMap());
// set selected
eMapping.selectedFields().addAll(sourceFields);
eMapping.selectedFields().addAll(targetFields);
eMapping.selectedFields().addAll(fieldMappings.keySet());
// set null_values
Set<Object> nullValues = new HashSet<>();
nullValues.addAll(mapping.getNullValues().getChecked());
nullValues.addAll(mapping.getNullValues().getCustomized());
eMapping.nullValues(nullValues);
eMappings.add(eMapping);
}
return eMappings;
}
use of com.baidu.hugegraph.entity.load.EdgeMapping in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method updateEdgeMapping.
@PutMapping("{id}/edge-mappings/{emid}")
public FileMapping updateEdgeMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @PathVariable("emid") String emId, @RequestBody EdgeMapping newEntity) {
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
this.checkEdgeMappingValid(connId, newEntity, mapping);
EdgeMapping edgeMapping = mapping.getEdgeMapping(emId);
Ex.check(edgeMapping != null, "load.file-mapping.edge-mapping.not-exist.id", emId);
newEntity.setId(emId);
Set<EdgeMapping> edgeMappings = mapping.getEdgeMappings();
edgeMappings.remove(edgeMapping);
edgeMappings.add(newEntity);
this.service.update(mapping);
return mapping;
}
use of com.baidu.hugegraph.entity.load.EdgeMapping in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method deleteEdgeMapping.
@DeleteMapping("{id}/edge-mappings/{emid}")
public FileMapping deleteEdgeMapping(@PathVariable("id") int id, @PathVariable("emid") String emid) {
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
EdgeMapping edgeMapping = mapping.getEdgeMapping(emid);
boolean removed = mapping.getEdgeMappings().remove(edgeMapping);
if (!removed) {
throw new ExternalException("load.file-mapping.edge-mapping.not-exist.id", emid);
}
this.service.update(mapping);
return mapping;
}
Aggregations