Package uk.ac.osswatch.simal.rdf

Examples of uk.ac.osswatch.simal.rdf.SimalException


  public Repository(com.hp.hpl.jena.rdf.model.Resource resource) throws SimalException {
    super(resource);
    Resource type = getJenaResource().getProperty(RDF.type).getResource();
    repoType = DoapRepositoryType.getMatchingDoapRepositoryType(type);
    if(repoType == null) {
      throw new SimalException("Attempt to create Repository of invalid type: " + type.getURI());
    }
  }
View Full Code Here


    URLConnection con;
    try {
      URL url = new URL(urlString);
      con = url.openConnection();
      if (!con.getHeaderField("Status").startsWith("200")) {
        throw new SimalException("Unable to open connection to " + url
            + " status: " + con.getHeaderField("Status"));
      }
    } catch (MalformedURLException e) {
      throw new SimalException(
          "The Ohloh URL is malformed, how can that happen since it is hard coded?",
          e);
    } catch (IOException e) {
      throw new SimalException("Unable to open connection to Ohloh", e);
    }
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = null;

    DocumentBuilder db;
    try {
      db = dbf.newDocumentBuilder();
      doc = db.parse(con.getInputStream());
    } catch (ParserConfigurationException e) {
      throw new SimalException("Unable to configure XML parser", e);
    } catch (SAXException e) {
      throw new SimalException("Unable to parse XML document", e);
    } catch (IOException e) {
      throw new SimalException("Unable to read XML response", e);
    }
    return doc;
  }
View Full Code Here

      try {
        builder = factory.newDocumentBuilder();
        domResult = builder.parse(new InputSource(new StringReader(xmlSource)));
      } catch (ParserConfigurationException e) {
        LOGGER.warn("Unexpected ParserConfigurationException: " + e.getMessage(),e);
        throw new SimalException("Invalid configuration", e);
      } catch (SAXException e) {
        LOGGER.warn("Unexpected SAXException: " + e.getMessage(),e);
        throw new SimalException("Tried to create DOM Document from invalid XML", e);
      } catch (IOException e) {
        LOGGER.warn("Unexpected IOException: " + e.getMessage(),e);
        throw new SimalException("IOException when trying to parse xml source.", e);
      }
    }
    return domResult;
  }
