Package uk.ac.osswatch.simal.model

Examples of uk.ac.osswatch.simal.model.IProject


    LOGGER.debug("Get project with SPARQL:\n" + queryStr);
      Query query = QueryFactory.create(queryStr);
      QueryExecution qe = QueryExecutionFactory.create(query, getModel());
      ResultSet results = qe.execSelect();

      IProject project = null;
      while (results.hasNext()) {
        QuerySolution soln = results.nextSolution();
        RDFNode node = soln.get("project");
        if (node.isResource()) {
          project = new Project((com.hp.hpl.jena.rdf.model.Resource) node);
View Full Code Here


      // data
      if (sourceXml == null) {
        throw new SimalRepositoryException("Supplied RDF/XML document is null.");
      }
     
      IProject newProject = null;
      NodeList projects = sourceXml.getElementsByTagNameNS(RDFUtils.DOAP_NS,
          "Project");

      if (projects.getLength() == 0) {
        throw new SimalRepositoryException("No projects in the supplied RDF/XML document");
View Full Code Here

      throw new SimalRepositoryException(
          "Unable to encode URIs for blank nodes", e);
    }

    String uri = sourceProjectRoot.getAttributeNS(RDFUtils.RDF_NS, "about");
    IProject project = findOrCreateProject(sourceProjectRoot, uri);

    generateRelatedEntities(sourceProjectRoot, project);

    /**
     * record any new seeAlsos against the project
     */
    NodeList seeAlsos = sourceProjectRoot.getElementsByTagNameNS(
        RDFUtils.RDFS_NS, RDFS.seeAlso.getLocalName());
    for (int i = 0; i < seeAlsos.getLength(); i = i + 1) {
      Element seeAlso = (Element) seeAlsos.item(i);
      if (seeAlso.getParentNode().equals(sourceProjectRoot)) {
        String seeAlsoUri = seeAlso.getAttributeNS(RDFUtils.RDF_NS, "resource")
            .trim();
        try {
          project.addSeeAlso(new URI(seeAlsoUri));
        } catch (URISyntaxException e) {
          throw new SimalRepositoryException(
              "Unable to add see also to simal:Project", e);
        }
      }
View Full Code Here

    return project;
  }

  private IProject findOrCreateProject(Element sourceProjectRoot, String uri)
      throws SimalRepositoryException {
    IProject project = SimalRepositoryFactory.getProjectService()
        .findProjectBySeeAlso(uri);
    if (project == null) {
      // simal:Project entity for doap:Project does not currently exist
      // look to see if we have data about the same entity but with a different
      // URI
      project = findExistingProjectByHomepage(sourceProjectRoot);
    }
   
    if (project == null) {
      project = findExistingProjectBySeeAlso(sourceProjectRoot);
    }

    if (uri == null || uri.equals("")) {
      // we don't allow blank project nodes
      uri = RDFUtils.getDefaultProjectURI(getNewProjectID());
      sourceProjectRoot.setAttributeNS(RDFUtils.RDF_NS, "about", uri);
    }

    if (project == null) {
      project = createSimalProject(uri);
    } else {
      LOGGER.debug("Updating an existing simal:Project instance with URI "
          + project.getURI());
      try {
        project.addSeeAlso(new URI(uri));
      } catch (URISyntaxException e) {
        throw new SimalRepositoryException(
            "Unable to add a seeAlso attribute to an existing object", e);
      }
    }
View Full Code Here

    return project;
  }

  private IProject findExistingProjectBySeeAlso(Element sourceProjectRoot) throws SimalRepositoryException {
    // find existing simal:Project identified by a common rdf:seeAlso
    IProject project = null;
    NodeList seeAlsos = sourceProjectRoot.getElementsByTagNameNS(
        RDFUtils.RDFS_NS, RDFS.seeAlso.getLocalName());
    Element seeAlso;
    for (int i = 0; i < seeAlsos.getLength(); i = i + 1) {
      seeAlso = (Element) seeAlsos.item(i);
View Full Code Here

  }

  private IProject findExistingProjectByHomepage(Element sourceProjectRoot)
      throws SimalRepositoryException {
    // look for an existing simap:Project identified by a common homepage
    IProject project = null;
    NodeList homepages = sourceProjectRoot.getElementsByTagNameNS(
        RDFUtils.DOAP_NS, "homepage");
    Element homepage;
    for (int i = 0; i < homepages.getLength(); i = i + 1) {
      homepage = (Element) homepages.item(i);
      if (homepage.getParentNode().equals(sourceProjectRoot)) {
        String url = homepage.getAttributeNS(RDFUtils.RDF_NS, "resource")
            .trim();
        project = findProjectByHomepage(url);
        if (project != null) {
          LOGGER.debug("Simal already has a Project record with the homepage "
              + url + " with URI " + project.getURI());
          break;
        }
      }
    }
    return project;
View Full Code Here

      // ?project a simal:Project
      // ?project doap:homepage x
      // or ?project rdfs:seeAlso ?linkedProject
      // ?linkedProject doap:homepage x

      IProject project = null;
      Set<IProject> projects = findProjectsBySPARQL(queryStr);

      if (!projects.isEmpty()) {
        project = projects.iterator().next();
      }
View Full Code Here

      Set<IPerson> colleagues = new HashSet<IPerson>();
      Set<String> colleagueIDs = new HashSet<String>();
     
      Iterator<IProject> projects = person.getProjects().iterator();
      while (projects.hasNext()) {
        IProject project = projects.next();
        Iterator<IPerson> people = project.getAllPeople().iterator();
        while (people.hasNext()) {
          IPerson colleague = people.next();
          String id = colleague.getSimalID();
          if (!id.equals(person.getSimalID()) && !colleagueIDs.contains(id)) {
            colleagues.add(colleague);
View Full Code Here

    if (command.isGetAllProjects()) {
      execResult = getAllProjects(command);
    } else if (command.isGetProject()) {
      execResult = getProject(command);
    } else if (command.isAddProject()) {
      IProject newProject = addProject(command);
      if (newProject instanceof Project) {
        execResult = ((Project) newProject).generateURL();
      }
    } else {
      throw new SimalAPIException("Unknown command: " + command);
View Full Code Here

  private String getProject(RESTCommand command) throws SimalAPIException {
    String id = command.getProjectID();
    if (id == null) {
      id = "featured";
    }
    IProject project;
   
    try {
      if (id.equals("featured")) {
        project = getRepository().getFeaturedProject();
      } else if (id.startsWith("prj")){
        project = SimalRepositoryFactory.getProjectService().getProjectById(
            getRepository().getUniqueSimalID(id));
      } else {
        String uri = "http://jisc.ac.uk/project#" + id;
        LOGGER.info("Requesting JISC project with URI" + uri);
        project = SimalRepositoryFactory.getProjectService().getProject(uri);
      }
      if (project == null) {
        throw new SimalAPIException("Project with Simal ID " + id
            + " does not exist");
      }
    } catch (SimalRepositoryException e) {
      throw new SimalAPIException(
        "Unable to get XML representation of project from the repository",
        e);
    }
   
    try {
      if (command.isXML()) {
        return project.toXML();
      } else if (command.isJSON()) {
        return project.toJSON();
      } else {
        throw new SimalAPIException("Unkown format requested - " + command);
      }
    } catch (SimalRepositoryException e) {
      throw new SimalAPIException("Unable to convert project to the chosen format", e);
View Full Code Here

TOP

Related Classes of uk.ac.osswatch.simal.model.IProject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.