public <T> T removeProperty(final Vertex vertex, final String key) { return vertex.removeProperty(generateGetKey(key)); } }
public void project(Collection<String> projection) { if (projection.contains("*")) { return; } for (Vertex vertex : graph.getVertices()) { for (String key : vertex.getPropertyKeys()) { if (!projection.contains(key) && !PROTECTED_PROPERTY_KEYS.contains(key)) { vertex.removeProperty(key); } } } }
@Override public void migrateEntity( Vertex vertex, TypeMetadataSet<EntityTypeMetadata<TitanVertexMetadata>> types, Set<String> discriminators, TypeMetadataSet<EntityTypeMetadata<TitanVertexMetadata>> targetTypes, Set<String> targetDiscriminators) { for (String discriminator : discriminators) { if (!targetDiscriminators.contains(discriminator)) { vertex.removeProperty(TitanStoreSession.XO_DISCRIMINATORS_PROPERTY + discriminator); } } for (String discriminator : targetDiscriminators) { if (!discriminators.contains(discriminator)) { vertex.setProperty(TitanStoreSession.XO_DISCRIMINATORS_PROPERTY + discriminator, discriminator); } } }
@Override public void removeProperty(Vertex vertex, PrimitivePropertyMethodMetadata<TitanPropertyMetadata> metadata) { vertex.removeProperty(metadata.getDatastoreMetadata().getName()); }
private void updateMicroschemas(Vertex meshRoot) { Vertex microschemaRoot = meshRoot.getVertices(OUT, "HAS_MICROSCHEMA_ROOT").iterator().next(); Iterator<Vertex> microschemaIt = microschemaRoot.getVertices(OUT, "HAS_SCHEMA_CONTAINER_ITEM").iterator(); while (microschemaIt.hasNext()) { Vertex microschemaVertex = microschemaIt.next(); Iterator<Vertex> versionIt = microschemaVertex.getVertices(OUT, "HAS_PARENT_CONTAINER").iterator(); while (versionIt.hasNext()) { Vertex schemaVersion = versionIt.next(); // Update the version within the vertex int vertexVersion = schemaVersion.getProperty("version"); schemaVersion.removeProperty("version"); schemaVersion.setProperty("version", String.valueOf(vertexVersion) + ".0"); // Update the version within the json String json = schemaVersion.getProperty("json"); JsonObject schema = new JsonObject(json); int version = schema.getInteger("version"); schema.remove("version"); schema.put("version", String.valueOf(version) + ".0"); schemaVersion.setProperty("json", schema.toString()); } } }
@Override protected void unsetAttribute(PersistentEObject object, EAttribute attribute) { Vertex vertex = backend.getVertex(object.id()); String propertyName = attribute.getName(); if (attribute.isMany()) { propertyName += SEPARATOR + SIZE_LITERAL; Integer size = vertex.getProperty(propertyName); for (int i = 0; i < size; i++) { vertex.removeProperty(attribute.getName() + SEPARATOR + i); } } vertex.removeProperty(propertyName); }
private void updateSchemas(Vertex meshRoot) { Vertex schemaRoot = meshRoot.getVertices(OUT, "HAS_ROOT_SCHEMA").iterator().next(); Iterator<Vertex> schemaIt = schemaRoot.getVertices(OUT, "HAS_SCHEMA_CONTAINER_ITEM").iterator(); while (schemaIt.hasNext()) { Vertex schemaVertex = schemaIt.next(); Iterator<Vertex> versionIt = schemaVertex.getVertices(OUT, "HAS_PARENT_CONTAINER").iterator(); while (versionIt.hasNext()) { Vertex schemaVersion = versionIt.next(); // Update the version within the vertex int vertexVersion = schemaVersion.getProperty("version"); schemaVersion.removeProperty("version"); schemaVersion.setProperty("version", String.valueOf(vertexVersion) + ".0"); // Update the version within the json String json = schemaVersion.getProperty("json"); JsonObject schema = new JsonObject(json); Object versionValue = schema.getValue("version"); schema.remove("version"); if (versionValue instanceof String) { int version = Integer.valueOf((String) versionValue); schema.put("version", String.valueOf(version) + ".0"); } else { int version = Integer.valueOf((Integer) versionValue); schema.put("version", String.valueOf(version) + ".0"); } schemaVersion.setProperty("json", schema.toString()); } } }
private void migrateProperty(Vertex vertex, String oldPropertyKey, String newPropertyKey) { log.info("Migrating vertex: " + vertex.getId()); String value = vertex.getProperty(oldPropertyKey); vertex.removeProperty(oldPropertyKey); if (value != null) { vertex.setProperty(newPropertyKey, value); } }
protected void updConfigDb(Map<String, Object> data) throws Exception { String configId = (String)data.get("configId"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId")); Vertex config = graph.getVertexByKey("Config.configId", configId); if(config != null) { if(data.get("description") != null) { config.setProperty("description", data.get("description")); } else { config.removeProperty("description"); } if(data.get("properties") != null) { config.setProperty("properties", data.get("properties")); } else { config.removeProperty("properties"); } config.setProperty("updateDate", data.get("updateDate")); // updateUser updateUser.addEdge("Update", config); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected String activateUser(Map<String, Object> data) throws Exception { String email = (String)data.get("email"); String code = (String)data.get("code"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.email", email); if(user != null) { String s = user.getProperty("code"); if(code.equals(s)) { user.removeProperty("code"); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } return code; }
@Override protected void clearAttribute(PersistentEObject object, EAttribute attribute) { Vertex vertex = backend.getVertex(object.id()); Integer size = getSize(vertex, attribute); for (int i = 0; i < size; i++) { vertex.removeProperty(attribute.getName() + SEPARATOR + i); } setSize(vertex, attribute, 0); }
rule.setProperty("schema", schemaMap); } else { rule.removeProperty("schema");
private void migrateNode(Vertex node) { // Extract and remove the published flag from the node String publishFlag = node.getProperty("published"); node.removeProperty("published"); // Set the published flag to all node graph field containers Iterable<Vertex> containers = node.getVertices(Direction.OUT, "HAS_FIELD_CONTAINER"); for (Vertex container : containers) { if (publishFlag != null) { container.setProperty("published", publishFlag); } } log.info("Migrated node {" + node.getProperty("uuid") + "}"); }
protected void updEtag(Map<String, Object> data) throws Exception { String ruleClass = (String)data.get("ruleClass"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass); if(rule != null) { rule.setProperty("enableEtag", data.get("enableEtag")); String cacheControl = (String)data.get("cacheControl"); if(cacheControl != null) { rule.setProperty("cacheControl", cacheControl); } else { rule.removeProperty("cacheControl"); } rule.setProperty("updateDate", data.get("updateDate")); Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap"); ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache"); if(cache != null) { cache.remove(ruleClass); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
private void migrateContainer(Vertex container) { boolean isPublished = false; Iterable<Edge> edges = container.getEdges(Direction.IN, "HAS_FIELD_CONTAINER"); // Check whether the container is published for (Edge edge : edges) { String type = edge.getProperty("edgeType"); if ("P".equals(type)) { isPublished = true; } } // The container is not published anywhere. Remove the bogus publish webroot info which otherwise causes publish webroot conflicts with new versions. if (!isPublished) { if (container.getProperty(WEBROOT_PUB) != null) { log.info("Found inconsistency on container {" + container.getProperty("uuid") + "}"); container.removeProperty(WEBROOT_PUB); log.info("Inconsistency fixed"); } } }
protected void updRole(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId")); Vertex role = graph.getVertexByKey("Role.roleId", data.get("roleId")); if(role != null) { String host = (String)data.get("host"); if(host != null && host.length() > 0) { if(!host.equals(role.getProperty("host"))) role.setProperty("host", host); } else { role.removeProperty("host"); } String description = (String)data.get("description"); if(description != null && !description.equals(role.getProperty("description"))) { role.setProperty("description", description); } role.setProperty("updateDate", data.get("updateDate")); updateUser.addEdge("Update", role); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
private void updateProperty(String propertyName, Vertex node) { Object obj = node.getProperty(propertyName); if (obj == null) { return; } if (!(obj instanceof String)) { if (log.isDebugEnabled()) { log.debug("Property '{}' for node '{}' in database is no string so we don't convert it. {}: '{}'", propertyName, node.getProperty(UUID), obj.getClass(), obj); } return; } String strVal = (String) obj; Number numVal; try { numVal = format.parse(strVal); } catch (ParseException e) { log.warn("Could not parse the number '{}', for field '{}' in node {}", strVal, propertyName, node.getId()); numVal = 0; } node.removeProperty(propertyName); node.setProperty(propertyName, numVal); }
protected void updCors(Map<String, Object> data) throws Exception { String ruleClass = (String)data.get("ruleClass"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass); if(rule != null) { rule.setProperty("enableCors", data.get("enableCors")); String corsHosts = (String)data.get("corsHosts"); if(corsHosts != null) { rule.setProperty("corsHosts", corsHosts); } else { rule.removeProperty("corsHosts"); } rule.setProperty("updateDate", data.get("updateDate")); Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap"); ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache"); if(cache != null) { cache.remove(ruleClass); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
protected void revokeRefreshToken(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.get("userId")); if(user != null) { Vertex credential = user.getProperty("credential"); if(credential != null) { credential.removeProperty("clientRefreshTokens"); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
@Override protected void unsetReference(PersistentEObject object, EReference reference) { Vertex vertex = backend.getVertex(object.id()); if (!reference.isMany()) { Edge edge = Iterables.getOnlyElement(vertex.getEdges(Direction.OUT, reference.getName()), null); if (nonNull(edge)) { edge.remove(); } } else { for (Edge edge : vertex.query().labels(reference.getName()).direction(Direction.OUT).edges()) { edge.remove(); } vertex.removeProperty(reference.getName() + SEPARATOR + SIZE_LITERAL); } }