Пример #1
0
 public void assignConceptForUpdate(Concept concept) {
   log.debug(":: assigning concept for update =" + concept);
   conceptsForUpdate.add(
       template.getNode(concept.getNodeId()),
       NamespaceConstants.DATE_UPDATED,
       new ValueContext(concept.getDateUpdated()).indexNumeric());
 }
Пример #2
0
 public void assignConceptForEnrichment(Concept concept) {
   synchronized (lock) {
     conceptsForEnrich.add(
         template.getNode(concept.getNodeId()),
         NamespaceConstants.DATE_ENRICHED,
         new ValueContext(concept.getDateEnriched()).indexNumeric());
   }
 }
Пример #3
0
  public Node persist(Concept concept) {

    Node node = null;

    /** extract node from index before creating */

    // regular index
    if (concept.getId() != null) {
      Node inIndex = getConcept(NamespaceConstants.NAME + NamespaceConstants.TYPE, concept.getId());
      if (inIndex != null) {
        node = inIndex;
      } else {
        node = template.createNode();
        node.setProperty(NamespaceConstants.DATE_CREATED, new Date().getTime());
        addConcept(node, concept.getId());
      }
    }

    // uri index
    if (concept.getUri() != null) {
      Node inUriIndex = getConcept(NamespaceConstants.URI, concept.getUri());
      if (inUriIndex != null) {
        node = inUriIndex;
      } else {
        if (node == null) {
          node = template.createNode();
          node.setProperty(NamespaceConstants.DATE_CREATED, new Date().getTime());
        }

        addConceptByUri(node, concept.getUri());
      }
    }

    if (node == null) {
      node = template.createNode();
      node.setProperty(NamespaceConstants.DATE_CREATED, new Date().getTime());
    }

    concept.setNodeId(node.getId());

    /** parse node */
    if (concept.getId() != null) {
      node.setProperty(NamespaceConstants.CONCEPT_ID, concept.getId());
    }

    utils.setNodeProperty(node, NamespaceConstants.ENRICHED, concept.isEnriched());

    utils.setNodeProperty(node, NamespaceConstants.URI_COUNTER, concept.getUriCounter());
    utils.setNodeProperty(node, NamespaceConstants.ENRICH_COUNTER, concept.getEnrichCounter());

    if (concept.getName() != null) node.setProperty(NamespaceConstants.NAME, concept.getName());
    if (concept.getType() != null) node.setProperty(NamespaceConstants.TYPE, concept.getType());
    if (concept.getUri() != null) {
      node.setProperty(NamespaceConstants.URI, concept.getUri());
    }
    if (concept.getProperties() != null && concept.getProperties().size() > 0) {
      Set<String> keys = concept.getProperties().keySet();
      for (String key : keys) {
        Object property = concept.getProperties().get(key);
        if (property instanceof Concept) {
          Concept c = (Concept) property;
          Node n = persist(c);

          utils.relate(node, n, new MyRelationshipType(key));
        } else if (property instanceof ArrayList) {
          try {
            ArrayList<Concept> concepts = (ArrayList<Concept>) property;
            for (Concept c : concepts) {
              Node n = persist(c);

              utils.relate(node, n, new MyRelationshipType(key));
            }
          } catch (Exception e) {
            ArrayList<Object> properties = (ArrayList<Object>) property;
            differenciateAndSetProperties(properties, node, key);
          }
        } else {
          node.setProperty(key, property);
        }
      }
    }

    if (concept.getDateCreated() != 0)
      node.setProperty(NamespaceConstants.DATE_CREATED, concept.getDateCreated());

    if (concept.getDateUpdated() != 0)
      node.setProperty(NamespaceConstants.DATE_UPDATED, concept.getDateUpdated());

    if (concept.getDateEnriched() != 0L)
      node.setProperty(NamespaceConstants.DATE_ENRICHED, concept.getDateEnriched());

    return node;
  }
Пример #4
0
  public Concept getByNode(Node node) {
    Concept concept = new Concept();
    if (node != null) {

      concept.setNodeId(node.getId());

      Iterable<String> iterable = node.getPropertyKeys();
      for (String key : iterable) {

        if (key.equals(NamespaceConstants.CONCEPT_ID)) {
          concept.setId(node.getProperty(NamespaceConstants.CONCEPT_ID).toString());
          continue;
        }

        if (key.equals(NamespaceConstants.NAME)) {
          concept.setName(node.getProperty(NamespaceConstants.NAME).toString());
          continue;
        }

        if (key.equals(NamespaceConstants.TYPE)) {
          concept.setType(node.getProperty(NamespaceConstants.TYPE).toString());
          continue;
        }

        if (key.equals(NamespaceConstants.URI)) {
          concept.setUri(node.getProperty(NamespaceConstants.URI).toString());
          continue;
        }

        if (key.equals(NamespaceConstants.DATE_CREATED)) {
          concept.setDateCreated(
              Long.parseLong(node.getProperty(NamespaceConstants.DATE_CREATED).toString()));
          continue;
        }

        if (key.equals(NamespaceConstants.DATE_UPDATED)) {
          concept.setDateUpdated(
              Long.parseLong(node.getProperty(NamespaceConstants.DATE_UPDATED).toString()));
          continue;
        }

        if (key.equals(NamespaceConstants.DATE_ENRICHED)) {
          concept.setDateEnriched(
              Long.parseLong(node.getProperty(NamespaceConstants.DATE_ENRICHED).toString()));
          continue;
        }

        if (key.equals(NamespaceConstants.ENRICHED)) {
          concept.setEnriched(
              Boolean.parseBoolean(node.getProperty(NamespaceConstants.ENRICHED).toString()));
          continue;
        }

        if (key.equals(NamespaceConstants.ENRICH_COUNTER)) {
          concept.setEnrichCounter(
              Integer.parseInt(node.getProperty(NamespaceConstants.ENRICH_COUNTER).toString()));
          continue;
        }

        if (key.equals(NamespaceConstants.URI_COUNTER)) {
          concept.setUriCounter(
              Integer.parseInt(node.getProperty(NamespaceConstants.URI_COUNTER).toString()));
          continue;
        }

        //					if (key.equals(NamespaceConstants.GEO_LAT)){
        //						concept.(node.getProperty(NamespaceConstants.GEO_LAT).toString());
        //						continue;
        //					}

        concept.addProperty(key, node.getProperty(key));
      }
    }
    return concept;
  }