@Override
  protected Protocol convert(File directory) {
    Protocol protocol = new Protocol();
    protocol.setIdentifier(directory.getName());
    if (key != null) {}

    return protocol;
  }
예제 #2
0
  @Override
  public Resource objectToJena(Model toAddTo, Protocol protocol) throws IllegalArgumentException {

    if (protocol.getResourceURL() == null) {
      throw new IllegalArgumentException(String.format(msg_ResourceWithoutURI, "protocols"));
    }
    Resource res = toAddTo.createResource(protocol.getResourceURL().toString());
    toAddTo.add(res, RDF.type, TOXBANK.PROTOCOL);

    if (protocol.isSearchable() != null)
      res.addLiteral(TOXBANK.ISSUMMARYSEARCHABLE, protocol.isSearchable());

    res.addLiteral(TOXBANK.HASVERSIONINFO, protocol.getVersion());

    if (protocol.getTitle() != null) res.addLiteral(DCTerms.title, protocol.getTitle());

    if (protocol.getTimeModified() != null)
      res.addLiteral(DCTerms.modified, protocol.getTimeModified());

    if (protocol.getSubmissionDate() != null)
      res.addLiteral(DCTerms.dateSubmitted, protocol.getSubmissionDate());

    if (protocol.isPublished() != null) res.addLiteral(TOXBANK.ISPUBLISHED, protocol.isPublished());

    if (protocol.getStatus() != null)
      res.addLiteral(TOXBANK.HASSTATUS, protocol.getStatus().name());

    if (protocol.getIdentifier() != null)
      res.addLiteral(DCTerms.identifier, protocol.getIdentifier());

    if (protocol.getAbstract() != null)
      res.addLiteral(TOXBANK.HASABSTRACT, cleanLiteral(protocol.getAbstract()));

    List<String> keywords = protocol.getKeywords();
    if (keywords != null) {
      for (String keyword : keywords) res.addLiteral(TOXBANK.HASKEYWORD, keyword);
    }

    if (protocol.getProjects() != null)
      for (Project aproject : protocol.getProjects()) {
        if (aproject.getResourceURL() == null)
          throw new IllegalArgumentException(
              String.format(msg_InvalidURI, "project", res.getURI()));
        Resource project = projectIO.objectToJena(toAddTo, aproject);
        res.addProperty(TOXBANK.HASPROJECT, project);
      }

    if (protocol.getOrganisation() != null) {
      if (protocol.getOrganisation().getResourceURL() == null)
        throw new IllegalArgumentException(
            String.format(msg_InvalidURI, "organisation", res.getURI()));
      Resource org = organisationIO.objectToJena(toAddTo, protocol.getOrganisation());
      res.addProperty(TOXBANK.HASORGANISATION, org);
    }

    if (protocol.getOwner() != null) {
      if (protocol.getOwner().getResourceURL() == null)
        throw new IllegalArgumentException(
            String.format(msg_InvalidURI, "protocol owner", res.getURI()));

      Resource ownerRes = toAddTo.createResource(protocol.getOwner().getResourceURL().toString());
      res.addProperty(TOXBANK.HASOWNER, ownerRes);
    }
    ToxBankResourceSet<User> authors = protocol.getAuthors();
    if (authors != null)
      for (User author : authors) {
        if (author.getResourceURL() == null)
          throw new IllegalArgumentException(String.format(msg_InvalidURI, "author", res.getURI()));
        Resource user = userIO.objectToJena(toAddTo, author);
        res.addProperty(TOXBANK.HASAUTHOR, user);
      }

    if (protocol.getDocument() != null) {
      if (protocol.getDocument().getResourceURL() == null)
        throw new IllegalArgumentException(String.format(msg_InvalidURI, "document", res.getURI()));

      Resource documentRes =
          toAddTo.createResource(protocol.getDocument().getResourceURL().toString());
      res.addProperty(TOXBANK.HASDOCUMENT, documentRes);
    }

    if (protocol.getDataTemplate() != null) {
      if (protocol.getDataTemplate().getResourceURL() == null)
        throw new IllegalArgumentException(
            String.format(msg_InvalidURI, "data template", res.getURI()));

      Resource templateRes =
          toAddTo.createResource(protocol.getDataTemplate().getResourceURL().toString());
      res.addProperty(TOXBANK.HASTEMPLATE, templateRes);
    }
    if (protocol.getLicense() != null) {
      toAddTo.add(res, DCTerms.license, toAddTo.createResource(protocol.getLicense().toString()));
    }

    return res;
  }
