Skip to content

Method: afterPropertiesSet()

1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.mediascanner.impl;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import java.util.ArrayList;
32: import java.util.List;
33: import org.eclipse.rdf4j.model.IRI;
34: import org.eclipse.rdf4j.model.Model;
35: import org.eclipse.rdf4j.model.Resource;
36: import org.eclipse.rdf4j.model.Statement;
37: import org.eclipse.rdf4j.model.Value;
38: import org.eclipse.rdf4j.repository.RepositoryException;
39: import it.tidalwave.util.annotation.VisibleForTesting;
40: import it.tidalwave.messagebus.MessageBus;
41: import it.tidalwave.messagebus.annotation.ListensTo;
42: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
43: import it.tidalwave.bluemarine2.persistence.Persistence;
44: import lombok.extern.slf4j.Slf4j;
45: import static it.tidalwave.util.FunctionalCheckedExceptionWrappers.*;
46:
47: /***********************************************************************************************************************
48: *
49: * @author Fabrizio Giudici
50: *
51: **********************************************************************************************************************/
52: @SimpleMessageSubscriber @Slf4j
53: public class StatementManager
54: {
55: @Inject
56: private MessageBus messageBus;
57:
58: @Inject
59: private Persistence persistence;
60:
61: @Inject
62: private ProgressHandler progress;
63:
64: /*******************************************************************************************************************
65: *
66: *
67: ******************************************************************************************************************/
68: public void requestAdd (@Nonnull final Resource subject, @Nonnull final IRI predicate, @Nonnull final Value literal)
69: {
70: requestAdd(new AddStatementsRequest(subject, predicate, literal));
71: }
72:
73: /*******************************************************************************************************************
74: *
75: *
76: ******************************************************************************************************************/
77: public void requestAdd (@Nonnull final List<Statement> statements)
78: {
79: requestAdd(new AddStatementsRequest(statements));
80: }
81:
82: /*******************************************************************************************************************
83: *
84: *
85: ******************************************************************************************************************/
86: public void requestAdd (@Nonnull final Model model)
87: {
88: requestAdd(new AddStatementsRequest(new ArrayList<>(model)));
89: }
90:
91: /*******************************************************************************************************************
92: *
93: *
94: ******************************************************************************************************************/
95: public void requestAdd (@Nonnull final AddStatementsRequest request)
96: {
97: progress.incrementTotalInsertions();
98: messageBus.publish(request);
99: }
100:
101: /*******************************************************************************************************************
102: *
103: *
104: ******************************************************************************************************************/
105: @VisibleForTesting void onAddStatementsRequest (@ListensTo @Nonnull final AddStatementsRequest request)
106: throws RepositoryException
107: {
108: log.info("onAddStatementsRequest({})", request);
109: progress.incrementCompletedInsertions();
110: persistence.runInTransaction(connection -> request.getStatements().forEach(_c(connection::add)));
111: }
112: }