View Full Code Here

        HSSFSheet sheet = wb.getSheetAt(0);
       
        HSSFRow row = sheet.getRow(0);
        String title = getNullSafeStringValue(row, 1);
        if (!title.equals("name")) {
          throw new SimalException(url + " is not a valid PIMS project export file");
        }
       
        int lastRow = sheet.getLastRowNum();
        for (int i = 1; i <= lastRow; i++) {
          Document doc;
          Element foaf;
          try {
        doc = createRdfDocument();
        foaf = doc.createElementNS(Foaf.getURI(), "Organization");
      } catch (ParserConfigurationException e1) {
        throw new SimalException("Unable to create XML document for import");
      }
     
          row   = sheet.getRow(i);
         
          // rdf:about
View Full Code Here

        HSSFSheet sheet = wb.getSheetAt(0);
       
        HSSFRow row = sheet.getRow(0);
        String title = getNullSafeStringValue(row, 2);
        if (!title.equals(VALID_PROJECTS_FILE_ID)) {
          throw new SimalException(url + " is not a valid PIMS project export file");
        }
       
        int errorsOccurred = 0;
        StringBuffer errorReports = new StringBuffer();
        int lastRow = sheet.getLastRowNum();
        for (int i = 1; i<= lastRow; i++) {
          Document doc;
          Element doap;
          try {
            doc = createRdfDocument();
            doap = doc.createElementNS(Doap.getURI(), "Project");
          } catch (ParserConfigurationException e1) {
            throw new SimalException("Unable to create XML document for import");
          }
         
          row = sheet.getRow(i);
         
          // rdf:about
          int id = getNullSafeIntValue(row, 0);
          doap.setAttributeNS(RDF.getURI(), "about", getProjectURI(id));
         
          // doap:name
          String name = getNullSafeStringValue(row, 2);
          Element elem = doc.createElementNS(Doap.getURI(), "name");
          elem.setTextContent(name);
          doap.appendChild(elem);
         
          // doap:description
          String value = getNullSafeStringValue(row, 4);
          elem = doc.createElementNS(Doap.getURI(), "description");
          elem.setTextContent(value);
          doap.appendChild(elem);

          // doap:homepage
          value = getNullSafeStringValue(row, 6);
          if (value.length() != 0 && !value.equals("tbc")) {
            elem = doc.createElementNS(Doap.getURI(), "homepage");
            elem.setAttributeNS(RDF.getURI(), "resource", value);
            elem.setAttributeNS(RDFS.getURI(), "label", "Homepage");
            doap.appendChild(elem);
          }
         
          //TODO: capture workpackage info: String projectWorkpackage = row.getCell(5).getStringCellValue();

          //TODO: capture short name: String shortName = row.getCell(3).getStringCellValue();
         
          // doap:category
          value = getCategoryURI(getNullSafeIntValue(row,1));
          elem = doc.createElementNS(Doap.getURI(), "category");
          elem.setAttributeNS(RDF.getURI(), "resource", value);
          doap.appendChild(elem);
         
          // TODO: Capture state info: String projectStateName = row.getCell(7).getStringCellValue();
          // TODO: Capture start date info: String projectStartDate = row.getCell(8).getStringCellValue();
          // TODO: Capture start date info: String projectEndDate = row.getCell(9).getStringCellValue();
         
          doc.getDocumentElement().appendChild(doap);
          // serialise(doc);
          try {
            SimalRepositoryFactory.getProjectService().createProject(doc);
          } catch (SimalRepositoryException e) {
            errorReports.append("Error when importing project named '" + name + "': ");
            errorReports.append(e.getMessage());
            errorReports.append(NEW_LINE);
            errorsOccurred ++;
            if (errorsOccurred > MAX_IMPORT_ERRORS) {
              throw new SimalException ("Too many errors (" + MAX_IMPORT_ERRORS + ")" + NEW_LINE + errorReports.toString());
            }
          }
        }
        if(errorsOccurred > 0 ) {
          throw new SimalException("Import resulted in " + errorsOccurred + " errors:" + NEW_LINE + errorReports.toString());
        }
  }
