auth-server/src/main/java/com/stktrk/app/AppApplication.java

64 lines
2.5 KiB
Java

package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.github.javafaker.Faker;
import com.stktrk.app.configuration.GraphDbConfig;
import com.stktrk.app.db.ConnectionPool;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.StringJoiner;
// https://stackoverflow.com/questions/51221777/failed-to-configure-a-datasource-url-attribute-is-not-specified-and-no-embedd
@SpringBootApplication(exclude = {FlywayAutoConfiguration.class})
@RestController
public class AppApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
// klkjlkjlkjlkj
@GetMapping("/hello")
public String sayHello(@RequestParam(value = "myName", defaultValue = "World") String name) {
List<Vertex> x = List.of();
ArcadeGraph g = ConnectionPool.getGraph();
x = g.traversal().V().toList();
Vertex target = !x.isEmpty() ? x.get(new Random().nextInt(x.size())) : null;
Faker faker = new Faker();
Vertex res = g.traversal().addV("Profile").property("name", faker.name().firstName()).property("lastName", faker.name().lastName())
.next();
if (target != null) {
g.traversal().V(res.id()).addE("friend").to(target).iterate();
}
g.close();
x.add(res);
x.sort(Comparator.comparing(a -> a.id().toString()));
StringJoiner sj = new StringJoiner("<br />\n");
x.forEach(v -> sj.add(v.id().toString() + " - " + (String) v.property("name").value() + " " + (String) v.property("lastName").value()));
return "Hello, " + name + "! Added " + res.property("name").value() + ". There are " + x.size() + " vertices.<br/>\n" + sj;
}
@GetMapping("/delete")
public String delete() {
ArcadeGraph g = ConnectionPool.getGraph();
g.traversal().V().hasLabel("Profile").drop().iterate();
g.close();
return "Done.";
}
}