public NoteStoreNotesAPIImpl(OWLAPIProject project) {
    this.project = project;
    try {
      OWLAPIProjectDocumentStore documentStore =
          OWLAPIProjectDocumentStore.getProjectDocumentStore(project.getProjectId());
      File notesDataDirectory = documentStore.getNotesDataDirectory();
      notesOntologyDocument = new File(notesDataDirectory, NOTES_ONTOLOGY_DOCUMENT_NAME);
      if (!notesOntologyDocument.exists()) {
        createEmptyNotesOntology();
      } else {
        loadExistingNotesOntology();
      }

      notesManager =
          NotesManager.createNotesManager(notesOntology, getChangeOntologyDocumentIRI().toString());
      notesManager
          .getOWLOntology()
          .getOWLOntologyManager()
          .addOntologyChangeListener(
              new OWLOntologyChangeListener() {
                public void ontologiesChanged(List<? extends OWLOntologyChange> changes)
                    throws OWLException {
                  handleNotesOntologyChanged(Collections.unmodifiableList(changes));
                }
              });
    } catch (OWLOntologyCreationException e) {
      // Can't start - too dangerous to do anything without human intervention
      throw new RuntimeException(e);
    } catch (NotesException e) {
      throw new RuntimeException(e);
    }
  }
 @Override
 public RequestValidationResult validateAction(A action, RequestContext requestContext) {
   ProjectId projectId = action.getProjectId();
   OWLAPIProjectDocumentStore ds = OWLAPIProjectDocumentStore.getProjectDocumentStore(projectId);
   if (ds.exists()) {
     return RequestValidationResult.getValid();
   } else {
     return RequestValidationResult.getInvalid("Project does not exist");
   }
 }
  private void handleNotesOntologyChanged(List<OWLOntologyChange> changes) {
    try {
      OWLOntologyManager notesOntologyManager = notesOntology.getOWLOntologyManager();
      if (notesOntologyManager.getOntologyFormat(notesOntology)
          instanceof BinaryOWLOntologyDocumentFormat) {
        OWLAPIProjectDocumentStore documentStore =
            OWLAPIProjectDocumentStore.getProjectDocumentStore(project.getProjectId());
        List<OWLOntologyChangeData> infoList = new ArrayList<OWLOntologyChangeData>();
        for (OWLOntologyChange change : changes) {
          OWLOntologyChangeRecord rec = change.getChangeRecord();
          OWLOntologyChangeData info = rec.getData();
          infoList.add(info);
        }
        BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
        serializer.appendOntologyChanges(
            notesOntologyDocument,
            new OntologyChangeDataList(infoList, System.currentTimeMillis()));
      } else {
        // Swap it over
        notesOntologyManager.saveOntology(notesOntology, new BinaryOWLOntologyDocumentFormat());
      }

    } catch (OWLOntologyStorageException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 public List<ProjectDetails> getListableReadableProjects(UserId userId) {
   Policy policy = metaproject.getPolicy();
   User user = policy.getUserByName(userId.getUserName());
   List<ProjectDetails> result = new ArrayList<ProjectDetails>();
   for (ProjectInstance projectInstance : metaproject.getProjects()) {
     final String name = projectInstance.getName();
     if (name != null && ProjectId.isWelFormedProjectId(name)) {
       final ProjectId projectId = ProjectId.get(name);
       if (isAuthorisedToReadAndList(policy, user, projectInstance)) {
         OWLAPIProjectDocumentStore ds =
             OWLAPIProjectDocumentStore.getProjectDocumentStore(projectId);
         if (ds.exists()) {
           final ProjectDetails projectDetails =
               createProjectDetailsFromProjectInstance(projectInstance);
           result.add(projectDetails);
         }
       }
     }
   }
   return result;
 }