[Major] Implemented AuditQuery

This commit is contained in:
Robert von Burg 2014-08-28 21:45:03 +02:00
parent b8bfaf8408
commit 7cb7c2749c
7 changed files with 24 additions and 118 deletions

View File

@ -18,32 +18,31 @@ package li.strolch.model.audit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import ch.eitchnet.utils.collections.DateRange;
import ch.eitchnet.utils.dbc.DBC;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public class AuditQuery { public class AuditQuery {
private int maxResults; private String elementTypeSelection;
private List<AuditSelection> selections; private List<AuditSelection> selections;
private DateRange dateRange;
public AuditQuery() { public AuditQuery(String elementTypeSelection, DateRange dateRange) {
DBC.PRE.assertFalse("dateRange may not be unbounded!", dateRange.isUnbounded());
this.elementTypeSelection = elementTypeSelection;
this.dateRange = dateRange;
this.selections = new ArrayList<>(); this.selections = new ArrayList<>();
} }
/** public String getElementTypeSelection() {
* @return the maxResults return this.elementTypeSelection;
*/
public int getMaxResults() {
return this.maxResults;
} }
/** public DateRange getDateRange() {
* @param maxResults return this.dateRange;
* the maxResults to set
*/
public void setMaxResults(int maxResults) {
this.maxResults = maxResults;
} }
public ActionSelection action() { public ActionSelection action() {
@ -52,12 +51,6 @@ public class AuditQuery {
return selection; return selection;
} }
public DateRangeSelection dateRange() {
DateRangeSelection selection = new DateRangeSelection(this);
this.selections.add(selection);
return selection;
}
public ElementSelection element() { public ElementSelection element() {
ElementSelection selection = new ElementSelection(this); ElementSelection selection = new ElementSelection(this);
this.selections.add(selection); this.selections.add(selection);
@ -71,6 +64,8 @@ public class AuditQuery {
} }
public void accept(AuditQueryVisitor visitor) { public void accept(AuditQueryVisitor visitor) {
DBC.PRE.assertNotNull("No elementTypeSelection (navigation) set!", this.elementTypeSelection); //$NON-NLS-1$
DBC.PRE.assertNotNull("No dateRange set!", this.dateRange); //$NON-NLS-1$
visitor.visit(this); visitor.visit(this);
for (AuditSelection selection : selections) { for (AuditSelection selection : selections) {
selection.accept(visitor); selection.accept(visitor);

View File

@ -15,7 +15,6 @@
*/ */
package li.strolch.model.audit; package li.strolch.model.audit;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
@ -25,8 +24,6 @@ public interface AuditQueryVisitor {
public void visit(IdentitySelection selection); public void visit(IdentitySelection selection);
public void visit(DateRangeSelection selection);
public void visit(ActionSelection selection); public void visit(ActionSelection selection);
public void visit(AuditQuery auditQuery); public void visit(AuditQuery auditQuery);

View File

@ -1,74 +0,0 @@
/*
* 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.model.audit;
import java.util.Date;
import ch.eitchnet.utils.collections.DateRange;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateRangeSelection extends AuditSelection {
private DateRange dateRange;
public DateRangeSelection(AuditQuery query) {
super(query);
this.dateRange = new DateRange();
}
public DateRange from(Date from, boolean inclusive) {
return this.dateRange.from(from, inclusive);
}
public DateRange to(Date to, boolean inclusive) {
return this.dateRange.to(to, inclusive);
}
public Date getFromDate() {
return this.dateRange.getFromDate();
}
public Date getToDate() {
return this.dateRange.getToDate();
}
public boolean isFromBounded() {
return this.dateRange.isFromBounded();
}
public boolean isToBounded() {
return this.dateRange.isToBounded();
}
public boolean isUnbounded() {
return this.dateRange.isUnbounded();
}
public boolean isBounded() {
return this.dateRange.isBounded();
}
public boolean contains(Date date) {
return this.dateRange.contains(date);
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -23,18 +23,12 @@ import ch.eitchnet.utils.StringMatchMode;
*/ */
public class ElementSelection extends AuditSelection { public class ElementSelection extends AuditSelection {
private StringSelection elementTypeSelection;
private StringSelection elementAccessedSelection; private StringSelection elementAccessedSelection;
public ElementSelection(AuditQuery query) { public ElementSelection(AuditQuery query) {
super(query); super(query);
} }
public ElementSelection elementTypes(StringMatchMode matchMode, String... elementTypes) {
this.elementTypeSelection = new StringSelection(matchMode, elementTypes);
return this;
}
public ElementSelection elementsAccessed(StringMatchMode matchMode, String... elementsAccessed) { public ElementSelection elementsAccessed(StringMatchMode matchMode, String... elementsAccessed) {
this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed); this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed);
return this; return this;
@ -44,22 +38,10 @@ public class ElementSelection extends AuditSelection {
return this.elementAccessedSelection; return this.elementAccessedSelection;
} }
public StringSelection getElementTypeSelection() {
return this.elementTypeSelection;
}
public boolean isElementTypesWildcard() {
return this.elementTypeSelection == null || this.elementTypeSelection.isWildCard();
}
public boolean isElementsAccessedWildcard() { public boolean isElementsAccessedWildcard() {
return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard(); return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard();
} }
public boolean isWildcard() {
return this.isElementsAccessedWildcard() && this.isElementTypesWildcard();
}
@Override @Override
public void accept(AuditQueryVisitor visitor) { public void accept(AuditQueryVisitor visitor) {
visitor.visit(this); visitor.visit(this);

View File

@ -17,10 +17,8 @@ package li.strolch.model.query;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*
*/ */
public interface Navigation { public interface Navigation {
// marker interface
public void accept(QueryVisitor visitor); public void accept(QueryVisitor visitor);
} }

View File

@ -21,6 +21,6 @@ package li.strolch.model.query;
public interface Selection { public interface Selection {
public void accept(QueryVisitor visitor); public void accept(QueryVisitor visitor);
public boolean hasSelection(); public boolean hasSelection();
} }

View File

@ -74,4 +74,12 @@ public class StringSelection {
public boolean isWildCard() { public boolean isWildCard() {
return this.values == null || this.values.length == 0; return this.values == null || this.values.length == 0;
} }
public boolean matches(String value) {
for (String sel : values) {
if (this.matchMode.matches(value, sel))
return true;
}
return false;
}
} }