/** * Get descriptors of all folders. * * @return folder descriptors. */ public ResourceDescriptor[] getLabelDescriptors() { ArrayList<ResourceDescriptor> result = new ArrayList<ResourceDescriptor>(); Seq mindMap = labelsModel.getModel().getSeq(MindRaiderVocabulary.getMindMapUri()); if (mindMap != null) { String folderUri; for (int i = 0; i < mindMap.size(); i++) { folderUri = mindMap.getResource(i + 1).toString(); if (!LABEL_TRASH_URI.equals(folderUri)) { String folderLabel = labelsModel.getModel().getResource(folderUri).getProperty(RDFS.label) .getString(); result.add(new ResourceDescriptor(folderLabel, folderUri)); } } } if (result.size() == 0) { return null; } return (ResourceDescriptor[]) (result.toArray(new ResourceDescriptor[result.size()])); }
/** * Rename folder. * * @param folderUri * the folder Uri * @param newLabel * the new label * @throws Exception * a generic exception */ public void rename(String folderUri, String newLabel) throws Exception { logger.debug("Renaming folder '" + folderUri + "' to '" + newLabel + "'"); if (folderUri != null && newLabel != null) { // rename folder resource FolderResource folderResource = new FolderResource(get(folderUri)); folderResource.getLabelProperty().setLabelContent(newLabel); folderResource.save(); // change label in the tree Seq folderSeq = labelsModel.getModel().getSeq(folderUri); if (folderSeq != null) { folderSeq.removeAll(RDFS.label); folderSeq.addProperty(RDFS.label, newLabel); labelsModel.save(); } } }
/** * Restore notebook - move it from the trash folder back to another folder. * * @param folderUri * the folder uri * @param notebookUri * the notebook uri */ public void restoreNotebook(String folderUri, String notebookUri) { if (folderUri != null && notebookUri != null) { com.hp.hpl.jena.rdf.model.Resource notebookRdfResource = labelsModel.getResource(notebookUri); // remove discarded flag notebookRdfResource.removeAll(MindRaiderVocabulary.isDiscarded); // remove it from trash Seq discardedNotebooksFolder = labelsModel.getModel().getSeq(LABEL_TRASH_URI); int idx = discardedNotebooksFolder.indexOf(notebookRdfResource); if (idx > 0) { discardedNotebooksFolder.remove(idx); } // put it the target folder Seq folderRdfResource = labelsModel.getModel().getSeq(folderUri); folderRdfResource.add(notebookRdfResource); labelsModel.save(); } }
/** * Initialize folders model helper. * * @param notebookUris * @param j * @param resource */ private void initializeFoldersModelHelper(String[] notebookUris, int j, Resource resource) { String notebookPath; com.hp.hpl.jena.rdf.model.Resource notebookRdfResource = labelsModel.getResource(notebookUris[j]); notebookRdfResource.addProperty(MindRaiderVocabulary.isDiscarded, true); // rdfs:label - specify label (it's not in the model) notebookRdfResource.addProperty(RDFS.label, new OutlineResource(resource).getLabel()); // xlink:href - specify relative location (along with profile's // repository home it allows to construct full path notebookPath = MindRaider.outlineCustodian.getModelFilenameByDirectory(MindRaider.outlineCustodian .getOutlineDirectory(notebookUris[j])); notebookRdfResource.addProperty(MindRaiderVocabulary.xlinkHref, MindRaider.profile .getRelativePath(notebookPath)); // add to the discarded sequence Seq discardedNotebooksFolder = labelsModel.getModel().getSeq(LABEL_TRASH_URI); discardedNotebooksFolder.add(notebookRdfResource); }
/** * Add notebook to the model. * * @param folderSequence * the folder sequence. * @param notebookType * the notebook type resource. * @param nResource * the resource. * @param notebookPath * the notebook path String. * @return Returns the added resource. */ private com.hp.hpl.jena.rdf.model.Resource addOutlineToModel(Seq folderSequence, com.hp.hpl.jena.rdf.model.Resource notebookType, Resource nResource, String notebookPath) { com.hp.hpl.jena.rdf.model.Resource notebookRdfResource = (com.hp.hpl.jena.rdf.model.Resource) labelsModel .newResource(nResource.getMetadata().getUri().toString(), false); // rdf:type - it's notebook notebookRdfResource.addProperty(RDF.type, notebookType); // xlink:href - specify relative location (along with profile's // repository home it allows to construct full path notebookRdfResource.addProperty(MindRaiderVocabulary.xlinkHref, MindRaider.profile .getRelativePath(notebookPath)); // rdfs:label notebookRdfResource.addProperty(RDFS.label, new OutlineResource(nResource).getLabel()); // add notebook to the folder's sequence folderSequence.add(notebookRdfResource); return notebookRdfResource; }
/** * Add folder to the model. * * @param mindMapSequence * the mind map sequence. * @param folderType * the folder type. * @param fResource * the resource. * @param folderResourcePath * the folder resource path String * @return the resource */ private com.hp.hpl.jena.rdf.model.Resource addFolderToModel( Seq mindMapSequence, com.hp.hpl.jena.rdf.model.Resource folderType, Resource fResource, String folderResourcePath) { com.hp.hpl.jena.rdf.model.Resource folderRdfResource; folderRdfResource = (com.hp.hpl.jena.rdf.model.Resource) labelsModel.newResource(fResource.getMetadata().getUri().toString(), false); // rdf:type - it's sequence folderRdfResource.addProperty(RDF.type, RDF.Seq); // rdf:type - it's folder folderRdfResource.addProperty(RDF.type, folderType); // xlink:href - specify relative location (along with profile's // repository home it allows to construct full path folderRdfResource.addProperty(MindRaiderVocabulary.xlinkHref, MindRaider.profile.getRelativePath(folderResourcePath)); // rdfs:label folderRdfResource.addProperty(RDFS.label, new FolderResource(fResource).getLabel()); // add folder to the parent sequence mindMapSequence.add(folderRdfResource); return folderRdfResource; }
/** * Move up. * * @param parentResource * the Resource object * @param resourceUri * the resource uri String * @return <code>true</code> if moved. */ public boolean upInSequence(Resource parentResource, String resourceUri) { Seq seq = model.getSeq(parentResource); Resource movedResource = model.getResource(resourceUri); int movedResourceIndex = seq.indexOf(movedResource); logger .debug(" UP: concept index in sequence is " + movedResourceIndex); if (movedResourceIndex > 1) { // switch previous resource with the actual one com.hp.hpl.jena.rdf.model.Resource auxResource = seq .getResource(movedResourceIndex - 1); seq.set(movedResourceIndex, auxResource); seq.set(movedResourceIndex - 1, movedResource); save(); logger.debug(" UP: after up index: " + seq.indexOf(movedResource)); return true; } return false; }
/** * Move down. * * @param parentResource * the Resource * @param resourceUri * the resource uri * @return <code>true</code> if moved. */ public boolean downInSequence(Resource parentResource, String resourceUri) { Seq seq = model.getSeq(parentResource); Resource movedResource = model.getResource(resourceUri); int movedResourceIndex = seq.indexOf(movedResource); logger.debug(" DOWN: concept index in sequence is " + movedResourceIndex); if (movedResourceIndex < seq.size()) { // switch previous resource with the actual one com.hp.hpl.jena.rdf.model.Resource auxResource = seq .getResource(movedResourceIndex + 1); seq.set(movedResourceIndex, auxResource); seq.set(movedResourceIndex + 1, movedResource); save(); logger.debug(" DOWN: after down index: " + seq.indexOf(movedResource)); return true; } return false; }
/** * Returns the notebook childred count. * * @return the number of children. */ public int getActiveNotebookChildCount() { if (activeOutlineResource != null) { Seq seq = activeOutlineResource.rdfModel.getModel() .getSeq(activeOutlineResource.resource.getMetadata().getUri().toString()); return seq.size(); } return 0; }
/** * Return the resource descriptor for child the given indexed position. * * @param i * the index. * @return the resource descriptor. */ public ResourceDescriptor getActiveNotebookChildAt(int i) { if (activeOutlineResource != null) { Seq seq = activeOutlineResource.rdfModel.getModel() .getSeq(activeOutlineResource.resource.getMetadata().getUri().toString()); return getRdfResourceDescriptor(i, seq); } return null; }
/** * Returns the children count for active notebook concept. * * @param conceptUri * the concept uri string. * @return the number of children. */ public int getActiveNotebookConceptChildCount(String conceptUri) { if (activeOutlineResource != null && conceptUri != null && conceptUri.length() > 0) { Seq seq = activeOutlineResource.rdfModel.getModel().getSeq(conceptUri); return seq.size(); } return 0; }
/** * Get detailed resource descriptor. * * @param i * the index * @param seq * the Seq */ private ResourceDescriptor getRdfResourceDescriptor(int i, Seq seq) { ResourceDescriptor result = null; if (i < seq.size()) { com.hp.hpl.jena.rdf.model.Resource resource = seq.getResource(i + 1); if (resource != null) { result = getRdfResourceDescriptor(resource); } } return result; }
/** * Create notebook RDF resource. * * @param notebook * the notebook * @param oldModel * the old model * @param notebookRdf * the notebook RDF */ public static void createOutlineRdfResource(ResourceDescriptor notebook, Model oldModel, com.hp.hpl.jena.rdf.model.Resource notebookRdf) { notebookRdf.addProperty(RDF.type, RDF.Seq); // * MR type notebookRdf.addProperty(RDF.type, oldModel.createResource(MindRaiderConstants.MR_OWL_CLASS_NOTEBOOK)); // * rdfs:label notebookRdf.addProperty(RDFS.label, oldModel.createLiteral(notebook.getLabel())); // * DC.date notebookRdf.addProperty(DC.date, oldModel.createLiteral(notebook.getCreated())); // * rdfs:comment (annotation snippet) notebookRdf.addProperty(RDFS.comment, oldModel.createLiteral(OutlineTreeInstance.getAnnotationCite(notebook.getAnnotationCite()))); }
/** * Move concept down one level (in the outliner mode). * * @param notebook * the notebook resource. * @param parentConceptUri * the parent concept uri. * @param conceptUri * the concept uri. */ public void demote(OutlineResource notebook, String parentConceptUri, String conceptUri) { if (MindRaider.spidersGraph != null && MindRaider.spidersGraph.getRdfModel() != null) { RdfModel rdfModel = MindRaider.spidersGraph.getRdfModel(); // get previous sibling and make parent of the current node from it com.hp.hpl.jena.rdf.model.Resource parentResource = getParentResource( notebook.resource.getMetadata().getUri().toString(), parentConceptUri, rdfModel); if (parentResource == null) { logger.debug(Messages.getString( "ConceptCustodian.unableToFindParentResource", parentConceptUri)); } else { Seq seq = rdfModel.getModel().getSeq(parentResource); com.hp.hpl.jena.rdf.model.Resource conceptResource = rdfModel .getModel().getResource(conceptUri); int conceptIndex = seq.indexOf(conceptResource); logger.debug(Messages.getString( "ConceptCustodian.demoteConceptIndex", conceptIndex)); if (conceptIndex > 0) { com.hp.hpl.jena.rdf.model.Resource siblingResource = seq .getResource(conceptIndex - 1); Seq siblingSeq = rdfModel.getModel() .getSeq(siblingResource); siblingSeq.add(conceptResource); seq.remove(conceptIndex); MindRaider.spidersGraph.save(); MindRaider.spidersGraph.renderModel(); } } } else { logger.error("demote() - Spiders graph is null!", null); } }
/** * Get descriptors of all notebooks within particular folder. * * @return notebook descriptors. */ public ResourceDescriptor[] getOutlineDescriptors(String folderUri) { // TODO cope with discarded notebooks ArrayList<ResourceDescriptor> result = new ArrayList<ResourceDescriptor>(); Seq folderSequence = labelsModel.getModel().getSeq(folderUri); for (int i = 0; i < folderSequence.size(); i++) { ResourceDescriptor resourceDescriptor = new ResourceDescriptor(); resourceDescriptor.setUri(folderSequence.getResource(i + 1).toString()); // logger.debug("<-> getNotebookDescriptors: "+resourceDescriptor.uri); Statement labelProperty = labelsModel.getModel().getResource(resourceDescriptor.getUri()).getProperty(RDFS.label); if (labelProperty != null) { resourceDescriptor.setLabel(labelProperty.getObject().toString()); } else { resourceDescriptor.setLabel("[NO LABEL]"); } result.add(resourceDescriptor); } if (result.size() == 0) { return null; } return (ResourceDescriptor[]) (result.toArray(new ResourceDescriptor[result.size()])); }
/** * Discard label. * * @param uri * folder URI. * @return Returns <code>true</code> if it discards, otherwise * <code>false</code> * @throws Exception * a generic exception */ public boolean discardLabel(String uri) throws Exception { if (uri != null && !LABEL_TRASH_URI.equals(uri)) { // only empty folder can be discarded Seq folderSeq = labelsModel.getModel().getSeq(uri); if (folderSeq.size() == 0) { folderSeq.removeProperties(); // remove it from model mind map Seq mindMap = labelsModel.getModel().getSeq(MindRaiderVocabulary.getMindMapUri()); int idx = mindMap.indexOf(folderSeq); if (idx >= 0) { try { mindMap.remove(idx); } catch(Exception e) { logger.error("Removal of the discarded property in the sequence failed: #"+idx+" "+uri); // {{debug}} } } labelsModel.save(); // delete it from file system Utils.deleteSubtree(new File(getFolderPathFromUri(uri)).getParentFile()); logger.debug("Folder deleted: "+uri); // {{debug}} return true; } } return false; }
/** * Discard notebook - in this case discarding means removing notebook from * the folder (both in model and folder resource). BUT note that notebook * doesn't have to be discarded itself (since in principle it can be shared * by multiple folders). If there is a folder referencing such notebook, * then notebook is not discarded. But notebook may also become orphan, in * this case it is discarded automatically. * * @param labelUri * the folder uri * @param outlineUri * the notebook uri * @throws Exception * a generic exception */ public void discardOutlineFromLabel(String labelUri, String outlineUri, boolean discard) throws Exception { logger.debug("Discarding outline from the particular label: "+labelUri+" # "+outlineUri); if (labelUri != null && outlineUri != null) { FolderResource folderResource = new FolderResource(get(labelUri)); folderResource.removeNotebook(outlineUri); save(folderResource.getResource()); // mark notebook as discarded in the model and move it to the // discarded notebooks com.hp.hpl.jena.rdf.model.Resource folderRdfResource = labelsModel.getResource(labelUri); com.hp.hpl.jena.rdf.model.Resource notebookRdfResource = labelsModel.getResource(outlineUri); // remove notebook from folder Seq folderSequence = labelsModel.getModel().getSeq(folderRdfResource); int idx = folderSequence.indexOf(notebookRdfResource); if (idx >= 0) { folderSequence.remove(idx); } if(discard) { markNotebookAsDiscarded(outlineUri, notebookRdfResource); } // will be discarded only if empty discardLabel(labelUri); // save model labelsModel.save(); } }
private void markNotebookAsDiscarded(String notebookUri, com.hp.hpl.jena.rdf.model.Resource notebookRdfResource) throws Exception { // mark notebook resource as discarded Resource notebookResource = MindRaider.outlineCustodian.get(notebookUri); if (notebookResource != null) { new OutlineResource(notebookResource).discard(); } // mark notebook as discarded notebookRdfResource.addProperty(MindRaiderVocabulary.isDiscarded, true); // add to the discarded sequence Seq discardedNotebooksFolder = labelsModel.getModel().getSeq(LABEL_TRASH_URI); discardedNotebooksFolder.add(notebookRdfResource); }
private void buildNotesTree( Model model, String parentResourceUri, String notebookUri, ConceptTreeNode parentNode, AnnotationTransformer annotationTransformer) throws Exception { String conceptUri; ConceptResource concept; RDFNode statement; Seq seq = model.getSeq(parentResourceUri); NodeIterator i = seq.iterator(); cat.debug("<-> concept tree builder - got root: " + parentResourceUri); ConceptTreeNode child; while (i.hasNext()) { statement = i.nextNode(); // add children to parent node conceptUri = statement.toString(); cat.debug(" <-> concept tree builder - child '" + conceptUri + "'"); concept = MindRaider.noteCustodian.get(notebookUri, conceptUri); child = new ConceptTreeNode(); // TODO create resource clone to avoid changing of annotations if (annotationTransformer != null) { concept.setAnnotation(annotationTransformer.transform(concept.getAnnotation())); } child.setConcept(concept.resource); parentNode.getChildren().add(child); // now dive recursively for each existing node... buildNotesTree(model, conceptUri, notebookUri, child, annotationTransformer); } }
public void testGetSeq() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 170; model.createSeq(uri); final Seq s = model.getSeq(uri); Assert.assertEquals(uri, s.getURI()); Assert.assertTrue(model.contains(s, RDF.type, RDF.Seq)); }
public void undiscard(String outlineUri, String conceptUri) throws Exception { String outlineFilename = MindRaider.outlineCustodian.getModelFilename(outlineUri); Model outlineModel=null; URI activeOutlineUri = MindRaider.profile.getActiveOutlineUri(); if(outlineUri!=null && activeOutlineUri!=null && outlineUri.equals(activeOutlineUri.toString())) { // use active outline model RdfModel rdfModel = MindRaider.spidersGraph.getRdfModel(); if(rdfModel!=null) { outlineModel = rdfModel.getModel(); } } else { RdfModel.loadModel(outlineFilename); } // RDF: remove the concept from the trash sequence String trashUri = getTrashConceptUri(outlineUri); Seq trashRdfSequence = outlineModel.getSeq(trashUri); int indexOf = trashRdfSequence.indexOf(outlineModel.getResource(conceptUri)); trashRdfSequence.remove(indexOf); // RDF: remove discarded property of the concept com.hp.hpl.jena.rdf.model.Resource conceptRdfResource = outlineModel.getResource(conceptUri); StmtIterator listStatements = outlineModel.listStatements(conceptRdfResource, MindRaiderVocabulary.isDiscarded, true); if(listStatements!=null && listStatements.hasNext()) { Statement statement=(Statement)listStatements.next(); statement.remove(); } // RDF: get the root resource ~ outline URI Seq outlineRdfResource = outlineModel.getSeq(outlineUri); // RDF: add the concept's URI to outline's resource sequence outlineRdfResource.add(conceptRdfResource); // RDF save it back RdfModel.saveModel(outlineModel, outlineFilename); // XML: set the parentResource element in the concept's XML ConceptResource conceptResource = get(outlineUri, conceptUri); conceptResource.save(); }
/** * Move concept up one level (in the outliner mode). * * @param notebook * the notebook resource. * @param parentParentConceptUri * the parent parent concept uri. * @param parentConceptUri * the parent concept uri. * @param conceptUri * the concept uri */ public void promote(OutlineResource notebook, String parentParentConceptUri, String parentConceptUri, String conceptUri) { if (MindRaider.spidersGraph != null && MindRaider.spidersGraph.getRdfModel() != null) { RdfModel rdfModel = MindRaider.spidersGraph.getRdfModel(); // get parent's parent and move the node there String notebookUri = notebook.resource.getMetadata().getUri() .toString(); com.hp.hpl.jena.rdf.model.Resource parentResource = getParentResource( notebookUri, parentConceptUri, rdfModel); com.hp.hpl.jena.rdf.model.Resource parentParentResource = getParentResource( notebookUri, parentParentConceptUri, rdfModel); if (parentResource == null || parentParentResource == null) { logger .debug(Messages .getString("ConceptCustodian.unableToFindParentParent")); } else { Seq parentSeq = rdfModel.getModel().getSeq(parentResource); com.hp.hpl.jena.rdf.model.Resource conceptResource = rdfModel .getModel().getResource(conceptUri); int conceptIndex = parentSeq.indexOf(conceptResource); logger.debug(Messages.getString( "ConceptCustodian.promoteConceptIndex", conceptIndex)); // move it to parent's parent (behind parent) Seq parentParentSeq = rdfModel.getModel().getSeq( parentParentResource); int parentIndex = parentParentSeq.indexOf(parentResource); parentParentSeq.add(parentIndex + 1, conceptResource); parentSeq.remove(conceptIndex); MindRaider.spidersGraph.save(); MindRaider.spidersGraph.renderModel(); } } else { logger.error(Messages .getString("ConceptCustodian.spidersGraphAreNull")); } }
/** * Render tree recursively. */ private void rebuildTree(String notebookUri, String parentResourceUri, DefaultMutableTreeNode parentNode, Model model) throws Exception { cat.debug("=-> rebuildTree: " + notebookUri); Resource resource; Seq childrenSeq; NotebookOutlineEntry entry; ResourceDescriptor resourceDescriptor; Statement flagStatement; String flag = null; if(model!=null) { Seq parentSeq = model.getSeq(parentResourceUri); NodeIterator i = parentSeq.iterator(); while (i.hasNext()) { resource = (Resource) i.nextNode(); resourceDescriptor = MindRaider.outlineCustodian.getRdfResourceDescriptor(resource); // category flag if ((flagStatement = resource.getProperty(MindRaiderVocabulary.flagProperty)) != null) { flag = flagStatement.getObject().toString(); } else { flag = null; } // TODO handle DISCARDS // TODO slow? String conceptAnnotationType=null; try { conceptAnnotationType= MindRaider.noteCustodian.get(notebookUri, resourceDescriptor.getUri()).getAnnotationContentType(); } catch(Exception e) { } entry = new NotebookOutlineEntry( resourceDescriptor.getUri(), resourceDescriptor.getLabel(), getAnnotationToRender(resourceDescriptor.getAnnotationCite(), flag), conceptAnnotationType, getCreatedToRender(resourceDescriptor.getCreated())); parentNode.add(entry); // process children childrenSeq = model.getSeq(resourceDescriptor.getUri()); if (childrenSeq.size() > 0) { // now dive recursively for each existing node... rebuildTree(notebookUri, resourceDescriptor.getUri(), entry, model); } } } }
@Override public Seq getSeq() { return baseStmt.getSeq(); }
/** * Returns the resource descriptor for notebook concept child at index * position. * * @param i * the index position. * @param conceptUri * the concept string. * @return rhe resource descriptor. */ public ResourceDescriptor getActiveNotebookConceptChildAt(int i, String conceptUri) { if (activeOutlineResource != null && conceptUri != null) { Seq seq = activeOutlineResource.rdfModel.getModel().getSeq(conceptUri); return getRdfResourceDescriptor(i, seq); } return null; }