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); }
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); } }
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; }
private void markAsUnpublished(ZdoModel model, ZdoModel kdrModel) throws IOException { if (ZdoGroup.ZDO.name().equals(model.get(ZdoTerms.group))) { model.replaceValueOfProperty(ZdoTerms.group, ZdoGroup.UNPUBLISHED.name()); // Unlock kdr object kdrModel.decreaseLockCount(); String pdfUrl = kdrModel.get(ZdoTerms.pdfUrl); String epubUrl = kdrModel.get(ZdoTerms.epubUrl); if (pdfUrl != null) { store.delete(pdfUrl); kdrModel.removeAllValuesOfProperty(ZdoTerms.pdfUrl); } if (epubUrl != null) { store.delete(epubUrl); kdrModel.removeAllValuesOfProperty(ZdoTerms.epubUrl); } // And unindex original published doc if (ZdoType.isRootCategory(model.get(ZdoTerms.zdoType))) { rootsToDelete.add(store.getOnlyIdFromUrl(model.getUrl())); } } }