@Override
  protected void onAfterDatabaseCreation(final OrientBaseGraph graph) {
    System.out.println("Creating graph schema...");

    // CREATE BASIC SCHEMA
    OrientVertexType personClass = graph.createVertexType("Person");
    personClass.createProperty("id", OType.STRING);
    personClass.createProperty("name", OType.STRING);
    personClass.createProperty("birthday", OType.DATE);
    personClass.createProperty("children", OType.STRING);

    OrientVertexType person = graph.getVertexType("Person");
    person.createIndex("Person.name", OClass.INDEX_TYPE.UNIQUE, "name");

    OrientVertexType customer = graph.createVertexType("Customer", person);
    customer.createProperty("totalSold", OType.DECIMAL);

    OrientVertexType provider = graph.createVertexType("Provider", person);
    provider.createProperty("totalPurchased", OType.DECIMAL);

    factory = new OrientGraphFactory(graph.getRawGraph().getURL(), "admin", "admin", false);
    factory.setStandardElementConstraints(false);

    v = createVertex(graph, 0, 0, 0).getIdentity();
  }
예제 #2
0
 public String getRoleProperty(String roleName, String key, String def) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   ORole role = security.getRole(roleName);
   if (role == null) return def;
   String ret = role.getDocument().field("properties." + key);
   if (ret == null) ret = def;
   return ret;
 }
예제 #3
0
  public List<String> listPublicDomains() {

    String q = "select from Space where role is not null";

    List<ODocument> docs = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(q));

    return new GenericNodeCollection<String>(docs, new NameAttributeProvider());
  }
예제 #4
0
 public List<ODocument> query(String query) {
   try {
     List<ODocument> docs = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(query));
     return docs;
   } catch (Exception ex) {
     ex.printStackTrace();
     return new ArrayList<ODocument>();
   }
 }
예제 #5
0
 public List<String> listRoles() {
   List<ODocument> list =
       graph
           .getRawGraph()
           .query(new OSQLSynchQuery<ODocument>("SELECT FROM orole WHERE type='template'"));
   return new GenericNodeCollection<String>(
       list,
       new AttributeProvider<String>() {
         @Override
         public String getValue(ODocument doc) {
           return doc.field("name");
         }
       });
 }
예제 #6
0
  public List<String> listUsers(String from, String max, String pattern) {

    String q = "SELECT FROM ouser";
    if (pattern != null) if (!"".equals(pattern)) q += " WHERE name like '" + pattern + "'";
    q += " SKIP " + from;
    q += " LIMIT " + max;
    List<ODocument> list = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(q));
    return new GenericNodeCollection<String>(
        list,
        new AttributeProvider<String>() {
          @Override
          public String getValue(ODocument doc) {
            return doc.field("name");
          }
        });
  }
예제 #7
0
 public void createRole(String roleName) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   if (security.getRole(roleName) == null) {
     ORole role = security.createRole(roleName, ALLOW_MODES.ALLOW_ALL_BUT);
     //			role.addRule(ORule.ResourceGeneric.DATABASE, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.SCHEMA, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, OMetadataDefault.CLUSTER_INTERNAL_NAME,
     // ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, "orole", ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, "ouser", ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.COMMAND, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.RECORD_HOOK, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.FUNCTION, null, ORole.PERMISSION_ALL);
     role.getDocument().field("type", "template");
     role.save();
   }
 }
예제 #8
0
 private Vertex getRoot(String cls) {
   try {
     List<ODocument> list =
         graph
             .getRawGraph()
             .query(
                 new OSQLSynchQuery<ODocument>(
                     "SELECT FROM "
                         + GDomConfig.global().getRootClass()
                         + " WHERE tag='"
                         + cls
                         + "'"));
     if (list == null) return null;
     if (!(list.size() > 0)) return null;
     return graph.getVertex(list.get(0).getIdentity());
   } catch (Exception ex) {
     return null;
   }
 }
예제 #9
0
  public List<String> listDomains(String username) {

    Set<? extends OSecurityRole> roles = graph.getRawGraph().getUser().getRoles();
    for (OSecurityRole role : roles) {
      if (role.hasRule(ResourceGeneric.BYPASS_RESTRICTED, null)) {
        return new GenericNodeCollection<String>(
            query("select from " + GDomConfig.global().getRootClass()),
            new NameAttributeProvider());
      }
    }

    String q =
        "select from ( select expand(domain) from (select from orole where @this in (select expand(roles) from ouser where name = '"
            + username
            + "')))";

    List<ODocument> list = query(q);

    return new GenericNodeCollection<String>(list, new NameAttributeProvider());
  }
예제 #10
0
 public void setRoleProperty(String roleName, String key, String value) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   ORole role = security.getRole(roleName);
   if (role == null) return;
   role.getDocument().field("properties." + key, value);
 }
예제 #11
0
 public void execute(String cmd) {
   graph.getRawGraph().command(new OCommandSQL(cmd)).execute();
 }