예제 #3
0
  @Override
  public Protocol fromJena(Model source, Resource res) throws IllegalArgumentException {
    Protocol protocol = new Protocol();
    try {
      protocol.setResourceURL(new URL(res.getURI()));
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException(String.format(msg_InvalidURI, "protocol", res.getURI()));
    }
    try {
      protocol.setSearchable(res.getProperty(TOXBANK.ISSUMMARYSEARCHABLE).getBoolean());
    } catch (Exception x) {
      protocol.setSearchable(false);
    }
    try {
      protocol.setVersion(res.getProperty(TOXBANK.HASVERSIONINFO).getInt());
    } catch (Exception x) {
      protocol.setVersion(0);
    }
    try {
      protocol.setPublished(res.getProperty(TOXBANK.ISPUBLISHED).getBoolean());
    } catch (Exception x) {
      protocol.setPublished(null);
    }
    try {
      protocol.setTimeModified(res.getProperty(DCTerms.modified).getLong());
    } catch (Exception x) {
      protocol.setTimeModified(null);
    }
    try {
      protocol.setSubmissionDate(res.getProperty(DCTerms.dateSubmitted).getLong());
    } catch (Exception x) {
      protocol.setSubmissionDate(null);
    }
    if (res.getProperty(DCTerms.title) != null)
      protocol.setTitle(res.getProperty(DCTerms.title).getString());
    if (res.getProperty(TOXBANK.HASSTATUS) != null)
      try {
        protocol.setStatus(Protocol.STATUS.valueOf(res.getProperty(TOXBANK.HASSTATUS).getString()));
      } catch (Exception x) {
        protocol.setStatus(STATUS.RESEARCH);
      }
    if (res.getProperty(DCTerms.identifier) != null)
      protocol.setIdentifier(res.getProperty(DCTerms.identifier).getString());
    if (res.getProperty(TOXBANK.HASABSTRACT) != null)
      protocol.setAbstract(res.getProperty(TOXBANK.HASABSTRACT).getString());
    StmtIterator keywords = res.listProperties(TOXBANK.HASKEYWORD);
    while (keywords.hasNext()) {
      protocol.addKeyword(keywords.next().getString());
    }

    String uri = null;
    StmtIterator authors = res.listProperties(TOXBANK.HASAUTHOR);
    while (authors.hasNext()) {
      Resource authorRes = authors.next().getResource();
      User author = userIO.fromJena(source, authorRes);
      protocol.addAuthor(author);
    }
    authors.close();

    StmtIterator projects = res.listProperties(TOXBANK.HASPROJECT);
    while (projects.hasNext()) {
      Resource projectRes = projects.next().getResource();
      Project project = projectIO.fromJena(source, projectRes);
      protocol.addProject(project);
    }
    projects.close();

    if (res.getProperty(TOXBANK.HASORGANISATION) != null) {
      Organisation org =
          organisationIO.fromJena(source, res.getProperty(TOXBANK.HASORGANISATION).getResource());
      protocol.setOrganisation(org);
    }

    if (res.getProperty(TOXBANK.HASOWNER) != null)
      try {
        uri = res.getProperty(TOXBANK.HASOWNER).getResource().getURI();
        User author = new User();

        author.setResourceURL(new URL(uri));
        protocol.setOwner(author);
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format(msg_InvalidURI, "a protocol owner", uri));
      }

    if (res.getProperty(TOXBANK.HASDOCUMENT) != null)
      try {
        uri = res.getProperty(TOXBANK.HASDOCUMENT).getResource().getURI();
        Document document = new Document(new URL(uri));

        protocol.setDocument(document);
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format(msg_InvalidURI, "a document", uri));
      }

    if (res.getProperty(TOXBANK.HASTEMPLATE) != null)
      try {
        uri = res.getProperty(TOXBANK.HASTEMPLATE).getResource().getURI();
        Template dataTemplate = new Template(new URL(uri));

        protocol.setDataTemplate(dataTemplate);
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format(msg_InvalidURI, "data template", uri));
      }
    if (res.getProperty(DCTerms.license) != null)
      try {
        protocol.setLicense(new URL(res.getProperty(DCTerms.license).getObject().toString()));
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException(
            String.format(
                msg_InvalidURI, "a license", res.getProperty(DCTerms.license).getObject()));
      }
    return protocol;
  }