001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.kernel.impl.services;
007
008import org.fcrepo.kernel.api.Transaction;
009import org.fcrepo.kernel.api.TransactionManager;
010import org.fcrepo.kernel.api.identifiers.FedoraId;
011import org.fcrepo.kernel.api.operations.ReindexResourceOperationFactory;
012import org.fcrepo.kernel.api.services.ReindexService;
013import org.fcrepo.persistence.api.PersistentStorageSessionManager;
014import org.springframework.stereotype.Component;
015
016import javax.inject.Inject;
017
018/**
019 * Implementation of {@link org.fcrepo.kernel.api.services.ReindexService}
020 *
021 * @author dbernstein
022 */
023@Component
024public class ReindexServiceImpl extends AbstractService implements ReindexService {
025
026    @Inject
027    private TransactionManager transactionManager;
028
029    @Inject
030    private PersistentStorageSessionManager persistentStorageSessionManager;
031
032    @Inject
033    private ReindexResourceOperationFactory resourceOperationFactory;
034
035    @Override
036    public void reindexByFedoraId(final Transaction transaction, final String principal, final FedoraId fedoraId) {
037        final var tx = transactionManager.get(transaction.getId());
038        final var psession = persistentStorageSessionManager.getSession(transaction);
039        final var operation = resourceOperationFactory.create(transaction, fedoraId)
040                .userPrincipal(principal).build();
041        tx.lockResource(fedoraId);
042
043        psession.persist(operation);
044    }
045}