001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.impl.services; 019 020import org.apache.jena.graph.Node; 021import org.apache.jena.graph.Triple; 022import org.fcrepo.kernel.api.ContainmentIndex; 023import org.fcrepo.kernel.api.Transaction; 024import org.fcrepo.kernel.api.models.FedoraResource; 025import org.fcrepo.kernel.api.services.ContainmentTriplesService; 026import org.springframework.beans.factory.annotation.Autowired; 027import org.springframework.beans.factory.annotation.Qualifier; 028import org.springframework.stereotype.Component; 029 030import java.util.stream.Stream; 031 032import static org.apache.jena.graph.NodeFactory.createURI; 033import static org.fcrepo.kernel.api.RdfLexicon.CONTAINS; 034 035/** 036 * Containment Triples service. 037 * @author whikloj 038 * @since 6.0.0 039 */ 040@Component 041public class ContainmentTriplesServiceImpl implements ContainmentTriplesService { 042 043 @Autowired 044 @Qualifier("containmentIndex") 045 private ContainmentIndex containmentIndex; 046 047 @Override 048 public Stream<Triple> get(final Transaction tx, final FedoraResource resource) { 049 final var fedoraId = resource.getFedoraId(); 050 final var nodeUri = fedoraId.isMemento() ? fedoraId.getBaseId() : fedoraId.getFullId(); 051 final Node currentNode = createURI(nodeUri); 052 return containmentIndex.getContains(tx, fedoraId).map(c -> 053 new Triple(currentNode, CONTAINS.asNode(), createURI(c))); 054 } 055 056}