Example #1
0
  private void resolveChildren(ModelTreeNode modelTreeNode, String oldModelUrl) throws IOException {
    ZdoModel model = modelTreeNode.getModel();

    // If there is also a published version of this doc, find it, remove it and adopt all its
    // children
    if (oldModelUrl != null) {
      // Change its children to be ours
      String queryString =
          "SELECT ?subject WHERE {\n"
              + " ?subject <"
              + DCTerms.isPartOf.getURI()
              + "> <"
              + oldModelUrl
              + ">.\n"
              + "}";
      QueryExecution queryExecution =
          QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, queryString);
      ResultSet resultSet = queryExecution.execSelect();
      while (resultSet.hasNext()) {
        QuerySolution querySolution = resultSet.next();
        RDFNode childNode = querySolution.get("subject");
        String childToAdoptUrl = childNode.asResource().getURI();
        ZdoModel childModel = store.get(childToAdoptUrl);
        childModel.replaceValueOfProperty(
            DCTerms.isPartOf, store.removeTransactionFromUrl(model.getUrl()));

        // If this children was published
        if (ZdoGroup.ZDO.name().equals(childModel.get(ZdoTerms.group))) {
          // Is this children getting replaced by newer version?
          if (modelTreeNodeKdrIndex.containsKey(childModel.get(ZdoTerms.kdrObject))) {
            // Yes, unpublish it
            ZdoModel childKdrObject = store.get(childModel.get(ZdoTerms.kdrObject));
            markAsUnpublished(childModel, childKdrObject);
            store.update(childKdrObject);
          } else { // No, it should be added to our tree to solr
            ModelTreeNode childModelTreeNode = new ModelTreeNode();
            childModelTreeNode.setModel(childModel);
            modelTreeNodeKdrIndex.put(childModel.get(ZdoTerms.kdrObject), childModelTreeNode);
            modelTreeNodeIndex.put(
                store.removeTransactionFromUrl(childModel.getUrl()), modelTreeNode);
            modelTreeNode.getChildren().add(childModelTreeNode);
          }
        }
        store.update(childModel);
      }
    }

    // Recurse on children
    for (ModelTreeNode childNode : modelTreeNode.getChildren()) {
      // Get kdr version of this doc
      ZdoModel kdrDoc = store.get(childNode.getModel().get(ZdoTerms.kdrObject));
      resolveChildren(childNode, kdrDoc.get(ZdoTerms.newestPublished));
      kdrDoc.replaceValueOfProperty(
          ZdoTerms.newestPublished, store.removeTransactionFromUrl(childNode.getModel().getUrl()));
      store.update(kdrDoc);
    }
  }
Example #2
0
  private void resolveRoots(ModelTreeNode modelTreeNode) throws IOException {
    ZdoModel model = modelTreeNode.getModel();

    // Get kdr version of this doc
    String kdrUrl = model.get(ZdoTerms.kdrObject);
    ZdoModel kdrDoc = store.get(kdrUrl);

    // If there is also a published version of this doc, find it, remove it and adopt all its
    // children
    String oldModelUrl = kdrDoc.get(ZdoTerms.newestPublished);
    if (oldModelUrl != null) {
      // Mark the old published doc as unpublished
      ZdoModel oldModel = store.get(oldModelUrl);
      if (ZdoGroup.ZDO.name().equals(oldModel.get(ZdoTerms.group))) {
        markAsUnpublished(oldModel, kdrDoc);
        store.update(oldModel);
      }
    }
    resolveChildren(modelTreeNode, oldModelUrl);

    // Set to KDR doc that this will be its published version
    kdrDoc.replaceValueOfProperty(
        ZdoTerms.newestPublished, store.removeTransactionFromUrl(model.getUrl()));
    store.update(kdrDoc);
  }
Example #3
0
  private ModelTreeNode addNodeToStructure(ZdoModel model) throws IOException {
    // Was this node already parsed?
    ModelTreeNode modelTreeNode =
        modelTreeNodeIndex.get(store.removeTransactionFromUrl(model.getUrl()));
    if (modelTreeNode != null) {
      return modelTreeNode;
    }
    // Can it be published?
    if (!"true".equals(model.get(ZdoTerms.validToPublish))) {
      throw new RuntimeException("This model is not ready for publishing!");
    }

    // Create tree structure with model for Solr
    modelTreeNode = new ModelTreeNode();
    modelTreeNode.setModel(model);
    modelTreeNodeIndex.put(store.removeTransactionFromUrl(model.getUrl()), modelTreeNode);
    modelTreeNodeKdrIndex.put(model.get(ZdoTerms.kdrObject), modelTreeNode);

    // Parse ancestors and add us as their children
    String parentUrl = model.get(DCTerms.isPartOf);
    if (parentUrl != null) {
      ZdoModel parent = store.get(parentUrl);
      ModelTreeNode parentNode = addNodeToStructure(parent);
      parentNode.getChildren().add(modelTreeNode);
    } else {
      // This is a root
      dataToIndex.add(modelTreeNode);
    }

    // Published periodicals and volumes shouldn't have batch
    if (!ZdoType.isBranchEndCategory(model.get(ZdoTerms.zdoType))) {
      model.removeAllValuesOfProperty(ZdoTerms.batchId);
    }

    // Mark doc as published
    model.replaceValueOfProperty(ZdoTerms.group, ZdoGroup.ZDO.name());
    store.update(model);

    // Leaf children like page and binary don't need to be changed, but images must be tiled
    if (ZdoType.isBranchEndCategory(model.get(ZdoTerms.zdoType))) {
      imagesToTile.addAll(
          triplestoreStuff.fetchUrlsOfTileableImageDescendants(model.get(ZdoTerms.kdrObject)));
    }

    return modelTreeNode;
  }