private void findAnnotations()

in taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/combine/CombineManifest.java [343:451]


	private void findAnnotations() throws IOException {
		Path metadataRdf = null;
		for (PathMetadata agg : manifest.getAggregates())
			if (OMEX_METADATA.equals(agg.getConformsTo())) {
				metadataRdf = agg.getFile();
				break; // TODO: Support not just the first one
				// TODO: support external metadata with agg.getUri() ?
			}
		if (metadataRdf == null)
			// fallback to hard-coded filename
			metadataRdf = bundle.getRoot().resolve("metadata.rdf");
		if (!exists(metadataRdf))
			return;

		Model metadata;
		try {
			metadata = parseRDF(metadataRdf);
		} catch (IOException e) {
			logger.log(WARNING, "Can't read " + metadataRdf, e);
			return;
		} catch (RiotException e) {
			logger.log(WARNING, "Can't parse " + metadataRdf, e);
			return;
		}

		Set<Pair<URI,URI>> foundAnnotations = new HashSet<>();
		for (URI subject : bundleSubjects()) {
			Resource resource = metadata.getResource(fakeFileURI(subject));
			if (!metadata.containsResource(resource)) {
				// No metadata about that resource, probably OK, but
				// could be an absolute/relative path issue
				logger.info("No metadata.rdf triples found about " + resource);
				continue;
			}

			URI about = manifest.relativeToBundleRoot(subject);
			URI content = manifest.relativeToBundleRoot(metadataRdf.toUri());
			if (! foundAnnotations.add(Pair.of(about, content))) {
				// Avoid duplication
				PathAnnotation ann = new PathAnnotation();
				ann.setAbout(subject);
				ann.setContent(content);
				manifest.getAnnotations().add(ann);
			}

			// Extract information that could be in our manifest
			PathMetadata pathMetadata = manifest.getAggregation(subject);

			// Created date. We'll prefer dcModified.
			Property dcCreated = metadata
					.getProperty("http://purl.org/dc/terms/created");
			Property dcModified = metadata
					.getProperty("http://purl.org/dc/terms/modified");
			Statement createdSt = resource.getProperty(dcModified);
			if (createdSt == null)
				createdSt = resource.getProperty(dcCreated);
			if (createdSt != null) {
				FileTime fileTime = literalAsFileTime(createdSt.getObject());
				if (fileTime != null) {
					pathMetadata.setCreatedOn(fileTime);
					if (pathMetadata.getFile() != null)
						setLastModifiedTime(pathMetadata.getFile(),
								fileTime);
				}
			}

			// add the COMBINE "creators" as RO "authors"
			List<Agent> authors = pathMetadata.getAuthoredBy ();

			for (RDFNode s : creatingAgentsFor(resource)) {
				if (authors == null)
				{
					authors = new ArrayList<Agent> ();
					pathMetadata.setAuthoredBy (authors);
				}

				if (s.isLiteral()) {
					authors.add (new Agent(s.asLiteral()
							.getLexicalForm()));
					continue;
				}
				Resource agentResource = s.asResource();
				Agent agent = new Agent();
				if (agentResource.isURIResource()) {
					URI agentUri = URI.create(agentResource.getURI());
					if (agentResource.getURI().startsWith("http://orcid.org/"))
						agent.setOrcid(agentUri);
					else
						agent.setUri(agentUri);
				} else {
					Resource mbox = mboxForAgent(agentResource);
					if (mbox != null && mbox.isURIResource())
						agent.setUri(URI.create(mbox.getURI()));
				}
				agent.setName(nameForAgent(agentResource));
				authors.add (agent);
			}
			// if there is a single COMBINE "creator" it is also the RO "creator"
			if (authors != null && authors.size () == 1)
				pathMetadata.setCreatedBy (authors.get (0));

			if (pathMetadata.getFile().equals(bundle.getRoot())
					|| pathMetadata.getFile().equals(metadataRdf)) {
				// Statements where about the RO itself
				manifest.setCreatedOn(pathMetadata.getCreatedOn());
				manifest.setCreatedBy(pathMetadata.getCreatedBy());
			}
		}
	}