[Minor] Added doc to Auditing*MapFacades and impl. query auditing

This commit is contained in:
Robert von Burg 2015-04-22 12:06:20 +02:00
parent 47881df2ee
commit 64c6a01083
4 changed files with 104 additions and 91 deletions

View File

@ -1,23 +1,17 @@
/*
* Copyright (c) 2012, Robert von Burg
*
* All rights reserved.
*
* This file is part of the XXX.
*
* XXX is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* XXX is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XXX. If not, see
* <http://www.gnu.org/licenses/>.
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.agent.impl;
@ -37,6 +31,16 @@ import ch.eitchnet.utils.collections.DateRange;
import ch.eitchnet.utils.dbc.DBC;
/**
* <p>
* This {@link AuditTrail} facade registers all actions performed i.e. it registers which {@link Audit Audits} are
* retrieved, created, updated and deleted.
* </p>
*
* <p>
* In a single transaction an Audit may be created, updated and then deleted - this implementation does not "squash"
* such actions, but registers them separately
* </p>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditingAuditMapFacade implements AuditTrail {
@ -201,14 +205,16 @@ public class AuditingAuditMapFacade implements AuditTrail {
@Override
public List<Audit> doQuery(StrolchTransaction tx, AuditQuery query) {
List<Audit> elements = this.auditTrail.doQuery(tx, query, new NoStrategyAuditVisitor());
// TODO decide how to audit these queried elements
this.read.addAll(elements);
return elements;
}
@Override
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery query, AuditVisitor<U> auditVisitor) {
List<U> elements = this.auditTrail.doQuery(tx, query, auditVisitor);
// TODO decide how to audit these queried elements
List<U> elements = this.auditTrail.doQuery(tx, query, audit -> {
this.read.add(audit);
return auditVisitor.visitAudit(audit);
});
return elements;
}
}

View File

@ -1,23 +1,17 @@
/*
* Copyright (c) 2012, Robert von Burg
*
* All rights reserved.
*
* This file is part of the XXX.
*
* XXX is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* XXX is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XXX. If not, see
* <http://www.gnu.org/licenses/>.
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.agent.impl;
@ -27,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import li.strolch.agent.api.AuditTrail;
import li.strolch.agent.api.ElementMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchRootElement;
@ -36,20 +31,30 @@ import li.strolch.persistence.api.StrolchTransaction;
import ch.eitchnet.utils.dbc.DBC;
/**
* <p>
* This {@link AuditTrail} facade registers all actions performed i.e. it registers which {@link StrolchRootElement
* StrolchRootElements} are retrieved, created, updated and deleted.
* </p>
*
* <p>
* In a single transaction an StrolchRootElement may be created, updated and then deleted - this implementation does not
* "squash" such actions, but registers them separately
* </p>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditingElementMapFacade<T extends StrolchRootElement> implements ElementMap<T> {
private ElementMap<T> elementMap;
protected ElementMap<T> elementMap;
private Set<T> read;
private Set<T> created;
private Set<T> updated;
private Set<T> deleted;
private long deletedAll;
private Map<String, Long> deletedAllByType;
protected Set<T> read;
protected Set<T> created;
protected Set<T> updated;
protected Set<T> deleted;
protected long deletedAll;
protected Map<String, Long> deletedAllByType;
private boolean observeAccessReads;
protected boolean observeAccessReads;
public AuditingElementMapFacade(ElementMap<T> elementMap, boolean observeAccessReads) {
DBC.PRE.assertNotNull("ElementMap must be set!", elementMap); //$NON-NLS-1$

View File

@ -1,28 +1,23 @@
/*
* Copyright (c) 2012, Robert von Burg
*
* All rights reserved.
*
* This file is part of the XXX.
*
* XXX is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* XXX is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XXX. If not, see
* <http://www.gnu.org/licenses/>.
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.agent.impl;
import java.util.List;
import li.strolch.agent.api.AuditTrail;
import li.strolch.agent.api.ElementMap;
import li.strolch.agent.api.OrderMap;
import li.strolch.model.Order;
@ -31,7 +26,11 @@ import li.strolch.model.query.OrderQuery;
import li.strolch.persistence.api.StrolchTransaction;
/**
* This is the {@link AuditTrail} for {@link Order Orders}
*
* @author Robert von Burg <eitch@eitchnet.ch>
*
* @see AuditingElementMapFacade
*/
public class AuditingOrderMap extends AuditingElementMapFacade<Order> implements OrderMap {
@ -49,8 +48,10 @@ public class AuditingOrderMap extends AuditingElementMapFacade<Order> implements
@Override
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery query, OrderVisitor<U> orderVisitor) {
List<U> result = getElementMap().doQuery(tx, query, orderVisitor);
// TODO decide how to audit these queried elements
List<U> result = getElementMap().doQuery(tx, query, order -> {
this.read.add(order);
return orderVisitor.visit(order);
});
return result;
}
}

View File

@ -1,28 +1,23 @@
/*
* Copyright (c) 2012, Robert von Burg
*
* All rights reserved.
*
* This file is part of the XXX.
*
* XXX is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* XXX is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XXX. If not, see
* <http://www.gnu.org/licenses/>.
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.agent.impl;
import java.util.List;
import li.strolch.agent.api.AuditTrail;
import li.strolch.agent.api.ElementMap;
import li.strolch.agent.api.ResourceMap;
import li.strolch.model.Resource;
@ -31,7 +26,11 @@ import li.strolch.model.query.ResourceQuery;
import li.strolch.persistence.api.StrolchTransaction;
/**
* This is the {@link AuditTrail} for {@link Resource Resources}
*
* @author Robert von Burg <eitch@eitchnet.ch>
*
* @see AuditingElementMapFacade
*/
public class AuditingResourceMap extends AuditingElementMapFacade<Resource> implements ResourceMap {
@ -49,8 +48,10 @@ public class AuditingResourceMap extends AuditingElementMapFacade<Resource> impl
@Override
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery query, ResourceVisitor<U> resourceVisitor) {
List<U> result = getElementMap().doQuery(tx, query, resourceVisitor);
// TODO decide how to audit these queried elements
List<U> result = getElementMap().doQuery(tx, query, resource -> {
this.read.add(resource);
return resourceVisitor.visit(resource);
});
return result;
}
}