@@ -0,0 +1,3004 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.trellisldp.spi;%0A%0Aimport static java.time.Instant.now;%0Aimport static java.util.Arrays.asList;%0Aimport static org.trellisldp.vocabulary.RDF.type;%0Aimport static org.trellisldp.vocabulary.Trellis.PreferAudit;%0A%0Aimport java.util.ServiceLoader;%0Aimport java.util.List;%0A%0Aimport org.apache.commons.rdf.api.BlankNodeOrIRI;%0Aimport org.apache.commons.rdf.api.Dataset;%0Aimport org.apache.commons.rdf.api.IRI;%0Aimport org.apache.commons.rdf.api.RDF;%0A%0Aimport org.trellisldp.vocabulary.AS;%0Aimport org.trellisldp.vocabulary.PROV;%0Aimport org.trellisldp.vocabulary.XSD;%0A%0A/**%0A * The Audit Event class provides methods for adding audit-related quads%0A * to datasets.%0A *%0A * @author acoburn%0A */%0Apublic class AuditData %7B%0A%0A    private static RDF rdf = ServiceLoader.load(RDF.class).iterator().next();%0A%0A    /**%0A     * Create audit-related creation data%0A     * @param subject the subject%0A     * @param session the session%0A     * @return the quads%0A     */%0A    public Dataset creationData(final BlankNodeOrIRI subject, final Session session) %7B%0A        return genData(subject, session, asList(PROV.Activity, AS.Create));%0A    %7D%0A%0A    /**%0A     * Create audit-related deletion data%0A     * @param subject the subject%0A     * @param session the session%0A     * @return the quads%0A     */%0A    public Dataset deletionData(final BlankNodeOrIRI subject, final Session session) %7B%0A        return genData(subject, session, asList(PROV.Activity, AS.Delete));%0A    %7D%0A%0A    /**%0A     * Create audit-related update data%0A     * @param subject the subject%0A     * @param session the session%0A     * @return the quads%0A     */%0A    public Dataset updateData(final BlankNodeOrIRI subject, final Session session) %7B%0A        return genData(subject, session, asList(PROV.Activity, AS.Update));%0A    %7D%0A%0A    private Dataset genData(final BlankNodeOrIRI subject, final Session session, final List%3CIRI%3E types) %7B%0A        final Dataset dataset = rdf.createDataset();%0A        types.forEach(t -%3E%0A            dataset.add(rdf.createQuad(PreferAudit, subject, type, t)));%0A        dataset.add(rdf.createQuad(PreferAudit, subject, PROV.wasAssociatedWith, session.getAgent()));%0A        dataset.add(rdf.createQuad(PreferAudit, subject, PROV.startedAtTime,%0A                    rdf.createLiteral(now().toString(), XSD.dateTime)));%0A        session.getDelegatedBy().ifPresent(delegate -%3E%0A                dataset.add(rdf.createQuad(PreferAudit, subject, PROV.actedOnBehalfOf, delegate)));%0A        return dataset;%0A    %7D%0A%7D%0A

Add audit data class