View Full Code Here

        HSSFSheet sheet = wb.getSheetAt(0);
       
        HSSFRow row = sheet.getRow(0);
        String title = getNullSafeStringValue(row, 1);
        if (!title.equals(VALID_PROGRAMMES_FILE_ID)) {
          throw new SimalException(url + " is not a valid PIMS programme export file");
        }
       
        int lastRow = sheet.getLastRowNum();
        for (int i = 1; i<= lastRow; i++) {
          Document doc;
          Element cat;
          try {
        doc = createRdfDocument();
        cat = doc.createElementNS(Doap.getURI(), "category");
      } catch (ParserConfigurationException e1) {
        throw new SimalException("Unable to create XML document for import");
      }

      row = sheet.getRow(i);
     
          // rdf:about
View Full Code Here

        HSSFSheet sheet = wb.getSheetAt(0);
       
        HSSFRow row = sheet.getRow(0);
        String title = getNullSafeStringValue(row, 2);
        if (!title.equals(VALID_PROJECT_CONTACTS_FILE_ID)) {
          throw new SimalException(url + " is not a valid PIMS project contact export file");
        }
       
        StringBuffer errorReports = new StringBuffer();
        int errorsOccurred = 0;
        int lastRow = sheet.getLastRowNum();
        for (int i = 1; i<= lastRow; i++) {
          Document doc;
          Element project;
          try {
            doc = createRdfDocument();
            project = doc.createElementNS(Doap.getURI(), "Project");
          } catch (ParserConfigurationException e1) {
            throw new SimalException("Unable to create XML document for import");
          }
     
          row = sheet.getRow(i);
         
          // rdf:about (Project)
          int projectId = getNullSafeIntValue(row, 1);
          project.setAttributeNS(RDF.getURI(), "about", getProjectURI(projectId));
         
          // foaf:Person
          Element person = doc.createElementNS(Foaf.getURI(), "Person");
         
          // rdf:about (Person)
          int id = getNullSafeIntValue(row, 0);
          person.setAttributeNS(RDF.getURI(), "about", getPersonURI(id));
                   
          // foaf:name
          String name = getNullSafeStringValue(row, 2);
          Element elem = doc.createElementNS(Foaf.getURI(), "name");
          elem.setTextContent(name);
          person.appendChild(elem);
         
          // TODO: record the contacts job_title
          // TODO: record the contacts institutions.name
         
          // foaf:mbox
          String email = getNullSafeStringValue(row, 6);
          if (email.contains("@")) {
            if (!email.startsWith("mailto:")) {
              email = "mailto:" + email;
            }
            elem = doc.createElementNS(Foaf.getURI(), "mbox");
            elem.setAttributeNS(RDF.getURI(), "resource", email);
            person.appendChild(elem);
          } else {
            logger.info("Contact in PIMS import has a strange looking email: " + email)
          }
         
          // TODO: record contact telephone detail
          //HSSFRichTextString tel = row.getCell(7).getRichStringCellValue();


          // add appropriate doap:* element for person
          String role = getNullSafeStringValue(row, 3);
          if (role.equals("Programme Stream Manager") || role.equals("Programme Strand Manager") || role.equals("Programme Manager")) {
            elem = doc.createElementNS(Doap.getURI(), "helper");
            elem.appendChild(person);
          } else if (role.equals("Project Director") || role.equals("Project Manager")) {
            elem = doc.createElementNS(Doap.getURI(), "maintainer");
            elem.appendChild(person);
          } else if (role.equals("Project Team Member")) {
            elem = doc.createElementNS(Doap.getURI(), "developer");
            elem.appendChild(person);
          } else {
            logger.warn("Got a person (" + name + ") with an unkown role, adding as helper: " + role);
          }
          project.appendChild(elem);
         
          doc.getDocumentElement().appendChild(project);
          serialise(doc);

          try {
            SimalRepositoryFactory.getProjectService().createProject(doc);
          } catch (SimalRepositoryException e) {
            errorReports.append("Error when importing person named '" + name + "': ");
            errorReports.append(e.getMessage());
            errorReports.append(NEW_LINE);
            errorsOccurred ++;
            if (errorsOccurred > MAX_IMPORT_ERRORS) {
              throw new SimalException ("Too many errors (" + MAX_IMPORT_ERRORS + ")" + NEW_LINE + errorReports.toString());
            }
          }
        }
        if(errorsOccurred > 0 ) {
          throw new SimalException("Import resulted in " + errorsOccurred + " errors:" + NEW_LINE + errorReports.toString());
        }

  }
View Full Code Here

    try {
      repo = create(uri, type);
    } catch (DuplicateURIException e) {
      String msg = "Generated URI unexpectedly duplicate : " + uri;
      LOGGER.warn(msg);
      throw new SimalException(msg, e);
    } catch (InvalidURIException e) {
      String msg = "Generated URI unexpectedly invalid : " + uri;
      LOGGER.warn(msg);
      throw new SimalException(msg, e);
    }
    return repo;
  }
View Full Code Here

  public Document getLatestPingsAsRDF() throws SimalException {
    URL url;
    try {
      url = new URL("http://pingthesemanticweb.com/export/");
    } catch (MalformedURLException e) {
      throw new SimalException(
          "The PTSW URL is malformed, how can that happen since it is hard coded?",
          e);
    }
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = null;

    DocumentBuilder db;
    try {
      db = dbf.newDocumentBuilder();
      doc = db.parse(url.openStream());
    } catch (Exception e) {
      throw new SimalException("Unable to retrive the PTSW export file", e);
    }

    return getPingsAsRDF(doc);
  }
View Full Code Here

    HashSet<URI> uris = new HashSet<URI>();
    Element root = export.getDocumentElement();
   
    NodeList errors = root.getElementsByTagName("error");
    if (errors.getLength() > 0) {
      throw new SimalException("Unable to communicate with PTSW: " + errors.item(0).getTextContent());
    }
   
    NodeList pings = root.getElementsByTagName("rdfdocument");
    for (int i = 0; i < pings.getLength(); i++) {
      Element ping = (Element) pings.item(i);
View Full Code Here

TOP

Related Classes of uk.ac.osswatch.simal.rdf.SimalException

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.